feat(mcp): start MCP servers in bounded parallel batches - #358
Open
raymondginger2018-sudo wants to merge 2 commits into
Open
raymondginger2018-sudo wants to merge 2 commits into
raymondginger2018-sudo wants to merge 2 commits into
Conversation
Initialize configured MCP servers in batches of 5 instead of strictly serial. Total startup drops to roughly 1/5 of the serial path while the bounded batch avoids spawning every process at once (memory peak). Promise.allSettled keeps a single failing server from blocking its batch; per-server status/failure handling is unchanged. Extracted from the earlier closed PR lessweb#266 (kept as a focused change).
Assert that initialize() runs connects concurrently (peak in flight > 1) while staying inside the batch bound, and that a disconnect raised during startup starts no further batch. Both use a stubbed connectServer so the test exercises scheduling only and does not spawn child processes. Reverting the batch loop back to serial makes the first test fail with "expected overlapping connections, saw peak=1".
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.
What
MCP server startup in
McpManager.initialize()was strictly serial: each configured server paid its own spawn + handshake before the next one started, so startup time was the sum over all servers.This starts servers in batches of 5 (
Promise.allSettled), which cuts total startup to roughly 1/5 for typical configs while keeping the process/memory peak bounded — unlike launching every server at once.Change
packages/core/src/mcp/mcp-manager.ts(+9/-2):Promise.allSettledalso isolates failures: previously an exception thrown while connecting one server aborted the loop and left every later server unstarted. Per-server status reporting and crash handling (onServerCrash) are unchanged.Why this is safe
connectServermutatesclients/tools/prompts/resourcessynchronously between itsawaitpoints, and the namespaced-name reservation block contains noawait, so concurrent callers cannot interleave and corrupt that state. The only observable difference is that status/log lines may now appear in a different order.Tests
packages/core/src/tests/mcp-manager-parallel.test.ts(new, 2 tests, no child processes —connectServeris stubbed so the test exercises scheduling only):disconnect()raised mid-startup starts no further batch.Checked that the test has teeth: reverting the loop to the previous serial form makes the first test fail with
expected overlapping connections, saw peak=1.Verification (local, full CI equivalent)
npm run check(typecheck + eslint + prettier) ·npm run build --workspace=@vegamo/deepcode-core·npm run bundle·npm run build:vscode·npm test— all pass (59 tests, 0 failures).Overlap
Open PR #198 also edits
mcp-manager.ts, but its hunks are disjoint from this one (import restructure +createMcpClientinsideconnectServer), so the two can land in either order.