Skip to content

Don't create sessions for requests without a sessionId #1000

@mikekistler

Description

@mikekistler

Describe the bug

Currently the C# SDK (http server) allows requests, e.g. tools/call, without a sessionId but creates and returns a sessionId in the response.

The TypeScript, Java, and Go MCP SDKs do not do this.

The Python SDK, while it does return a sessionId, this sesionId is unusable because the server knows that it was not generated by initialize -- requests using this sessionId fail with the server log message:

WARNING  Failed to validate request: Received request before initialization was complete

In addition, I do not think a strict reading of the spec allows creating a new session for any request other than initialize:

A server using the Streamable HTTP transport MAY assign a session ID at initialization time, by including it in an Mcp-Session-Id header on the HTTP response containing the InitializeResult

To Reproduce

Issue a tools/call request to the server without an mcp-session-id header.

POST {{HostAddress}}/
Accept: application/json, text/event-stream
Content-Type: application/json
MCP-Protocol-Version: 2025-06-18

{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "tools/call",
    "params": {
        "name": "get_random_number",
        "arguments": {}
    }
}

The request succeeds and returns a newly minted sessionId in the mcp-session-id header of the response.

HTTP/1.1 200 OK
Connection: close
Content-Type: text/event-stream
Date: Thu, 20 Nov 2025 22:00:39 GMT
Server: Kestrel
Cache-Control: no-cache,no-store
Content-Encoding: identity
Transfer-Encoding: chunked
Mcp-Session-Id: B9-naagwnKD6Y3X5SzhXUw

event: message
data: {"result":{"content":[{"type":"text","text":"94"}]},"id":1,"jsonrpc":"2.0"}

Expected behavior

No sessionId should be returned in the response.

Additional context

This repo contains my investigations of the behavior of the other SDKs.

https://github.com/mikekistler/mcp-session-experiments

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions