Skip to content

mcp: ignore the session ID on server/discover responses - #1523

Merged
guglielmo-san merged 3 commits into
modelcontextprotocol:mainfrom
simon0191:discover-session-id
Nov 16, 2026
Merged

guglielmo-san merged 3 commits into
modelcontextprotocol:mainfrom
simon0191:discover-session-id

Conversation

@simon0191

@simon0191 simon0191 commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

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 now records a session ID only from the response to initialize.

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.

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>
@github-actions github-actions Bot added the missing-issue-link Auto-closed: PR needs a linked issue assigned to its author (see CONTRIBUTING.md) label Nov 12, 2026
@github-actions github-actions Bot closed this Nov 12, 2026
@github-actions github-actions Bot reopened this Nov 13, 2026
@github-actions github-actions Bot removed the missing-issue-link Auto-closed: PR needs a linked issue assigned to its author (see CONTRIBUTING.md) label Nov 13, 2026
Comment thread mcp/streamable.go Resolved
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
guglielmo-san merged commit ed66761 into modelcontextprotocol:main Nov 16, 2026
9 checks passed
@guglielmo-san

Copy link
Copy Markdown
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.
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: streamable client keeps the session ID from a rejected server/discover, so the fallback initialize fails

2 participants