Your lightweight open-source personal agent.
Python agent-frameworkai-agentai-agentschatbotchatopsdiscord-botllm-agentsllmslocal-llmmcpmodel-context-protocolmulti-agentopenai-compatibleopenclawpersonal-ai-assistantpythonself-hostedtelegram-bot-ai-assistantwebuiworkflow-automation
fix(mcp): add 30s timeout to MCP tool calls to prevent agent hangs
muskliu6b7d7e2eb874
diff --git a/nanobot/agent/tools/mcp.py b/nanobot/agent/tools/mcp.pyindex ad352bf43..a5e619acb 100644--- a/nanobot/agent/tools/mcp.py+++ b/nanobot/agent/tools/mcp.py@@ -1,11 +1,15 @@"""MCP client: connects to MCP servers and wraps their tools as native nanobot tools."""+import asynciofrom contextlib import AsyncExitStackfrom typing import Anyimport httpxfrom loguru import logger+# Timeout for individual MCP tool calls (seconds).+MCP_TOOL_TIMEOUT = 30+from nanobot.agent.tools.base import Toolfrom nanobot.agent.tools.registry import ToolRegistry@@ -34,7 +38,14 @@ class MCPToolWrapper(Tool):async def execute(self, **kwargs: Any) -> str:from mcp import types- result = await self._session.call_tool(self._original_name, arguments=kwargs)+ try:+ result = await asyncio.wait_for(+ self._session.call_tool(self._original_name, arguments=kwargs),+ timeout=MCP_TOOL_TIMEOUT,+ )+ except asyncio.TimeoutError:+ logger.warning("MCP tool '{}' timed out after {}s", self._name, MCP_TOOL_TIMEOUT)+ return f"(MCP tool call timed out after {MCP_TOOL_TIMEOUT}s)"parts = []for block in result.content:if isinstance(block, types.TextContent):