Skip to content

mcp: streamable transport terminating stream prematurely #227

@aryannr97

Description

@aryannr97

There's a race condition between the notification being queued and the tool response clearing streamRequests. The response can trigger premature stream termination before notifications are sent.

To Reproduce

$ go test -timeout 60s -run ^TestStreamableServerTransport$ github.com/modelcontextprotocol/go-sdk/mcp -race 
--- FAIL: TestStreamableServerTransport (0.02s)
    --- FAIL: TestStreamableServerTransport/tool_notification (0.00s)
        streamable_test.go:556: received unexpected messages (-want +got):
              []jsonrpc2.Message{
                &jsonrpc2.Request{Method: "notifications/progress", Params: `{"progress":0,"progressToken":null}`},
            -   &jsonrpc2.Response{Result: json.RawMessage(`{"content":null}`), ID: jsonrpc2.ID{value: int64(2)}},
              }
FAIL
FAIL    github.com/modelcontextprotocol/go-sdk/mcp      0.633s
FAIL

Expected behavior
Response stream should not terminate prematurely and messages should not be lost

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions