Commit 5df03f1
fix(tools): handle toolset errors gracefully in canonical_tools
When an MCP server (or any toolset) is unavailable or raises an
exception during get_tools(), the error previously propagated uncaught
through _convert_tool_union_to_tools() and canonical_tools(), crashing
the entire agent silently with no log output.
This change wraps the toolset.get_tools_with_prefix() call in a
try-except that catches exceptions, logs a warning with the toolset
class name and error details, and returns an empty tool list. This
allows the agent to continue operating with tools from other working
toolsets.
The fix preserves the existing retry behavior — McpToolset's
@retry_on_errors decorator still attempts reconnection before the
error reaches this handler. On subsequent agent invocations,
get_tools() is called again, naturally retrying the connection.
Fixes: #3341
Co-authored-by: Xiang (Sean) Zhou <seanzhougoogle@google.com>
PiperOrigin-RevId: 8905121461 parent fe41817 commit 5df03f1
File tree
2 files changed
+43
-1
lines changed- src/google/adk/agents
- tests/unittests/agents
2 files changed
+43
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
181 | 181 | | |
182 | 182 | | |
183 | 183 | | |
184 | | - | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
185 | 193 | | |
186 | 194 | | |
187 | 195 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
472 | 472 | | |
473 | 473 | | |
474 | 474 | | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
475 | 509 | | |
476 | 510 | | |
477 | 511 | | |
| |||
0 commit comments