Skip to content

fix: reinitialize expired streamable sessions#2150

Open
he-yufeng wants to merge 1 commit into
modelcontextprotocol:mainfrom
he-yufeng:fix/streamable-http-session-expiry-reinit
Open

fix: reinitialize expired streamable sessions#2150
he-yufeng wants to merge 1 commit into
modelcontextprotocol:mainfrom
he-yufeng:fix/streamable-http-session-expiry-reinit

Conversation

@he-yufeng
Copy link
Copy Markdown

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 as ClientHttpNotImplemented and leaves the expired session in place.

This change handles a 404 from a request that used a session ID as an expired-session signal:

  • clear the cached session ID
  • let Client run a fresh initialize handshake on the same transport
  • retry the original message once with the new session ID

The 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.ts
  • pnpm --filter @modelcontextprotocol/client typecheck
  • pnpm --filter @modelcontextprotocol/client lint
  • git diff --check
  • pre-push hook: full workspace typecheck, build, and lint

@he-yufeng he-yufeng requested a review from a team as a code owner May 24, 2026 09:48
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 24, 2026

⚠️ No Changeset found

Latest commit: dc2a285

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 24, 2026

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/client@2150

@modelcontextprotocol/codemod

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/codemod@2150

@modelcontextprotocol/server

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/server@2150

@modelcontextprotocol/express

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/express@2150

@modelcontextprotocol/fastify

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/fastify@2150

@modelcontextprotocol/hono

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/hono@2150

@modelcontextprotocol/node

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/node@2150

commit: dc2a285

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.

Client received "no session ID or not initialization request" when server restart

1 participant