Skip to content

Commit ae0bc81

Browse files
committed
Log warning for unhandled exceptions in default message handler
Transport errors that are not tied to a specific pending request (e.g., GET stream failures) were silently swallowed by the default message handler. Add a warning log so these exceptions are at least visible in logs as an observability safety net. Github-Issue: #1401
1 parent 0efb392 commit ae0bc81

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/mcp/client/session.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ async def __call__(
5757
async def _default_message_handler(
5858
message: RequestResponder[types.ServerRequest, types.ClientResult] | types.ServerNotification | Exception,
5959
) -> None:
60+
if isinstance(message, Exception):
61+
logger.warning("Unhandled exception in message handler: %s", message)
6062
await anyio.lowlevel.checkpoint()
6163

6264

0 commit comments

Comments
 (0)