Repository navigation
fix(mcp): carry session and protocol headers after initialization - #935
rudycelekli wants to merge 1 commit into
Conversation
Yanami-2K
left a comment
There was a problem hiding this comment.
核对了 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。
d2fe0b5 to
ff1241a
Compare
|
Rebased this PR onto current main ( I also checked coordination with #936 at 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. |
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
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 useshttp.NewRequestWithContext.Fresh focused validation:
go test ./internal/mcpclient -count=1 -timeout=60s,go vet ./internal/mcpclient, andgit diff --checkpassed. No full platform/frontend/browser suite was run; hosted required CI still needs verification.Coordination with #936: its reviewed head
b6c593436cf8d2b88011fb0cb744d80fe99782dband 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 mergedlistToolsPageretainssetSessionHeaders; 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.