Repository navigation
mcp: ignore the session ID on server/discover responses - #1523
Merged
guglielmo-san merged 3 commits intoNov 16, 2026
Merged
Conversation
A legacy server may reject server/discover with HTTP 200 and a JSON-RPC error while setting Mcp-Session-Id. The streamable client stored that ID and sent it on the fallback initialize, so a server that assigned a new session ID made Connect fail with "mismatching session IDs". server/discover is sessionless in 2026-07-28, and under 2025-11-25 the session ID belongs to the response carrying the InitializeResult, so the client no longer records a session ID from a server/discover response. Fixes modelcontextprotocol#1522 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Per review, adopt Mcp-Session-Id only on the response to initialize, which is where 2025-11-25 assigns it, instead of excluding server/discover. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
guglielmo-san
approved these changes
Nov 16, 2026
Contributor
|
@simon0191 thank you for the contribution! |
birdayz
pushed a commit
to redpanda-data/ai-sdk-go
that referenced
this pull request
Nov 26, 2026
…on ID (#354) * fix(mcp): connect to servers that reject server/discover with a session ID go-sdk v1.8.0 keeps the Mcp-Session-Id of every response it accepts, the rejection of server/discover included. A server that rejects discover with a session ID of its own, and then answers the initialize fallback with another session ID, makes the client fail the connection with "mismatching session IDs". Redpanda AI Gateway puts such a server in front of each remote MCP member, so an agent loses every tool on that member and stops before its first model call. Retry with the newest MCP revision that does not send server/discover. The session then opens with initialize, and only one session ID ever exists. Remove the retry after go.mod carries a go-sdk release that includes modelcontextprotocol/go-sdk#1523. * refactor(mcp): simplify the discover session mismatch retry Remove the context check from the retry guard. A cancelled context gives an error without the mismatch text, so the text check already covers it. Fold isDiscoverSessionMismatch into its only caller. Remove the null ID branch from the test server. The client always sends server/discover as a request, so it always has an ID. * docs(mcp): trim the discover session mismatch comments Remove the production impact from the godoc of connectSession and of its test. The PR and the first commit already record it. * docs(mcp): describe the discover session mismatch without naming a product The workaround applies to any server that rejects server/discover with a session ID of its own. * test(mcp): show which handshake opens the session after a discover mismatch The stand-in server now records each request and its Mcp-Session-Id. The test checks that the retry sends no server/discover, and that the initialize that opens the session carries no session ID. Both checks also pass on go-sdk v1.9.0-pre.1. A comment on the ProtocolVersion option of the retry now says that this option is the fix.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A legacy server may reject
server/discoverwith HTTP 200 and a JSON-RPC error while settingMcp-Session-Id. The streamable client stored that ID and sent it on the fallbackinitialize, so a server that assigned a new session ID madeConnectfail withmismatching session IDs.server/discoveris sessionless in 2026-07-28, and under 2025-11-25 the session ID belongs to the response carrying theInitializeResult, so the client now records a session ID only from the response toinitialize.The new table test covers the HTTP 200 / -32601 case and four HTTP 400 rejection shapes seen from real legacy servers (plain text, -32600 with an unmatched id, -32600 with legacy-only
data.supported), each with a session ID on the discover response.Fixes #1522
AI disclosure: written with Claude Code; I reviewed the change and can explain it.