fix(mcp): deduplicate managed servers - #4591
Merged
Merged
Conversation
seratch
approved these changes
Aug 22, 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.
Summary
MCPServerManageralready deduplicated its connection attempt list by server identity, but retained repeated instances in its configured and active lists. Passing the same server object twice therefore connected it once while exposing it twice and cleaning it up twice.Normalize the constructor iterable with the manager's existing identity-based deduplication helper. First-occurrence ordering is preserved, and distinct server objects remain distinct. This changes no transport, retry, timeout, failure, or parallel-worker behavior.
Test plan
all_servers, connects once, appears once in the active result, and cleans up once.uv run pytest tests/mcp/test_mcp_server_manager_cleanup_state.py tests/mcp/test_mcp_server_manager.py tests/mcp/test_connect_disconnect.py -q—85 passedmake typecheck— mypy passed for 307 source files; Pyright reported 0 errors.agents/skills/code-change-verification/scripts/run.sh— format and lint passed; the broad suite completed with9029 passed, 28 skipped, 3 failed. The failures were unrelated native-sandbox and timing-sensitive tests. The timing-sensitive failures passed when rerun individually;test_python_skill_uses_absolute_root_from_nested_workdirremains unavailable on this host because its native sandbox command does not create the expected output file.git diff --check— passedIssue number
N/A
Checks
.agents/skills/code-change-verification/scripts/run.sh/reviewbefore submitting this PR