cli-55: Add retry logic for MCP connections#613
Merged
Conversation
added 5 commits
July 17, 2026 14:20
<description>Added retry logic to `McpServerManager.connect_server` and simplified `add_server_with_retry` to use async retry with exponential backoff.</description>
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.
Purpose:
This PR introduces robust retry logic for MCP server connections within the
McpServerManager. Previously, transient connection failures could lead to immediate disconnections. This change enhances the reliability and resilience of MCP server connections by implementing exponential backoff and retry mechanisms.Design Considerations:
asyncio.CancelledErroris now explicitly re-raised to ensure proper propagation of cancellation signals, preventing silent suppression of critical control flow.LocalServerconnections are exempt from retry logic as they are local and not subject to network-related transient failures.from_serversmethod andadd_server_with_retryhelper were simplified, as the retry logic is now encapsulated withinconnect_server.What Changed:
cecli/mcp/manager.py:forloop withmax_retries,delay,backoff, andmax_delayvariables toconnect_server.asyncio.sleepfor delays between retries._log_warningfor intermediate failures and_log_errorfor final failure.asyncio.CancelledError.add_server_with_retryinfrom_servers.tests/mcp/test_manager.py:test_connect_server_failureto reflect the new retry count (3 calls toconnect).tool_warningandtool_errorcalls.tests/mcp/test_manager_retry.py:/load-mcp,/load-session,ResourceManager, and regression tests.Tests:
A new test file
tests/mcp/test_manager_retry.pyhas been added, containing 28 detailed test cases to validate the new retry logic and ensure no regressions were introduced. These tests cover:LocalServeror non-existent servers.asyncio.CancelledError.from_servers,/load-mcpcommand,/load-sessioncommand, andResourceManagertool.