We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent a9548e8 commit a28a650Copy full SHA for a28a650
1 file changed
src/mcp/shared/session.py
@@ -462,9 +462,12 @@ async def _handle_response(self, message: SessionMessage) -> None:
462
"""
463
root = message.message.root
464
465
- # Type guard: this method is only called for responses/errors
466
- if not isinstance(root, JSONRPCResponse | JSONRPCError): # pragma: no cover
467
- return
+ # This check is always true at runtime: the caller (_receive_loop) only invokes
+ # this method in the else branch after checking for JSONRPCRequest and
+ # JSONRPCNotification. However, the type checker can't infer this from the
468
+ # method signature, so we need this guard for type narrowing.
469
+ if not isinstance(root, JSONRPCResponse | JSONRPCError):
470
+ return # pragma: no cover
471
472
response_id: RequestId = root.id
473
0 commit comments