Skip to content

Commit f380341

Browse files
g97iulio1609Copilot
andcommitted
fix: use 'is not None' for related_request_id to handle id=0
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 #1218 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 62575ed commit f380341

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

src/mcp/shared/session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ async def send_notification(
303303
)
304304
session_message = SessionMessage(
305305
message=jsonrpc_notification,
306-
metadata=ServerMessageMetadata(related_request_id=related_request_id) if related_request_id else None,
306+
metadata=ServerMessageMetadata(related_request_id=related_request_id) if related_request_id is not None else None,
307307
)
308308
await self._write_stream.send(session_message)
309309

0 commit comments

Comments
 (0)