fix: send HTTP DELETE to terminate server sessions after each scenario#316
Open
pugsatoshi wants to merge 1 commit into
Open
fix: send HTTP DELETE to terminate server sessions after each scenario#316pugsatoshi wants to merge 1 commit into
pugsatoshi wants to merge 1 commit into
Conversation
The conformance test harness opened sessions against servers under test but never issued an HTTP DELETE to terminate them, leaving a dangling session on the server after each scenario. This violates the "hermetic" expectation called out in the Streamable HTTP transport spec. - `client-helper.connectToServer` now calls `transport.terminateSession()` before `client.close()`. A 405 response (DELETE not supported) is tolerated because the spec allows the server to refuse. - A new `terminateSessionRaw` helper handles scenarios that bypass the SDK client and open sessions via raw `fetch` (`lifecycle.ts`, `http-standard-headers.ts`). - `sse-polling.ts` and `sse-multiple-streams.ts`, which manage their own transport, now terminate the session in their existing `finally` block before closing the client. - `lifecycle.test.ts` gains two cases asserting that DELETE is sent with the issued session ID and that no DELETE is sent when the server did not assign one. Verified manually against `examples/servers/typescript/everything-server.ts` that running a server scenario now causes the server to log `Received session termination request for session <id>`. Fixes modelcontextprotocol#79 Signed-off-by: Satoshi Ito <satoshi.ito.tf@hitachi.com>
commit: |
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.
This pull request makes server-targeting scenarios issue an HTTP DELETE to terminate the MCP session before closing the
client, so that each scenario leaves the server under test in a hermetic state. The fix lands in the shared
connectToServerhelper plus a newterminateSessionRawfor scenarios that bypass the SDK transport. A follow-up PR willadd a dedicated
session-lifecyclescenario that exercises the second half of the issue (servers MUST return 404 forrequests on a terminated session ID).
Motivation and Context
Fixes #79.
The Streamable HTTP transport spec says clients SHOULD send an HTTP DELETE with the
Mcp-Session-Idheader to explicitly terminate a session when they no longer need it.The conformance harness never did this — every scenario opened a session via
initialize, ran its checks, and let the server hold onto the dangling session.For real servers that gate resources by active session (in-memory state, connection slots, etc.), this is observable as drift between conformance runs.
How Has This Been Tested?
npm run check— typecheck + lint pass.npm run test— 173/173 tests pass.lifecycle.test.tsgains two new cases asserting that DELETE is sent with the issuedexamples/servers/typescript/everything-server.ts:$ PORT=3010 npx tsx examples/servers/typescript/everything-server.ts
$ npx tsx src/index.ts server --url http://localhost:3010/mcp --scenario tools-call-simple-text
Running client scenario 'tools-call-simple-text' against server: http://localhost:3010/mcp
Checks:
2026-05-21T10:23:18.394Z [tools-call-simple-text] SUCCESS Tool returns simple text content
Test Results:
Passed: 1/1, 0 failed, 0 warnings
The everything-server now logs
Received session termination request for session <id>for every scenario, which was previously absent.Breaking Changes
None
Types of changes
Checklist
Additional context