Skip to main content

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)
2. Well-known URLs (fallback)
The PRM document tells the client which authorization servers to use:

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:
Use this when your OAuth provider requires manual app registration (like GitHub).

2. Client ID Metadata Documents (CIMD)

CIMD lets you use a URL as your client_id. The authorization server fetches your client metadata from that URL. Create a metadata document (host at a public HTTPS URL):
Configure mcp-use:
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:
DCR sends a registration request to the registration_endpoint:
Registered credentials are cached in ~/.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:
  1. Client generates a random code_verifier
  2. Client computes code_challenge = BASE64URL(SHA256(code_verifier))
  3. Authorization request includes code_challenge and code_challenge_method=S256
  4. Token request includes code_verifier for validation
Servers that don’t support PKCE S256 are rejected. This is a security requirement of the MCP spec.

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:
  1. WWW-Authenticate header - Use scope from 401 response
  2. PRM document - Use scopes_supported if no scope in header
  3. Configured scope - Use your explicit scope configuration
  4. Omit - Let the authorization server decide

Configuration Reference

All OAuth parameters go inside the auth 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

The authorization server doesn’t advertise code_challenge_methods_supported: ["S256"].
PKCE S256 is required by the MCP spec. Contact the server administrator to enable it.
The server has client_id_metadata_document_supported: true but no registration_endpoint.Solution: Configure a CIMD document URL:
Another process is using port 8080.Solution: Use a different callback port:
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 URIs
2

Or use DCR

Remove client_id from config to use automatic registration
3

Or match the port

Set callback_port to match your registered redirect URI

Servers with OAuth Support