diff --git a/tools/mcp_tool.py b/tools/mcp_tool.py index 56dd228ca44a..8cd4d5de1ac7 100644 --- a/tools/mcp_tool.py +++ b/tools/mcp_tool.py @@ -1761,10 +1761,12 @@ async def _wait_for_lifecycle_event(self) -> str: finally: for t in (shutdown_task, reconnect_task): if not t.done(): - t.cancel() try: + t.cancel() await t - except (asyncio.CancelledError, Exception): + except (asyncio.CancelledError, RuntimeError): + pass + except Exception: pass if self._shutdown_event.is_set(): @@ -1797,10 +1799,12 @@ async def _wait_for_reconnect_or_shutdown(self) -> str: finally: for t in (shutdown_task, reconnect_task): if not t.done(): - t.cancel() try: + t.cancel() await t - except (asyncio.CancelledError, Exception): + except (asyncio.CancelledError, RuntimeError): + pass + except Exception: pass if self._shutdown_event.is_set(): return "shutdown"