Skip to main content

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.

Remote transport and auth context

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

TransportTypical 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

  1. Client connects → server returns 401 with WWW-Authenticate pointing at Protected Resource Metadata (PRM).
  2. Client fetches PRM (resource URL, authorization servers, scopes).
  3. Client discovers authorization-server metadata (OIDC / RFC 8414).
  4. Client registers (dynamic or pre-registered) and completes the authorization code flow with PKCE.
  5. 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:

Negative cases

RiskMitigation
Skipping PKCERequire PKCE for public clients
Over-broad scopesLeast privilege; document scopes
Token in logs / LLM contextNever echo tokens to models or stdout
Accepting tokens for the wrong audienceValidate 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…