Add timeouts to remote MCP initialization and tool calls#2131
Merged
dgageot merged 1 commit intodocker:mainfrom Mar 16, 2026
Merged
Conversation
Prevent the agent from hanging indefinitely when a remote MCP server accepts a TCP connection but never responds. Three timeout constants are introduced: - mcpInitTimeout (2 min): caps the initialization handshake - mcpCallToolTimeout (10 min): caps individual tool calls - mcpListTimeout (1 min): caps ListTools, ListPrompts, and GetPrompt The init timeout is applied in doStart via a derived context. The operation timeouts are applied in sessionClient so they cover both stdio and remote transports. Assisted-By: docker-agent
There was a problem hiding this comment.
Review Summary
Assessment: 🟢 APPROVE
The timeout implementation is well-designed and addresses the core issue of preventing indefinite hangs when remote MCP servers accept connections but never respond. The code correctly applies timeouts at appropriate layers and follows Go best practices for context handling.
Summary
This PR successfully adds three timeout constants to prevent the agent from hanging:
- mcpInitTimeout (2 min): initialization handshake
- mcpCallToolTimeout (10 min): individual tool calls
- mcpListTimeout (1 min): list operations
The implementation is sound with proper defer cancel() patterns and correct timeout propagation. One minor observation about iterator usage patterns is noted below, but it does not block approval.
Findings
One low-severity observation about the iterator wrapper pattern:
derekmisler
approved these changes
Mar 16, 2026
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.
Prevent the agent from hanging indefinitely when a remote MCP server accepts a TCP connection but never responds.
Three timeout constants are introduced:
doStartListTools,ListPrompts, andGetPromptThe init timeout is applied via a derived context in
doStart. The operation timeouts are applied insessionClientso they cover both stdio and remote transports.