fix(client): include Mcp-Session-Id header on proxy-mode requests (spec compliance)#1376
Open
aicayzer wants to merge 1 commit into
Open
Conversation
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.
Closes #905.
Problem
Per the MCP spec at
docs/specification/2025-11-25/basic/transports.mdx:The Inspector's proxy-mode fetch closure throws the SDK-supplied session header away. The SDK's
StreamableHTTPClientTransportcapturesMcp-Session-Idfrom the init response and threads it intoinit.headerson every subsequent fetch. The closure atclient/src/lib/hooks/useConnection.ts:711-737spreads...initbefore settingheaders: { ...headers, ...proxyHeaders }, so the latter overwrites the SDK headers — including the session ID.The direct-mode closure at L602-633 has the inverse spread order (
headersfirst, then...init) and works correctly. The asymmetry is the bug.This is independent of and complementary to the
Access-Control-Expose-Headers: Mcp-Session-IdCORS workaround that several users discovered on the issue thread (#905). That workaround fixes a separate direct-mode CORS-visibility problem; this PR fixes a proxy-mode header-propagation bug that exists regardless of CORS configuration.Fix
Build the final headers object with explicit precedence: user
headers→proxyHeaders→ SDK-suppliedinit.headers. The three sources don't share keys today, but explicit ordering documents intent and keeps the SDK'sMcp-Session-Idwinning.Applied to all three proxy-mode
eventSourceInit.fetchclosures (stdio, sse, streamable-http). For the streamable-http proxy path additionally pre-seedmcp-session-idfrom React state intorequestInit.headersbelt-and-braces, mirroring the direct-mode pattern at L573-576. Direct mode is unchanged.Files
client/src/lib/hooks/useConnection.ts— three proxyeventSourceInit.fetchclosures + streamable-httprequestInitpre-seedclient/src/lib/hooks/__tests__/useConnection.test.tsx— newMcp-Session-Id header propagation (issue #905)describe block with four tests:Mcp-Session-IdX-MCP-Proxy-Authwhen SDK-supplied headers are present (precedence regression guard)Mcp-Protocol-Version)Test plan
npm testpasses (full unit suite, 519 tests including 4 new regression tests)npm run prettier-checkpassescd client && npm run lintpassesNotes
upstream/v2/mainclients/web/) has a different transport architecture (core/mcp/remote/createRemoteTransport.ts+useInspectorClient) with no equivalent closure — no V2 mirror needed.