Repository navigation
Conversation
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
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
There was a problem hiding this comment.
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
|
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). |
Issue for this PR
Closes #66101
Type of change
What does this PR do?
Since v2.4.0 (bda12b5) remote MCP servers negotiate by default: probe
server/discover, fall back to legacyinitializewhen 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 withVersion negotiation failed: the server answered the probe with HTTP 500, even though a plaininitializeagainst the same server works. The stdio path of that same commit already falls back onEraNegotiationFailed; 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
protocolpins are unchanged.How did you verify your code works?
server/discoverwith HTTP 500 whileinitializeworks 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) andbun test test/mcp-oauth.test.ts(40 pass);bun typecheckand rootbun run checkclean.server/discoveronhttps://mcp.mate-ds.de/mate-mcpanswers 500,initializeanswers 200 (curl -i -X POST, any machine). With this change aMcpClient.connectto 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
Added by the opencode bot (AI-generated).
Related: #39354