Learn how to implement fine-grained authorization for your MCP server tools using Auth0 FGA with roles, groups, and temporal access.
Fine-grained authorization goes beyond simple scope-based access control by enabling sophisticated permission models based on relationships between users, roles, groups, and resources. This quickstart demonstrates how to use Auth0 FGA to implement Relationship-Based Access Control (ReBAC) for your MCP server tools.The sample application showcases five authorization patterns:
Public Tools - Accessible to all authenticated users without additional permissions
Role-Based Access - Tools assigned to specific roles (admin, content_editor)
Group Membership - Users inherit permissions through group membership (managers, marketing)
Temporal Access - Time-limited tool access with automatic expiration
Resource-Specific Permissions - Fine-grained control over tool features (e.g., viewing private documents)
By the end of this quickstart, you will have an MCP server that:
Authenticates users with Auth0 OAuth 2.0
Uses Auth0 FGA to determine which tools each user can access
Dynamically filters tool lists based on user permissions
Supports time-limited access grants that automatically expire
Provides different data based on user roles (public vs private documents)
Auth for MCP is currently available in Early Access. To join the Early Access program, please complete this form. We’ll reach out to you when your request is processed.
1. Create or log in to your Auth0 account
To continue with this quickstart, you need to have an Auth0 account.
2. Enable your tenant to use the Resource Parameter Compatibility Profile
To use the resource parameter in your access tokens, you need to enable the compatibility profile.The quickest way to enable it is through the Auth0 Dashboard:
Confirm you are in the correct tenant by double-checking the tenant domain in the terminal, or run the command below:
Report incorrect code
Copy
Ask AI
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. This will allow you to easily parse JSON responses from the CLI.
macOS
Linux
Windows
Report incorrect code
Copy
Ask AI
brew install jq
Report incorrect code
Copy
Ask AI
sudo apt-get install jq
Report incorrect code
Copy
Ask AI
choco install jq
Now install and setup the dependencies for FGA:
1. Install the FGA CLI
This guide uses the OpenFGA CLI to manage authorization models and permissions.
# 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.gztar -xzf fga_0.6.3_linux_amd64.tar.gzsudo mv fga /usr/local/bin/
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. Best for production use.
OpenFGA: Self-hosted open-source option. Best for local development and testing.
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 enabling third-party applications.
1
List Your Connection
List your connections to get their IDs
Report incorrect code
Copy
Ask AI
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).
Report incorrect code
Copy
Ask AI
auth0 api patch connections/YOUR_CONNECTION_ID --data '{"is_domain_connection": true}'
An MCP server is treated just like any other API 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 in Auth0:
Report incorrect code
Copy
Ask AI
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 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.
This quickstart uses two OAuth scopes for demonstration: tool:greet and tool:whoami. The get_datetime tool is public and doesn’t require scopes, while get_documents uses FGA for authorization.
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).
1
Install OpenFGA
Install OpenFGA using Homebrew or Docker:
Homebrew
Docker
Report incorrect code
Copy
Ask AI
brew install openfga
Docker installation will be used in the next step to run the server.
Start by downloading or cloning the sample app for this quickstart. The sample includes a FastMCP MCP server with Auth0 OAuth and Auth0 FGA integration in JavaScript/TypeScript.
Use sample app (recommended)
Clone GitHub repository
Once downloaded, extract the files and open the project in your preferred IDE.
Clone the repository and navigate to the sample app folder:
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.
Report incorrect code
Copy
Ask AI
# 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.
Report incorrect code
Copy
Ask AI
# 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.
Report incorrect code
Copy
Ask AI
# 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 → ToolWhen 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.
Report incorrect code
Copy
Ask AI
// In fga/model.fgacondition temporal_access(grant_time: timestamp, grant_duration: duration, current_time: timestamp) { current_time < grant_time + grant_duration}// Tools can be assigned with temporal conditionsdefine 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.
Report incorrect code
Copy
Ask AI
# 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:
The authorization model is defined in fga/model.fga. It includes types for users, groups, roles, and tools, plus a temporal access condition.The initial tuples are defined in fga/tuples.yaml and establish the baseline permissions.
2
Import the model and tuples
From the root of your sample app directory, run:
Report incorrect code
Copy
Ask AI
fga store import --file fga/store.fga.yaml
This command will:
Create a new FGA store (if using OpenFGA locally)
Upload the authorization model from fga/model.fga
Import the initial tuples from fga/tuples.yaml
Run tests defined in fga/store.fga.yaml to verify the setup
If using OpenFGA, the command output will include a store ID. Copy this ID and add it to your .env file as FGA_STORE_ID. If using Auth0 FGA with existing store, the command will update your store with the new model and tuples.
3
Verify the import
If the import is successful, you should see output similar to:
The tests at the end should show all checks passing, confirming that the authorization model is working correctly.
You can view and manage your authorization model in the Auth0 FGA Dashboard if you’re using Auth0 FGA. The dashboard provides a visual Model Explorer and allows you to view, add, and delete tuples in real-time.
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.
# 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:
# 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
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:
Report incorrect code
Copy
Ask AI
./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.
This script removes all user assignments, including any custom permissions you’ve added. Use with caution.
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.
You can also manage tuples directly in the Auth0 FGA Dashboard if you’re using Auth0 FGA. The dashboard provides a visual interface for viewing, adding, and removing authorization tuples in real-time.
Now test different authorization scenarios to see how FGA controls tool access. You’ll need to use an MCP client like MCP Inspector to connect to your server.
1
Test baseline access
Connect to your MCP server using your user credentials. Initially, you should only see the public tool.Expected tools: get_datetimeThis demonstrates that without any role or group assignments, authenticated users only have access to public tools.
2
Grant admin access via managers group
Add your user to the managers group to grant admin role permissions:
Report incorrect code
Copy
Ask AI
./fga/add-user-to-group.sh YOUR_EMAIL managers
Replace YOUR_EMAIL with the email address you use to authenticate.Reconnect in your MCP client and verify you now see all tools.Expected tools: get_datetime, greet, whoami, get_documentsCall the get_documents tool and verify that you see both public and private documents in the response. This demonstrates resource-specific permissions based on the admin role.
In MCP Inspector, you’ll need to disconnect and reconnect (or refresh the connection) after changing permissions. The server queries FGA on each new connection to determine available tools.
3
Test content editor role
Switch from admin to content editor by changing group membership:
Reconnect in your MCP client.Expected tools: get_datetime, greet, whoami, get_documentsCall the get_documents tool and verify that you now see only public documents (no private documents). This demonstrates how the same tool can provide different data based on user roles.Key difference: Content editors have access to the same tools as admins but don’t have the can_view_private_documents permission.
4
Test temporal access
Remove all group memberships and grant time-limited access to a specific tool:
This grants 20 seconds of access to the greet tool.Immediately reconnect in your MCP client.Expected tools: get_datetime, greetCall the greet tool to verify it works.Wait 25 seconds and reconnect again.Expected tools: get_datetime (only)The greet tool should no longer appear. This demonstrates automatic expiration of temporal access without any cleanup required.
Temporal access is evaluated in real-time on each request. Once the duration expires, FGA automatically denies access even if the tuple still exists in the database.