Skip to content

Comments

fix(examples): use 404 status for invalid session IDs#1560

Open
corvid-agent wants to merge 1 commit intomodelcontextprotocol:mainfrom
corvid-agent:fix/invalid-session-status-code
Open

fix(examples): use 404 status for invalid session IDs#1560
corvid-agent wants to merge 1 commit intomodelcontextprotocol:mainfrom
corvid-agent:fix/invalid-session-status-code

Conversation

@corvid-agent
Copy link
Contributor

Summary

  • Changes HTTP status code from 400 to 404 for invalid/missing session ID responses across all streamable HTTP examples
  • Per the MCP spec: "When a client receives HTTP 404 in response to a request containing an Mcp-Session-Id, it MUST start a new session"
  • Updated error messages from "Bad Request" to "Not Found" for consistency

Files changed

  • jsonResponseStreamableHttp.ts — POST handler
  • simpleStreamableHttp.ts — POST, GET, DELETE handlers
  • standaloneSseWithGetStreamableHttp.ts — POST, GET handlers
  • simpleTaskInteractive.ts — POST, GET, DELETE handlers
  • elicitationFormExample.ts — POST, GET, DELETE handlers
  • elicitationUrlExample.ts — POST, GET, DELETE handlers

Closes #389

Test plan

  • Verify all session-related 400 responses changed to 404
  • Non-session 400 responses (e.g., missing parameters) left unchanged

🤖 Generated with Claude Code

Per the MCP spec, servers should respond with 404 when presented with
an invalid session ID, so clients know to start a new session. The
examples incorrectly used 400 for this case.

Closes modelcontextprotocol#389

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@corvid-agent corvid-agent requested a review from a team as a code owner February 20, 2026 16:43
@changeset-bot
Copy link

changeset-bot bot commented Feb 20, 2026

⚠️ No Changeset found

Latest commit: cbe631d

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 Feb 20, 2026

Open in StackBlitz

@modelcontextprotocol/client

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

@modelcontextprotocol/server

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

@modelcontextprotocol/express

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

@modelcontextprotocol/hono

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

@modelcontextprotocol/node

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

commit: cbe631d

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