Skip to content

Commit 18e029d

Browse files
committed
refactor: improve notification handling
- Always validate all notifications to ensure proper model structure - Handle cancellation notifications separately (no forwarding to stream) - Simplify notification type checking and error handling - Improve code structure and documentation
1 parent 12692ff commit 18e029d

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

src/mcp/shared/session.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -289,15 +289,11 @@ async def _send_response(
289289
)
290290
await self._write_stream.send(JSONRPCMessage(jsonrpc_response))
291291

292-
def _should_validate_notification(self, message_root: JSONRPCNotification) -> bool:
292+
def _is_cancellation_notification(self, message_root: JSONRPCNotification) -> bool:
293293
"""
294-
Determines if a notification should be validated.
295-
Internal notifications (like notifications/cancelled) should be ignored.
294+
Determines if a notification is a cancellation notification.
296295
"""
297-
return (
298-
getattr(message_root, "method", None) != "notifications/cancelled" and
299-
not self._closed
300-
)
296+
return getattr(message_root, "method", None) == "notifications/cancelled"
301297

302298
async def _receive_loop(self) -> None:
303299
async with (

0 commit comments

Comments
 (0)