From 11be3f515ed2a53b888084b3213608b4ed304e06 Mon Sep 17 00:00:00 2001 From: askdevai-bot Date: Fri, 30 May 2025 23:14:36 -0400 Subject: [PATCH] fix: broaden exception handling in MCPClient.close to avoid cancel-scope errors --- tinyagent/mcp_client.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tinyagent/mcp_client.py b/tinyagent/mcp_client.py index eb1919f..e4fab50 100644 --- a/tinyagent/mcp_client.py +++ b/tinyagent/mcp_client.py @@ -109,11 +109,11 @@ async def close(self): if self.exit_stack: try: await self.exit_stack.aclose() - except (RuntimeError, asyncio.CancelledError) as e: - # Log the error but don't re-raise it + except Exception as e: + # Log any cleanup error (including cancel-scope mismatches) but don’t re-raise self.logger.error(f"Error during client cleanup: {e}") finally: - # Always reset these regardless of success or failure + # Reset client state unconditionally self.session = None self.exit_stack = AsyncExitStack()