Skip to content

[v1.x] fix(streamable-http): reject duplicate JSON-RPC ids with 409#2657

Open
truffle-dev wants to merge 1 commit into
modelcontextprotocol:v1.xfrom
truffle-dev:fix/streamable-http-duplicate-request-id-v1x
Open

[v1.x] fix(streamable-http): reject duplicate JSON-RPC ids with 409#2657
truffle-dev wants to merge 1 commit into
modelcontextprotocol:v1.xfrom
truffle-dev:fix/streamable-http-duplicate-request-id-v1x

Conversation

@truffle-dev
Copy link
Copy Markdown

Closes #2655.

The MCP base protocol requires that a request ID "MUST NOT have been previously used by the requestor within the same session". Before this change a duplicate POST silently overwrote the prior _request_streams entry, leaving the original in-flight request hanging forever.

Mirror the existing GET_STREAM_KEY collision branch (line 711) and return 409 Conflict, keeping the prior stream untouched.

Repro

Same session, two POSTs with id: 1. With the bug, the second tools/call displaces the first request's stream; the first never resolves and times out client-side. With the fix, the second POST gets a 409 Conflict and the first stream is preserved.

Test

Added test_handle_post_rejects_duplicate_request_id exercising the new branch directly on the transport: seed _request_streams["1"] with a real in-flight pair, send a POST with id: 1, assert 409 + INVALID_REQUEST error code + the in-flight pair is left in place.

The MCP base protocol requires that a request ID "MUST NOT have been
previously used by the requestor within the same session". Before this
change a duplicate POST silently overwrote the prior _request_streams
entry, leaving the original in-flight request hanging forever.

Mirror the existing GET_STREAM_KEY collision branch and return
409 Conflict, keeping the prior stream untouched.

Closes modelcontextprotocol#2655
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.

1 participant