fix: use 'is not None' for related_request_id to handle id=0#2158
Open
giulio-leone wants to merge 2 commits intomodelcontextprotocol:mainfrom
Open
fix: use 'is not None' for related_request_id to handle id=0#2158giulio-leone wants to merge 2 commits intomodelcontextprotocol:mainfrom
giulio-leone wants to merge 2 commits intomodelcontextprotocol:mainfrom
Conversation
When a JSON-RPC request uses id=0, notifications sent during tool execution were not routed to the correct request stream because the condition 'if related_request_id' evaluates to False for integer 0. This caused notifications to be sent to the GET stream instead of the POST stream for the specific request, making them invisible to clients that don't have a GET SSE connection open (e.g. stateless mode). Fix: change 'if related_request_id' to 'if related_request_id is not None' in send_notification(), consistent with similar checks elsewhere in the codebase (e.g. streamable_http.py line 984, 993, 997). Fixes modelcontextprotocol#1218 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.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.
Problem
When a JSON-RPC request uses
id=0, notifications sent during tool execution are not routed to the correct request stream. The client never receives them.Root cause: In
send_notification(), the condition:evaluates to
Falsewhenrelated_request_idis0(integer zero is falsy in Python). This means theServerMessageMetadatais not attached, so the message router instreamable_http.pyfalls through to theGET_STREAM_KEYinstead of the request-specific stream.Fix
This is consistent with the identity checks already used in
streamable_http.py:message.id is not Nonesession_message.metadata.related_request_id is not Nonetarget_request_id is not NoneTesting
test_session.pyandtest_streamable_http.py(2 consecutive clean runs)id=0as a valid request identifierFixes #1218