CONCEPT Remote MCP servers use OAuth 2.1
Authorization in MCP is defined at the transport level for HTTP-based transports, and it's optional — but when a remote server protects its resources, the spec says it SHOULD conform to the MCP authorization model, which is built on OAuth 2.1. (STDIO servers are the exception: they SHOULD NOT use this flow and instead read credentials from the environment.) The roles map cleanly onto OAuth:
| MCP role | OAuth 2.1 role | Responsibility |
|---|---|---|
| MCP server | Resource server | Accepts & validates access tokens on each request |
| MCP client (your host) | Client | Obtains tokens, sends Authorization: Bearer |
| Authorization server | Authorization server | Authenticates the user, issues tokens |
The client doesn't need the auth server configured up front. The server advertises it: an unauthenticated
request gets a 401 with a WWW-Authenticate header pointing at Protected Resource
Metadata (RFC 9728), which names the authorization server. The client discovers the auth server's metadata
(RFC 8414), runs the OAuth 2.1 flow with PKCE (MUST), and returns with a token.
Authorization: Bearer <token> — never in the URL query string (MUST NOT),
where they'd leak into logs and referrers. HTTPS is required for all auth endpoints.CONCEPT Least privilege: scopes + audience binding
Two mechanisms keep a token from becoming a skeleton key.
Scoped, least-privilege access. The spec's own guidance warns against publishing every
scope in scopes_supported and requesting them all up front — a broad token (files:*,
admin:*) means a bigger blast radius if it leaks, noisier audit trails, and consent fatigue.
Prefer a minimal initial scope and incrementally elevate (the server issues
a WWW-Authenticate challenge naming the extra scope only when a privileged operation is first
attempted). Servers may issue a subset of what was requested.
Token audience binding. This is the load-bearing rule. Clients MUST
include the resource parameter (RFC 8707 Resource Indicators) in both authorization and token
requests, naming the specific MCP server the token is for. Servers MUST validate
that a presented token was issued for them — and MUST reject tokens whose audience
doesn't include them. This stops a token minted for one service from being replayed against another.
DIAGRAM Discovery-driven OAuth 2.1 flow
CODE Sending a scoped, audience-bound token
The token request pins the resource (audience) and asks for the narrowest scope; every MCP
request then carries the bearer token in the header.
# Token request — resource param binds the token to THIS server; # scope is minimal, not the whole catalog. POST /token HTTP/1.1 grant_type=authorization_code code="..." code_verifier="..." # PKCE (required) resource="https://mcp.example.com/mcp" # RFC 8707 audience scope="mcp:tools-basic" # least privilege, elevate later # Every MCP request — bearer in the HEADER, never the URL. GET /mcp HTTP/1.1 Host: mcp.example.com Authorization: Bearer eyJhbGciOiJIUzI1NiIs... # Server MUST: validate the token was issued for it (audience), # return 401 on invalid/expired, 403 on insufficient scope.
TRADE-OFFS Broad token vs. scoped + audience-bound
✅ Minimal scope + audience binding
- A leaked token unlocks little
- Token can't be replayed across services
- Cleaner audit trail per operation
- Short-lived tokens + refresh rotation limit theft impact
⚠️ One broad, long-lived token
- Fewer consent prompts up front
- But: leak = full-scope compromise
- Reusable across services if audience unchecked
- Users decline dialogs listing excessive scopes
EXAM TRAPS
Authorization: Bearer. URLs leak into logs and referrers.PRACTICE
Q1 · How does a client discover how to authenticate to a remote MCP server?
It makes a request; the server replies 401 with a WWW-Authenticate header
pointing to its Protected Resource Metadata (RFC 9728), which names the authorization server. The client then
fetches the auth server's metadata (RFC 8414) and runs the OAuth 2.1 flow with PKCE. No pre-configuration
needed.
Q2 · What does the resource parameter do and why is it mandatory?
It's the RFC 8707 resource indicator that binds the token to a specific MCP server (its audience). Clients MUST send it on authorization and token requests; servers MUST validate that presented tokens were issued for them. This prevents a token minted for one service being replayed against another — the core defense against cross-service token misuse.
Q3 · Why prefer minimal scope over requesting everything up front?
Broad tokens expand the blast radius of a leak, obscure per-operation audit trails, and
cause consent fatigue (users decline dialogs listing excessive scopes). Least-privilege scoping — a minimal
initial scope with incremental elevation via WWW-Authenticate scope challenges — constrains
compromise impact and keeps consent meaningful.