technical

MCP OAuth Explained: How MCP Server Authentication Works

How MCP OAuth works step by step: the 401, discovery, PKCE and token exchange. Plus how MCPize authenticates hosted servers and issues one token for many.

Oleg Kopachovets
Oleg KopachovetsCEO & Founder
December 29, 20257 min read
Multi-Server OAuth flow showing single authentication providing access to multiple MCP servers

MCP OAuth Explained: How MCP Server Authentication Works#

TL;DR: MCP OAuth is OAuth 2.1 with PKCE, metadata discovery and dynamic client registration, so a client can connect to a remote MCP server it has never seen before. The catch is that every server is its own protected resource, so ten servers mean ten logins. Multi-Server OAuth on MCPize gives you one token that works across all the servers you pick.

The MCP authorization spec gets the security model right. OAuth 2.1, PKCE, refresh tokens, audience-bound tokens. The part people feel day to day is the UX: one consent screen per server, forever.

This post covers both halves. First, how MCP server authentication works under the spec. Then, how MCPize runs it for hosted servers and how a single authorization can cover many of them.

Do MCP Servers Require Authentication?#

It depends on the transport.

A local server that runs over stdio is a child process of your client. It inherits your user account and reads secrets from its own environment, so there is nothing to log in to.

A remote server that speaks Streamable HTTP is a public URL. Anyone who finds it can call it. The MCP spec treats authorization as optional, but for a remote server that touches user data or costs money per call, you want it. The spec defines how: OAuth 2.1, with the MCP server acting as a resource server and a separate authorization server issuing tokens.

How MCP OAuth Works, Step by Step#

Here is the flow a client like Claude or Cursor runs the first time it connects to a protected server:

  1. Unauthenticated call. The client sends a request without a token. The server answers 401 Unauthorized with a WWW-Authenticate header that points to its Protected Resource Metadata (RFC 9728).
  2. Discovery. The client reads that metadata to find the authorization server, then fetches the authorization server's own metadata (RFC 8414) to learn its endpoints and supported scopes.
  3. Client registration. The client registers itself, either through Dynamic Client Registration (RFC 7591) or, under the 2025-11-25 spec, by using a URL to a Client ID Metadata Document as its client_id.
  4. Consent with PKCE. The client opens the browser to the authorize endpoint with a PKCE code_challenge and a resource parameter (RFC 8707) that names the server it wants. The user signs in and approves.
  5. Token exchange. The client trades the authorization code and the PKCE verifier for an access token and a refresh token.
  6. Authenticated calls. Every MCP request now carries Authorization: Bearer <token>. The server checks the token's audience to make sure it was issued for this server and not another one.

The audience check in step 6 is what makes per-server tokens safe. A token issued for one server cannot be replayed against a different one.

How MCPize Handles MCP Server Authentication#

Every server hosted on MCPize is reachable at https://<slug>.mcpize.run/mcp, and every request goes through the MCPize gateway first. The gateway is the resource server, so server authors never write auth code.

What the gateway and the MCPize authorization server do today:

  • Two kinds of bearer token. The gateway accepts either an OAuth access token or an MCPize API key in the Authorization: Bearer header. API keys suit scripts and CI. OAuth suits desktop clients.
  • Spec-shaped discovery. Unauthenticated requests get a 401 with a resource_metadata pointer, and both RFC 9728 and RFC 8414 metadata documents are published.
  • Registration without setup. Dynamic Client Registration and Client ID Metadata Documents are both supported, so clients register on first connect.
  • PKCE only, public clients. The authorize endpoint requires S256 PKCE, and the token endpoint expects public clients with no client secret.
  • Scopes. mcp:tools, mcp:resources and mcp:prompts.
  • Token lifetimes. Access tokens last 24 hours. Refresh tokens last 30 days and rotate on every use: the old one is revoked the moment you get a new one.

If you host an MCP server on MCPize, all of this is already in front of it.

The Problem: N Servers = N Logins#

Here is what standard MCP OAuth looks like once you use more than a couple of servers:

ServersLogin FlowsYour Experience
11Fine
55Annoying
1010Frustrating
20+20+"I'll just use API keys"

Every MCP server is a separate protected resource, and every resource needs its own authorization. Technically correct, practically painful.

Claude Desktop and Cursor hide some of this, but under the hood each server still has its own token and its own auth state.

The Solution: Global Authorization#

Multi-Server OAuth changes one thing: you authorize without naming a single server.

A normal request names one server:

resource=https://github-mcp.mcpize.run

For global authorization, leave the resource parameter out of the authorize request.

The authorization server sees no target server and shows you a picker instead.

How It Works#

  1. Start global auth. No specific server in the authorize request.
  2. Pick servers. Check the ones you want.
  3. Get one token. It lists every server you picked.
  4. Use it everywhere. Any server you selected accepts it.

One flow instead of ten.

What Changes in the Token#

A single-server token names one server in its audience:

{
  "aud": "3f9c2b1e-...",
  "scope": "mcp:tools mcp:resources mcp:prompts"
}

A multi-server token names all of them:

{
  "aud": ["3f9c2b1e-...", "a71d04c8-...", "c5e8f930-..."],
  "scope": "mcp:tools mcp:resources mcp:prompts"
}

The difference is the aud claim: a string for one server, an array for many. The server list is also stored with the refresh token on the authorization server, so a refresh returns a token for the same set of servers.

Same JWT, same validation.

Token Validation#

When a server receives this token, validation stays simple:

def validate_token(token, my_server_id):
    audience = decode_jwt(token)['aud']

    if isinstance(audience, list):
        return my_server_id in audience
    return my_server_id == audience

If your server is in the audience, the token is valid for you.

Security: Same Model, Better UX#

The obvious concern: doesn't one token for many servers increase risk?

ConcernReality
Bigger blast radius?Yes, somewhat. But you would hold N tokens anyway.
Easier to steal?Same token format, same transport security.
Harder to revoke?No. Revoke the token and every server loses access.

You are consolidating access you already had, not adding new access.

Built-in protections:

  • 24-hour access token lifetime
  • 30-day refresh tokens that rotate on every use
  • Audience checks on every request, so a token only works on the servers you picked

When This Makes Sense#

Good fit:

  • Developers with 5+ MCP servers
  • Teams sharing a common toolset
  • Server bundles rolled out to a whole company
  • Anyone tired of re-authenticating

Skip it if:

  • You have one server
  • Your servers have different trust levels
  • You need maximum isolation

The sweet spot is several servers, the same trust level and the same user.

Implementation for MCP Clients#

If you are building an MCP client and want to support this, here is what you need.

Detect Support#

The Protected Resource Metadata that MCPize serves without a server identifier lists mcp:global in its scopes:

const metadata = await fetch(
  'https://<gateway>/.well-known/oauth-protected-resource'
).then(r => r.json())

const supportsMultiServer = metadata.scopes_supported?.includes('mcp:global')

Start Global Auth#

const authUrl = new URL(authServerMetadata.authorization_endpoint)
authUrl.searchParams.set('client_id', clientId)
authUrl.searchParams.set('response_type', 'code')
authUrl.searchParams.set('redirect_uri', redirectUri)
authUrl.searchParams.set('code_challenge', codeChallenge)
authUrl.searchParams.set('code_challenge_method', 'S256')
// No resource param = global auth

Store the Token#

const tokenData = {
  access_token: tokens.access_token,
  refresh_token: tokens.refresh_token,
  expires_at: Date.now() + tokens.expires_in * 1000,
}
await secureStore.set('mcp_token', JSON.stringify(tokenData))

Keep tokens in the OS keychain or another secure store, not in plain browser storage.

FAQ#

Is this RFC compliant?#

Yes. RFC 7519 allows the aud claim to be an array, and RFC 8707 lets a client request access to more than one resource. Nothing here bends a spec.

Can I use both single and multi-server tokens?#

Yes. Use multi-server tokens for convenience and single-server tokens for sensitive work.

What if I need to add a server later?#

Authorize again. The server list is fixed at consent time on purpose, so a token never gains access silently.

Is this part of the official MCP spec?#

Not yet. It is an implementation pattern that works inside the existing specs. Array audiences are standard OAuth.

The Bottom Line#

MCP OAuth is solid security with a UX cost that grows with every server you add. Multi-Server OAuth keeps the security model and removes the repeated logins.

What to remember:

  • Remote MCP servers authenticate with OAuth 2.1, PKCE and audience-bound tokens
  • Leave out the resource parameter to start global authorization on MCPize
  • A multi-server token has an array audience
  • Everything else stays the same

If you run more than a handful of MCP servers, this is the difference between tolerable and tedious.

Related:

Questions about MCP OAuth? Join MCPize Discord for discussions with the community.

Enjoyed this article?

Share it with your network

Oleg Kopachovets

Oleg Kopachovets

CEO & Founder

CEO & Founder of MCPize and ProCoders. Been tinkering with neural networks since the early 2000s, training LLMs since 2020. Now building the MCP ecosystem where developers ship servers and earn.

Stay Updated

Get the latest MCP tutorials, product updates, and developer tips delivered to your inbox.

No spam, ever. Unsubscribe anytime.

Related Articles

Continue exploring similar topics

View all articles