From 8e0648df23d0694afd3e245ec4a3c41aa935120a Mon Sep 17 00:00:00 2001 From: Kathy Wu Date: Thu, 6 Nov 2025 16:12:08 -0800 Subject: [PATCH] fix: Fix MCPToolset crashing with anyio.BrokenResourceError Add error handling for broken resource error so that it retries. Fixes https://github.com/google/adk-python/issues/2769. Co-authored-by: Kathy Wu PiperOrigin-RevId: 829146121 --- src/google/adk/tools/mcp_tool/mcp_session_manager.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/google/adk/tools/mcp_tool/mcp_session_manager.py b/src/google/adk/tools/mcp_tool/mcp_session_manager.py index 7d42467a..d95d48f2 100644 --- a/src/google/adk/tools/mcp_tool/mcp_session_manager.py +++ b/src/google/adk/tools/mcp_tool/mcp_session_manager.py @@ -126,9 +126,10 @@ def retry_on_closed_resource(func): async def wrapper(self, *args, **kwargs): try: return await func(self, *args, **kwargs) - except anyio.ClosedResourceError: - # Simply retry the function - create_session will handle - # detecting and replacing disconnected sessions + except (anyio.ClosedResourceError, anyio.BrokenResourceError): + # If the session connection is closed or unusable, we will retry the + # function to reconnect to the server. create_session will handle + # detecting and replacing disconnected sessions. logger.info('Retrying %s due to closed resource', func.__name__) return await func(self, *args, **kwargs)