add 15s timeout to MCP tool calls
This commit is contained in:
@@ -74,13 +74,20 @@ async def run_fce(
|
|||||||
origin = flight_status.get("origin", "")
|
origin = flight_status.get("origin", "")
|
||||||
destination = flight_status.get("destination", "")
|
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()
|
t = time.time()
|
||||||
try:
|
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)
|
lat = int((time.time() - t) * 1000)
|
||||||
await emit("tool_call_end", tool=tool, latency_ms=lat, is_live=is_live)
|
await emit("tool_call_end", tool=tool, latency_ms=lat, is_live=is_live)
|
||||||
return result
|
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:
|
except Exception as e:
|
||||||
lat = int((time.time() - t) * 1000)
|
lat = int((time.time() - t) * 1000)
|
||||||
await emit("tool_call_error", tool=tool, error=str(e), latency_ms=lat)
|
await emit("tool_call_error", tool=tool, error=str(e), latency_ms=lat)
|
||||||
|
|||||||
@@ -52,13 +52,20 @@ async def run_handover(
|
|||||||
|
|
||||||
await emit("node_enter", node="gather_all")
|
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()
|
t = time.time()
|
||||||
try:
|
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)
|
lat = int((time.time() - t) * 1000)
|
||||||
await emit("tool_call_end", tool=tool, latency_ms=lat, is_live=is_live)
|
await emit("tool_call_end", tool=tool, latency_ms=lat, is_live=is_live)
|
||||||
return result
|
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:
|
except Exception as e:
|
||||||
lat = int((time.time() - t) * 1000)
|
lat = int((time.time() - t) * 1000)
|
||||||
await emit("tool_call_error", tool=tool, error=str(e), latency_ms=lat)
|
await emit("tool_call_error", tool=tool, error=str(e), latency_ms=lat)
|
||||||
|
|||||||
Reference in New Issue
Block a user