Skip to content

McpToolset does not handle errors in ListTool calls #3341

@flansen

Description

@flansen

** Please make sure you read the contribution guide and file the issues in the right place. **
Contribution guide.

Describe the bug

When an MCP Server is not available (anymore) when the ListTools call happens, the complete Agent fails to run and just finishes without log or error message.

To Reproduce
Steps to reproduce the behavior:

  1. Connect ADK to an MCP server via streamable http
  2. MCP server must raise an exception when responding to ListTools call
  3. Try to talk to the agent

There is not error log, the agent immediately fails and does not respond anything

2025-10-30 10:35:53 - /app/agenthub/.venv/lib/python3.13/site-packages/google/adk/cli/utils/envs.py - INFO - Loaded .env file for root at /app/agenthub/agents/.env
2025-10-30 10:35:53 - /app/agenthub/.venv/lib/python3.13/site-packages/google/adk/cli/utils/envs.py - INFO - Loaded .env file for root at /app/agenthub/agents/.env
2025-10-30 10:35:54 - google_adk.google.adk.cli.utils.agent_loader - INFO - Found root_agent in root.agent
2025-10-30 10:35:54 - mcp.client.streamable_http - INFO - Received session ID: 6464e0fd631a47638b838775d84367d7
2025-10-30 10:35:54 - mcp.client.streamable_http - INFO - Negotiated protocol version: 2025-06-18
2025-10-30 10:35:54 - mcp.client.streamable_http - INFO - Received session ID: 9b122639fd914d0b9f96e2b8820abfaf
2025-10-30 10:35:54 - mcp.client.streamable_http - INFO - Negotiated protocol version: 2025-06-18

Expected behavior

When a single MCP Server can not respond to requests,

  1. do not fail to whole agent
  2. try to reconnect to it later
  3. give proper logs

Desktop (please complete the following information):

  • OS: MacOS, Linux
  • Python version(python -V): 3.13.7
  • ADK version(pip show google-adk): 1.17.0

Model Information:

  • Are you using LiteLLM: Yes
  • Which model is being used(e.g. gemini-2.5-pro): gpt-5

Additional context

We have a patch in place to handle this, but it is kind-of ugly and it does not handle proper reconnect attempts.

--- a/google/adk/tools/mcp_tool/mcp_toolset.py
+++ b/google/adk/tools/mcp_tool/mcp_toolset.py
@@ -152,11 +152,22 @@
     Returns:
         List[BaseTool]: A list of tools available under the specified context.
     """
-    # Get session from session manager
-    session = await self._mcp_session_manager.create_session()
+    # Try to get session from session manager, but handle failures gracefully
+    try:
+      session = await self._mcp_session_manager.create_session()
+    except Exception as e:
+      # Log the error but don't crash - just return empty tool list for this MCP server
+      logger = logging.getLogger(__name__)
+      logger.warning(f"Failed to create MCP session for {self._mcp_session_manager._connection_params}: {e}")
+      return []  # Return empty tool list if connection fails

     # Fetch available tools from the MCP server
-    tools_response: ListToolsResult = await session.list_tools()
+    try:
+      tools_response: ListToolsResult = await session.list_tools()
+    except Exception as e:
+      logger = logging.getLogger(__name__)
+      logger.warning(f"Failed to list tools from MCP server: {e}")
+      return []  # Return empty tool list if tool listing fails

     # Apply filtering based on context and tool_filter
     tools = []

Metadata

Metadata

Labels

mcp[Component] Issues about MCP supporttools[Component] This issue is related to tools

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions