> ## Documentation Index
> Fetch the complete documentation index at: https://auth0.com/llms.txt
> Use this file to discover all available pages before exploring further.

# FGAでMCPツールへのアクセスを制御する

> Auth0 FGAを使用して、ロール、グループ、時間制限付きアクセスに基づくきめ細かな認可をMCPサーバーのツールに実装する方法を説明します。

きめ細かな認可 (Fine-grained authorization) は、ユーザー、ロール、グループ、リソース間の関係に基づく高度な権限モデルを実現し、単純なスコープベースのアクセス制御よりも柔軟な制御を可能にします。このクイックスタートでは、[Auth0 FGA](https://auth0.com/fine-grained-authorization)を使用して、MCPサーバーのツールに[関係ベースのアクセス制御 (ReBAC) ](https://docs.fga.dev/authorization-concepts#what-is-relationship-based-access-control)を実装する方法を説明します。

サンプルアプリケーションでは、次の5つの認可パターンを紹介します。

1. **パブリックツール** - 追加の権限がなくても、認証済みのすべてのユーザーがアクセス可能
2. **ロールベースのアクセス** - 特定のロール (`admin`、`content_editor`) に割り当てられたツール
3. **グループメンバーシップ** - ユーザーはグループ (managers、marketing) への所属を通じて権限を継承
4. **時間制限付きアクセス** - 期限が来ると自動的に失効する、期間限定のツールアクセス
5. **リソース固有の権限** - ツール機能に対するきめ細かな制御 (例：非公開ドキュメントの閲覧)

このクイックスタートを完了すると、次の機能を備えたMCPサーバーが完成します。

* Auth0 OAuth 2.0でユーザーを認証する
* Auth0 FGAを使用して、各ユーザーがアクセスできるツールを判定する
* ユーザーの権限に応じてツール一覧を動的に絞り込む
* 自動的に失効する期間限定のアクセス権の付与をサポートする
* ユーザーのロールに応じて異なるデータ (公開ドキュメントと非公開ドキュメント) を提供する

## Prerequisites

> **1. Create or log in to your Auth0 account**
>
> To continue with this quickstart, you need to have an [Auth0 account](https://auth0.com/signup).

> **2. Enable the Resource Parameter Compatibility Profile and Include Issuer in Authorization Responses**
>
> To use the `resource` parameter in your access tokens and the `iss` claim to identify your authorization server, you need to enable two toggles in the [Auth0 Dashboard](https://manage.auth0.com/dashboard/):
>
> 1. Navigate to **Settings** on the left sidebar.
> 2. Select [**Advanced**](https://manage.auth0.com/dashboard/#/tenant/advanced) in the top right corner.
> 3. Scroll down to the **Settings** section and enable the following toggles:
>    * **Resource Parameter Compatibility Profile**: Enables support for the `resource` parameter in authorization requests, allowing access tokens to be scoped to a specific API.
>    * **Include Issuer in Authorization Responses**: Includes the `iss` parameter identifying the authorization server in authorization responses, helping clients defend against mix-up attacks.

> **3. Install the Auth0 CLI**
>
> This guide uses [Auth0 CLI](https://auth0.github.io/auth0-cli/) to configure an Auth0 tenant for secure MCP tool access.
>
> 1. Follow the [Auth0 CLI installation instructions](https://auth0.github.io/auth0-cli/).
> 2. Log in to your account with the Auth0 CLI:
>
> ```shell wrap lines theme={null}
> auth0 login --scopes "read:client_grants,create:client_grants,delete:client_grants,read:clients,create:clients,update:clients,read:resource_servers,create:resource_servers,update:resource_servers,read:roles,create:roles,update:roles,update:tenant_settings,read:connections,update:connections"
> ```
>
> Confirm you are in the correct tenant by double-checking the tenant domain in the terminal, or run the command below:
>
> ```shell theme={null}
> auth0 tenants list
> ```
>
> If more than one tenant is configured, the default tenant will be indicated by an arrow.

> **4. Install jq**
>
> To simplify the process of interacting with the Auth0 CLI, we recommend installing [jq](https://jqlang.org/download/). This will allow you to easily parse JSON responses from the CLI.
>
> **macOS**
>
> brew install jq
>
> **Linux**
>
> sudo apt-get install jq
>
> **Windows**
>
> choco install jq

次に、FGAに必要な依存関係をインストールしてセットアップします。

> **1. FGA CLIをインストールする**
>
> This guide uses the [OpenFGA CLI](https://github.com/openfga/cli?tab=readme-ov-file#installation) to manage authorization models and permissions.
>
> 1. Install the FGA CLI:
>
> **macOS**
>
> ```shell theme={null}
> brew install openfga/tap/fga
> ```
>
> **Linux**
>
> Download the latest release from the [OpenFGA CLI releases page](https://github.com/openfga/cli/releases) and add it to your PATH.
>
> ```shell theme={null}
> # Example for Linux (replace version with latest)
> wget https://github.com/openfga/cli/releases/download/v0.6.3/fga_0.6.3_linux_amd64.tar.gz
> tar -xzf fga_0.6.3_linux_amd64.tar.gz
> sudo mv fga /usr/local/bin/
> ```
>
> **Windows**
>
> Download the latest release from the [OpenFGA CLI releases page](https://github.com/openfga/cli/releases) and add it to your PATH.
>
> 2. Verify the installation:
>
> ```shell theme={null}
> fga version
> ```

> **2. Auth0 FGAまたはOpenFGAをセットアップする**
>
> You'll need an Auth0 FGA or OpenFGA store to manage fine-grained authorization for your MCP tools.
>
> **Choose your FGA provider:**
>
> * **Auth0 FGA**: Fully managed service at [fga.dev](https://fga.dev). Best for production use.
>
> * **OpenFGA**: Self-hosted open-source option. Best for local development and testing.
>
> > [!NOTE]
> >
> > Both options use the same authorization model and API. You can start with OpenFGA locally and migrate to Auth0 FGA for production.
>
> The sample application includes a complete authorization model (`fga/model.fga`) and initial permission tuples (`fga/tuples.yaml`) that will be imported using the FGA CLI.

## テナント設定を構成する

> **1. Promote the connection to a domain-level connection**
>
> To allow third-party clients like MCP Inspector to use a connection such as a username-and-password database or a social connection, you need to promote the connection to a domain-level connection. [Learn more about configuring third-party applications](https://auth0.com/docs/get-started/applications/third-party-applications/configure-third-party-applications.md).
>
> **1. List Your Connection**
>
> List your connections to get their IDs
>
> ```shell theme={null}
> auth0 api get connections
> ```
>
> **2. Choose Your Connections**
>
> From the list, identify which connections you want to use for the MCP server and copy the ID.
>
> * For the username-and-password database, look for the connection with the strategy `auth0`.
> * For the Google social connection, look for the connection with the strategy `google-oauth2`.
>
> **3. Upgrade the Connection to Domain-Level**
>
> For each of those specific connection IDs, run the following command to mark it as a domain-level connection. Replace `YOUR_CONNECTION_ID` with the actual ID (e.g., `con_XXXXXXXXXXXXXXXX`).
>
> ```shell wrap lines theme={null}
> auth0 api patch connections/YOUR_CONNECTION_ID --data '{"is_domain_connection": true}'
> ```

## MCPサーバーを表すAPIを作成する

An MCP server is treated just like any other [API](https://auth0.com/docs/get-started/apis.md) in your Auth0 tenant, which means you can use the same access control, scoping, and authorization features. The API (also known as a Resource Server) represents your protected MCP Server.

Run the following command to [create an API](https://auth0.com/docs/get-started/auth0-overview/set-up-apis.md) in Auth0:

```shell wrap lines theme={null}
auth0 api post resource-servers --data '{
  "identifier": "http://localhost:3001/",
  "name": "MCP Tools API",
  "signing_alg": "RS256",
  "token_dialect": "rfc9068_profile_authz",
  "enforce_policies": true,
  "scopes": [
    {"value": "tool:whoami", "description": "Access the WhoAmI tool"},
    {"value": "tool:greet", "description": "Access the Greeting tool"}
  ]
}'
```

Note that `rfc9068_profile_authz` is used as the [token dialect](https://auth0.com/docs/get-started/apis/enable-role-based-access-control-for-apis.md#token-dialect-options) to include the `permissions` claim in the access token, which can be useful for the API to check user permissions without making additional calls.

For more details on protecting APIs with Auth0, check our [quickstarts](https://auth0.com/docs/quickstarts.md#backend%2Fapi).

> [!NOTE]
>
> このクイックスタートでは、デモ用に`tool:greet`と`tool:whoami`の2つのOAuthスコープを使用します。`get_datetime`ツールはパブリックなためスコープは不要です。一方、`get_documents`はFGAを使って認可を行います。

## FGA ストアをセットアップする

**Auth0 FGA**

**1. Create an Auth0 FGA account**

Sign up for a free account at [fga.dev](https://fga.dev).

**2. Create a store**

In the [Auth0 FGA dashboard](https://dashboard.fga.dev/), create a new store for your MCP server.

**3. Generate API credentials**

1. Navigate to **Settings** in your store.
2. In the **Authorized Clients** section, click **+ Create Client**.
3. Give your client a name and select the following permissions:
   * **Read/Write model, changes, and assertions** - To query authorization decisions
   * **Write and delete tuples** - To import tuples (user permissions)
   * **Read and query** - To import the authorization model
4. Click **Create**.
5. Save the credentials shown in the confirmation modal.

**4. Configure environment variables**

Set the following environment variables in your terminal. These will be used by the FGA CLI to connect to your store.

```shell wrap lines theme={null}
export FGA_API_URL='https://api.us1.fga.dev'
export FGA_STORE_ID='<your-store-id>'
export FGA_API_TOKEN_ISSUER='auth.fga.dev'
export FGA_API_AUDIENCE='https://api.us1.fga.dev/'
export FGA_CLIENT_ID='<your-client-id>'
export FGA_CLIENT_SECRET='<your-client-secret>'
```

Replace the placeholders with the credentials from the previous step. Note that `FGA_API_URL` may vary based on your region (e.g., `api.eu1.fga.dev` for Europe).

**OpenFGA (Local)**

**1. Install OpenFGA**

Install OpenFGA using Homebrew or Docker:

**Homebrew**

```shell theme={null}
brew install openfga
```

**Docker**

Docker installation will be used in the next step to run the server.

For other installation methods, see the [OpenFGA releases page](https://github.com/openfga/openfga/releases).

**2. Start OpenFGA**

Start the OpenFGA server:

**Homebrew**

```shell theme={null}
openfga run
```

**Docker**

```shell theme={null}
docker run -p 8080:8080 -p 8081:8081 -p 3000:3000 openfga/openfga run
```

The server will start on port 8080 by default. Leave this running in a separate terminal window.

**3. Configure environment variables**

Set the following environment variables in your terminal (in a different terminal from where OpenFGA is running):

```shell theme={null}
export FGA_API_URL='http://localhost:8080'
```

> [!NOTE]
>
> The `FGA_STORE_ID` will be set after importing the model in the next section.

## サンプルアプリ

まず、このクイックスタート用のサンプルアプリをダウンロードまたはクローンしてください。このサンプルには、Auth0 OAuthとAuth0 FGAを統合した、JavaScript/TypeScript製のFastMCP MCPサーバーが含まれています。

**サンプルアプリを使用する（推奨）**

auth-for-mcp fastmcp-mcp-fga-js のサンプルコードをダウンロード

ダウンロードしたらファイルを展開し、お好みのIDEでプロジェクトを開いてください。

**GitHubリポジトリをクローンする**

リポジトリをクローンし、サンプルアプリのフォルダーに移動します。

```shell wrap lines theme={null}
git clone https://github.com/auth0-samples/auth0-ai-samples.git
cd auth0-ai-samples/auth-for-mcp/fastmcp-mcp-fga-js
```

クローンしたら、お好みのIDEでプロジェクトを開いてください。

## パッケージのインストール

必要な依存関係をインストールします。

```shell theme={null}
npm install
```

## 環境ファイルを作成する

From the root of your sample app directory, run the following command to create a new `.env` file with your Auth0 configuration:

```shell wrap lines expandable theme={null}
DOMAIN=$(auth0 tenants list --json | jq -r '.[] | select(.active == true) | .name') \
&& touch .env \
&& echo "AUTH0_DOMAIN=${DOMAIN}" > .env \
&& echo "AUTH0_AUDIENCE=http://localhost:3001/" >> .env \
&& echo "PORT=3001" >> .env \
&& echo "MCP_SERVER_URL=http://localhost:3001" >> .env \
&& echo "" >> .env \
&& echo ".env file created with your Auth0 configuration:" \
&& cat .env
```

Next, add your FGA configuration to the `.env` file. The variables you need depend on which FGA provider you're using:

**Auth0 FGA**

Add the following to your `.env` file using the credentials from your Auth0 FGA store:

```shell .env wrap lines theme={null}
# Auth0 FGA Configuration
FGA_API_URL=https://api.us1.fga.dev
FGA_STORE_ID=YOUR_STORE_ID
FGA_API_TOKEN_ISSUER=auth.fga.dev
FGA_API_AUDIENCE=https://api.us1.fga.dev/
FGA_CLIENT_ID=YOUR_CLIENT_ID
FGA_CLIENT_SECRET=YOUR_CLIENT_SECRET
```

Replace:

* `YOUR_STORE_ID` with your store ID from the Auth0 FGA dashboard
* `YOUR_CLIENT_ID` with your client ID
* `YOUR_CLIENT_SECRET` with your client secret
* Update `FGA_API_URL` if your store is in a different region (e.g., `https://api.eu1.fga.dev` for Europe)

**OpenFGA (Local)**

Add the following to your `.env` file:

```shell .env wrap lines theme={null}
# OpenFGA Configuration
FGA_API_URL=http://localhost:8080
FGA_STORE_ID=YOUR_STORE_ID
```

Replace `YOUR_STORE_ID` with the store ID that will be generated when you import the authorization model in the next step.

> [!NOTE]
>
> If you haven't run `fga store import` yet, you can leave `FGA_STORE_ID` empty for now and add it after the import completes.

Your complete `.env` file should look like this:

**Auth0 FGA**

```shell .env wrap lines theme={null}
AUTH0_DOMAIN=YOUR_TENANT.us.auth0.com
AUTH0_AUDIENCE=http://localhost:3001/
PORT=3001
MCP_SERVER_URL=http://localhost:3001

# Auth0 FGA Configuration
FGA_API_URL=https://api.us1.fga.dev
FGA_STORE_ID=YOUR_STORE_ID
FGA_API_TOKEN_ISSUER=auth.fga.dev
FGA_API_AUDIENCE=https://api.us1.fga.dev/
FGA_CLIENT_ID=YOUR_CLIENT_ID
FGA_CLIENT_SECRET=YOUR_CLIENT_SECRET
```

**OpenFGA (Local)**

```shell .env wrap lines theme={null}
AUTH0_DOMAIN=YOUR_TENANT.us.auth0.com
AUTH0_AUDIENCE=http://localhost:3001/
PORT=3001
MCP_SERVER_URL=http://localhost:3001

# OpenFGA Configuration
FGA_API_URL=http://localhost:8080
FGA_STORE_ID=YOUR_STORE_ID
```

## 認可モデルについて

The authorization model in this sample demonstrates how [Auth0 FGA](https://auth0.com/fine-grained-authorization) provides fine-grained access control using [Relationship-Based Access Control (ReBAC)](https://docs.fga.dev/authorization-concepts#what-is-relationship-based-access-control).

### Authorization Model Structure

The complete model is defined in `fga/model.fga`:

```typescript theme={null}
model
  schema 1.1

  type user

  # User groups
  type group
    relations
      define member : [user]

  # Roles can be linked to users or members of a user group
  type role
    relations
      define assignee : [user, group#member]

  type tool
    relations
      # Public access, role-based, and temporal access
      define can_use : [user:*, user, role#assignee, user with temporal_access, role#assignee with temporal_access]

      # Resource-specific permission for get_documents tool
      define can_view_private_documents : [role#assignee]

  # Temporal access condition
  condition temporal_access(grant_time: timestamp, grant_duration: duration, current_time: timestamp) {
    current_time < grant_time + grant_duration
  }
```

The model defines four authorization patterns:

> **1. Public Tools**
>
> Tools that are accessible to all authenticated users without requiring specific permissions.
>
> ```yaml theme={null}
> # In fga/tuples.yaml
> - user: user:*
>   relation: can_use
>   object: tool:get_datetime
> ```
>
> The wildcard `user:*` means any authenticated user can use the `get_datetime` tool.

> **2. Role-Based Access**
>
> Tools are assigned to specific roles, and users with those roles can access the tools.
>
> ```yaml theme={null}
> # In fga/tuples.yaml
> # Admin role can use all tools
> - user: role:admin#assignee
>   relation: can_use
>   object: tool:greet
>
> - user: role:admin#assignee
>   relation: can_use
>   object: tool:whoami
>
> - user: role:admin#assignee
>   relation: can_use
>   object: tool:get_documents
> ```
>
> Users assigned the `admin` role automatically gain access to these tools.

> **3. Group Membership**
>
> Users inherit permissions through group membership. Groups are assigned to roles, creating a permission chain.
>
> ```yaml theme={null}
> # In fga/tuples.yaml
> # Managers group is assigned the admin role
> - user: group:managers#member
>   relation: assignee
>   object: role:admin
>
> # Marketing group is assigned the content_editor role
> - user: group:marketing#member
>   relation: assignee
>   object: role:content_editor
> ```
>
> **Permission Chain**: User → Group → Role → Tool
>
> When you add a user to the `managers` group, they automatically inherit all permissions of the `admin` role, including access to all tools.

> **4. Temporal Access**
>
> Time-limited access to tools that automatically expires after a specified duration.
>
> ```typescript theme={null}
> // In fga/model.fga
> condition temporal_access(grant_time: timestamp, grant_duration: duration, current_time: timestamp) {
>   current_time < grant_time + grant_duration
> }
>
> // Tools can be assigned with temporal conditions
> define can_use : [user:*, user, role#assignee, user with temporal_access, role#assignee with temporal_access]
> ```
>
> When you grant temporal access (e.g., "20 seconds to use the greet tool"), FGA evaluates the condition on each request. Access is automatically revoked when the time expires.

> **5. Resource-Specific Permissions**
>
> Fine-grained permissions for specific features or data within tools.
>
> ```yaml theme={null}
> # In fga/tuples.yaml
> # Admin role can view private documents
> - user: role:admin#assignee
>   relation: can_view_private_documents
>   object: tool:get_documents
> ```
>
> The `get_documents` tool checks this permission separately to determine whether to return private documents. This allows the same tool to provide different data based on user permissions.
>
> **Example**:
>
> * Admin role: Sees all documents (public + private)
> * Content editor role: Sees only public documents

### How Authorization Works

When a user connects to the MCP server:

1. The server authenticates the user with Auth0 (validates JWT token)
2. The server queries FGA to get all tools the user can access:
   * Checks `can_use` relation for each tool
   * Evaluates group memberships, role assignments, and temporal conditions
3. The server returns only authorized tools to the MCP client
4. When the user calls a tool like `get_documents`, the server checks `can_view_private_documents` to determine what data to return

This approach ensures that authorization decisions are centralized in FGA and can be updated dynamically without changing code.

## 認可モデルとタプルをインポートする

このサンプルには、完全な認可モデルと初期の権限タプルが含まれており、次の内容が定義されています。

* すべてのユーザーに対する `get_datetime` へのパブリックアクセス
* ロールの割り当て (`admin`、`content_editor`)
* グループとロールのマッピング (`managers` → `admin`、`marketing` → `content_editor`)
* 各ロールのツールアクセス権限

**1. 認可モデルを確認する**

認可モデルは `fga/model.fga` で定義されています。ユーザー、グループ、ロール、ツールの型に加え、時間制限付きアクセスの条件が含まれています。

初期タプルは `fga/tuples.yaml` で定義されており、ベースとなる権限を設定します。

**2. モデルとタプルをインポートする**

サンプルアプリのディレクトリのルートで、次のコマンドを実行します。

```shell wrap lines theme={null}
fga store import --file fga/store.fga.yaml
```

このコマンドは次の処理を行います。

1. 新しい FGA ストアを作成する (OpenFGA をローカルで使用している場合)
2. `fga/model.fga` の認可モデルをアップロードする
3. `fga/tuples.yaml` の初期タプルをインポートする
4. `fga/store.fga.yaml` で定義されたテストを実行し、設定を検証する

> [!NOTE]
>
> OpenFGA を使用している場合は、コマンドの出力にストア ID が含まれます。この ID をコピーし、`.env` ファイルに `FGA_STORE_ID` として追加してください。Auth0 FGA で既存のストアを使用している場合は、新しいモデルとタプルでストアが更新されます。

**3. インポートを確認する**

インポートが成功すると、次のような出力が表示されます。

```json theme={null}
{
  "store": {
    "id": "01KB0NZZFAV9AX7SAPWY23KJAF",
    "name": "fastmcp-fga-example",
    "created_at": "2025-01-22T10:30:00Z",
    "updated_at": "2025-01-22T10:30:00Z"
  },
  "model": {
    "authorization_model_id": "01KED54TEMBDE753YBK7NT3DRZ"
  }
}
```

最後に実行されるテストですべてのチェックが成功していれば、認可モデルは正しく機能しています。

> [!NOTE]
>
> Auth0 FGA を使用している場合は、[Auth0 FGA ダッシュボード](https://dashboard.fga.dev)で認可モデルを表示・管理できます。ダッシュボードではビジュアルなモデルエクスプローラーを利用でき、タプルの表示、追加、削除もリアルタイムで行えます。

## MCPサーバーを実行する

MCPサーバーを起動します。

```shell theme={null}
npm run start
```

サーバーはポート 3001 (または `.env` ファイルで指定したポート) で起動します。コンソールに、次の内容を示す出力が表示されるはずです。

* サーバーが正常に起動したこと
* FGA クライアントが初期化されたこと
* サーバーが `http://localhost:3001/mcp` で接続を待ち受けていること

```
FastMCP Auth0 Example Server started
FGA client initialized for store: 01KB0NZZFAV9AX7SAPWY23KJAF
Server listening on http://localhost:3001/mcp
```

以降のセクションでテストを行うため、サーバーは起動したままにしておいてください。

## ユーザー権限を管理する

The sample application includes helper scripts in the `fga/` directory to make permission management easier. These scripts use the FGA CLI to add or remove authorization tuples dynamically.

### Available Scripts

> **Add User to Group**
>
> Grant a user all permissions associated with a group (and its assigned role).
>
> **Usage**:
>
> ```shell theme={null}
> ./fga/add-user-to-group.sh <user-email> <group-name>
> ```
>
> **Examples**:
>
> ```shell theme={null}
> # Add user to managers group (grants admin role with full access)
> ./fga/add-user-to-group.sh user@example.com managers
>
> # Add user to marketing group (grants content_editor role)
> ./fga/add-user-to-group.sh user@example.com marketing
> ```
>
> **What it does**: Creates an FGA tuple that makes the user a member of the specified group. Since groups are assigned to roles, the user automatically inherits all role permissions.
>
> **Available groups**:
>
> * `managers` - Assigned to `admin` role (all tools + private documents)
> * `marketing` - Assigned to `content_editor` role (all tools, public documents only)

> **Remove User from Group**
>
> Revoke a user's group membership and all associated permissions.
>
> **Usage**:
>
> ```shell theme={null}
> ./fga/remove-user-from-group.sh <user-email> <group-name>
> ```
>
> **Example**:
>
> ```shell theme={null}
> # Remove user from managers group
> ./fga/remove-user-from-group.sh user@example.com managers
> ```
>
> **What it does**: Deletes the FGA tuple that grants group membership. The user immediately loses all permissions from that group's role.

> **Grant Temporal Access**
>
> Provide time-limited access to a specific tool that automatically expires.
>
> **Usage**:
>
> ```shell theme={null}
> ./fga/add-temporal-access.sh <user-email> <tool-name> <duration>
> ```
>
> **Examples**:
>
> ```shell theme={null}
> # Grant 20-second access to the greet tool
> ./fga/add-temporal-access.sh user@example.com greet 20s
>
> # Grant 1-hour access to the whoami tool
> ./fga/add-temporal-access.sh user@example.com whoami 1h
>
> # Grant 5-minute access
> ./fga/add-temporal-access.sh user@example.com greet 5m
> ```
>
> **What it does**: Creates an FGA tuple with a temporal condition. FGA evaluates the condition on each request and automatically denies access when the duration expires. No cleanup is needed.
>
> **Supported durations**: Use standard time notation (`s` for seconds, `m` for minutes, `h` for hours).
>
> **Available tools**: `greet`, `whoami`, `get_documents`
>
> > [!NOTE]
> >
> > Public tools like `get_datetime` don't need temporal access grants since they're already accessible to all authenticated users.

> **Reset Tuples**
>
> Reset all tuples to the initial state defined in `fga/tuples.yaml`.
>
> **Usage**:
>
> ```shell theme={null}
> ./fga/reset-tuples.sh
> ```
>
> **What it does**: Deletes all existing tuples and reimports the default tuples from `fga/tuples.yaml`. Useful for returning to a clean state during testing.
>
> > [!WARNING]
> >
> > This script removes all user assignments, including any custom permissions you've added. Use with caution.

### Testing Permission Changes

After running any of these scripts, you need to reload the tools:

* for MCP inspector: click 'Clear' in the MCP inspector tools panel and then 'List Tools'
* for other MCP clients: you might need to reconnect the MCP Client to see the updated tool list.

The server queries FGA on each connection to determine available tools.

> [!TIP]
>
> You can also manage tuples directly in the [Auth0 FGA Dashboard](https://dashboard.fga.dev) if you're using Auth0 FGA. The dashboard provides a visual interface for viewing, adding, and removing authorization tuples in real-time.

## Testing your MCP server

Now that your MCP server is up and running, you can test it by using tools like [MCP Inspector](https://modelcontextprotocol.io/docs/tools/inspector).

> **[Learn how to test your Auth0-powered MCP server](/ai/docs/mcp/guides/test-your-mcp-server-with-mcp-inspector.md)**

### 認可シナリオをテストする

次に、さまざまな認可シナリオをテストして、FGAがツールへのアクセスをどのように制御するかを確認します。サーバーへの接続には、[MCP Inspector](https://github.com/modelcontextprotocol/inspector)などのMCPクライアントが必要です。

**1. 基本アクセスをテストする**

ユーザーの認証情報を使用してMCPサーバーに接続します。初期状態では、パブリックツールのみが表示されるはずです。

**想定されるツール**：`get_datetime`

このことから、ロールやグループが割り当てられていない場合、認証済みユーザーはパブリックツールにしかアクセスできないことがわかります。

**2. managersグループで管理者アクセスを付与する**

ユーザーをmanagersグループに追加して、管理者ロールの権限を付与します。

```shell wrap lines theme={null}
./fga/add-user-to-group.sh YOUR_EMAIL managers
```

`YOUR_EMAIL`は、認証に使用するメールアドレスに置き換えてください。

MCPクライアントで再接続し、すべてのツールが表示されることを確認します。

**想定されるツール**：`get_datetime`、`greet`、`whoami`、`get_documents`

`get_documents`ツールを呼び出し、レスポンスにパブリックとプライベートの両方のドキュメントが含まれていることを確認します。これは、管理者ロールに基づくリソース固有の権限が機能していることを示しています。

> [!TIP]
>
> MCP Inspectorでは、権限を変更した後に切断して再接続する (または接続を更新する) 必要があります。サーバーは新しい接続のたびにFGAに問い合わせて、利用可能なツールを判断します。

**3. コンテンツ編集者ロールをテストする**

グループのメンバーシップを変更して、管理者からコンテンツ編集者に切り替えます。

```shell wrap lines theme={null}
./fga/remove-user-from-group.sh YOUR_EMAIL managers
./fga/add-user-to-group.sh YOUR_EMAIL marketing
```

MCPクライアントで再接続します。

**想定されるツール**：`get_datetime`、`greet`、`whoami`、`get_documents`

`get_documents`ツールを呼び出し、今度はパブリックドキュメントのみが表示される (プライベートドキュメントは表示されない) ことを確認します。このように、同じツールでもユーザーのロールに応じて異なるデータを返すことができます。

**主な違い**：コンテンツ編集者は管理者と同じツールにアクセスできますが、`can_view_private_documents`権限は持っていません。

**4. 時間制限付きアクセスをテストする**

すべてのグループメンバーシップを削除し、特定のツールへの時間制限付きアクセスを付与します。

```shell wrap lines theme={null}
./fga/remove-user-from-group.sh YOUR_EMAIL marketing
./fga/add-temporal-access.sh YOUR_EMAIL greet 20s
```

これにより、`greet`ツールへの20秒間のアクセスが付与されます。

MCPクライアントで**すぐに再接続**します。

**想定されるツール**：`get_datetime`、`greet`

`greet`ツールを呼び出して、動作することを確認します。

**25秒待ってから**もう一度再接続します。

**想定されるツール**：`get_datetime` (のみ)

`greet`ツールは表示されなくなっているはずです。このように、時間制限付きアクセスはクリーンアップ作業なしで自動的に失効します。

> [!WARNING]
>
> 時間制限付きアクセスは、リクエストごとにリアルタイムで評価されます。期限が切れると、データベースにタプルが残っていても、FGAは自動的にアクセスを拒否します。

## 次のステップ

* よりシンプルなスコープベースのアプローチについては、[MCPサーバーの認可](/ai/docs/ja-jp/mcp/get-started/authorization-for-your-mcp-server.md)を参照してください
* 認可モデルの設計について詳しくは、[Auth0 FGA のドキュメント](https://auth0.com/fine-grained-authorization)をご覧ください
* 高度なモデリングパターンやベストプラクティスについては、[OpenFGA](https://openfga.dev/docs)のドキュメントを参照してください
* [MCP Inspector を使用して MCPサーバーをテストする](/ai/docs/ja-jp/mcp/guides/test-your-mcp-server-with-mcp-inspector.md)方法をご確認ください
