feat: propagate per-server MCP timeout to tool executors#3254
Open
billbtbillb-ui wants to merge 1 commit into
Open
feat: propagate per-server MCP timeout to tool executors#3254billbtbillb-ui wants to merge 1 commit into
billbtbillb-ui wants to merge 1 commit into
Conversation
- Add _extract_timeout_from_config() to read per-server timeout (ms→s) from MCPConfig, using max when multiple servers are configured - Add timeout parameter to MCPToolDefinition.create(), falling back to MCP_TOOL_TIMEOUT_SECONDS (300s) when not specified - Thread tool_timeout through create_mcp_tools() → _connect_and_list_tools() → MCPToolDefinition.create() → MCPToolExecutor - Add comprehensive tests covering config extraction, timeout propagation, default fallback, and timeout error observation handling
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.
Summary
This PR implements per-server MCP tool execution timeout propagation, allowing users to configure tool timeouts in their
.mcp.jsonconfig and have them automatically applied to tool executors.Changes
openhands-sdk/openhands/sdk/mcp/utils.py_extract_timeout_from_config()— reads per-servertimeoutfields (milliseconds) fromMCPConfig, converts to seconds, and returns the maximum across all servers (orNoneif none configured)_connect_and_list_tools()to accept and forwardtool_timeouttoMCPToolDefinition.create()create_mcp_tools()to extract the timeout from config and pass it throughopenhands-sdk/openhands/sdk/mcp/tool.pytimeout: float | None = Noneparameter toMCPToolDefinition.create()timeoutisNone, falls back toMCP_TOOL_TIMEOUT_SECONDS(300s)MCPToolExecutortests/sdk/mcp/test_mcp_timeout.py(new)_extract_timeout_from_config(): empty config, single server, multiple servers, no timeout, missing attributeMCPToolDefinition.create(): custom timeout propagation, None fallback, omitted fallbackMCPToolExecutor: timeout error observation, default valueHow it works
Users can now configure per-server timeouts in their MCP config:
{ "mcpServers": { "my_server": { "url": "http://localhost:3000/mcp", "timeout": 60000 } } }The
timeoutvalue (in milliseconds, matching FastMCP convention) is converted to seconds and applied to tool execution. When multiple servers are configured, the maximum timeout is used. When no timeout is specified, the existing default of 300 seconds applies.