Skip to content

fix(mcp): fall back to legacy when the probe answer is an HTTP error - #66111

Open
johnp wants to merge 1 commit into
anomalyco:devfrom
johnp:mcp-probe-fallback
Open

johnp wants to merge 1 commit into
anomalyco:devfrom
johnp:mcp-probe-fallback

Conversation

@johnp

@johnp johnp commented Nov 24, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #66101

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Since v2.4.0 (bda12b5) remote MCP servers negotiate by default: probe server/discover, fall back to legacy initialize when nothing answers. But a server that answers the probe with an HTTP 5xx — what Spring AI / mcp-java transports do for unimplemented methods — fails the whole connect with Version negotiation failed: the server answered the probe with HTTP 500, even though a plain initialize against the same server works. The stdio path of that same commit already falls back on EraNegotiationFailed; over HTTP only the timeout was caught.

This extends the remote fallback to probe failures that got an HTTP error answer. Availability statuses (408/429/502/503/504) are excluded because a server that is down needs the probe retried, not a doubled request, and auth refusals can't hit the fallback: the SDK delivers probe 401/403 under separate error codes. Explicit protocol pins are unchanged.

How did you verify your code works?

  • Added a test: a server that answers server/discover with HTTP 500 while initialize works now connects as legacy and lists its tools. Reverting the predicate fails the test with the issue's exact error.
  • packages/core: bun test test/mcp.test.ts (115 pass, including the pool tests that assert a 503 server still sees exactly one probe per retry) and bun test test/mcp-oauth.test.ts (40 pass); bun typecheck and root bun run check clean.
  • Against the live server from the issue: server/discover on https://mcp.mate-ds.de/mate-mcp answers 500, initialize answers 200 (curl -i -X POST, any machine). With this change a McpClient.connect to that URL comes up in the legacy era and lists its 17 tools; without it, it throws the 500 negotiation error.

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Added by the opencode bot (AI-generated).

Related: #39354

Remote connects fell back from the server/discover probe only on timeout. Servers that answer the probe with an HTTP error (Spring AI crashes with a 500) failed the whole connect although their initialize handshake works. The stdio path already falls back on EraNegotiationFailed; mirror that over HTTP, except for statuses that only say unavailable. Auth refusals arrive as their own errors and stay fatal.

Addresses anomalyco#66101
@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels Nov 24, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix works and I found nothing that should block a merge.

How I checked: the public server from #66101 now answers server/discover with 200, so it no longer shows the bug. I put a local proxy in front of it that returns HTTP 500 for the probe and ran the issue's repro script from source on both checkouts. On the base, the default protocol fails with Version negotiation failed: the server answered the probe with HTTP 500. With this PR it connects as legacy after one probe and one initialize. The new test fails on the base and passes here. mcp.test.ts has one failure, which also happens on the base; mcp-oauth.test.ts passes.

I confirmed in the bundled SDK (2.4.0) that a 5xx probe answer arrives directly as SdkHttpError with EraNegotiationFailed, so the new check matches it. 401/403 still go to the auth path, and an explicit protocol setting is unaffected.

Public API: unchanged.

Related: #39354

@johannespfrang-h-d

Copy link
Copy Markdown

Thanks for checking. Yes, that public server was just changed over to dual-protocol support, but since Spring AI 2.1.0 was just released a few days ago, there are likely still many servers out there which 500 (plus, Spring AI has no native dual-protocol support, so we wrote our own).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mcp: server/discover probe answered with HTTP 500 hard-fails; no legacy fallback despite docs

2 participants