MCPServer protects the transport, publishes discovery metadata, verifies bearer tokens, and exposes the verified identity on ctx.auth.
Choose a provider
Pick the provider for your identity system. Most providers run an authorization server that supports Dynamic Client Registration (DCR), and your MCP server only verifies their tokens. For a provider without DCR, such as GitHub or Google, use the OAuth Proxy: your MCP server becomes the authorization server itself.
With a DCR provider, the MCP client registers and performs the authorization flow directly with the authorization server. Your MCP server does not handle authorization codes or exchange them for tokens. With the OAuth Proxy, your MCP server runs that flow: it shows a consent page, signs the user in upstream as one OAuth app, and issues its own tokens.
Configure the server
Import the server frommcp-use and the provider from its dedicated OAuth entry point, then pass the provider’s settings as options.
MCP_USE_OAUTH_* environment variable instead. With the variables set, you can call the factory with no arguments, for example oauthAuth0Provider(). An option you pass always takes precedence over its variable.
The OAuth Proxy reads only
MCP_USE_OAUTH_SECRET, for its secret option, and always needs upstream. See OAuth Proxy.
The Auth0 and Keycloak *_AUDIENCE variables become the provider’s resource when you don’t pass one, so they override MCP_URL. The value must be the full MCP endpoint URL, with a path equal to basePath (default /mcp), or the server throws at startup.
The provider binds token verification to the resolved MCP resource. Set MCP_URL to the public server origin in production, or pass the provider’s resource option when you need an explicit canonical MCP endpoint.
Authorize a tool
An OAuth-configured server gives tool callbacks a provider-specificctx.auth.user. All built-in providers normalize the stable subject to id; additional fields depend on the provider. The OAuth Proxy exposes the upstream user as { subject, profile } unless you reshape it with mapUser.
scopes come from the verified SDK auth information. permissions and user come from the provider’s verified claim mapping. Use User Context for the complete shape and authorization patterns.
What OAuth changes
Whenoauth is configured:
- protected-resource and authorization-server metadata are published for clients;
- MCP transport requests require a bearer token;
- invalid, expired, incorrectly resourced tokens, and tokens missing configured
requiredScopesare rejected before tool code runs; - callbacks receive the verified access token, identity, scopes, permissions, expiry, client ID when present, and resource.
mixedAuth: true and declare securitySchemes with { type: "noauth" } on each public or optional tool. See Mixed Authentication.
Next steps
User Context
Use verified identity and authorization data inside callbacks.
Mixed Authentication
Serve public, optional, and sign-in tools from one endpoint.
Custom Provider
Integrate another DCR-capable authorization server.
OAuth Proxy
Sign users in with GitHub, Google, or another provider without DCR.
Client Authentication
Connect a TypeScript MCP client to an OAuth-protected server.