mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-07-24 05:16:09 +00:00
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:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user