MCP server returns 401 without resource_metadata in WWW-Authenticate: how to fix
Unauthenticated MCP calls must return 401 with a WWW-Authenticate header containing resource_metadata. Reproduce with curl and fix it.
An OAuth-protected MCP server must answer an unauthenticated request with HTTP 401 and a WWW-Authenticate: Bearer resource_metadata="<url>" header. A 200 or 403, or a 401 with no resource_metadata, makes OAuth discovery harder or impossible for the client.
What you see
A scan reports auth.challenge-401 with one of two details:
- "Unauthenticated status was 403, expected 401" (or 200). This is a failure.
- "WWW-Authenticate has no resource_metadata pointer". This is reported as a warning.
In a client the symptom is a failed or never-starting sign-in. The exact client message varies and is not verified here.
Why it happens
Frameworks and gateways often return 403 for missing credentials, return 200 with a JSON-RPC error, or send a bare WWW-Authenticate: Bearer. The rule's fix text says Claude ignores WWW-Authenticate on a 200 and only falls back to well-known probing when the pointer is absent.
Check it yourself
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/mcp"
Fix
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/mcp"'
)
.json({ error: "unauthorized" });
return;
}
next();
}
# FastAPI example
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/mcp"'},
)
Check that a CDN, WAF or API gateway in front of the server does not rewrite the status or strip the header.
Verify
Re-run the curl command: status 401 and the header present. Then fetch the URL inside resource_metadata and confirm it returns JSON (see auth.prm-missing).
Which clients care
The rule lists Claude and ChatGPT. For Claude, the rule text states that a WWW-Authenticate on a 200 is ignored. ChatGPT behaviour is not described in the rule beyond the platform tag.
Source
Claude authentication docs: https://claude.com/docs/connectors/building/authentication
Run a free scan at https://mcpshipyard.com/scan to check every rule at once.
Check every rule at once
A free scan runs this check and the other 152 against your live URL.
Related fixes
- Add Client ID Metadata Documents (CIMD) next to Dynamic Client Registration
- API key or token in the MCP server URL (?key=): why it fails and how to fix
- ChatGPT MCP: dynamic client registration not supported (CIMD or DCR required)
- Claude says "Couldn't reach the MCP server": missing protected resource metadata