Lesson 36.5 · 5 of 5 · 8 min read · Reviewed 24 Nov 2026
MCP authorization: OAuth 2.1 and client identity
By the end, you can
- Explain how a remote MCP server authorizes a client with OAuth 2.1.
- Name the authorization mistakes that turn an MCP server into a security hole.
A local stdio server runs with your own permissionsPermission rule: An allow, ask or deny rule that controls which tools, commands or paths a coding agent may use., so it needs no login. A remote MCPModel Context Protocol (MCP): An open protocol that standardises how AI applications connect to tools, data and prompts through servers. server over Streamable HTTP (35.4) serves many users, so it has to know who is calling and what they may do. MCP doesn’t invent its own scheme. It uses OAuthOAuth: A standard for granting an application limited access to a user’s account on another service without sharing their password. 2.1, the same standard behind “Sign in with…” buttons, with a few rules that suit agentsAgent: A system where a model decides its own next steps, calling tools in a loop until the task is done..
The three parties
| Role in OAuth | In MCP | Job |
|---|---|---|
| Resource server | The MCP server | Holds the tools and data; accepts only valid tokens |
| Authorization server | Your identity provider (for example your company SSO) | Logs the user in, asks for consent, issues tokens |
| Client | The MCP client inside the host app | Gets a token for the user and sends it with each request |
Keeping the authorization server separate means the MCP serverMCP server: A program that exposes tools, resources and prompts to AI applications using the Model Context Protocol. never sees a password. It only checks tokensToken: The unit a model reads and writes: a word, part of a word, a space or a symbol, mapped to an integer id..
The flow, step by step
- The client calls without a token. The server replies
401 Unauthorizedwith aWWW-Authenticateheader that points to its protected resource metadata (RFC 9728). - The client reads that metadata. It names the authorization server(s) the MCP server trusts and the scopes it understands.
- The client identifies itself. In current MCP it uses a Client ID Metadata DocumentClient ID Metadata Document: A JSON document at an HTTPS URL that describes an OAuth client; the URL itself is the client id.: its client id is an HTTPS URL, and the document at that URL lists the client’s name, logo and allowed redirect addresses. The authorization server fetches it, so no registration step is needed for every server. Dynamic client registration, the older way, is deprecatedDeprecation: Announcing that a model or feature will be retired on a set date. in the 2026-07-28 revision but still works for now.
- The user logs in and consents in the browser, using authorization code flow with PKCE, which stops a stolen code being redeemed by someone else.
- The client checks the issuer (
iss) on the response matches the authorization server it expected, then swaps the code for an access token. It asks for the token with a resource indicator (RFC 8707) naming this one MCP server. - Every MCP request carries the token in an
Authorization: Bearerheader. The server validates it each time.
If a later tool needs a wider scope, the server can answer with an error that asks for it, and the client asks the user for just that extra consent. Users grant what a task needs, not everything up front.
What the server must check on every request
| Check | Why |
|---|---|
| Signature and expiry | The token is genuine and still valid |
| Audience is this server | A token issued for another service must not work here |
| Issuer is a trusted authorization server | Tokens from anywhere else are rejected |
| Scope covers this tool | A read-only token cannot call delete_record |
Map scopes onto tools deliberately. A simple pattern is one scope per risk level, such as tickets.read and tickets.write, and a tool list filtered by what the token allows (34.5).
The mistakes that matter
- Token passthroughToken passthrough: Forwarding a token you received to another service that it was not issued for.. The server forwards the client’s token to a downstream API. That token was issued for the MCP server, not for the API, so audience checks break and one leaked token works in more places. Instead, have the MCP server get its own token for the downstream API, ideally by token exchangeToken exchange: An OAuth flow (RFC 8693) that swaps one token for another with a different audience and narrower scope. on behalf of the same user (65.10).
- Skipping the audience check. Any valid token from your identity provider then works on every server, including tokens a malicious server collected from its own users.
- Long-lived tokens in config files. Use short-lived access tokens and refresh tokens held by the host, never a token pasted into
.mcp.json(36.2). - One shared service key. The server calls everything as itself, so every user gets the server’s full power. That is the confused deputyConfused deputy: A program with more authority than its caller that is tricked into using that authority for the caller. problem.
- Trusting tool descriptions from an unvetted server. Authorization proves who the user is. It says nothing about whether the server is honest (65.3).
In practice
Most teams don’t write this by hand. MCP SDKs include auth helpers, and identity providers increasingly support Client ID Metadata Documents and resource indicators directly. Your design job is the policy: which identity provider, which scopes per tool, how long tokens live, and which downstream calls need their own exchanged token.
Key points
- A remote MCP server is an OAuth resource server. It publishes metadata that names its authorization server, and the client gets a token from there.
- Clients identify themselves with a Client ID Metadata Document: an HTTPS URL that describes the client. Dynamic client registration is deprecated in the 2026-07-28 revision.
- Every token is bound to one server (its audience) and must be checked for that audience, issuer and scope on every request.
- Never pass the user's token through to a downstream API. Exchange it for a new token scoped to that API.
Map the authorization flow for a remote MCP server
Trace how a client gets and uses a token for one remote MCP server, and write the server's token checks and scope map.
You will have: A one-page design: the flow from 401 to first tool call, the four checks the server runs on every request, a scope for each tool, and how downstream calls get their own tokens.
Steps
- Pick a remote MCP server you use or could build, for example a ticketing server with read and write tools.
- Write the flow as numbered steps: unauthenticated call, 401 with resource metadata, client metadata document, sign-in with PKCE, issuer check, token with a resource indicator, authorized call.
- List the checks the server runs on every request: signature and expiry, audience, issuer and scope.
- Give every tool a scope, such as tickets.read or tickets.write, and mark which tools also need a human approval.
- For any downstream API the server calls, write how it gets a token for that API by token exchange instead of passing the client's token through.
Done when
- Every tool has exactly one scope and the write tools are listed separately.
- The design names the audience check and rejects token passthrough in writing.
- Someone else can follow the flow without asking what happens between the 401 and the first tool call.
Docs: MCP specification: Authorization · MCP specification: Security best practices
Finished the chapter? Take the chapter check.