MCP authentication: how OAuth works for remote MCP servers
By Natnael Girma ยท Published
A remote MCP server authenticates clients with OAuth 2.1. The server answers an unauthenticated request with a 401 that points to its protected resource metadata. The client follows that to the authorization server, gets a client ID, runs an authorization code flow with PKCE, and then sends a bearer token on every request. The rules live in the authorization section of the MCP specification, revision 2026-07-28, which is the current version as of December 2026.
That revision changed one thing many guides still get wrong. Client ID Metadata Documents are now the recommended way for a client to identify itself, and Dynamic Client Registration is deprecated.
Who does what
| Role | In MCP | Job |
|---|---|---|
| Resource server | The MCP server | Checks the token on every request and rejects anything not issued for it |
| Client | Claude, ChatGPT, Cursor or another MCP client | Discovers the authorization server, gets the user's consent, stores and refreshes tokens |
| Authorization server | Often the same service as the MCP server, sometimes a separate identity provider | Signs the user in, shows consent, issues tokens |
Authorization is optional in MCP and applies to HTTP transports. A local server that runs over stdio should take its credentials from the environment instead.
The flow, request by request
The responses below are what Taskwind's MCP server at https://taskwind.ai/mcp returns as of December 2026, trimmed for length. Every remote MCP server that follows the spec answers the same way.
1. The client calls the server without a token and gets a 401.
curl -i -X POST https://taskwind.ai/mcp \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'
HTTP/2 401
www-authenticate: Bearer realm="OAuth", resource_metadata="https://taskwind.ai/.well-known/oauth-protected-resource/mcp"
The resource_metadata value tells the client where to look next. If a server leaves it out, the client tries /.well-known/oauth-protected-resource/<mcp path> and then /.well-known/oauth-protected-resource at the root, as the discovery rules require.
2. The client reads the protected resource metadata (RFC 9728).
{
"resource": "https://taskwind.ai/mcp",
"authorization_servers": ["https://taskwind.ai"],
"bearer_methods_supported": ["header"],
"resource_name": "Taskwind"
}
3. The client reads the authorization server metadata (RFC 8414) at https://taskwind.ai/.well-known/oauth-authorization-server.
{
"issuer": "https://taskwind.ai",
"authorization_endpoint": "https://taskwind.ai/oauth/authorize",
"token_endpoint": "https://taskwind.ai/oauth/token",
"registration_endpoint": "https://taskwind.ai/oauth/register",
"scopes_supported": ["mcp:read", "mcp:write"],
"grant_types_supported": ["authorization_code", "refresh_token"],
"token_endpoint_auth_methods_supported": ["client_secret_basic", "client_secret_post", "none", "private_key_jwt"],
"code_challenge_methods_supported": ["S256"],
"authorization_response_iss_parameter_supported": true,
"client_id_metadata_document_supported": true
}
The client must check that issuer matches the URL it built the request from, and it must refuse to continue if code_challenge_methods_supported is missing, because that means no PKCE.
4. The client gets a client ID. With a Client ID Metadata Document, the client_id is simply an HTTPS URL the client hosts, such as https://chatgpt.com/oauth/client.json. With Dynamic Client Registration, the client first POSTs its details to /oauth/register. More on the difference below.
5. The browser opens the authorization URL.
https://taskwind.ai/oauth/authorize?response_type=code
&client_id=https%3A%2F%2Fapp.example.com%2Foauth%2Fclient.json
&redirect_uri=https%3A%2F%2Fapp.example.com%2Fcallback
&code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM
&code_challenge_method=S256
&state=af0ifjsldkj
&resource=https%3A%2F%2Ftaskwind.ai%2Fmcp
The user signs in and approves. The server redirects back with code, state and iss. Before using the code, the client compares iss to the issuer it recorded in step 3. That check, from RFC 9207, stops a malicious server from tricking the client into handing over a code issued elsewhere.
6. The client exchanges the code for tokens.
curl -X POST https://taskwind.ai/oauth/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-d grant_type=authorization_code \
-d code=$CODE \
-d redirect_uri=https://app.example.com/callback \
-d client_id=https://app.example.com/oauth/client.json \
-d code_verifier=$VERIFIER \
-d resource=https://taskwind.ai/mcp
7. Every MCP request carries the token.
curl -X POST https://taskwind.ai/mcp \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-d '{"jsonrpc":"2.0","id":2,"method":"tools/list"}'
The token goes in the Authorization header on every HTTP request, never in the query string.
Client ID Metadata Documents vs Dynamic Client Registration
Before the flow starts, the client needs a client ID. The client registration rules offer three ways.
| Method | How it works | Status in 2026-07-28 |
|---|---|---|
| Client ID Metadata Document (CIMD) | The client_id is an HTTPS URL. The authorization server fetches the JSON there and checks the redirect URIs against it. |
SHOULD support. The recommended default. |
| Pre-registration | The client already has a client ID for that server, from a developer portal or entered by the user. | SHOULD support |
| Dynamic Client Registration (DCR, RFC 7591) | The client POSTs to /register and receives a new client ID. |
MAY support. Deprecated, kept at least 12 months for compatibility. |
A client that supports all three should use pre-registered details first, then CIMD if the server advertises client_id_metadata_document_supported, then DCR if there is a registration_endpoint, and finally ask the user.
The practical reason to prefer CIMD is that DCR creates a new client record for every fresh connection. Anthropic's connector docs warn that DCR "can result in very large numbers of registered clients" on a popular server. A CIMD client ID is a stable URL, so there is nothing to register and nothing to clean up. A minimal document has client_id (matching its own URL exactly), client_name and redirect_uris.
If you run an authorization server today, support both. Older clients still use DCR.
PKCE, the resource parameter and token audience
Three requirements stop stolen codes and tokens from working anywhere useful.
- PKCE with S256. The client creates a random verifier, sends its SHA-256 hash as
code_challenge, and proves it owns the verifier at the token step. A stolen authorization code is useless without it. - The
resourceparameter (RFC 8707). The client must send the MCP server's canonical URI, such ashttps://taskwind.ai/mcp, in both the authorization and token requests, even if the authorization server ignores it. - Audience validation. The MCP server must accept only tokens issued for itself, and reject any token whose audience is another service.
Scopes and step-up
A server should say which scopes it needs by adding scope="..." to the WWW-Authenticate header on its 401. If it doesn't, the client requests everything in scopes_supported from the protected resource metadata, and if that is missing too, it sends no scope at all.
When a token is valid but too weak for an operation, the server answers 403:
HTTP/1.1 403 Forbidden
WWW-Authenticate: Bearer error="insufficient_scope",
scope="mcp:write",
resource_metadata="https://mcp.example.com/.well-known/oauth-protected-resource"
The client then re-authorizes with the union of the scopes it already had and the new ones, so it doesn't lose access it was using. Servers should list every scope an operation needs in one challenge rather than one at a time. Don't put offline_access in your protected resource metadata, since refresh tokens are the authorization server's business.
API keys or OAuth?
| OAuth | API key | |
|---|---|---|
| Who it identifies | A specific person, with the access they approved | A workspace or account, not a person |
| Where the secret lives | Nowhere the user sees. Tokens stay inside the client. | Pasted into a config file or environment variable |
| Granularity | Scopes chosen at consent | Usually all or nothing |
| Revoking | Per assistant, from the service's settings | Delete the key, which breaks every place it was used |
| Best for | People connecting Claude, ChatGPT or Cursor | Scripts, CI jobs, your own backend |
OAuth is the right default for anything a person connects. API keys still make sense for unattended jobs. On the client side, Claude offers request-header credentials as a beta for some organizations, and ChatGPT does not support client-credentials grants.
Identity matters beyond permissions, too. Taskwind accepts both on the same /mcp endpoint, and a key gets full access to its workspace. But TikTok requires the creator to choose privacy settings and confirm every post, so a request made with an API key can't post to TikTok at all, because there is no signed-in person to confirm it. An OAuth connection from Claude can, after the user answers TikTok's questions in the chat.
How Claude and ChatGPT handle MCP authentication
Both follow the spec, and each adds a few rules of its own that cause most "couldn't connect" errors.
| Claude | ChatGPT | |
|---|---|---|
| Redirect URI | https://claude.ai/api/mcp/auth_callback. Claude Code uses a loopback redirect on a random port, so match localhost and 127.0.0.1 with any port. |
https://chatgpt.com/connector_platform_oauth_redirect, or https://chatgpt.com/connector/oauth/{callback_id} for servers without iss support |
| Client ID | CIMD only when the server advertises CIMD and none in token_endpoint_auth_methods_supported, otherwise DCR |
Prefers CIMD, supports DCR |
| Starting sign-in | Needs a 401. A WWW-Authenticate header on a 200 is ignored. |
Needs resource metadata, and tool errors that carry _meta["mcp/www_authenticate"] |
| Multiple authorization servers | Uses only the first one listed | Not stated in the guide |
| Timeouts | 10 seconds for discovery, registration and token calls, 30 for refresh | Not stated in the guide |
| Refresh | On a 401, and up to 5 minutes before expiry | Not stated in the guide |
| Also note | Requests come from 160.79.104.0/21 |
Presents an OpenAI client certificate (mTLS) |
Sources: Anthropic's connector authentication docs and OpenAI's Apps SDK auth guide.
Two ChatGPT details are easy to miss. Set authorization_response_iss_parameter_supported to true only if every authorization response returns iss, including errors. And echo the resource value into the token's audience, because ChatGPT expects you to reject tokens without it.
Security pitfalls
- Token passthrough. If your MCP server calls another API, it needs its own token for that API. It must not forward the token the MCP client sent, and it must not accept tokens issued for someone else.
- Confused deputy. A proxy server that uses one static client ID with an upstream provider can be abused to get tokens without the user's consent. The spec requires such proxies to get the user's consent for each dynamically registered client before forwarding to the upstream authorization server.
- Skipping the
isscheck. Without it, a malicious authorization server can collect codes meant for an honest one. - Loopback impersonation. Any program on a computer can listen on
localhost. Authorization servers must show the redirect hostname on the consent screen and should warn when it is a loopback address. - Loose redirect matching. Match redirect URIs exactly, apart from the port on loopback addresses.
- Refresh token storage. Keep them encrypted, and rotate them for public clients, as OAuth 2.1 requires.
- CIMD fetching. Your authorization server fetches URLs that clients choose, so protect it against server-side request forgery.
How Taskwind implements MCP authentication
Taskwind runs its authorization server and MCP server together on Cloudflare Workers, using Cloudflare's workers-oauth-provider library. These details come from its code.
- One origin for everything. The MCP endpoint is
/mcp. The library serves the protected resource metadata, the authorization server metadata,/oauth/registerfor DCR and/oauth/token, and accepts CIMD client IDs. Because the server advertises both CIMD and thenoneauth method, Claude normally identifies itself with a metadata document rather than registering. - The consent screen is Taskwind's own page. It names the assistant, shows which signed-in email it will act as, and states the hostname you'll return to. If the redirect is a loopback address, it adds a warning to continue only if you started the connection yourself.
- Two scopes, picked by the user. You choose Read only (
mcp:read) or Read, publish and message (mcp:readandmcp:write). With read-only, the server doesn't register the acting tools at all, so the model never seescreate_postorsend_messageand can't try to call them. - No scope hint in the challenge. Taskwind's 401 has no
scopeparameter and its resource metadata has noscopes_supported, so clients request no particular scope and the person chooses on the consent screen. Under the spec that is allowed, though adding the hint would be the more standard choice. - Consent can't be forged. The approval form only accepts a POST from Taskwind's own origin, the pending request expires after 10 minutes, and it must be approved by the same signed-in user who opened it.
- No token passthrough. The token Claude holds only works at
taskwind.ai/mcp. Calls to Instagram, LinkedIn and the other networks use separate per-network tokens that Taskwind stores encrypted and refreshes before they expire. - Stateless transport. The server uses Streamable HTTP with JSON responses and no session ID, and answers
GETandDELETEon/mcpwith 405. - Redirects that keep the request intact. Requests to
www.taskwind.aiare redirected with a 308 rather than a 301, because a 308 keeps a POST to/mcpa POST.
You can revoke any assistant from Taskwind's dashboard settings. To set it up, see connecting Claude, ChatGPT or Cursor, or read MCP vs REST API if you are deciding between the two.
Questions
Is OAuth required for a remote MCP server?
No. Authorization is optional in the spec, and Claude supports servers with no authentication. If your server touches anyone's private data or can act for them, you should use OAuth.
How long should MCP access tokens last?
The spec doesn't set a number. It says authorization servers should issue short-lived access tokens and must rotate refresh tokens for public clients, so keep access tokens brief and let clients refresh them.