fix(mcp): ignore EOF during MCP initialization #1426
Merged
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.
What I did
Adjusted the MCP toolset initialization logic to gracefully handle
EOFerrors during client initialization.When running
cagentfrom WSL with Docker Desktop MCP enabled, the MCP server may transiently close the connection during startup, causing the client initialization to fail withEOF. 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.EOFduring 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
io.EOFduring MCP initialization as a non-fatal conditionScreenshot (Explain)
This diagram illustrates the MCP toolset initialization flow during agent startup and highlights why the observed
EOFis not a functional bug.During agent startup, the MCP toolset is initialized by sending an
initializerequest followed by aninitializednotification. 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 anEOF.Previously, this
EOFwas 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,
EOFduring 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.Tests
Before
When an MCP toolset was defined and the MCP server closed the connection during startup:
EOFAfter
When MCP initialization encounters
EOF: