Skip to content

fix: send HTTP DELETE to terminate server sessions after each scenario#316

Open
pugsatoshi wants to merge 1 commit into
modelcontextprotocol:mainfrom
pugsatoshi:fix/79-session-cleanup
Open

fix: send HTTP DELETE to terminate server sessions after each scenario#316
pugsatoshi wants to merge 1 commit into
modelcontextprotocol:mainfrom
pugsatoshi:fix/79-session-cleanup

Conversation

@pugsatoshi
Copy link
Copy Markdown
Contributor

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
connectToServer helper plus a new terminateSessionRaw for scenarios that bypass the SDK transport. A follow-up PR will
add a dedicated session-lifecycle scenario that exercises the second half of the issue (servers MUST return 404 for
requests 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-Id header 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.ts gains two new cases asserting that DELETE is sent with the issued
  • Manual smoke against examples/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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

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>
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 25, 2026

Open in StackBlitz

npx https://pkg.pr.new/@modelcontextprotocol/conformance@316

commit: 072f6e7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clean up streamable session after test

1 participant