fix: reinitialize expired streamable sessions#2150
Conversation
🦋 Changeset detectedLatest commit: 0c15f0c The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@modelcontextprotocol/client
@modelcontextprotocol/codemod
@modelcontextprotocol/server
@modelcontextprotocol/server-legacy
@modelcontextprotocol/express
@modelcontextprotocol/fastify
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
|
Added a patch changeset for @modelcontextprotocol/client. Local validation: pnpm exec changeset status --since upstream/main shows the client patch bump, git diff --check passed, and the pre-push hook completed typecheck, build, and lint successfully. |
80b3f60 to
b2a0df1
Compare
|
Rebased on current Validated locally:
The pre-push hook also completed the repo-wide build, typecheck, and lint steps successfully. |
b2a0df1 to
0c15f0c
Compare
|
Updated the branch to include the e2e expectation changes for session-expiry recovery. The red e2e job was from two stale expectations:
Validation: The pre-push hook also completed full repo typecheck, build, and lint before the force-push. |
Summary
Fixes #1476.
When a Streamable HTTP server restarts, a client can keep sending POST requests with a stale
MCP-Session-Id. The SDK currently reports the server's 404 response asClientHttpNotImplementedand leaves the expired session in place.This change handles a 404 from a request that used a session ID as an expired-session signal:
Clientrun a fresh initialize handshake on the same transportThe retry is limited to one attempt so repeated 404s still surface as errors instead of looping.
To verify
pnpm --filter @modelcontextprotocol/client exec vitest run test/client/streamableHttp.test.ts -t "reinitializes and retries once"pnpm --filter @modelcontextprotocol/client exec vitest run test/client/streamableHttp.test.tspnpm --filter @modelcontextprotocol/client typecheckpnpm --filter @modelcontextprotocol/client lintgit diff --checktypecheck,build, andlint