fix(agentgateway): bound MCP protocol calls with a wall-clock deadline - #319
Open
wangzhengzhuo05 wants to merge 1 commit into
Open
fix(agentgateway): bound MCP protocol calls with a wall-clock deadline#319wangzhengzhuo05 wants to merge 1 commit into
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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