Skip to content

Add timeouts to remote MCP initialization and tool calls#2131

Merged
dgageot merged 1 commit intodocker:mainfrom
dgageot:board/do-we-handle-the-case-where-remote-mcp-n-2192a508
Mar 16, 2026
Merged

Add timeouts to remote MCP initialization and tool calls#2131
dgageot merged 1 commit intodocker:mainfrom
dgageot:board/do-we-handle-the-case-where-remote-mcp-n-2192a508

Conversation

@dgageot
Copy link
Member

@dgageot dgageot commented Mar 16, 2026

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 (connect + initialize) in doStart
  • mcpCallToolTimeout (10 min): caps individual tool calls (generous because tools can be long-running)
  • mcpListTimeout (1 min): caps ListTools, ListPrompts, and GetPrompt

The init timeout is applied via a derived context in doStart. The operation timeouts are applied in sessionClient so they cover both stdio and remote transports.

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
@dgageot dgageot requested a review from a team as a code owner March 16, 2026 18:19
Copy link

@docker-agent docker-agent bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

@dgageot dgageot merged commit 4bfd2ec into docker:main Mar 16, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants