Installation
Features
- OAuth 2.0 with Dynamic Client Registration (DCR)
- Resource Parameter support for MCP protocol
- Fine-grained permissions using Auth0 API scopes
- Access to Auth0 Management API
- JWT token verification with JWKS
- Tool-level authorization
Setup
1. Configure Auth0 Tenant
Your Auth0 tenant requires specific configuration for MCP compatibility.Enable Dynamic Client Registration
- Go to Auth0 Dashboard → Settings → Advanced
- Enable “OIDC Dynamic Application Registration”
- Save changes
Enable Resource Parameter
- Go to Auth0 Dashboard → Settings → Advanced
- Enable “Resource Parameter Compatibility Profile”
- Save changes
Promote Connection to Domain Level
- Go to Auth0 Dashboard → Authentication → Database
- Select your connection (e.g.,
Username-Password-Authentication) - Enable “Enable for third-party clients”
- Save changes
Create API Resource
- Go to Auth0 Dashboard → Applications → APIs
- Click Create API
- Set:
- Name:
MCP Server API - Identifier:
http://localhost:3001/(with trailing slash)
- Name:
- Go to Permissions tab and add tool permissions:
tool:greettool:whoami- Add more as needed
Set Default Audience
- Go to Auth0 Dashboard → Settings → General
- Set Default Audience to your API identifier
- Save changes
2. Environment Variables
Create a.env file:
Create a Machine-to-Machine application in Auth0 to get your
CLIENT_ID and CLIENT_SECRET. Authorize it for the Management API.3. Create Middleware
Createsrc/middleware.ts:
4. Configure xmcp
Inxmcp.config.ts, enable HTTP transport:
Configuration
Required Options
| Option | Type | Description |
|---|---|---|
domain | string | Auth0 tenant domain (e.g., your-tenant.auth0.com) |
audience | string | API identifier (must match baseURL with trailing slash) |
baseURL | string | Base URL of your MCP server |
clientId | string | Auth0 M2M application client ID |
clientSecret | string | Auth0 M2M application client secret |
Optional Options
| Option | Type | Description |
|---|---|---|
scopesSupported | string[] | Additional OAuth scopes beyond default (openid, profile, email) |
management.audience | string | Custom Management API audience |
management.resourceServerIdentifier | string | Custom resource server identifier for permissions |
Usage in Tools
Access Authentication Info
src/tools/whoami.ts
Use in Tool Logic
src/tools/greet.ts
Access Management API
Access the Auth0 Management API client:Check Permissions Programmatically
AuthInfo Type
ThegetAuthInfo() function returns:
Tool-Level Authorization
The Auth0 plugin automatically enforces tool permissions:- Permission Defined: If a tool permission exists in Auth0 (e.g.,
tool:greet), the user’s token must include it - No Permission Defined: If the permission doesn’t exist in Auth0, the tool is public
- Management API Failure: If the Management API is unavailable, access is denied (secure default)
Define Tool Permissions
Add permissions in Auth0 Dashboard:- Go to Applications → APIs → Your API
- Click Permissions tab
- Add permission with format
tool:<toolName>:tool:greettool:whoamitool:admin-action
Assign Permissions to Users
Assign permissions via Management API or dashboard:OAuth Metadata Endpoints
The plugin automatically exposes:Resource Metadata
Authorization Server Metadata
Example Project
Complete example atexamples/auth0-http:
src/middleware.ts
src/tools/greet.ts
Troubleshooting
”Missing or invalid bearer token”
The MCP client isn’t sending an access token:- Verify Dynamic Client Registration is enabled
- Check Resource Parameter is enabled
- Ensure the client completed OAuth flow
”Token has expired”
Access tokens are short-lived. The client should automatically refresh:- Disconnect and reconnect in the MCP client
- Check system clock is accurate
- Verify refresh token grant is enabled
”Token verification failed”
- Verify
DOMAINmatches your Auth0 tenant - Check
AUDIENCEexactly matches the API identifier - Ensure API is not deleted or disabled
- Verify JWKS endpoint is accessible
”You don’t have permission to use the tool”
User lacks required permission:- Check permission exists in Auth0 API permissions
- Verify user has been assigned the permission
- Ensure permission name format is
tool:<toolName> - Check Management API credentials are valid
API Reference
Functions
auth0Provider(config: Config): Middleware
Creates Auth0 authentication middleware.
getAuthInfo(): AuthInfo
Returns current authenticated user’s information. Must be called within a request context.
getClient(): ApiClient
Returns Auth0 API client instance for Token Vault operations.
getManagement(): ManagementClient
Returns Auth0 Management API client.
fetchResourceServerScopes(management: ManagementClient, audience: string): Promise<string[]>
Fetches available scopes from the Auth0 API resource.
fetchUserPermissions(management: ManagementClient, userId: string, audience: string): Promise<string[]>
Fetches user’s assigned permissions for an API.
isToolPermissionDefined(management: ManagementClient, audience: string, toolName: string): Promise<boolean | null>
Checks if a tool permission exists in Auth0. Returns null on API failure.
userHasToolPermission(management: ManagementClient, userId: string, audience: string, toolName: string): Promise<boolean | null>
Checks if user has a specific tool permission. Returns null on API failure.