Answer progress0%
← All questions

Production question

How do I debug MCP OAuth failures?

Walk the MCP authorization flow in order: the 401 response and its WWW-Authenticate header, the protected resource metadata, the authorization server metadata, client registration, the authorization code exchange with PKCE, and audience validation on your server. Most failures come from a mismatched resource URL, a rejected redirect URI or a token issued for the wrong audience.

The answer

A remote MCP server that requires sign-in acts as an OAuth protected resource. When a client calls it without a valid token, the server answers 401 with a WWW-Authenticate header that points to its protected resource metadata. The client then discovers the authorization server, registers or identifies itself, runs the authorization code flow with PKCE, and retries with a token issued for your server.

SymptomLikely causeCheck
Client never shows a sign-in promptNo WWW-Authenticate header on the 401, or unreachable metadata.Request the server without a token and read the header.
Sign-in fails before the consent screenRedirect URI not allowed, or registration rejected.Authorization server logs and allowed redirect URIs.
Token exchange failsPKCE method not supported, or the code was reused.That S256 is advertised and used.
Signed in, but every call returns 401Token audience or resource does not match your server URL.Canonical URL, scheme and trailing slash on both sides.
Some tools return 403Scope not granted for that operation.Requested scopes against what the tool requires.
Works, then fails laterExpired token and a failed refresh.Token lifetime, refresh grant and clock skew.

Compare your server with a working example. Flowlines publishes its own protected resource metadata and authorization server metadata. The MCP authorization specification defines each step; check the revision your server implements.

Never log tokens or authorization headers while debugging. Record authentication failures as their own error class, by client. A failed handshake never reaches a tool, so it will not appear as a failed tool call. In Flowlines, a sudden drop in calls from one client after an authentication change is the clue to look here.

Published

100 MCP sessions a month, free

Answer it with your own production evidence.