fix(agentgateway): bound MCP protocol calls with a wall-clock deadline - #319
wangzhengzhuo05 wants to merge 1 commit into
Conversation
The httpx.AsyncClient timeout only bounds individual HTTP chunk reads; SSE keep-alives from an unresponsive MCP server reset that timer continuously, so session.initialize() / list_tools() / call_tool() could hang forever instead of failing fast. Add _mcp_call_with_deadline() which wraps a protocol call in asyncio.wait_for, enforcing a deadline that keep-alives cannot extend, and raises AgentGatewaySDKError on timeout. Apply it to initialize, list_tools and call_tool in the LoB flow so tool listing and invocation both surface a clear error when the server stalls. Fixes SAP#313
|
Closing this out. It has been waiting 9 days without any maintainer review, and we are winding down this contribution effort — a stale PR sitting in the queue costs maintainers attention without giving them a decision to make, so it is better closed than left open indefinitely. If the direction is useful, the branch is intact on the fork ( What it contains: fix(agentgateway): bound MCP protocol calls with a wall-clock deadline — When an MCP server is unresponsive, It was verified locally before opening (target test suite green, plus a mutation check that reverts only the fix and confirms the new regression test fails). Thanks for the time. |
What
When an MCP server is unresponsive,
session.initialize()/list_tools()/call_tool()in the LoB flow hang indefinitely instead of failing fast.Root cause
The
httpx.AsyncClienttimeout only bounds individual HTTP chunk reads. An MCP stream's SSE keep-alives reset that timer continuously, so an unresponsive server never trips the client timeout — the protocol call stays alive forever.How
Add
_mcp_call_with_deadline(), which wraps a protocol call inasyncio.wait_forand raisesAgentGatewaySDKErroron timeout. Keep-alives cannot extend a wall-clock deadline. Applied toinitialize,list_tools(inlist_server_tools) andinitialize,call_tool(incall_mcp_tool_lob), matching the issue's expectation that listing fails fast with a clear error.Tests
test_initialize_timeout_raises_agent_gateway_error— stalled initialize fails fast onlist_server_tools.test_list_tools_timeout_raises_agent_gateway_error— stalled list_tools fails fast.test_call_tool_timeout_raises_agent_gateway_error— stalled call_tool fails fast.tests/agentgateway/unit/test_lob.pytests pass.Fixes #313