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
Challenge
The client calls the MCP server without a token and gets a 401 with a pointer to the server's resource metadata.
Discover
It reads the protected resource metadata, then the authorization server's metadata.
Identify itself
The client presents its CIMD URL as the client_id, or uses pre-registration or DCR if CIMD is unavailable.
Authorize
The user signs in and consents, with PKCE and a resource parameter binding the request to this server.
Get a token
The client exchanges the code for a short-lived access token scoped and audience-bound to the server.
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.
| Standard | What 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 Metadata | How an MCP server tells clients which authorization server to use. Required for servers. |
| RFC 8414 and OpenID Connect Discovery | How a client finds the authorization server's endpoints and capabilities. Clients must support both. |
| RFC 8707, Resource Indicators | The resource parameter that binds a token to one specific MCP server. |
| OAuth Client ID Metadata Documents | An IETF draft: a client's client_id is an HTTPS URL that points to its metadata. The recommended registration approach. |
| RFC 7591, Dynamic Client Registration | The 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.
Call the server
The client sends a request to the MCP endpoint with no token.
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.
Read resource metadata
The client fetches the Protected Resource Metadata document, which lists authorization_servers.
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.
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer resource_metadata="https://mcp.example.com/.well-known/oauth-protected-resource",
scope="files:read"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"]
}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.
| Approach | How it works and its trade-offs |
|---|---|
| Pre-registration | A 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:
| Order | Rule |
|---|---|
| 1 | Use pre-registered client information if the client has it for this server. |
| 2 | Otherwise use CIMD if the authorization server advertises client_id_metadata_document_supported. |
| 3 | Otherwise fall back to Dynamic Client Registration if the metadata lists a registration_endpoint. |
| 4 | Otherwise 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.
{
"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
- No open write endpoint. DCR lets anonymous callers create records. CIMD only causes a validated read.
- No per-client storage. The server keeps a cache, not a database of registrations to expire and clean up.
- Stable, verifiable identity. The same URL is the same client everywhere, and the domain is visible to the user and to policy.
- Easy to update. The client changes its redirect URIs or logo by editing one document.
The end-to-end flow
Discover
401 challenge, protected resource metadata, authorization server metadata.
Choose a registration method
Pre-registered, CIMD, DCR or manual, in that order of preference.
Check PKCE
The client confirms code_challenge_methods_supported is present and refuses to continue if it is not.
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.
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.
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).
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.
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.comTokens, scopes and step-up authorization
- Send the token on every request. Use the Authorization: Bearer header on each HTTP request, never in the URL query string.
- Bind tokens to the server. The client sends the resource parameter (RFC 8707) in both the authorization and token requests. The server rejects tokens not issued for it.
- Never pass tokens through. A server must not accept tokens meant for another service, and must not forward the client's token to a downstream API. Use a separate token for the downstream call.
- Keep tokens short-lived. Short access token lifetimes limit damage from a leak. Public clients must have refresh tokens rotated.
- Ask for the minimum scope. Use the scope from the WWW-Authenticate challenge, otherwise scopes_supported, and add more only when needed.
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.
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.
- Server-side request forgery. The authorization server fetches a URL supplied by an unknown client. Block private and internal addresses, limit size and time, follow redirects carefully and cache sensibly.
- Localhost impersonation. CIMD alone cannot stop an attacker who uses a legitimate client's metadata URL with their own localhost redirect and receives the code. Show the redirect host prominently, warn on localhost-only redirects and consider attestation for sensitive servers.
- Phishing through client names. A document can claim any name or logo. Display the client's hostname, not just its self-declared name.
- Trust policy is yours. Allowlist trusted domains for protected servers, accept any HTTPS client_id for open ones, or apply reputation and domain-age checks.
- Exact redirect URI matching. Compare the requested redirect URI against the document's list with no wildcards, and verify state.
- Confused deputy. A proxy MCP server using a static client ID with a third-party authorization server must obtain user consent for each client it registers dynamically.
- Token passthrough. Do not accept tokens issued to someone else, and do not relay yours downstream.
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
- MCP specification: Authorization (2025-11-25)Model Context Protocol
- MCP specification: Authorization (draft)Model Context Protocol
- OAuth Client ID Metadata Document (IETF draft)IETF OAuth Working Group
- RFC 9728: OAuth 2.0 Protected Resource MetadataIETF
- RFC 8707: Resource Indicators for OAuth 2.0IETF
- RFC 8414: OAuth 2.0 Authorization Server MetadataIETF
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
Standards
Building blocks
Skills employers look for
- Explaining the roles of client, resource server and authorization server in MCP.
- Implementing discovery with protected resource metadata and WWW-Authenticate challenges.
- Choosing between pre-registration, CIMD and DCR, and implementing CIMD safely.
- Applying PKCE, exact redirect matching, resource indicators and audience validation.
- Designing per-tool scopes and step-up authorization.
- Defending against SSRF, localhost impersonation, confused deputy and token passthrough.
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
- Using shared API keys on remote servers — they cannot express who is calling or what they may do.
- Skipping audience validation — a server that accepts any valid token can be handed one issued for a different service.
- Fetching CIMD URLs without SSRF controls — the authorization server becomes a proxy into your internal network.
- Trusting the client's self-declared name — show the domain and redirect host to users, and treat localhost redirects with suspicion.
- Over-broad scopes up front — start minimal and step up when a tool needs more.
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