Add HTTP client close for explicit session termination#326
Open
atesgoral wants to merge 1 commit intomodelcontextprotocol:mainfrom
Open
Add HTTP client close for explicit session termination#326atesgoral wants to merge 1 commit intomodelcontextprotocol:mainfrom
atesgoral wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
9f681a1 to
b56d607
Compare
Per MCP spec, clients that no longer need a session SHOULD send an HTTP DELETE to the MCP endpoint with the Mcp-Session-Id header to explicitly terminate it. Servers MAY respond with 405 Method Not Allowed when they don't support client-initiated termination. `MCP::Client::HTTP#close` sends the DELETE with session headers, clears local session state regardless of outcome, and is a no-op when no session has been established. https://modelcontextprotocol.io/specification/2025-11-25/basic/transports#session-management
b56d607 to
ff3a42f
Compare
This was referenced Apr 20, 2026
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.
Summary
Adds
MCP::Client::HTTP#closeto explicitly terminate a server session.Per the Streamable HTTP spec, clients that no longer need a session SHOULD send an HTTP DELETE to the MCP endpoint with the
Mcp-Session-Idheader. The server MAY respond with 405 Method Not Allowed when it doesn't support client-initiated termination.Behavior
DELETEto the MCP endpoint withMcp-Session-IdandMCP-Protocol-Versionheaderssession_id,protocol_version) regardless of the server's response405 Method Not Allowedis treated as successPart of a stacked series
This is PR #4 of a series splitting #321 into small, self-contained changes:
202 AcceptedhandlingMcp-Session-Id/MCP-Protocol-Version)connect)Test plan
bundle exec rake test— 762 runs)examples/streamable_http_server.rb: DELETE 200 from server, second request with the terminated session ID raisesSessionExpiredError🤖 Generated with Claude Code