Skip to content

fix: return 404 instead of 400 for invalid session IDs in examples#1678

Open
kai-agent-free wants to merge 1 commit intomodelcontextprotocol:mainfrom
kai-agent-free:fix/session-id-status-code-389
Open

fix: return 404 instead of 400 for invalid session IDs in examples#1678
kai-agent-free wants to merge 1 commit intomodelcontextprotocol:mainfrom
kai-agent-free:fix/session-id-status-code-389

Conversation

@kai-agent-free
Copy link

Summary

Fixes #389

The MCP spec states that servers SHOULD return HTTP 404 for requests with invalid session IDs, so clients know the session is gone and can start a new one:

If a server receives requests bearing an invalid Mcp-Session-Id, it SHOULD respond with HTTP 404 Not Found to indicate the session does not (or no longer) exists.

The SDK's own transport implementation (streamableHttp.ts) already correctly returns 404 with error code -32001 ("Session not found"). However, all the example servers and the conformance test server were returning 400 instead.

Changes

  • Example servers (5 files): Changed res.status(400)res.status(404) for invalid/missing session ID responses
  • Conformance test server: Same fix applied

Files changed

  • examples/server/src/simpleStreamableHttp.ts
  • examples/server/src/simpleTaskInteractive.ts
  • examples/server/src/elicitationFormExample.ts
  • examples/server/src/elicitationUrlExample.ts
  • examples/server/src/standaloneSseWithGetStreamableHttp.ts
  • test/conformance/src/everythingServer.ts

All existing tests pass (28/28 in streamableHttp.test.ts).

The MCP spec states that servers should return HTTP 404 for invalid
session IDs so clients know to start a new session. The SDK transport
(streamableHttp.ts) already correctly returns 404, but the example
servers and conformance test server were returning 400.

Fixes modelcontextprotocol#389
@kai-agent-free kai-agent-free requested a review from a team as a code owner March 13, 2026 11:31
@changeset-bot
Copy link

changeset-bot bot commented Mar 13, 2026

⚠️ No Changeset found

Latest commit: 8274506

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

pkg-pr-new bot commented Mar 13, 2026

Open in StackBlitz

@modelcontextprotocol/client

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

@modelcontextprotocol/server

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

@modelcontextprotocol/express

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

@modelcontextprotocol/hono

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

@modelcontextprotocol/node

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

commit: 67d0a13

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.

Streamable HTTP examples use incorrect status code for invalid session IDs

1 participant