MCP 401 without resource_metadata in WWW-Authenticate
Why an OAuth-protected MCP server must answer 401 with a resource_metadata pointer, how to check yours with curl, and how to fix gateways that drop the header.
If your MCP server returns 401 with no resource_metadata in the WWW-Authenticate header, clients have to guess where your OAuth metadata lives, and some will fail. Return 401 plus WWW-Authenticate: Bearer resource_metadata="<url>" pointing at an HTTPS URL that serves your protected resource metadata, and make sure no gateway rewrites the status or strips the header.
This page covers the case where the server does require sign-in. If your server is meant to be public, none of this applies.
What the spec and Claude's docs say
The MCP authorization specification (2025-11-25 revision) says servers must implement one of two discovery mechanisms: include the metadata URL in WWW-Authenticate under resource_metadata when returning 401, or serve metadata at a well-known URI (/.well-known/oauth-protected-resource at the root, or with the endpoint path appended). Clients must support both: use the header when it is present and otherwise fall back to constructing the well-known URIs. The spec also says servers should include a scope parameter in the header.
Anthropic's docs add Claude specifics. A WWW-Authenticate header on a 200 response is ignored, so the status has to be 401. If the pointer is absent, Claude looks at the standard well-known paths on your MCP origin, and if those return 404, discovery fails. Anthropic describes a failure that surfaces as "Couldn't reach the MCP server", or as a sign-in that sends the browser to /authorize on your MCP host, which does not exist. Sources: the MCP authorization spec and Claude's authentication docs.
The exact text each client shows for this failure varies and is not verified here.
Diagnosis tree
1. What status does an unauthenticated call return?
curl -i -X POST https://mcp.acme.example/mcp \
-H 'Content-Type: application/json' \
-H 'Accept: application/json, text/event-stream' \
-d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'
Expected:
HTTP/2 401
www-authenticate: Bearer resource_metadata="https://mcp.acme.example/.well-known/oauth-protected-resource", scope="orders:read"
Read the result:
200with a JSON-RPC error body: the server treats missing credentials as an application error. Clients that key off the status never start OAuth. Change it to 401.403: many frameworks and gateways use 403 for "no credentials". The MCP spec reserves 403 for invalid scopes or insufficient permissions and uses 401 for "authorization required or token invalid". Change it.401with a bareWWW-Authenticate: Beareror no header: continue to step 2.
The scanner reports this as auth.challenge-401: a non-401 status is a failure and a missing pointer is a warning.
2. Is the header being stripped between your app and the internet?
Compare what the app emits with what a public client receives.
# on the host, bypassing the proxy
curl -si -X POST http://127.0.0.1:8080/mcp -H 'Content-Type: application/json' \
-H 'Accept: application/json, text/event-stream' \
-d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}' | grep -i '^www-authenticate'
# through the public edge, from another network
curl -si -X POST https://mcp.acme.example/mcp -H 'Content-Type: application/json' \
-H 'Accept: application/json, text/event-stream' \
-d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}' | grep -i '^www-authenticate'
If the first prints the header and the second prints nothing, a CDN, WAF or API gateway is dropping or rewriting it. Fix the proxy rule. Some gateways also replace your 401 with their own page when they handle auth themselves, in which case the pointer has to be configured there.
3. Does the pointer URL serve metadata?
curl -i https://mcp.acme.example/.well-known/oauth-protected-resource
Expect 200 and JSON. A 404 here is auth.prm-missing. The resource field must equal the URL users enter, including the path (auth.resource-mismatch). The authorization_servers list should put the issuer you want first: Anthropic says Claude uses only the first entry.
{
"resource": "https://mcp.acme.example/mcp",
"authorization_servers": ["https://auth.acme.example"],
"scopes_supported": ["orders:read", "orders:write"],
"bearer_methods_supported": ["header"]
}
4. Does the authorization server publish metadata?
curl -i https://auth.acme.example/.well-known/oauth-authorization-server
curl -i https://auth.acme.example/.well-known/openid-configuration
Either one is enough for Claude, per Anthropic's docs. If both 404 or are blocked, see auth.as-metadata-missing.
Fixes
Set the header in your auth middleware.
function requireAuth(req, res, next) {
if (!validToken(req.headers.authorization)) {
res
.status(401)
.set(
"WWW-Authenticate",
'Bearer resource_metadata="https://mcp.acme.example/.well-known/oauth-protected-resource", scope="orders:read"'
)
.json({ error: "unauthorized" });
return;
}
next();
}
from fastapi import Response
def challenge() -> Response:
return Response(
status_code=401,
headers={
"WWW-Authenticate": 'Bearer resource_metadata="https://mcp.acme.example/.well-known/oauth-protected-resource", scope="orders:read"'
},
)
Point resource_metadata at an absolute HTTPS URL that your platform actually routes. On serverless or edge platforms that only forward a path prefix, a URL under your MCP path or a separate route is more reliable than relying on the root /.well-known/ path.
Common traps:
- A
WWW-Authenticatevalue that is not a Bearer challenge, or that lists several challenges with the pointer on the wrong one. - A health check or
OPTIONShandler answering before the auth middleware runs, so only some routes challenge. - Returning the challenge on
GETbut not onPOST. Test the same method clients use. - A 401 that lacks CORS exposure for browser-based clients: the browser hides
WWW-Authenticateunless you list it inAccess-Control-Expose-Headers. See the CORS guide.
Verify
Re-run step 1 from a network that is not yours and confirm the status and header, then fetch the URL inside resource_metadata. Then connect from the client you care about and confirm the sign-in page opens on your authorization server, not on your MCP host.
If sign-in opens but fails afterward, the problem is later in the flow: see invalid_token after OAuth and dynamic client registration not supported.
Run a free scan at https://mcpshipyard.com/scan to check every rule at once.
Check your server against these rules
Scan runs the checks from this guide against a live URL and lists each failing rule with its fix.