Understanding Authorization in MCP
Learn how to implement secure authorization for MCP servers using OAuth 2.1 to protect sensitive resources and operations.
Adapted from Understanding Authorization in MCP. Normative detail: Authorization specification.

OAuth flows apply primarily to HTTP-based (remote) transports.
When to use authorization
Use authorization when:
- The server accesses user-specific data (email, documents, databases)
- You must audit who performed which actions
- APIs require user consent
- Enterprise environments demand strict access control
- You need per-user rate limiting or usage tracking
Local (stdio) vs remote
| Transport | Typical auth approach |
|---|---|
| stdio (local) | OS user + env credentials / embedded libraries; OAuth browser flows are often unnecessary |
| Streamable HTTP (remote) | OAuth 2.1 between client and remotely hosted server |
High-level flow
- Client connects → server returns 401 with
WWW-Authenticatepointing at Protected Resource Metadata (PRM). - Client fetches PRM (resource URL, authorization servers, scopes).
- Client discovers authorization-server metadata (OIDC / RFC 8414).
- Client registers (dynamic or pre-registered) and completes the authorization code flow with PKCE.
- Client retries MCP requests with a bearer access token.
Example challenge:
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer realm="mcp",
resource_metadata="https://your-server.com/.well-known/oauth-protected-resource"
Example PRM document:
{
"resource": "https://your-server.com/mcp",
"authorization_servers": ["https://auth.your-server.com"],
"scopes_supported": ["mcp:tools", "mcp:resources"]
}
Enterprise extensions
Beyond core auth, see:
- Authorization extensions overview
- OAuth client credentials (machine-to-machine)
- Enterprise-managed authorization
Negative cases
| Risk | Mitigation |
|---|---|
| Skipping PKCE | Require PKCE for public clients |
| Over-broad scopes | Least privilege; document scopes |
| Token in logs / LLM context | Never echo tokens to models or stdout |
| Accepting tokens for the wrong audience | Validate aud / resource indicators |
| Local server pretending OAuth is “done” | Still sandbox filesystem and secrets |
Discussion
Comments
Share feedback or questions about this page. No account required.
Loading comments…