From ffde483c7190bad375e2e503af2e6052ff9b7d42 Mon Sep 17 00:00:00 2001 From: buenosairesam Date: Tue, 14 Apr 2026 11:18:08 -0300 Subject: [PATCH] add 15s timeout to MCP tool calls --- agents/fce.py | 11 +++++++++-- agents/handover.py | 11 +++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/agents/fce.py b/agents/fce.py index da33ad5..1a8b747 100644 --- a/agents/fce.py +++ b/agents/fce.py @@ -74,13 +74,20 @@ async def run_fce( origin = flight_status.get("origin", "") destination = flight_status.get("destination", "") - async def _call(server, tool, args, is_live=False): + async def _call(server, tool, args, is_live=False, timeout=15.0): t = time.time() try: - result = await mcp.call_tool(server, tool, args) + result = await asyncio.wait_for( + mcp.call_tool(server, tool, args), timeout=timeout, + ) lat = int((time.time() - t) * 1000) await emit("tool_call_end", tool=tool, latency_ms=lat, is_live=is_live) return result + except asyncio.TimeoutError: + lat = int((time.time() - t) * 1000) + await emit("tool_call_error", tool=tool, error="timeout", latency_ms=lat) + errors.append(f"{tool}: timeout after {timeout}s") + return None except Exception as e: lat = int((time.time() - t) * 1000) await emit("tool_call_error", tool=tool, error=str(e), latency_ms=lat) diff --git a/agents/handover.py b/agents/handover.py index 14897bf..6efbb16 100644 --- a/agents/handover.py +++ b/agents/handover.py @@ -52,13 +52,20 @@ async def run_handover( await emit("node_enter", node="gather_all") - async def _call(server, tool, args, is_live=False): + async def _call(server, tool, args, is_live=False, timeout=15.0): t = time.time() try: - result = await mcp.call_tool(server, tool, args) + result = await asyncio.wait_for( + mcp.call_tool(server, tool, args), timeout=timeout, + ) lat = int((time.time() - t) * 1000) await emit("tool_call_end", tool=tool, latency_ms=lat, is_live=is_live) return result + except asyncio.TimeoutError: + lat = int((time.time() - t) * 1000) + await emit("tool_call_error", tool=tool, error="timeout", latency_ms=lat) + errors.append(f"{tool}: timeout after {timeout}s") + return None except Exception as e: lat = int((time.time() - t) * 1000) await emit("tool_call_error", tool=tool, error=str(e), latency_ms=lat)