Skip to content

Commit dd95fce

Browse files
author
g97iulio1609
committed
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
1 parent 62575ed commit dd95fce

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

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)