fix(mcp): emit a single Mcp-Session-Id header and relay DELETE results in the identity proxy#79
Open
maxlamagna wants to merge 1 commit into
Open
Conversation
maxlamagna
marked this pull request as ready for review
July 22, 2026 10:44
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.
The identity proxy's
_send_response_headerslisted bothMcp-Session-Idandmcp-session-id. Python's response-header lookup is case-insensitive, so both lookups returned the same session ID and the proxy emitted it twice. Strict streamable HTTP clients, including Claude Code 2.1.216 and 2.1.217, combine those duplicate values intoS, S, then echo the invalid ID on the next request. The server returns404 Session not foundduring theinitializetonotifications/initializedhandshake, so native MCP tools never attach. Older clients tolerated the duplicate, which hid the defect.do_DELETEalso collapsed every upstream HTTP error into a generic 502. It now relays the upstream HTTP status, body, and session header. Only network-levelURLErrorandOSErrorfailures become 502.tests/test_mcp_proxy.pyadds five regression tests covering a single case-insensitive session header, follow-up POST session preservation, DELETE success and HTTP-error relay, and an SDK-styleinitializetonotifications/initializedtotools/listlifecycle through the proxy.Live verification: Claude Code 2.1.217 attached native MCP tools and completed
chat_readandchat_sendthrough the patched proxy.Full suite: 80 tests ran; 78 passed, 1 Windows-only test was skipped on macOS, and 1 unrelated test failed.
test_stale_token_is_rejected_after_deregisterfails identically on upstreammainat51660a1without this patch and passes at372196e, immediately before #75. This PR does not modify that behavior.Fixes #80