[v1.x] fix(streamable-http): reject duplicate JSON-RPC ids with 409#2657
Conversation
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
a9cf0da to
e7df44c
Compare
|
Friendly bump — this has been ready for 12 days, all 21 CI checks are green, and the linked issue #2655 now has independent confirmation of the fix shape (mcp-claude reproduced on both I incorporated their Happy to rebase, split, or restructure if any of the shape needs adjusting. @maxisbey if you have a moment — no rush. |
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_streamsentry, leaving the original in-flight request hanging forever.Mirror the existing
GET_STREAM_KEYcollision branch (line 711) and return 409 Conflict, keeping the prior stream untouched.Repro
Same session, two POSTs with
id: 1. With the bug, the secondtools/calldisplaces 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_idexercising the new branch directly on the transport: seed_request_streams["1"]with a real in-flight pair, send a POST withid: 1, assert 409 +INVALID_REQUESTerror code + the in-flight pair is left in place.