Skip to content

fix(mcp): carry session and protocol headers after initialization - #935

Open
rudycelekli wants to merge 1 commit into
Tencent:mainfrom
rudycelekli:fix/mcp-stateful-http-session
Open

rudycelekli wants to merge 1 commit into
Tencent:mainfrom
rudycelekli:fix/mcp-stateful-http-session

Conversation

@rudycelekli

@rudycelekli rudycelekli commented Nov 16, 2026 •

Copy link
Copy Markdown

What changed

Stateful Streamable HTTP MCP servers can require a returned session ID and negotiated protocol version on subsequent requests. The client discarded both and encoded the initialized notification with an ID. Send the session and protocol headers on the notification, tools/list, and tools/call, and encode the notification without an ID. Protocol contract: https://modelcontextprotocol.io/specification/2025-11-25/basic/transports

Scope

  • Platform core / API / runner

Validation

A strict synthetic HTTP endpoint rejects the baseline handshake and passes initialization, listing, and calling with this fix. The mcpclient package tests and vet pass.

Full platform build and public browser checks were not run for this branch. All fixtures are synthetic.

Current-base review follow-up

Rebased onto 6f606cf2a7354f05d1dbf2085f4eb832b7e89ccb, preserving current upstream request cancellation. The initialized notification omits its JSON-RPC ID and still uses http.NewRequestWithContext.

Fresh focused validation: go test ./internal/mcpclient -count=1 -timeout=60s, go vet ./internal/mcpclient, and git diff --check passed. No full platform/frontend/browser suite was run; hosted required CI still needs verification.

Coordination with #936: its reviewed head b6c593436cf8d2b88011fb0cb744d80fe99782db and this rebased head automatically merge cleanly in both orders, producing identical Git trees. The combined MCP package tests and vet passed. An additional integration-only strict HTTP fixture verifies session/protocol headers on both catalog pages, the initialized notification without an ID, cursor forwarding, and cancellation during the second page without returning a partial catalog. The merged listToolsPage retains setSessionHeaders; pagination bounds and upstream context propagation remain intact. These remain independent PRs against main; no production coordination patch is required for these tested heads.

The pinned secret-scan helper supports Linux x86_64 only and is unsupported on this macOS ARM64 environment. Full platform/hosted CI remains a separate merge gate. Fixtures are synthetic and no providers were called.

Yanami-2K
Yanami-2K previously approved these changes Nov 16, 2026

@Yanami-2K Yanami-2K left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

核对了 internal/mcpclient/client.go:初始化成功(2xx 且无 JSON-RPC error)时记录 Mcp-Session-Id 和协商出的 protocolVersion,并通过 setSessionHeaders 带到 notifications/initialized、tools/list、tools/call;通知去掉了 id 字段,符合 Streamable HTTP 规范。新测试用严格的假服务端分别断言缺头、通知带 id、未发通知三种情况都会被拒,确实覆盖了修复点。提醒:#936、#939、#940 也改了同一个文件(其中 #939 同样改了 Client 结构体和 ensureInit),先合入的会让其余 PR 需要 rebase;另外本 PR 只跑了开源扫描,合入前请触发 platform CI。

@rudycelekli

Copy link
Copy Markdown
Author

Rebased this PR onto current main (6f606cf) as ff1241a4a5fed7cf2a602392153b90f3bb0117e5. The notification remains ID-free while retaining upstream NewRequestWithContext cancellation. Fresh MCP package tests, vet and git diff --check passed.

I also checked coordination with #936 at b6c593436cf8d2b88011fb0cb744d80fe99782db: both merge orders automatically merge cleanly and produce the same Git tree. The combined MCP package tests and vet pass. An integration-only strict synthetic endpoint additionally verifies both pages receive the session/protocol headers, pagination cursors are forwarded, the initialized notification has no ID, and cancellation during the second page returns no partial catalog. setSessionHeaders is retained inside the extracted listToolsPage; the 100-page bound and context cancellation remain intact. These tested heads can stay independent main-targeted PRs.

Full platform/frontend/browser checks were not run. The pinned secret-scan helper supports Linux x86_64 only and is unsupported on this macOS ARM64 environment; hosted required CI still needs verification before merge. The PR description now records these limits explicitly. No paid providers were called.

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.

2 participants