How MCP Authentication and Authorization Work With OAuth 2.1

Himanshu

Written by

Himanshu
Rohit Joshi

Reviewed by

Rohit Joshi

Published 21 October 2026

Expert Verified

<p>explaining MCP authentication and authorization with OAuth 2.1 for secure AI agent access to tools and task execution.</p>

Summarize this post with AI

Quick answer

MCP uses OAuth 2.1 in two stages. Authentication comes first, when a client without a token gets a 401, discovers the authorization server, and sends the user through a browser sign-in that ends in an access token. Authorization follows on every request, when the MCP server checks that the token was issued for it and that its scopes, which are named permissions, cover the tool being called.

TL;DR

  • MCP authentication proves who is connecting to your MCP server, and MCP authorization limits what that caller can do.
  • Remote HTTP servers should handle both through one OAuth 2.1 flow, and local stdio servers read credentials from the environment instead.
  • Choose the credential by caller, with OAuth for people, machine credentials for background jobs, and API keys for links that one team controls end to end.

A developer connects an AI agent to a calendar through a Model Context Protocol (MCP) server. The integration works perfectly during testing. Then a second employee connects, and both users’ requests reach the calendar API through the same shared credential.

The problem isn’t that the agent can’t call the API. It’s that the server may not know which employee authorized each action or whether that employee should be allowed to perform it.


What Is MCP OAuth?

MCP OAuth refers to the OAuth-based authorization mechanism defined for HTTP-based Model Context Protocol connections. It allows an MCP client, such as an AI assistant, to request access to a protected MCP server without requiring the application to expose a permanent API credential to the language model.

Three components participate in the process:

  • MCP client: The application requesting access to tools or resources.
  • MCP server: The protected resource server that receives requests and enforces access restrictions.
  • Authorization server: The service that handles authorization and issues access tokens.

The authorization server may be operated alongside the MCP server or by a separate identity provider.

An important distinction: OAuth access tokens do not automatically represent a specific human user. Depending on the grant and implementation, a token may represent delegated user access or an application’s own authority. For user-facing AI agents, delegated access is often the appropriate design because individual users may need different permissions.

MCP’s authorization specification is optional. When authorization is implemented for HTTP-based MCP transports, the protocol defines a standard way for clients and servers to handle it. Local STDIO-based integrations generally use credentials provided through their execution environment instead.


MCP authentication vs. authorization

Authentication answers “who is calling?” and authorization answers “what may this caller do?” A support agent connecting to a company’s order system shows both. Signing in as a named staff member is authentication. The token that lets the agent read orders but blocks refunds is authorization.

One precision note before the details. OAuth 2.1 is a delegated-authorization framework. The access token says a client may act for a user within certain limits, and the actual login happens at the authorization server, often through OpenID Connect (OIDC, an identity layer built on OAuth). The MCP specification calls the whole flow “authorization”. This guide splits it in two because the stages fail in different places: steps 1 to 6 of the flow produce a verified token (authentication), and everything your server does with that token afterward is authorization.

AuthenticationAuthorization
Question answeredWho is calling?What may this caller do?
Where it happensAuthorization server (login and consent), plus your server verifying the tokenYour MCP server, on every request
What the user seesA sign-in page and a consent screenNothing, unless a tool needs more access
Evidence usedToken signature, expiry, issuer and audience (the server the token was issued for)Scopes inside the token, plus your own policy
Failure response401 when no valid token arrives403 when a valid token lacks a scope

The two meet at the consent screen. The user’s approval decides which scopes go into the token, and your server enforces them on every request.

The three roles

OAuth names three parties, and the MCP specification maps each onto an MCP component.

  • MCP server: the OAuth resource server, the system that holds protected data and accepts access tokens.
  • MCP client: the OAuth client, the application that sends requests on the user’s behalf.
  • Authorization server: signs the user in, collects consent and issues tokens. It can run inside your MCP server or, more commonly in production, as a separate identity provider.

A scope is a named slice of access, such as files:read. Each step below is one of these three parties acting on another.


When Does an MCP Server Need Authentication?

The OAuth flow is optional in MCP, so your first decision is whether a given server needs it.

Under the MCP authorization spec, HTTP-based servers should follow its OAuth flow. A stdio server is a local program your client launches and talks to through standard input and output, and it should retrieve credentials from the environment instead. The flow is strongly recommended whenever your server meets any of these conditions.

  • The server reads user-specific data such as email, documents, or databases
  • You need an audit trail of who performed which action
  • Actions require user consent
  • You serve enterprise customers with strict access controls
  • You want rate limiting or usage tracking per user

The support agent from the last section shows the threshold. Anyone building an AI agent for customer service needs a verified identity behind every request once the agent gets write access, because each call touches one customer’s records on behalf of one staff member.

Pick OAuth the moment a second person shares the server, and keep environment credentials for servers that run on one machine.


How MCP Authentication Works With OAuth 2.1 Step by Step

The MCP OAuth flow follows OAuth 2.1 and has seven steps. A compliant client runs them automatically, and the person sees only the browser sign-in in step five. In plain terms, the flow does four jobs.

  1. Your server tells the client where to sign in (steps 1 to 3)
  2. The client identifies itself to the authorization server (step 4)
  3. The user signs in and approves access (step 5)
  4. The client receives an access token and starts using it (steps 6 and 7)

Steps 1 to 6 are authentication, and they end with a token. Step 7 is where authorization takes over.

MCP OAuth 2.1 authentication and authorization flow showing seven steps between a browser, MCP client, MCP server, and authorization server, from token discovery to access validation.

1. MCP Server Returns a 401 Challenge

A client that calls your server without a token receives HTTP 401 and a WWW-Authenticate header, the standard HTTP header that tells a client how to authenticate. The header points to your server’s metadata and can name the scope the operation needs.

HTTP/1.1 401 Unauthorized

WWW-Authenticate: Bearer resource_metadata=”https://mcp.example.com/.well-known/oauth-protected-resource&#8221;,

scope=”files:read”

Publish the metadata location in this header or at a well-known address, a fixed path that begins with /.well-known/. Clients must support both discovery paths, so either choice works.

2. Client Discovers Protected Resource Metadata

Protected resource metadata (PRM) is a JSON document, defined by RFC 9728, that names the authorization servers your resource accepts and the scopes it supports.

{

“resource”: “https://your-server.com/mcp&#8221;,

“authorization_servers”: [“https://auth.your-server.com”%5D,

“scopes_supported”: [“mcp:tools”, “mcp:resources”]

}

Make the resource value match your server URL exactly, because the client discards the document when it does not.

3. Client Discovers the Authorization Server

The client now reads the authorization server’s own metadata from fixed well-known addresses, trying the OAuth address first and then the OpenID Connect (OIDC, an identity layer built on OAuth) addresses. The issuer is the authorization server’s identifier URL, and the issuer in the returned document must equal the one used to build the address, or the client discards the metadata.

The client also stops when code_challenge_methods_supported is missing, because that field advertises PKCE, the protection described in step 5. Confirm your authorization server publishes it.

4. Client Identifies Itself to the Authorization Server

Before the browser opens, the client needs an identifier the authorization server recognizes. Clients that support every option follow this priority order.

  1. Use pre-registered client information for that server
  2. Use a Client ID Metadata Document (CIMD) if the authorization server advertises client_id_metadata_document_supported
  3. Fall back to Dynamic Client Registration (DCR) if the server exposes a registration_endpoint
  4. Prompt the user to enter client details

CIMD lets a client use an HTTPS URL as its client ID. The authorization server fetches the JSON document at that URL and checks that the client_id matches the URL and that the request’s redirect URIs appear in the document.

DCR is the older mechanism, in which a client registers itself over an API. The 2026-07-28 revision deprecates it in favor of CIMD and keeps it for backward compatibility, with a twelve-month minimum deprecation window. Treat DCR as legacy and build new work on CIMD.

5. User Authorization With PKCE and the Resource Parameter

The client opens the authorization endpoint in a browser and sends a PKCE challenge, the canonical URI of the target MCP server, and the scopes it selected.

Proof Key for Code Exchange (PKCE, RFC 7636) binds the authorization code to a secret the client generated, so a stolen code is useless without the matching verifier. Use the S256 method, which hashes the secret with SHA-256, whenever you can. The resource parameter from RFC 8707 tells the authorization server which MCP server the token is for. Clients must send it in both the authorization and token requests, even when the authorization server does not support it.

GET /authorize?response_type=code

&client_id=https%3A%2F%2Fapp.example.com%2Foauth%2Fclient-metadata.json

&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fcallback

&scope=files%3Aread

&state=xyz

&code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM

&code_challenge_method=S256

&resource=https%3A%2F%2Fmcp.example.com

The state value is random data the client checks when the browser returns. After sign-in and consent, the authorization server redirects to the callback with a code and an iss parameter naming the issuer. Compare iss with the issuer you recorded in step 3 before using the code, which blocks mix-up attacks.

6. Client Exchanges the Authorization Code for Tokens

The client posts the code, the original code verifier, and the same resource value to the token endpoint. The response holds an access token and may hold a refresh token, a longer-lived credential that obtains new access tokens.

Authorization servers should issue short-lived access tokens and must rotate refresh tokens for public clients, which are apps that cannot keep a secret, such as desktop, mobile, and browser apps. Clients keep refresh tokens confidential and never assume one will be issued.

7. Client Sends the Access Token With Each Request

From this point every HTTP request to your server includes the access token in the Authorization header. A bearer token works for whoever holds it, so send it only over HTTPS and never in the URL query string. The next section covers what your server checks before it accepts one.


Where Each Step Breaks and How to Fix It

A failed connection stops at one specific step, and the symptom tells you which. The Claude rows come from Claude’s connector requirements as of October 2026.

SymptomStepLikely causeFix
Your authorization server sees no traffic at all1 and 2The 401 carries no resource_metadata pointer and the well-known paths return 404Add the pointer or serve the metadata at the well-known paths
The client discards your metadata2 or 3The resource value differs from the server URL the user entered, or the issuer differs from the URL used to fetch the metadataMake both match exactly
The client stops before opening the browser3code_challenge_methods_supported is missing from the metadataPublish it with S256
Registration fails or falls back to DCR4The authorization server advertises neither CIMD nor a registration_endpoint, or for Claude lacks one of the two CIMD valuesAdvertise client_id_metadata_document_supported and, for Claude, “none” in token_endpoint_auth_methods_supported
The browser sign-in errors on redirect5The redirect URI does not match exactly, or a loopback redirect (a callback to localhost on the user’s machine) arrives on a new portMatch registered URIs exactly and accept loopback redirects on any port
Sign-in finishes but the connection still fails6The token endpoint answers too slowly or rejects form-encoded bodiesRespond within Claude’s 10-second limit (30 seconds for refresh) and accept application/x-www-form-urlencoded
Calls work, then return 4017The token expired or names a different audienceRefresh the token and send the resource parameter in both requests

Start with the earliest failing step, because every later step depends on it.


How MCP Authorization Works With Scopes and Token Checks

Authorization starts once the token exists. Your server decides what each request carrying it may touch, and scopes make that decision specific.

Scopes Set the Boundaries

OAuth defines no scope values, so you and your authorization server choose them, such as files:read for viewing and files:write for changes. Tell clients which scope an operation needs through a scope parameter in the 401 challenge. When the parameter is missing, clients request every scope in scopes_supported, so keep that list to the minimal set for basic use. The guidance on scope minimization recommends a small initial scope and incremental elevation when a privileged operation is first attempted.

Insufficient Scope and Step-Up Authorization

When a token lacks the scope for a requested operation, answer 403 and name the scope you need.

HTTP/1.1 403 Forbidden

WWW-Authenticate: Bearer error=”insufficient_scope”,

scope=”files:write”,

resource_metadata=”https://mcp.example.com/.well-known/oauth-protected-resource&#8221;,

error_description=”File write permission required for this operation”

The client then runs step-up authorization. It merges the scopes it already holds with the challenged scopes and sends the user through a new authorization. It then retries the original request, a few times at most, before treating the failure as permanent. List every scope an operation needs in a single challenge, because one scope per retry multiplies sign-in prompts.


What Your Server Checks on Every Request

Run these five checks before any tool executes. The first two confirm the token is genuine and meant for your server, which is why they answer 401. The other three decide what the caller may do.

MCP server security flow showing five checks before a tool runs: token validity, audience, scope, identity, and upstream credentials, with failed requests rejected.

Rely on maintained libraries for this validation, since hand-written token checks invite mistakes. A Node.js backend can host all five checks in one middleware layer in front of every tool. Fail the token or audience check and your server answers 401, fail the scope check and it answers 403, and in every failing case the tool never runs.


MCP Authentication Methods Compared

Match the credential to the caller. OAuth is the specified path for remote servers, but four other patterns turn up in real deployments, as the table shows for October 2026.

MethodWho approves accessBest forWatch for
Environment credentials over stdioThe person who starts the local serverLocal servers on one machineSecrets sit in config files and the server process inherits them
Static API key or bearer tokenAn administrator who creates the keyService-to-service links that one team controls end to endOne shared credential with no user identity and a long lifetime
OAuth 2.1 authorization code with PKCEEach user, on a consent screenRemote servers acting for a personDiscovery, registration, and token validation must all be correct
OAuth client credentials extensionThe application itself, with a secret or a signed JWT (JSON Web Token)Background services, CI/CD, schedulersDraft status, so details can still change
Enterprise-managed authorization extensionThe company’s identity provider policyOrganizations with central single sign-onOpt-in extension that needs identity provider support

MCP extensions are optional add-ons to the core protocol, and two of them cover callers that cannot use a browser. The client credentials extension serves scheduled jobs and CI pipelines, so plan for it when you wire unattended jobs into business automation tools. It accepts a client secret or a signed JWT assertion, and the JWT is the safer choice because a secret is a long-lived credential that grants access with no user behind it. The ext-auth repository lists it as Draft.

The enterprise-managed authorization extension, listed as Stable, hands company-wide access policy to the identity provider. The provider issues an Identity Assertion JWT Authorization Grant (ID-JAG), and the client exchanges it for an MCP access token with no per-server consent screen. Revoking an employee’s access then happens once, at the identity provider.

How Claude, GitHub, and Paddle Handle MCP Authentication

These three show where the specification meets production. Their behavior is as of October 2026, so check each vendor’s page before you build against it.

Whichever client you target, read its connector page for the registration methods and grant types it supports before you design the flow.


MCP Security Risks in Authentication and Authorization

MCP security for authentication and authorization comes down to the patterns below, so audit your server against them before every release. The specification’s security guidance pairs each attack with a required control.

RiskHow it worksControl
Token passthroughA server accepts a token issued for another resource and forwards it downstreamReject tokens not issued for this server and use a separate upstream token
Confused deputyA proxy with one static client ID at a third-party authorization server, which also accepts dynamic client registration, lets a malicious client reuse the third-party consent cookie and collect a code without the user’s consentPer-client consent before forwarding to the third-party authorization server
SSRF (server-side request forgery)A malicious server points metadata URLs at internal addresses, tricking the client into calling services it should never reachRequire HTTPS, block private and link-local address ranges (internal network addresses), validate redirects, and route requests through an egress proxy that filters outgoing traffic
Malicious authorization URLA server supplies a script or file scheme, or shell metacharacters, as the authorization endpointAllow only http and https and never open URLs through a shell
Authorization server mix-upA hostile authorization server collects a code meant for an honest oneValidate iss against the recorded issuer, as in step 5
Localhost redirect impersonationA local process claims a legitimate client’s metadata URL and binds a localhost callbackAccept only localhost or HTTPS redirect URIs matched exactly, and show the redirect hostname with extra warnings on the consent screen
Token theftTokens leak from logs, caches, or client storageFollow the token rules in step 6 and keep tokens out of logs and caches

A Real Case That Matches the Rules

Study CVE-2025-6514 before you write any code that handles authorization URLs. mcp-remote, a proxy that lets local MCP clients connect to remote servers, was exposed to operating system command injection when it connected to an untrusted server. It acted on crafted input in the authorization_endpoint value that the server returned, so a malicious server could run commands on the user’s machine.

The GitHub Advisory Database published the advisory on July 9, 2025 with a CVSS 9.6 rating, where CVSS is a 0 to 10 severity score. Versions 0.0.5 through 0.1.15 are affected and version 0.1.16 contains the fix. The specification now closes this gap with the rule in the malicious authorization URL row.

Before you connect any new server, read the permissions it requests, and shortlist candidates from the best MCP servers for AI agents.


Centralizing MCP Authentication With a Gateway

Managing authentication across multiple MCP servers becomes difficult as the number of connected tools grows. Each server may require different API keys, OAuth credentials, permissions, and configuration settings.

For example, in n8n, each MCP Client Tool node connects to a specific server. As teams add more integrations, they must manage additional credentials, monitor connections, and troubleshoot authentication failures separately.

An MCP gateway reduces this overhead by providing a single connection point for multiple tools.

MCP360, a unified MCP gateway, connects AI clients such as Claude and Cursor to more than 100 tools through one platform. Instead of configuring every integration separately, developers can generate an API key from the dashboard and manage tool access through the gateway.

According to the MCP360 documentation, the platform provides:

However, centralized authentication does not automatically mean stronger security. A gateway API key may provide access to multiple connected tools, increasing the impact if that credential is compromised.

Store gateway keys in a secrets manager, rotate them regularly, restrict access wherever supported, and maintain separate credentials across environments. For custom MCP endpoints, continue validating token audiences, scopes, and user permissions rather than relying solely on gateway authentication.

The goal is to reduce repeated credential configuration without weakening access controls at the individual tool level.


Frequently Asked Questions

Does MCP require OAuth?

No. The OAuth flow is optional, and local stdio servers read credentials from the environment instead. Remote HTTP servers should follow it, especially when they hold user-specific data.

Why does an MCP server show “needs authentication” in Claude Code?

Claude Code flags a server as needing authentication when it answers with a 401 or 403. Run /mcp, or claude mcp login followed by the server name, and finish the browser sign-in. If you set your own Authorization header and the server rejects it, Claude Code reports a failed connection and does not fall back to OAuth, so remove the header to use the sign-in flow.

How do I use MCP OAuth without Dynamic Client Registration?

Give the client an identity another way. On the server side, advertise Client ID Metadata Document support so clients can skip registration. On the client side, supply a pre-registered client ID. Claude Code accepts --client-id, --client-secret, and --callback-port for servers that fail with an “Incompatible auth server” error.

Should I use an API key or OAuth for an MCP server?

Use an API key for links that one team controls end to end, and OAuth whenever you need to know which user is calling. A key is one shared credential, so every request looks like the same caller and you lose per-user audit trails and limits.

How do I send a bearer token to a remote MCP server?

Put it in the Authorization header as Authorization: Bearer on every HTTP request, and never in the URL query string. In Claude Code, add --header "Authorization: Bearer your-token" to claude mcp add --transport http. The command does not validate the token, so run /mcp afterward and confirm the server shows as connected.

What redirect URI does an MCP client use for OAuth?

It depends on the client. The hosted Claude apps use https://claude.ai/api/mcp/auth_callback, while Claude Code redirects to a loopback address such as http://localhost:3118/callback on a port that changes per session. Your authorization server must therefore match loopback redirects with the port ignored, or you can pin the port in Claude Code with --callback-port.

Is it safe to run an MCP server without authentication?

Only for a local stdio server on your own machine, or a server on a network you fully control. A remote server with no authentication accepts requests from anyone who has its URL, which makes every tool it exposes public.


Conclusion

MCP authentication is not just about issuing access tokens. It ensures that every client connecting to an MCP server has a verified identity, the correct permissions, and access only to the resources it needs.

OAuth 2.1 provides a foundation for securing remote MCP connections, but implementing it correctly requires more than a login flow. Token validation, audience restrictions, scoped permissions, and proper error handling all play a role in protecting connected tools and sensitive data.

The MCP roadmap also points toward stronger authentication for autonomous agents, including agent identity, DPoP, and more restrictive permissions for sub-agents. While these capabilities continue to develop, teams can strengthen their existing implementations by following established security practices.

Start with one MCP server. Configure OAuth discovery, validate access tokens, test authentication failures, and assign permissions at the tool level. Once these controls work reliably, apply them across additional servers and integrations.

As AI agents gain access to more tools and business systems, secure authentication and authorization become increasingly important. The priority is not how many tools an agent can access, but how precisely that access is controlled.

Share

Tags

MCP AuthenticationMCP serversOAuth 2.1
Himanshu

Article by

Himanshu

Head of Growth & Engineering

Himanshu is Head of Growth & Engineering at Delta4 Infotech, writing about AI agents, MCP, and no-code automation from a go-to-market view. He covers how teams evaluate, adopt, and get real value from AI tools, translating what the tech does into what it means for a business.

Related posts

Best AI Customer Support Agents in 2026 Compared

Best AI Customer Support Agents in 2026 Compared

Quick answer The best AI support agent is the one that fits the help desk you already use. If you run Zendesk or Freshdesk, start with that vendor’s own agent. If you want to keep your current help desk and add AI on top, use Fin (formerly Intercom). If you want a no-code builder on [&hellip;] Share this: Share on X (Opens in new window) X Share on Facebook (Opens in new window) Facebook

RajniRajni·19 Oct 2026
Customer Satisfaction Surveys When AI Handles Most Tickets
AI

Customer Satisfaction Surveys When AI Handles Most Tickets

Quick answer: Customer satisfaction surveys still work when AI handles most of your tickets, but they rate only a small, self-selected slice of conversations. Close the gap by triggering surveys from a resolution signal, reporting AI and human scores separately, showing coverage beside every score, and adding signals that don’t depend on customers responding: behavioral [&hellip;] Share this: Share on X (Opens in new window) X Share on Facebook (Opens in new window) Facebook

HimanshuHimanshu·15 Oct 2026
What Are Browser Agents? How They Work and Real Use Cases
AI

What Are Browser Agents? How They Work and Real Use Cases

Quick Answer A browser agent is an AI that uses a web browser for you. Describe a goal in plain language, and it opens pages, reads them, clicks, types, and checks each result until the job is done. It helps most on sites with no API, such as price research, form filling, and dashboard pulls. [&hellip;] Share this: Share on X (Opens in new window) X Share on Facebook (Opens in new window) Facebook

RajniRajni·14 Oct 2026