Skip to content

Conversation

@Pnkcaht
Copy link
Contributor

@Pnkcaht Pnkcaht commented Jan 19, 2026


What I did

Adjusted the MCP toolset initialization logic to gracefully handle EOF errors during client initialization.

When running cagent from WSL with Docker Desktop MCP enabled, the MCP server may transiently close the connection during startup, causing the client initialization to fail with EOF. This scenario does not indicate a real failure of the agent execution, but it was previously treated as fatal and surfaced as a warning.

This change treats io.EOF during MCP initialization as a non-fatal condition, logs it at debug level, and skips the MCP toolset instead of failing the agent startup.

Related issue

Related to the reported warning:
Fixes #1347

Notes

  • Treats io.EOF during MCP initialization as a non-fatal condition
  • Prevents unnecessary warning logs when the MCP server is temporarily unavailable
  • Keeps existing retry logic intact for genuine initialization errors
  • Aligns behavior with existing comments describing transient MCP startup issues
  • No changes to MCP protocol, APIs, or tool execution behavior

Screenshot (Explain)

This diagram illustrates the MCP toolset initialization flow during agent startup and highlights why the observed EOF is not a functional bug.

During agent startup, the MCP toolset is initialized by sending an initialize request followed by an initialized notification. In environments such as WSL with Docker Desktop, the MCP server may still be completing its asynchronous startup when this notification is sent. In this case, the server may close the connection early, resulting in an EOF.

Previously, this EOF was treated as a fatal initialization error and surfaced as a warning, even though the agent execution itself was unaffected. The diagram shows how this condition occurs before any tool execution and does not indicate a broken or misconfigured MCP setup.

With the updated behavior, EOF during MCP initialization is treated as a transient, non-fatal condition. The MCP toolset is skipped gracefully, and the agent continues execution without emitting misleading warnings. This aligns with the existing comments in the codebase describing asynchronous MCP initialization behavior and avoids noisy logs for an expected startup scenario.

image

Tests

Before

When an MCP toolset was defined and the MCP server closed the connection during startup:

  • MCP initialization failed with EOF
  • The toolset startup returned an error
  • A warning was logged during agent execution
  • Agent execution continued, but with noisy and misleading logs

After

When MCP initialization encounters EOF:

  • The condition is detected explicitly
  • The MCP toolset is skipped gracefully
  • A debug-level log is emitted instead of a warning
  • Agent execution continues cleanly without misleading error output
  • Normal MCP behavior remains unchanged when the server is available

@rumpl rumpl merged commit 9775565 into docker:main Jan 19, 2026
5 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.

UI Warning: "*mcp.GatewayToolset start failed: failed to initialize MCP client"

3 participants