MCPServer protects the transport, publishes discovery metadata, verifies bearer tokens, and exposes the verified identity on ctx.auth.
Choose a provider
mcp-use supports resource-server providers whose authorization server supports Dynamic Client Registration (DCR).
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.
Configure the server
Import the server frommcp-use and the provider from its dedicated OAuth entry point. Provider configuration is explicit; mcp-use does not read provider-specific environment variables.
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 providers normalize the stable subject to id; additional fields depend on the provider.
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.
Next steps
User Context
Use verified identity and authorization data inside callbacks.
Custom Provider
Integrate another DCR-capable authorization server.
Client Authentication
Connect a TypeScript MCP client to an OAuth-protected server.