fix(mcp): apply timeout to initialize handshake and list_tools#2823
Merged
fix(mcp): apply timeout to initialize handshake and list_tools#2823
Conversation
Wraps handler.serve(transport) in connect(), connect_url(), and connect_url_with_headers() with tokio::time::timeout(timeout, ...), returning McpError::Timeout on expiry. Applies the same guard to list_all_tools() in list_tools(). Previously only call_tool had a timeout; a stalled MCP server during the initialize handshake or tool listing blocked connect_all() indefinitely, causing TUI startup to hang at "Connecting tools..." with no recovery path. Adds 4 unit tests covering the new timeout paths. Closes #2815
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
handler.serve(transport)inconnect(),connect_url(), andconnect_url_with_headers()withtokio::time::timeout(timeout, ...), returningMcpError::Timeouton expirylist_all_tools()inlist_tools()Root Cause
Only
call_toolapplied a timeout; the initialize handshake andtools/listRPC were unbounded. A stalled MCP server (slow Docker pull, unresponsive process, network issue) blockedconnect_all()indefinitely, causing TUI startup to hang at "Connecting tools..." with no recovery path.Test Plan
cargo +nightly fmt --check -p zeph-mcp— cleancargo clippy -p zeph-mcp --all-features -- -D warnings— 0 warningscargo nextest run -p zeph-mcp --lib— 418/418 passed (was 414; 4 new tests added)Closes #2815