Skip to main content
On this page

You have an MCP server with useful tools, but you do not want just anyone to call them.

Maybe those tools can read private data, update an account, or perform actions on behalf of a user. The server needs a way to decide who is allowed to access them.

That is where OAuth comes in.

For protected MCP servers, the authorization specification builds on OAuth 2.1. If you have worked with OAuth 2.0 before, most of the model will already be familiar. OAuth 2.1 narrows that model to a smaller set of modern authorization patterns.

You do not need to relearn OAuth to work with MCP. You need to understand what OAuth 2.1 changes and how MCP uses it when a client connects to a protected server.

This article walks through those changes, shows how they fit an MCP authorization flow, and explains the discovery and resource rules MCP adds on top.

OAuth 2.1 is a consolidation, not a reinvention​

OAuth 2.1 can sound like a major new version of OAuth, but the underlying model has not changed.

OAuth 2.0 gave developers a flexible framework for letting applications access protected resources on a user's behalf. Over time, security guidance refined how that framework should be used and moved developers away from older patterns.

OAuth 2.1 brings that guidance together. It is still an IETF Internet-Draft rather than a published RFC, and the MCP specification references a specific draft version, but the rules it collects are already established best practice.

If you already work with a modern OAuth 2.0 implementation, the roles remain familiar. A client requests access, an authorization server handles authorization and issues tokens, and a resource server accepts those tokens to protect its APIs.

In an MCP setup, the roles map directly:

OAuth roleIn MCPWhat it does
ClientMCP clientRequests access
Authorization serverYour identity providerHandles authorization and issues tokens
Resource serverMCP serverAccepts the access token and protects its tools

OAuth 2.1 changes the set of patterns those components are expected to use.

The OAuth 2.1 changes you see in MCP​

OAuth 2.1 keeps the same basic authorization model but tightens several parts of the flow and removes older options.

For MCP, those changes mostly affect how the client starts authorization, receives the user back, and handles credentials afterward.

The authorization code flow uses PKCE​

Suppose an MCP client needs permission to connect to a protected server.

The client sends the user to the authorization server, where they sign in and approve access. When that is complete, the browser returns to the client with an authorization code.

The client then exchanges that code for tokens.

PKCE adds an extra check so the authorization server can verify that the client exchanging the code is the same client that started the flow.

Before sending the user to the authorization server, the client creates a random value called a code_verifier. From that value, it creates a code_challenge.

Deriving the PKCE challenge
  1. code_verifier
  2. SHA-256, then Base64URL
  3. code_challenge

The client sends the challenge with the authorization request and keeps the verifier.

When the authorization code comes back, the client sends the original verifier during the token exchange. The authorization server creates the challenge again and checks that it matches the one from the original request.

An intercepted authorization code is therefore not enough on its own.

OAuth 2.1 makes PKCE part of the normal authorization code flow rather than an optional protection added separately. MCP goes one step further: a client must use the S256 method, and must refuse to continue if the authorization server's metadata doesn't advertise PKCE support in code_challenge_methods_supported.

Tokens no longer return directly through the browser​

Older OAuth 2.0 applications could use the implicit grant, where an access token was returned directly through the browser.

OAuth 2.1 removes that option.

Instead, the browser returns with an authorization code, and the client exchanges that code for an access token in a separate request:

Implicit grant versus authorization code
  1. Implicit grant (removed)
    1. Browser
    2. Authorization server
    3. Access token returned to the browser
    Authorization code (OAuth 2.1)
    1. Browser
    2. Authorization server
    3. Authorization code returned to the client
    4. Client calls the token endpoint
    5. Access token

For an MCP client, the browser is still used for login and authorization, but the access token is obtained through the token endpoint rather than being returned in the browser redirect.

The client does not collect the user's password​

OAuth 2.0 also included the Resource Owner Password Credentials grant.

That flow allowed an application to ask the user for a username and password and exchange those credentials for a token.

OAuth 2.1 removes it.

An MCP client should not collect the user's account password itself. Instead, it sends the user to the authorization server and lets that server handle authentication.

Login methods such as MFA, passkeys, and other authentication requirements stay with the authorization server. The MCP client receives tokens that represent the access that was granted, not the user's password.

Redirects must go back to the expected callback​

Once authorization is complete, the authorization server needs to return the user to the client.

It does that using the client's redirect URI, for example http://127.0.0.1:8765/callback.

OAuth 2.1 expects redirect URIs to match the registered value exactly. The one exception is a native app's loopback address, where the authorization server must allow the port to vary.

If the registered callback is https://client.example.com/oauth/callback, the authorization server should not accept https://client.example.com/anything-else simply because both URLs use the same host.

For an MCP client, the practical rule is to register the callback it actually uses and send that same callback during authorization. MCP also requires every redirect URI to be either a loopback address or HTTPS.

Access tokens stay out of URLs​

Once the client has an access token, it needs to send that token when calling the protected MCP server.

The token should not be placed in the URL:

https://mcp.example.com/mcp?access_token=eyJ...

URLs can appear in logs, browser history, traces, and debugging tools, which makes them a poor place for bearer credentials. OAuth 2.1 forbids clients from sending access tokens in a query parameter, and tells resource servers to ignore them there.

Instead, the client sends the token in the HTTP Authorization header:

Authorization: Bearer eyJ...

The MCP server validates that token before allowing access to the protected resource.

Refresh tokens for public clients are protected against replay​

Most MCP clients are public clients: desktop apps, IDE extensions, and CLIs that can't keep a client secret. If a refresh token issued to one of them leaks, nothing ties it to the client it was issued to.

OAuth 2.1 closes that gap. For public clients, the authorization server must detect refresh-token replay, either by binding the refresh token to the client instance or by rotating it, issuing a new refresh token on every refresh and invalidating the old one. The MCP specification requires rotation for public clients.

Rotation has a practical consequence for the client: always store the newest refresh token, and make sure two refreshes for the same user don't race each other. Why Your MCP Token Expires Mid-Run shows a per-user refresh lock for exactly this.

Together, these changes give MCP clients a narrower authorization path: use the authorization code flow with PKCE, keep authentication at the authorization server, return only to known callbacks, send access tokens in headers rather than URLs, and treat refresh tokens as single-use.

How those changes fit agent flows​

OAuth 2.1 was not designed specifically for AI agents. The same rules apply to ordinary applications.

What changes with agents is when authorization may happen.

In a traditional application, the user often starts the connection themselves. They click Connect calendar, complete authorization, and then use the calendar feature.

With an agent, the need for authorization may only become clear after the task has already started.

For example:

Move my meeting with Maya to Friday afternoon.

The agent decides it needs a calendar tool exposed through an MCP server. If that server requires authorization, the task cannot continue yet.

The client pauses the flow, sends the user through authorization, obtains the required access, and then continues the original task.

A simplified version looks like this:

Authorization in the middle of a task
  1. User asks the agent to perform a task
  2. Agent selects an MCP tool
  3. MCP server requires authorization
  4. User signs in and approves access
  5. Client obtains an access token
  6. Agent continues the task

The OAuth 2.1 rules from the previous section keep that interruption predictable.

The user authenticates with the authorization server rather than handing credentials to the agent. The browser returns an authorization code instead of an access token. PKCE ties that code to the client that started the flow, and the resulting token is sent to the MCP server through the Authorization header.

The agent does not need to handle the user's password or understand how they authenticated. The client only needs to obtain the access required for the tool call and resume the task afterward.

A single task may eventually involve several protected services, such as a calendar server, a document server, and a source-control server. Each can have its own authorization requirements without exposing the user's underlying login credentials to the agent.

OAuth provides the authorization model. MCP adds the discovery and resource rules that help the client determine where to authorize and which protected server the resulting token is intended for.

What MCP adds on top​

OAuth 2.1 gives the client a way to obtain and use access tokens.

For MCP, two practical questions remain:

  • Where should the client send the user for authorization?
  • How does it make sure the token it receives is meant for this MCP server?

MCP answers both by building on existing OAuth standards.

Finding the right authorization server​

Suppose an MCP client connects to https://mcp.example.com/mcp.

That MCP server may protect its tools without running its own login or token endpoints.

Authorization might instead be handled by https://identity.example.com.

The client needs a way to discover that relationship.

MCP uses OAuth 2.0 Protected Resource Metadata (RFC 9728) for this. The MCP server publishes metadata that tells the client which authorization server can be used with it.

A simplified document might look like this:

{
"resource": "https://mcp.example.com/mcp",
"authorization_servers": [
"https://identity.example.com"
]
}

From there, the client can discover the authorization server's own metadata and find the endpoints it needs.

Two hops of discovery
  1. MCP server
  2. RFC 9728Protected Resource Metadata
  3. Authorization server
  4. RFC 8414 or OpenID Connect DiscoveryAuthorization Server Metadata
  5. Authorization and token endpoints

The client does not need to know the authorization endpoint for every MCP server in advance. It can discover the setup from the protected resource.

Asking for a token for the right resource​

Finding the authorization server is only part of the problem.

The same authorization server may issue tokens for several APIs. The client therefore needs to say which protected resource it wants to access.

MCP uses the OAuth resource parameter (RFC 8707) for this.

When starting authorization, the client identifies the MCP server:

resource=https://mcp.example.com/mcp

The authorization server can then issue a token intended for that resource, and the MCP server rejects any token that wasn't issued for it.

This prevents the client from treating a token issued for one service as a generic credential for every service supported by the same authorization server.

MCP therefore uses OAuth 2.1 for the authorization flow, Protected Resource Metadata to discover where authorization happens, and the resource parameter to identify which MCP server the client wants to access.

MCP adds a few more rules

Discovery and resource binding are the two you'll meet first. The MCP specification also defines how a client identifies itself to an authorization server it has never seen, preferring Client ID Metadata Documents over the now-deprecated Dynamic Client Registration. It also requires the client to check the issuer on the authorization response (RFC 9207), and describes how a server asks for more scopes mid-task. MCP Authorization: The Complete Developer Guide covers each of them.

MCP does not replace OAuth. It defines how those existing OAuth pieces fit together when a client connects to a protected MCP server.

Putting the flow together​

We have now seen the individual pieces. Here is how they fit together from the MCP client's point of view.

Assume the client has already discovered the authorization server, its authorization and token endpoints, and the URL of the protected MCP server.

The flow starts when the client needs access to that server.

The authorization flow, end to end
  1. 1 · MCP clientStart authorization with PKCE
  2. 2 · Authorization serverUser signs in and approves access
  3. 3 · MCP clientReceives an authorization code
  4. 4 · Authorization serverClient exchanges the code and PKCE verifier
  5. 5 · MCP clientReceives an access token
  6. 6 · Protected MCP serverClient sends the access token

When it starts authorization, the client identifies the resource it wants to access, and creates a PKCE verifier and challenge and a random state value before opening the browser.

Conceptually, the authorization request looks like this:

GET /authorize?
response_type=code
&client_id=mcp-client
&redirect_uri=http://127.0.0.1:8765/callback
&code_challenge=...
&code_challenge_method=S256
&state=...
&resource=https://mcp.example.com/mcp

The user signs in and approves access at the authorization server.

After authorization, the browser sends the user back to the client's registered callback:

http://127.0.0.1:8765/callback?code=abc123&state=...

The client checks that state matches the value it sent, then exchanges the code at the token endpoint. A public client identifies itself with client_id and includes the PKCE verifier it created earlier:

POST /token
Content-Type: application/x-www-form-urlencoded

grant_type=authorization_code
&code=abc123
&client_id=mcp-client
&code_verifier=...
&resource=https://mcp.example.com/mcp

OAuth 2.1 drops redirect_uri from this request, because PKCE already ties the code to the client that requested it. Many authorization servers still accept it for OAuth 2.0 compatibility, so a client that sends it won't break anything.

If the request succeeds, the authorization server returns an access token.

The client can then call the protected MCP server:

POST /mcp
Authorization: Bearer <access-token>
Content-Type: application/json

The token stays in the Authorization header rather than appearing in the URL.

In practice, an MCP SDK or OAuth library will usually handle much of this plumbing. Connecting an AI Agent to an OAuth-Protected MCP Server shows FastMCP doing all of it. The flow is still useful to understand because it shows where OAuth 2.1 ends and the MCP-specific discovery and resource rules begin.

Migration checklist​

If you already have an MCP client built around OAuth 2.0, you probably do not need to rebuild the authorization layer from scratch.

Walk through the flow and check whether you still rely on any older patterns:

  • If you use the authorization code flow without PKCE, add a fresh verifier and S256 challenge for each authorization attempt.
  • If you use the implicit grant, move to the authorization code flow with PKCE.
  • If the client collects the user's username and password, move authentication back to the authorization server.
  • If redirect URIs are matched loosely, register and use the complete callback URI.
  • If access tokens appear in URLs, send them in the Authorization header instead.
  • If the client reuses an old refresh token after a refresh, store the new one each time, and serialize refreshes per user.
  • If the client assumes it already knows which authorization server to use, add Protected Resource Metadata discovery.
  • If the client requests a token without identifying the MCP server, include the resource parameter for that protected resource.

MCP does not introduce a new authorization model.

OAuth 2.1 provides the authorization flow. MCP adds the information a client needs when it connects to a protected server it may not already know: where authorization happens and which resource the token is meant for.

If you already understand OAuth 2.0, there is no need to start over. You mainly need to know which older paths are gone, which protections are now part of the normal flow, and how MCP uses discovery and resource-specific authorization to connect the client, authorization server, and protected MCP server.