claude-code - 💡(How to fix) Fix Streamable HTTP MCP: auth requirement should be based on 401 response, not well-known endpoint discovery [2 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#46879Fetched 2026-04-12 13:30:39
View on GitHub
Comments
2
Participants
2
Timeline
7
Reactions
0
Timeline (top)
labeled ×3commented ×2closed ×1cross-referenced ×1

Error Message

  • Server responds 200 to MCP initialize request (no Bearer token required)
  • /.well-known/oauth-authorization-server returns metadata
  • Claude Code displays "needs authentication"
RAW_BUFFERClick to expand / collapse

When connecting to a Streamable HTTP MCP server, Claude Code determines that authentication is required based solely on the presence of /.well-known/oauth-authorization-server (or /.well-known/oauth-protected-resource), and displays "needs authentication".

Per the MCP spec, the OAuth flow should only be triggered when the server responds with 401 Unauthorized to an MCP request — not when OAuth metadata endpoints merely exist. A server may expose these endpoints for clients that need them while still accepting unauthenticated requests (e.g., when a pre-authorized token is available server-side).

Observed behavior

  • Server responds 200 to MCP initialize request (no Bearer token required)
  • /.well-known/oauth-authorization-server returns metadata
  • Claude Code displays "needs authentication"

Expected behavior

  • Claude Code sends the MCP request first
  • Only if the server responds with 401 should the OAuth flow be initiated

extent analysis

TL;DR

Modify Claude Code to only trigger the OAuth flow when the server responds with a 401 Unauthorized status code to an MCP request.

Guidance

  • Review the Claude Code authentication logic to ensure it checks the server's response status code before initiating the OAuth flow.
  • Update the code to send the MCP request without authentication first and only trigger the OAuth flow if the server responds with a 401 status code.
  • Verify that the server's /.well-known/oauth-authorization-server endpoint is not being used as the sole indicator for authentication requirement.
  • Test the updated code with a server that exposes OAuth metadata endpoints but accepts unauthenticated requests to ensure the correct behavior.

Example

// Pseudo-code example of the updated authentication logic
if (serverResponse.statusCode == 401) {
  // Trigger OAuth flow
} else {
  // Proceed with the request without authentication
}

Notes

The current implementation of Claude Code may cause unnecessary authentication prompts when connecting to servers that expose OAuth metadata endpoints but do not require authentication for certain requests.

Recommendation

Apply workaround: Update the Claude Code authentication logic to follow the MCP spec and only trigger the OAuth flow when the server responds with a 401 Unauthorized status code. This ensures that the OAuth flow is only initiated when necessary, providing a better user experience.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

  • Claude Code sends the MCP request first
  • Only if the server responds with 401 should the OAuth flow be initiated

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix Streamable HTTP MCP: auth requirement should be based on 401 response, not well-known endpoint discovery [2 comments, 2 participants]