What MCP auth is, and when it applies
MCP auth is the Authorization specification of the Model Context Protocol: the rules for how an MCP client gets permission to call a protected MCP server on a user's behalf. It is not a new protocol. It is a selected subset of OAuth 2.1 and four companion standards: Authorization Server Metadata (RFC 8414), Protected Resource Metadata (RFC 9728), Dynamic Client Registration (RFC 7591) and the OAuth Client ID Metadata Document draft.
Authorization is optional in MCP. When it is supported, servers on an HTTP-based transport SHOULD conform to the specification, and servers on the stdio transport SHOULD NOT: a local server takes its credentials from the environment instead. Everything below is about remote servers reached over HTTP. Requirements are quoted at the strength the specification gives them (MUST, SHOULD, MAY); where something is our recommendation, it says so.
The three roles
- MCP server: the resource server. A protected MCP server acts as an OAuth 2.1 resource server. It accepts requests carrying access tokens, validates them, and tells clients where to get one. It does not have to issue tokens itself.
- MCP client: the OAuth client. The MCP client (the agent host, IDE or app the agent runs in) acts as an OAuth 2.1 client making requests on behalf of a resource owner, usually the user who connected the server.
- Authorization server: the token issuer. The authorization server interacts with the user if needed and issues access tokens for the MCP server. It may be hosted alongside the MCP server or be a separate identity provider; the specification leaves its implementation out of scope but requires it to implement OAuth 2.1 for both confidential and public clients.
The flow, step by step
- The client calls without a token and gets a 401. The server answers
401 Unauthorized. It SHOULD include aWWW-Authenticate: Bearerheader carryingresource_metadata(the URL of its Protected Resource Metadata document) and ascopeparameter naming the scopes the request needs. - The client reads the server's Protected Resource Metadata. MCP servers MUST implement RFC 9728, and the document MUST list at least one entry in
authorization_servers. Clients use the URL from the header when present, otherwise they MUST try the well-known URIs in order: at the endpoint's path (/.well-known/oauth-protected-resource/mcpfor a server at/mcp), then at the root (/.well-known/oauth-protected-resource). - The client discovers the authorization server's endpoints. Authorization servers MUST offer RFC 8414 metadata or OpenID Connect Discovery, and clients MUST support both. For an issuer without a path, clients try
/.well-known/oauth-authorization-server, then/.well-known/openid-configuration; for an issuer with a path, they try three locations in the order the specification lists. - The client identifies itself. Clients that support every option SHOULD use, in order: pre-registered client details, a Client ID Metadata Document when the authorization server advertises
client_id_metadata_document_supported, Dynamic Client Registration when it advertises aregistration_endpoint, and finally asking the user to enter client details. - The client sends the user to authorize, with PKCE and the resource parameter. Clients MUST use PKCE with the
S256method when technically capable, and MUST refuse to proceed if the authorization server's metadata has nocode_challenge_methods_supported. They MUST includeresource, set to the MCP server's canonical URI (for examplehttps://mcp.example.com/mcp), in both the authorization request and the token request, whether or not the authorization server supports it. - The client exchanges the code for a token. The token request carries the PKCE
code_verifierand the sameresource. Authorization servers SHOULD issue short-lived access tokens, and for public clients MUST rotate refresh tokens. - Every request carries the token in the header. Clients MUST send
Authorization: Bearer <access-token>on every HTTP request, even within one logical session, and MUST NOT put tokens in the query string.
Client registration: CIMD, pre-registration or DCR
Most MCP clients and servers have never met before a user connects them, so OAuth's usual step of registering the client ahead of time doesn't fit. The specification offers three ways around it.
- Client ID Metadata Documents (CIMD). The default for clients and servers with no prior relationship; clients and authorization servers SHOULD support it. The
client_idis an HTTPS URL with a path, pointing at a JSON document that MUST includeclient_id,client_nameandredirect_uris, and whoseclient_idMUST match the URL exactly. The authorization server fetches the document, validates it, and MUST check the request's redirect URI against it. - Pre-registration. For a client and server that already know each other: a client ID (and secret, if any) hardcoded in the client for that authorization server, or entered by the user after registering a client through the server's own configuration page. Clients SHOULD support supplying static credentials this way.
- Dynamic Client Registration (DCR). RFC 7591, where the client posts its details to a registration endpoint and gets a client ID back. It is now a MAY, kept for backwards compatibility with earlier versions of the MCP Authorization specification, which leaned on it.
Scopes, 403s and step-up authorization
The specification's scope rules are built so a client starts with little and asks for more only when a tool needs it.
- What the client asks for first. Clients SHOULD request the
scopefrom the 401'sWWW-Authenticateheader if there is one; otherwise every scope in the server'sscopes_supported, or noscopeparameter at all if that field is undefined. Because of that fallback,scopes_supportedis meant to hold the minimal set needed for basic use, not every scope the server has. - What the server says when a token isn't enough. A request with a valid token but too little scope SHOULD get
403 ForbiddenwithWWW-Authenticate: Bearer error="insufficient_scope", thescopeneeded, andresource_metadata. The specification recommends listing the scopes already granted alongside the new ones, so the client doesn't lose permissions when it re-authorizes. - How the client steps up. Clients acting for a user SHOULD re-authorize with the larger scope set and retry, a limited number of times, tracking upgrade attempts so the same operation doesn't loop. Clients acting on their own behalf with
client_credentialsMAY step up or abort.
What an MCP server must get right
- Publish Protected Resource Metadata. Serve the RFC 9728 document with at least one authorization server, and point to it from every 401 in
WWW-Authenticate. - Validate every token, and its audience. Validate access tokens as OAuth 2.1 Section 5.2 describes, and accept only tokens issued specifically for this server, for example by checking the audience claim. Invalid or expired tokens MUST get a 401.
- Never pass the client's token through. Servers MUST NOT accept or transit any other tokens. If a tool calls an upstream API, the server acts as an OAuth client to that API with its own, separate token.
- Return the right status codes. 401 when authorization is required or the token is invalid, 403 for insufficient scope or permissions, 400 for a malformed authorization request.
- Keep tokens out of logs and caches. Clients and servers MUST store tokens securely. A token cached or logged on the server can be replayed in requests that look legitimate.
- If you proxy a third-party API, ask for consent yourself. An MCP proxy server that uses a static client ID with a third-party authorization server MUST obtain user consent for each dynamically registered client before forwarding, or it can become a confused deputy. Our MCP server security guide covers this and the rest of the specification's threat list.
Applying it to an MCP server whose tools send email
Scopes are where MCP auth meets the risk of a send tool. These are our recommendations, built on the mechanisms above.
- Keep `scopes_supported` to reading and drafting. Since a client with no challenge falls back to requesting everything in
scopes_supported, leave send scopes out of it. An agent connecting for the first time then can't email anyone until a send is actually attempted. - Challenge per kind of send. Give a single transactional send and a list broadcast different scopes, and answer each with its own 403
insufficient_scopechallenge, so the user consents to a broadcast as a separate decision. - Check permissions in the tool, not only in the token. A token's scopes say what the client was granted; the server still decides who a given call may email and from which sending domain.
- Show the redirect host and client name on consent. If you run the authorization server and accept Client ID Metadata Documents, the specification requires showing the redirect URI's hostname and recommends extra warnings for
localhost-only redirect URIs, which any process on the user's machine can claim. For a server that can send mail as the user, that screen is the last check before an unknown client gets the right to send. - For agents with no user present, check the extensions. The core flow assumes a user in a browser. The
modelcontextprotocol/ext-authrepository holds optional authorization extensions, among them OAuth Client Credentials for machine-to-machine access; check its current status there, and check your client's and authorization server's documentation for whether they support it, before designing around it.
Common MCP auth failures
- The client never finds the authorization server. The 401 has no
WWW-Authenticateheader withresource_metadata, and neither well-known URI serves the metadata. Check both paths, including the one with the MCP endpoint's path appended. - The client refuses to start the flow. The authorization server's metadata lacks
code_challenge_methods_supported, so a conforming client assumes no PKCE support and stops. OpenID providers MUST include the field for MCP compatibility. - Tokens are rejected right after authorization. The token's audience doesn't match the server, often because the
resourcevalue differs from the server's canonical URI (a trailing slash, a different path or host). The specification recommends the form without a trailing slash. - The redirect fails. Authorization servers MUST match redirect URIs exactly against the registered ones, and every redirect URI MUST be
localhostor HTTPS. - The user is asked to sign in again and again. The server's 403 challenges list only the newly needed scope, so each re-authorization drops what was granted before. Include the existing relevant scopes in the challenge.
Sources
- Model Context Protocol: Authorization (2025-11-25)
- Model Context Protocol: Security Best Practices (2025-11-25)
- MCP Authorization Extensions (modelcontextprotocol/ext-auth)
- RFC 9728: OAuth 2.0 Protected Resource Metadata
- RFC 8414: OAuth 2.0 Authorization Server Metadata
- RFC 8707: Resource Indicators for OAuth 2.0
- OAuth Client ID Metadata Document (draft-ietf-oauth-client-id-metadata-document-00)
- OAuth 2.1 (draft-ietf-oauth-v2-1-13)