Skip to content

Streamable HTTP examples use incorrect status code for invalid session IDs #389

Closed

Description

@connor4312

Currently, the streamable HTTP examples give a 400 status code when presented with an invalid session ID. While this is not explicitly written out in the spec, it does say:

When a client receives HTTP 404 in response to a request containing an Mcp-Session-Id, it MUST start a new session by sending a new InitializeRequest without a session ID attached.

To me this implies that a server that receives a request with an invalid Mcp-Session-Id, it should respond with a 404 status code to signal the client should start a new session. However, the examples give a 400 here, e.g.

Activity

  1. flippinjoe commented on Apr 23, 2025

    @flippinjoe

    @connor4312
    This is actually to spec in the Session Management 2a. https://modelcontextprotocol.io/specification/2025-03-26/basic/transports

    Servers that require a session ID SHOULD respond to requests without an Mcp-Session-Id header (other than initialization) with HTTP 400 Bad Request.
    
  2. connor4312 commented on Apr 23, 2025

    @connor4312
    Author

    Indeed, they should respond to requests without a session ID with a 400, but they should respond to requests with an invalid session ID with a 404 (in order for clients to precisely implement refresh logic).

    (though in microsoft/vscode#247258 I decided to blindly will retry on an 4xx in case servers don't implement this 'correctly'_

  3. flippinjoe commented on Apr 23, 2025

    @flippinjoe

    Ah I see what you’re saying. This is ambiguous. On one hand if the client is sending arbitrary session-ids which they consider to be valid for some reason, then I feel like that 400 is appropriate. But for client recovery (in the event of accidental session-id state management discrepancies), issuing a 404 would help.

    Feels like the former would be better in terms of ensuring clients are managing sessions appropriately

  4. MasterOdin commented on Sep 11, 2025

    @MasterOdin

    The streamable HTTP example has two big issues imo that make it unusable in the wild:

    1. Responding with a 400 is against the spec and causes clients to not work as expected. Take claude code for example, if you return a 400 error from the server (because say you're debugging it locally and restarting it and it loses all sessions on restart), it'll show the following message:
      mcp-server - toolCall (MCP)()
        ⎿  Error: Error POSTing to endpoint (HTTP 400): {"jsonrpc":"2.0","error":{"code":-32000,"message":"Bad Request: No valid session ID provided"}}
      
      which isn't much help to you as an end-user, whereas if you return a 404, it gives back:

      The mcp-server system is disconnected again. You'll need to reconnect it before I can call the tool.
      where this gives actionable feedback (ideally it'd just call /mcp reconnect mcp-server for me, but 🤷)

    2. The call to isInitializeRequest call will fail if the client does application/json, event/stream as it's message format, where req.body will be undefined until you read to the end of the stream (which is what the SDK does internally.
  5. added
    good first issueGood for newcomers - can be tackled without deep knowledge of the codebase
    P2Moderate issues affecting some users, edge cases, potentially valuable feature
    on Dec 16, 2025
  6. added a commit that references this issue on Feb 20, 2026
    cbe631d
  7. added
    ready for workEnough information for someone to start working on
    and removed
    good first issueGood for newcomers - can be tackled without deep knowledge of the codebase
    on Mar 26, 2026
  8. added a commit that references this issue on Mar 26, 2026
    15e5b36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Moderate issues affecting some users, edge cases, potentially valuable featurebugSomething isn't workingready for workEnough information for someone to start working on

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions