claude-code - 💡(How to fix) Fix [Bug] MCP HTTP SDK crashes on non-JSON OAuth discovery responses [1 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#52158Fetched 2026-04-23 07:35:06
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
0
Participants
Timeline (top)
labeled ×3closed ×1

Error Message

the body unconditionally and propagates the SyntaxError as a fatal SDK auth failed error. This breaks connections to:

  • OAuth-capable servers fronted by CDNs (CloudFront) that return HTML error pages for blocked request methods The error surface is the same in both cases: Invalid OAuth error response: SyntaxError: JSON Parse error: ... Raw body: <...>.
RAW_BUFFERClick to expand / collapse

Bug Description MCP HTTP SDK hard-fails on non-JSON bodies from OAuth-flow requests (regression in 2.1.117)

Summary

The MCP HTTP client in Claude Code 2.1.117 crashes the entire connection whenever an OAuth-flow request returns a response body that isn't JSON. It attempts JSON.parse() on
the body unconditionally and propagates the SyntaxError as a fatal SDK auth failed error. This breaks connections to:

  • Servers that deliberately do not implement OAuth (404 Not Found on /.well-known/oauth-protected-resource) — should proceed unauthenticated per RFC 9728
  • OAuth-capable servers fronted by CDNs (CloudFront) that return HTML error pages for blocked request methods

The error surface is the same in both cases: Invalid OAuth error response: SyntaxError: JSON Parse error: ... Raw body: <...>.

Severity

High — renders any HTTP MCP server unreachable if it returns non-JSON on any OAuth-related request. In my setup this blocked 3 MCP servers that previously worked.

Environment

  • Claude Code: 2.1.117 (native install)
  • Platform: macOS 15.4 (darwin 25.4.0)
  • Installed via: native … Note: Content was truncated.

extent analysis

TL;DR

The MCP HTTP SDK needs to handle non-JSON response bodies from OAuth-flow requests to prevent crashes.

Guidance

  • Check the OAuth-flow request handling in the MCP HTTP client to ensure it can parse non-JSON response bodies without crashing.
  • Consider adding a try-catch block around the JSON.parse() call to catch and handle SyntaxError exceptions.
  • Verify that the SDK can proceed with unauthenticated requests when encountering non-JSON responses, as per RFC 9728.
  • Test the SDK with different types of non-JSON response bodies, such as HTML error pages, to ensure it can handle them correctly.

Example

try {
  const responseBody = JSON.parse(responseBodyString);
  // process JSON response body
} catch (error) {
  if (error instanceof SyntaxError) {
    // handle non-JSON response body
    console.log('Non-JSON response body encountered. Proceeding with unauthenticated request.');
  } else {
    throw error;
  }
}

Notes

The provided code snippet is a general example and may need to be adapted to the specific implementation of the MCP HTTP client. The exact fix will depend on the client's code and requirements.

Recommendation

Apply a workaround to handle non-JSON response bodies, such as adding a try-catch block around the JSON.parse() call, to prevent crashes and ensure the SDK can proceed with unauthenticated requests.

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…

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 [Bug] MCP HTTP SDK crashes on non-JSON OAuth discovery responses [1 participants]