Super AI · 08 / 12

MCP Authorization: OAuth 2.1 and Client ID Metadata Documents

How remote MCP servers authenticate agents with OAuth 2.1, and how Client ID Metadata Documents (CIMD) let clients and servers that have never met establish trust.

What it is

Remote MCP servers are shared network services, so the Model Context Protocol defines an authorization flow built on OAuth 2.1. The MCP server acts as an OAuth resource server that validates access tokens, the MCP client acts as an OAuth client working for the user, and an authorization server signs the user in and issues the tokens.

The hard part is that any client may meet any server for the first time. Client ID Metadata Documents (CIMD) solve it: the client's identifier is an HTTPS URL that hosts its metadata, which the authorization server fetches and validates. It is the recommended registration approach in the MCP specification, ahead of Dynamic Client Registration.

How it works

MCP authorization flow with OAuth 2.1 and CIMD A client calls the MCP server without a token and receives a 401 pointing to resource metadata. It reads the metadata, then starts authorization at the authorization server using its metadata URL as the client ID, PKCE and a resource parameter. The authorization server fetches and validates the client metadata, signs the user in and returns a code, which the client exchanges for a short-lived token it sends as a bearer token to the MCP server. MCP client + user's browser MCP server resource server Authorization server issues tokens Client metadata https://app.example/... 1 MCP request, no token 2 401 + resource_metadata 3 fetch resource metadata 4 fetch server metadata (PKCE, CIMD support) 5 authorize: client_id=URL, PKCE, resource 6 fetch + validate client metadata 7 user signs in, consents, returns code 8 token request: code + verifier + resource 9 short-lived access token 10 Authorization: Bearer token 11 tool result (after audience check) The URL in client_id is the identity: no registration call, and the server validates it on demand.
Discover, identify by URL, authorize with PKCE, then call with an audience-bound token.
  1. Challenge

    The client calls the MCP server without a token and gets a 401 with a pointer to the server's resource metadata.

  2. Discover

    It reads the protected resource metadata, then the authorization server's metadata.

  3. Identify itself

    The client presents its CIMD URL as the client_id, or uses pre-registration or DCR if CIMD is unavailable.

  4. Authorize

    The user signs in and consents, with PKCE and a resource parameter binding the request to this server.

  5. Get a token

    The client exchanges the code for a short-lived access token scoped and audience-bound to the server.

  6. Call and step up

    Every request carries the bearer token. If a tool needs more access, the server asks for more scope.

Why MCP needs OAuth

Local MCP servers started over stdio simply use the user's own credentials from the environment. A remote server is different: it is a network service that many people and agents reach. The MCP specification therefore defines an authorization flow for HTTP-based transports, built on OAuth 2.1. Authorization is optional in the protocol, but any remote server that touches real data should use it.

Remote servers are shared services

A remote MCP server fronts real systems for many users and many agents. It has to know who is calling and what that caller may do. A shared API key cannot express either.

The agent acts for a person

Tokens carry the user's identity and consented scopes, so the server can enforce per-user permissions and audit trails instead of acting as an all-powerful service account.

Clients and servers have never met

A user can point any MCP client at any MCP server. Neither was configured for the other in advance, which is exactly what makes client registration hard.

Prompt injection raises the stakes

A manipulated agent will try whatever its tools permit. Short-lived, narrowly scoped, audience-bound tokens limit what a hijacked session can reach.

It reuses what enterprises already run

OAuth with an existing identity provider (single sign-on, MFA, conditional access, revocation) means MCP servers join your current identity controls rather than inventing new ones.

Roles and standards

MCP does not invent a new security protocol. It selects a subset of existing OAuth standards and says how they fit together.

MCP server = OAuth 2.1 resource server

Accepts and validates access tokens, and returns 401 or 403 with discovery hints when a request is not authorized.

MCP client = OAuth 2.1 client

Runs the authorization flow on behalf of the user and sends the bearer token on every request.

Authorization server

Authenticates the user, obtains consent and issues tokens. It can be your identity provider, a separate service, or hosted with the MCP server.

StandardWhat it does for MCP
OAuth 2.1 (IETF draft)The base framework: authorization code flow with mandatory PKCE, exact redirect URI matching and no implicit flow.
RFC 9728, Protected Resource MetadataHow an MCP server tells clients which authorization server to use. Required for servers.
RFC 8414 and OpenID Connect DiscoveryHow a client finds the authorization server's endpoints and capabilities. Clients must support both.
RFC 8707, Resource IndicatorsThe resource parameter that binds a token to one specific MCP server.
OAuth Client ID Metadata DocumentsAn IETF draft: a client's client_id is an HTTPS URL that points to its metadata. The recommended registration approach.
RFC 7591, Dynamic Client RegistrationThe earlier way to register at runtime. Kept for backwards compatibility.

Discovery: how a client learns where to sign in

A client that has never seen a server needs no manual configuration. The server points it to the right authorization server, and the authorization server describes itself.

  1. Call the server

    The client sends a request to the MCP endpoint with no token.

  2. Receive a 401

    The server answers 401 Unauthorized with a WWW-Authenticate header carrying resource_metadata (and, ideally, the scope needed). If the header is missing, the client falls back to well-known URIs.

  3. Read resource metadata

    The client fetches the Protected Resource Metadata document, which lists authorization_servers.

  4. Read server metadata

    The client fetches the authorization server's metadata (RFC 8414 or OpenID Connect Discovery) to learn endpoints, PKCE support and registration options.

the 401 challenge
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer resource_metadata="https://mcp.example.com/.well-known/oauth-protected-resource",
                  scope="files:read"
protected resource metadata (RFC 9728)
GET https://mcp.example.com/.well-known/oauth-protected-resource

{
  "resource": "https://mcp.example.com",
  "authorization_servers": ["https://auth.example.com"],
  "scopes_supported": ["files:read"]
}
authorization server metadata (RFC 8414) · excerpt
GET https://auth.example.com/.well-known/oauth-authorization-server

{
  "issuer": "https://auth.example.com",
  "authorization_endpoint": "https://auth.example.com/authorize",
  "token_endpoint": "https://auth.example.com/token",
  "code_challenge_methods_supported": ["S256"],
  "client_id_metadata_document_supported": true
}

The client registration problem

OAuth needs the authorization server to recognize the client and know its redirect URIs. In most OAuth deployments a developer registers the app once. In MCP, any client may meet any server for the first time, so the specification offers three approaches.

ApproachHow it works and its trade-offs
Pre-registrationA fixed client ID configured by a person ahead of time. Works when client and server already have a relationship. Does not scale to arbitrary pairs.
Dynamic Client Registration (DCR)The client POSTs its details to a registration endpoint and gets a new client ID. Works with strangers, but every client instance creates a record the server must store, secure and clean up, and the registration endpoint is open to abuse.
Client ID Metadata Documents (CIMD)The client ID is an HTTPS URL that hosts the client's metadata. The authorization server fetches and validates it on demand. No registration call, nothing to store per client, and the client's identity is tied to a domain it controls.

Clients that support more than one should choose in this order:

OrderRule
1Use pre-registered client information if the client has it for this server.
2Otherwise use CIMD if the authorization server advertises client_id_metadata_document_supported.
3Otherwise fall back to Dynamic Client Registration if the metadata lists a registration_endpoint.
4Otherwise ask the user to enter client information.

Client ID Metadata Documents (CIMD)

With CIMD, the client's identifier is a URL it controls. When that URL appears as the client_id in an authorization request, the authorization server fetches it and reads the client's name, logo and allowed redirect URIs. Identity comes from control of a domain over HTTPS, and no registration step or stored per-client record is needed.

https://app.example.com/oauth/client-metadata.json
{
  "client_id": "https://app.example.com/oauth/client-metadata.json",
  "client_name": "Example MCP Client",
  "client_uri": "https://app.example.com",
  "logo_uri": "https://app.example.com/logo.png",
  "redirect_uris": ["http://127.0.0.1:3000/callback", "http://localhost:3000/callback"],
  "grant_types": ["authorization_code"],
  "response_types": ["code"],
  "token_endpoint_auth_method": "none"
}

What each party must do

MCP client

  • Host the metadata document at an HTTPS URL. The client_id must use https and include a path, such as https://example.com/client.json.
  • Include at least client_id, client_name and redirect_uris.
  • Make the client_id inside the document match the document's URL exactly.
  • Optionally authenticate at the token endpoint with private_key_jwt and a published JWKS.

Authorization server

  • Advertise support with client_id_metadata_document_supported: true in the authorization server metadata.
  • Fetch the document when it sees a URL-shaped client_id, and cache it according to HTTP cache headers.
  • Validate that the document is JSON, has the required fields and that its client_id matches the URL exactly.
  • Validate the redirect URI in each authorization request against the document's redirect_uris.
  • Guard the fetch against server-side request forgery, since the URL comes from an unknown client.

Why CIMD beats DCR for MCP

The end-to-end flow

  1. Discover

    401 challenge, protected resource metadata, authorization server metadata.

  2. Choose a registration method

    Pre-registered, CIMD, DCR or manual, in that order of preference.

  3. Check PKCE

    The client confirms code_challenge_methods_supported is present and refuses to continue if it is not.

  4. Authorize

    The client opens the browser with its client_id (the CIMD URL), redirect_uri, scope, state, a PKCE S256 code_challenge and the resource parameter.

  5. Sign in and consent

    The authorization server fetches and validates the client's metadata, shows the user who is asking and for what, authenticates the user and gets consent.

  6. Exchange the code

    The client posts the code with its code_verifier and resource parameter to the token endpoint and receives a short-lived access token (and refresh token).

  7. Call the MCP server

    Every HTTP request carries Authorization: Bearer <token>. The server validates the signature, expiry, scopes and that the token's audience is this server.

authorization request · PKCE and resource indicator
GET https://auth.example.com/authorize
  ?response_type=code
  &client_id=https%3A%2F%2Fapp.example.com%2Foauth%2Fclient-metadata.json
  &redirect_uri=http%3A%2F%2F127.0.0.1%3A3000%2Fcallback
  &scope=files%3Aread
  &state=xyz123
  &code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM
  &code_challenge_method=S256
  &resource=https%3A%2F%2Fmcp.example.com

Tokens, scopes and step-up authorization

Step-up when more access is needed

A client starts with the minimum scope. When a tool needs more, the server answers 403 with insufficient_scope and the full set of scopes it now requires. The client runs the authorization flow again for the larger set, and should limit retries so a refused upgrade does not loop.

403 insufficient_scope
HTTP/1.1 403 Forbidden
WWW-Authenticate: Bearer error="insufficient_scope",
                  scope="files:read files:write",
                  resource_metadata="https://mcp.example.com/.well-known/oauth-protected-resource",
                  error_description="Additional file write permission required"

CIMD security and trust

CIMD moves the trust decision to the authorization server, which has to judge strangers by their domain. These are the risks the specification calls out, and what to do about them.

Implementation checklist

MCP server

  • Serve Protected Resource Metadata (RFC 9728) and send resource_metadata in the 401 challenge.
  • Return 401 for missing or invalid tokens and 403 with insufficient_scope for step-up.
  • Validate signature, expiry, scopes and audience on every request.
  • Use per-tool scopes so read and write capabilities are separate.
  • Log the user, client, tool and outcome of each call.

Authorization server

  • Implement OAuth 2.1 with PKCE (S256) and exact redirect URI matching, and publish code_challenge_methods_supported.
  • Publish authorization server metadata and set client_id_metadata_document_supported to true.
  • Fetch CIMD documents safely, validate them and apply a domain trust policy.
  • Support the resource parameter and issue audience-restricted, short-lived tokens.
  • Keep DCR only if older clients need it.

MCP client

  • Host a stable, valid client metadata document and keep its redirect URIs exact.
  • Follow the priority order: pre-registered, CIMD, DCR, manual.
  • Always use PKCE S256, state and the resource parameter.
  • Store tokens securely, handle 401 and insufficient_scope, and limit retries.

Based on the 2025-11-25 revision of the MCP authorization specification. CIMD is an IETF draft and the protocol is evolving, so check the current specification before building. Examples are illustrative.

Sources

Key concepts

Protected Resource Metadata (RFC 9728)
A document the MCP server publishes naming its authorization servers and supported scopes.
Client ID Metadata Document
A JSON document at an HTTPS URL describing a client: name, logo, redirect URIs and authentication method. The URL is the client_id.
PKCE (S256)
A one-time secret pair that stops an intercepted authorization code from being redeemed by anyone but the original client. Mandatory in MCP.
Resource indicators (RFC 8707)
The resource parameter that ties a token to one specific MCP server, enabling audience validation.
Dynamic Client Registration (RFC 7591)
Runtime registration through an open endpoint. Retained for compatibility, not preferred.
Scopes and step-up
Least-privilege permissions requested up front, with additional scope requested on demand through 403 insufficient_scope.
Token passthrough
Accepting or forwarding tokens meant for another service. Explicitly forbidden.
Confused deputy
A proxy server tricked into using its own privileges for an attacker's request.

Tools & platforms

Identity providers

  • Microsoft Entra ID
  • Okta
  • Auth0
  • Keycloak
  • Google Identity

Standards

  • OAuth 2.1
  • RFC 9728
  • RFC 8707
  • RFC 8414
  • OpenID Connect
  • CIMD draft

Building blocks

  • MCP SDK auth helpers
  • API and MCP gateways
  • MCP Inspector
  • OpenTelemetry

Skills employers look for

Enterprise use cases

Enterprise agent platform

Agents sign in through the corporate identity provider and reach internal MCP servers with each user's own permissions.

Public MCP servers

A service lets any compliant client connect without a manual registration step, using CIMD.

SaaS vendors exposing MCP

A product offers an MCP endpoint that reuses its existing OAuth tenants and consent screens.

Regulated environments

Short-lived, audience-bound tokens and full audit trails per user and per tool.

Common pitfalls

How MrAI.dev helps

We design authorization for your MCP servers end to end: integrating with your identity provider, choosing a registration approach, enforcing per-tool scopes and audience binding, and testing the flow against the attacks that matter before agents reach production data.

Book a discovery call