Blog · · 12 min read

MCP authentication for one remote server: OAuth sign-in that works in Claude, ChatGPT, and Claude Code

MCP authentication for one remote server: OAuth sign-in that works in Claude, ChatGPT, and Claude Code

Your product now has a remote MCP endpoint, and sign-in works when you test it in one agent host. Then a customer adds the same URL in a different host and gets "Authorization with the MCP server failed", or the connection succeeds but your authorization server fills with near-identical OAuth clients. MCP authentication looks like ordinary OAuth, but each host reads your metadata through its own rules, and a server tuned to one host drifts from the others without telling you. This guide gives product and identity engineers one connection contract for an existing SaaS, plus a conformance matrix that proves it host by host.

The short answer: one resource, one issuer, a ladder, and a matrix

Build the connection in this order:

  1. Fix the resource identity. Publish one canonical MCP URL as resource, equal to the URL users paste.
  2. Fix the discovery chain. Answer unauthenticated calls with 401 pointing to that metadata, and list one issuer.
  3. Offer a registration ladder. Client ID Metadata Documents (CIMD) first, pre-registered clients for enterprise, Dynamic Client Registration (DCR) only as a capped fallback.
  4. Allowlist redirects exactly, including hosted callbacks and a port-agnostic loopback match.
  5. Make consent truthful. Name the client by the host of its client_id URL, and bind the chosen workspace into a grant you own.
  6. Validate every call for issuer, audience, expiry, scope, and grant, and rotate public-client refresh tokens.
  7. Prove it per host by recording the registration path, redirect URI, and token method each host used.

Why the same server passes in one host and fails in another

The MCP 2026-07-28 client registration rules give clients a priority order: use pre-registered credentials if they exist, then CIMD if the authorization server advertises client_id_metadata_document_supported, then DCR if a registration_endpoint exists, and finally ask the user. The same page marks DCR as deprecated and keeps it only for backward compatibility.

Hosts implement narrower versions of that order. Claude's connector authentication requirements say Claude requires a 401 to start sign-in, ignores WWW-Authenticate on a 200, uses only the first entry in authorization_servers, and needs a port-agnostic loopback match for Claude Code. OpenAI's MCP authentication guide says ChatGPT and Codex pick a token endpoint method from the overlap between what your server accepts and what their client supports (none or private_key_jwt), echo the resource parameter in both authorization and token requests, and change redirect URIs depending on whether you return an issuer identifier.

Practitioner threads show what happens when those rules meet a server built for one host. These are author reports, not vendor guarantees:

  • In anthropics/claude-code#38102, filed in March 2026, a developer reports that Claude Code ignored a configured client ID and failed with "does not support dynamic client registration" against an authorization server with no registration endpoint. Later commenters report the same error elsewhere, and the issue was closed as a duplicate.
  • In github/github-mcp-server#1081, a 2025 report shows ChatGPT failing with "Error fetching OAuth configuration" because the server did not support DCR at the time.
  • In home-assistant/core#153820, one self-hosted server collected at least four separate OAuth failures across Claude and ChatGPT: metadata with relative endpoints and no issuer on unconfigured hostnames, confusion about which client ID to enter, missing DCR by design, and a resource mismatch when internal and external URLs collided.

Pin the resource identity and discovery chain

Every host starts with an unauthenticated request.

HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer resource_metadata="https://mcp.example.com/.well-known/oauth-protected-resource/mcp", scope="projects:read"
{
  "resource": "https://mcp.example.com/mcp",
  "authorization_servers": ["https://auth.example.com"],
  "scopes_supported": ["projects:read", "projects:write"],
  "bearer_methods_supported": ["header"]
}

Three rules keep this stable:

  • The resource value is the URL users paste, path included. Claude's documentation requires an exact match, and the Home Assistant thread includes a reported resource mismatch.
  • The challenge is a real 401 returned before your MCP SDK runs. Claude's lazy authentication guide explains that a tool handler's error is wrapped in a 200, which Claude passes to the model as text instead of opening sign-in. OpenAI documents a second path where a tool result carries _meta["mcp/www_authenticate"] alongside per-tool securitySchemes. Implement the transport-level 401 for every host, and add the tool-level signal only as an extra for hosts that read it.
  • The scope in the challenge is the minimum you need. Claude requests every scope in scopes_supported when the challenge omits scope, plus offline_access when your authorization server lists it, which produces a broad consent prompt.

Your authorization server metadata must also be reachable and complete. The MCP security considerations tell clients to refuse to proceed when code_challenge_methods_supported is missing, so advertise S256. Claude notes that discovery requests come from Anthropic's egress range, so a firewall or bot rule in front of your identity provider can break sign-in even when the MCP endpoint answers.

Treat the issuer string as an identity rather than a URL to normalize: list one primary issuer, return the exact iss value, and expect DCR and pre-registered clients to break when you migrate authorization servers. The reasons come from three sources. Claude uses only the first authorization_servers entry and never falls back to later ones, while OpenAI says ChatGPT tries each listed entry, so two listed issuers can send two hosts to two different servers. OpenAI compares the returned iss with the metadata issuer by exact string, without normalizing trailing slashes, paths, ports, or case, and rejects the response when an advertised iss is missing or different. The MCP specification binds pre-registered and DCR credentials to the issuer that created them and requires clients to re-register after an issuer change, while CIMD client IDs stay portable. In practice, generate the issuer from one configuration value, reuse it byte for byte in protected resource metadata, server metadata, and every authorization response, and plan any identity provider migration as a client re-registration event.

Build the client registration ladder for MCP authentication

Some remote MCP guides, such as DocsAlot's setup walkthrough, still present DCR as the default. The specification and both host vendors point toward CIMD, where the client's client_id is an HTTPS URL that resolves to its own metadata. Your authorization server fetches that document, checks that its client_id equals the URL, and validates the requested redirect against its redirect_uris.

Advertising CIMD is not enough, because each host applies its own selection rule and Claude quietly falls back to DCR when none is missing from your token endpoint methods, so record which registration path every host actually took. The table below summarizes the documented rules:

HostChooses CIMD whenFalls back toRedirect to allowlist
Claude web, desktop, and mobileServer metadata has client_id_metadata_document_supported: true and none in token_endpoint_auth_methods_supportedDCR via registration_endpointhttps://claude.ai/api/mcp/auth_callback
Claude CodeSame rule, using its own metadata documentDCRhttp://localhost/callback and http://127.0.0.1/callback on any port
ChatGPT and CodexCIMD is advertised; ChatGPT prioritizes it unless the builder picks DCR, and takes the method from the overlap of none and private_key_jwt with your listDCR once per connection, or a predefined clienthttps://chatgpt.com/connector_platform_oauth_redirect with issuer identification, otherwise a callback-specific URI shown on the management page

An authorization server that advertises CIMD but only accepts client_secret_basic at the token endpoint does not get CIMD from Claude. It gets a DCR attempt, which either fails or creates a new client. No error message tells you CIMD was skipped.

Recommended configuration for most SaaS products:

{
  "issuer": "https://auth.example.com",
  "authorization_endpoint": "https://auth.example.com/oauth/authorize",
  "token_endpoint": "https://auth.example.com/oauth/token",
  "code_challenge_methods_supported": ["S256"],
  "client_id_metadata_document_supported": true,
  "token_endpoint_auth_methods_supported": ["none", "private_key_jwt"],
  "authorization_response_iss_parameter_supported": true,
  "registration_endpoint": "https://auth.example.com/oauth/register"
}

Keep registration_endpoint only if you will cap and clean up DCR clients. When you fetch CIMD documents, follow the specification's server-side request forgery guidance: restrict destinations, use short timeouts, and respect cache headers.

DCR as the default turns every fresh connection into a new OAuth client, and a CIMD client name is self-asserted, so show the host of the client_id URL on consent and keep DCR as a capped fallback. Claude's documentation warns that DCR makes Claude register a new client on every fresh connection, which can create very large numbers of registered clients for a directory-listed server, and recommends CIMD or Anthropic-held credentials instead. OpenAI says ChatGPT registers once per connection, which still adds up across many users. Meanwhile, Claude's lazy authentication guide says the consent screen should name the host of the client_id URL rather than client_name, because anyone can write any name into a metadata document they host. The MCP security considerations add that the redirect hostname must be shown, because any local process can claim a loopback redirect.

Your consent screen therefore shows the client host (for example chatgpt.com), the redirect hostname, and the scopes, plus a warning when every redirect is a loopback address.

Consent also decides tenancy, because OAuth scopes name actions and say nothing about the workspace they apply to. Makerkit's tested Supabase implementation shows the failure: Supabase ignores the resource parameter, every token carries the same audience, and a token minted for one workspace URL replays against another unless the product checks its own grant table. Store a grant record when the user approves:

{
  "grant_id": "grt_7f2c",
  "user_id": "usr_1043",
  "client_host": "chatgpt.com",
  "client_id": "https://chatgpt.com/oauth/client.json",
  "workspace_id": "ws_acme_eu",
  "scopes": ["projects:read"],
  "issuer": "https://auth.example.com",
  "created_at": "2026-10-07T09:12:00Z",
  "revoked_at": null
}

Record the exact client_id the host presented. OpenAI documents that ChatGPT uses https://chatgpt.com/oauth/client.json when your server supports issuer identification and a callback-specific document URL otherwise, so the same user can arrive with different client IDs depending on your metadata. Never accept a workspace ID from a tool argument the model filled in. Makerkit also reports that Supabase auto-approves repeat authorizations, so the workspace picker runs only once and a connected-apps settings screen becomes the only place a user can change or revoke the grant. Build that screen as part of the feature.

Validate every call, refresh, and revocation

Each MCP request needs the full resource-server check:

on every MCP request:
  token = bearer header only            # never a query string
  verify signature against issuer JWKS
  require token.iss == ISSUER           # exact string
  require token.aud == RESOURCE         # or client-bound substitute below
  require now < token.exp
  grant = grants.find(user, client, workspace_from_url)
  require grant and not grant.revoked_at
  require tool.scope in token.scope and in grant.scopes
  else: 401 with WWW-Authenticate resource_metadata
  on missing scope: 403 with error="insufficient_scope", scope="<all needed>"

If your identity provider cannot put the resource in aud, use the substitute Makerkit describes: pin the issuer and require a claim only OAuth client tokens carry, so a first-party browser session token cannot call the MCP endpoint. The MCP security considerations forbid passing the incoming token to upstream APIs; if your MCP server calls another service, it obtains a separate token for that service. Delegated credentials are covered in more depth in our guide to delegating user authority to product agents.

For step-up, Claude's lazy authentication guide recommends that a 403 challenge list every scope the user still needs, not only the missing one, because earlier step-up scopes are not reliably carried forward.

Long-lived connections also fail at refresh. The MCP security considerations require refresh-token rotation for public clients, and CIMD and DCR register hosts as public clients. Claude expects invalid_grant when a refresh token is dead, refreshes up to five minutes before expiry, sends form-encoded token requests, and gives discovery, registration, and token endpoints 10 seconds and refresh requests 30 seconds. OpenAI warns that deleting or rotating the registered client itself, rather than its tokens, produces invalid_client for users who are mid-connection.

Handle failure and recovery

Map each symptom to its layer before changing code:

SymptomLikely layerFix
MCP server sees requests, identity provider sees noneDiscoveryReturn 401 with resource_metadata, and confirm well-known paths return JSON, not your app's HTML
"Couldn't reach" only from hosted clientsNetworkAllow the host's documented egress range through firewalls in front of both servers
Host attempts DCR although you support CIMDSelection ruleAdd none to token methods, or accept that host on DCR deliberately
Callback rejectedRedirect allowlistAdd the exact hosted callback and a port-agnostic loopback match
Response rejected after loginIssuerMake iss, metadata issuer, and the first authorization_servers entry identical
Works for a day, then silent failuresRefreshRotate refresh tokens, return invalid_grant, keep endpoints under host time limits
Every user broken after an identity provider changeClient bindingRe-register DCR and pre-registered clients, and notify hosts that hold your client credentials

Claude caches discovery metadata per URL for about five minutes and serves the stale copy if a refresh fails, according to the lazy authentication guide, so wait out that window before judging a fix. Revoke at the grant, so the next tool call fails even while an access token is unexpired.

Verify the solution with a host conformance matrix

Before launch, run the same scripted connection in every host you claim to support and store the observed path:

host_matrix:
  - host: claude-web
    registration_observed: cimd        # cimd | dcr | preregistered
    token_method_observed: none
    redirect_uri_observed: https://claude.ai/api/mcp/auth_callback
    issuer_match: true
    workspace_bound: ws_acme_eu
    refresh_rotated: true
  - host: claude-code
    registration_observed: cimd
    redirect_uri_observed: http://127.0.0.1:<ephemeral>/callback
  - host: chatgpt
    registration_observed: cimd
    token_method_observed: private_key_jwt
    redirect_uri_observed: https://chatgpt.com/connector_platform_oauth_redirect

Read the registration path from your authorization server logs, not from the host's UI. Then run negative tests:

  • A token issued for another resource, or a session token without a client claim, gets 401 with a challenge.
  • A grant for workspace A cannot read workspace B through a different URL.
  • A revoked grant fails the next call.
  • A 403 step-up names every needed scope and the retried call succeeds.
  • A staged issuer change forces DCR and pre-registered clients to re-register while CIMD clients keep working.
  • Consent shows the client host and redirect hostname, never only client_name.

Test through a public HTTPS tunnel too. DocsAlot notes that hosted Claude connects from Anthropic's cloud, so localhost-only tests miss what customers hit.

Common mistakes

  • Treating a DCR-first tutorial as current. The 2026-07-28 specification deprecates DCR, and directory-scale DCR creates clients you cannot attribute or retire.
  • Listing two issuers for flexibility. Claude uses only the first one and ChatGPT may try both, so hosts disagree about which server issued the token.
  • Signalling auth only inside tool results. That works in hosts that read tool-level challenges and fails silently in Claude.
  • Letting the model choose the workspace. A tool argument can reach every workspace the user belongs to. Bind the workspace at consent.
  • Skipping the protocol boundary question. If you have not decided which product actions belong in MCP at all, start with our comparison of MCP, A2A, and a direct API.

What to do next

Pick the two hosts your customers ask for most, and connect your current MCP endpoint to both through a tunnel with logging enabled on your authorization server. Write down the registration path, token method, redirect URI, and issuer each one used. Any row that differs from what you intended, such as an unexpected DCR registration or a callback-specific redirect, is the first fix, and the matrix becomes the release gate for every later change to your MCP authentication setup.

Be first in line.

Join the waitlist and we'll email you the moment it's ready. No sales call.

Try the demo →
or talk to us