fix: reject duplicate JSON-RPC request IDs with 409 Conflict (fixes #2655)#2944
Open
kaXianc2-gom wants to merge 1 commit into
Open
Conversation
When a client reuses a JSON-RPC request id while the original request is still in flight, StreamableHTTPServerTransport now checks for a collision in _request_streams before registering a new stream slot. Previously the assignment was unconditional, which silently overwrote the prior (send, receive) pair — the original request's caller would hang until timeout and the response could be routed to the wrong caller. The fix mirrors the existing GET_STREAM_KEY collision guard at line 695. Also adds an optional request_id parameter to _create_error_response so the JSON-RPC error envelope carries the offending id instead of always using null. Fixes modelcontextprotocol#2655 Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2655:
StreamableHTTPServerTransportnow detects and rejects duplicate JSON-RPC request IDs before overwriting the in-flight stream slot.Before: A client sending two requests with the same
idon the same session would silently overwrite the first request's(send, receive)stream pair in_request_streams. The original caller hangs until timeout; the response may route to the wrong caller.After: The server returns HTTP 409 Conflict with a JSON-RPC
-32600 Invalid Requesterror, preserving the original in-flight stream.Changes
_handle_post_request— added collision check before stream registration, mirroring the existingGET_STREAM_KEYguard at line 695_create_error_response— added optional keyword-onlyrequest_idparameter so the JSON-RPC error envelope carries the offending id instead ofnullAI Assistance Disclosure
This contribution was developed with AI assistance (Claude / Anthropic Claude Code).
Verification Process
uv sync --no-group docsinstalled all dependenciesstreamable_http.py, +1noqa: C901)test_duplicate_request_id_rejected_with_409:_request_streamswith an in-flight requestruff format+ruff check: all cleanCross-Validation
idfieldnull🤖 Generated with Claude Code