Skip to main content
On a server configured with oauth, tool, resource, and prompt callbacks receive verified authentication data on ctx.auth. The provider determines the static type of ctx.auth.user; there is no generic UserInfo shape.

Auth shape

Every provider exposes this top-level shape:
  • user is the provider’s normalized user type.
  • payload contains the verified token claims or introspection data.
  • accessToken is the verified bearer token. Forward it only when calling an upstream API on behalf of the user. On an OAuth Proxy server it is the proxy’s own token, which upstream APIs do not accept.
  • scopes are copied from the auth information returned by the token verifier.
  • permissions are produced by the provider’s mapping.
  • clientId is present when the token has a client identifier.
  • expiresAt is a Unix timestamp in seconds.
  • resource is the protected resource validated by the verifier.
  • upstream is set only on an OAuth Proxy server. It holds the upstream provider’s token for the user; read it with upstreamToken(ctx.auth) from mcp-use/oauth.

Use provider-specific fields

All built-in users have id. Optional profile and organization fields vary: The OAuth Proxy is the exception: its user is { subject, profile }, where subject is the provider’s stable user ID and profile holds the provider’s fields. Pass mapUser to oauthProxy to return a user with id.
Use normalized fields for application logic. Read payload only when you deliberately need a provider claim that is not mapped.

Check scopes and permissions

Scopes describe OAuth grants. Permissions describe provider-mapped application authorization.
Provider mappings differ: Auth0 and WorkOS map their permission claim, Clerk maps organization permissions, Keycloak flattens resource roles as client:role, and Supabase maps AAL to aal:<level>.

Map custom claims

For another authorization server, oauthCustomProvider separates verification from application mapping:
This fixed-token verifier keeps the example small and is only suitable for local testing. In production, validate the token signature, issuer, expiry, and MCP resource, or introspect an opaque token with the authorization server. createTokenVerifier receives the canonical MCP resource. The verifier rejects a token by throwing OAuthError with OAuthErrorCode.InvalidToken, so the client gets 401 with a WWW-Authenticate challenge, or, for a ChatGPT tools/call request, an isError tool result carrying the same challenge (see Mixed auth). An error that is not an OAuthError is answered with 500. The auth information it returns must carry resource as a URL matching that resource, clientId as a string ("" when the token has no client), and expiresAt in Unix seconds in the future. mapAuthInfo runs only after SDK auth information has been verified and must return { user, payload, permissions }. It does not rewrite ctx.auth.scopes; those come from the verifier’s verified auth info.

Next steps

Authentication

Choose and configure an OAuth provider.

Custom Provider

Implement resource-bound token verification and claim mapping.

Middleware

Apply shared authorization checks.