Skip to content

Commit c3b70b0

Browse files
committed
More exception catching
1 parent 9a844a9 commit c3b70b0

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/mcp/shared/session.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,10 @@ async def _receive_loop(self) -> None:
418418
# Without this handler, the exception would propagate up and
419419
# crash the server's task group.
420420
logging.debug("Read stream closed by client")
421+
except Exception as e:
422+
# Other exceptions are not expected and should be logged. We purposefully
423+
# catch all exceptions here to avoid crashing the server.
424+
logging.exception(f"Unhandled exception in receive loop: {e}")
421425
finally:
422426
# after the read stream is closed, we need to send errors
423427
# to any pending requests

0 commit comments

Comments
 (0)