Skip to content

Commit 8e0648d

Browse files
wukathcopybara-github
authored andcommitted
fix: Fix MCPToolset crashing with anyio.BrokenResourceError
Add error handling for broken resource error so that it retries. Fixes #2769. Co-authored-by: Kathy Wu <wukathy@google.com> PiperOrigin-RevId: 829146121
1 parent c0be1df commit 8e0648d

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/google/adk/tools/mcp_tool/mcp_session_manager.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,10 @@ def retry_on_closed_resource(func):
126126
async def wrapper(self, *args, **kwargs):
127127
try:
128128
return await func(self, *args, **kwargs)
129-
except anyio.ClosedResourceError:
130-
# Simply retry the function - create_session will handle
131-
# detecting and replacing disconnected sessions
129+
except (anyio.ClosedResourceError, anyio.BrokenResourceError):
130+
# If the session connection is closed or unusable, we will retry the
131+
# function to reconnect to the server. create_session will handle
132+
# detecting and replacing disconnected sessions.
132133
logger.info('Retrying %s due to closed resource', func.__name__)
133134
return await func(self, *args, **kwargs)
134135

0 commit comments

Comments
 (0)