Overview
MCP implements OAuth 2.1 for HTTP transports, enabling clients to access restricted servers on behalf of users. The implementation follows the MCP Authorization Specification. Key requirements:- PKCE (S256) - Mandatory for all authorization flows
- Resource parameter - Tokens are bound to specific MCP servers
- Protected Resource Metadata - Standard discovery mechanism
Authorization Flow
Discovery
Protected Resource Metadata (PRM)
When connecting to an MCP server,mcp-use discovers how to authenticate:
1. WWW-Authenticate header (preferred)
Authorization Server Metadata
For each authorization server in PRM,mcp-use discovers OAuth endpoints using two standards:
For an issuer like
https://github.com/login/oauth:
When the issuer has no path, both methods produce the same URL.
mcp-use tries OAuth 2.0 style first, then falls back to OpenID Connect.Client Registration
mcp-use supports three methods to obtain OAuth credentials, in priority order:
1. Pre-registered Credentials
Use existing OAuth app credentials:2. Client ID Metadata Documents (CIMD)
CIMD lets you use a URL as yourclient_id. The authorization server fetches your client metadata from that URL.
Create a metadata document (host at a public HTTPS URL):
CIMD is available when the authorization server advertises
client_id_metadata_document_supported: true.3. Dynamic Client Registration (DCR)
When no credentials are configured and the server supports DCR,mcp-use registers automatically:
registration_endpoint:
~/.mcp_use/tokens/registrations/.
PKCE (Required)
PKCE (Proof Key for Code Exchange) protects against authorization code interception attacks.mcp-use implements PKCE S256 for all OAuth flows.
How it works:
- Client generates a random
code_verifier - Client computes
code_challenge = BASE64URL(SHA256(code_verifier)) - Authorization request includes
code_challengeandcode_challenge_method=S256 - Token request includes
code_verifierfor validation
Resource Parameter
Per RFC 8707,mcp-use includes the resource parameter in authorization requests to bind tokens to specific MCP servers.
This prevents tokens from being used with unintended servers (confused deputy attacks).
Scope Selection
mcp-use selects scopes in this order:
- WWW-Authenticate header - Use
scopefrom 401 response - PRM document - Use
scopes_supportedif no scope in header - Configured scope - Use your explicit
scopeconfiguration - Omit - Let the authorization server decide
Configuration Reference
All OAuth parameters go inside theauth object of your server configuration:
OAuth Provider (Skip Discovery)
If you know the OAuth endpoints, skip discovery:Token Storage
Tokens are stored locally and reused across sessions:Troubleshooting
Server requires PKCE S256
Server requires PKCE S256
The authorization server doesn’t advertise
code_challenge_methods_supported: ["S256"].OAuth server only supports CIMD
OAuth server only supports CIMD
The server has
client_id_metadata_document_supported: true but no registration_endpoint.Solution: Configure a CIMD document URL:Port already in use
Port already in use
Another process is using port 8080.Solution: Use a different callback port:
Invalid redirect URI
Invalid redirect URI
Your OAuth app’s registered redirect URI doesn’t match the callback URL.Solutions:
1
Update OAuth app
Add
http://127.0.0.1:8080/callback to your OAuth app’s allowed redirect URIs2
Or use DCR
Remove
client_id from config to use automatic registration3
Or match the port
Set
callback_port to match your registered redirect URI