fix(mcp): add 30s timeout to prevent MCP tool calls from hanging indefinitely

Previously, MCP tool calls via call_tool() had no timeout, so a hung MCP
server would block the entire session indefinitely (exacerbated by
concurrency.session=1). This wraps the call in asyncio.timeout(30) and
raises an Exception on expiry, letting the LLM recover gracefully.

Closes #2339
This commit is contained in:
douxt
2026-07-17 10:00:13 +08:00
committed by Junyan Qin
parent 73e47ea2d4
commit 7677d1a288
@@ -968,7 +968,12 @@ class RuntimeMCPSession:
raise Exception('MCP session is not connected')
try:
result = await self.session.call_tool(tool_name, arguments)
async with asyncio.timeout(30):
result = await self.session.call_tool(tool_name, arguments)
except TimeoutError as e:
raise Exception(
f"MCP tool '{tool_name}' on server '{self.server_name}' timed out after 30 seconds"
) from e
except Exception as e:
if attempt == 0 and self._is_session_terminated(e):
self.ap.logger.warning(