perf(mcp): lazy server startup from fingerprint-keyed schema cache (#56832 extract-salvage) - #77511
Merged
kshitijk4poor merged 3 commits intoAug 3, 2026
Conversation
Stores per-server tool manifests in ~/.hermes/mcp_schema_cache.json so tools can be registered into the agent snapshot without spawning the stdio child at startup. Entries are keyed by server name plus a fingerprint of the connection-defining config (command/args/url/ transport/tool filters), so any config change invalidates the entry. Extracted from NousResearch#56832.
…earch#56832) Wires the fingerprint-keyed schema cache (previous commit, @Vansh5632's design from NousResearch#56832) into the startup path, re-derived onto main's current connect machinery: - register_mcp_servers: servers with mcp_servers.<name>.lazy=true whose config fingerprint matches a valid cache entry register tools from cache WITHOUT spawning; miss/stale falls back to eager connect. - First tool use routes through _ensure_lazy_server_connected, which composes with the connect cooldown (NousResearch#50394) and _server_connecting dedup rather than duplicating the connect path. - resource/prompt utility handlers (list_resources/get_prompt) also connect-on-first-use — closes the gap flagged in the original sweeper review. - Write-through: a live connect refreshes the cache entry. Config gate is per-server, default OFF, matching the idle_timeout_seconds key pattern. 24 lazy/cache tests + 440 mcp-wide green; mutation-checked (cache-read disabled -> registration test fails; connect bypassed -> 3 first-use tests fail).
Five review findings folded: - schema cache writes via utils.atomic_json_write (fsync; was bare tmp+replace), file moved to cache/mcp_schema_cache.json with 0o600 (sibling precedent: registry discovery cache) - phantom-tool reconciliation: after a lazy server's first-use connect, cached tools the live server no longer offers are deregistered (were permanent registry ghosts burning circuit-breaker strikes on every 'Unknown tool' round-trip); stale fingerprint logged - cache-load path now runs _scan_mcp_description like the eager path (cache file is user-writable JSON; defense-in-depth) - write-through skips the disk rewrite when the entry is unchanged (a flapping stdio server was rewriting byte-identical JSON per revival) - _lazy_server_fingerprints no longer write-only dead state (consumed by the reconciliation logging) 444 mcp tests green (440 pre-fold + 4 new guards); phantom-dereg and write-skip mutation-checked.
kshitijk4poor
enabled auto-merge (rebase)
August 3, 2026 08:46
3 tasks
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.
Extract-salvage of #56832 by @Vansh5632 — the PR's still-novel core (lazy MCP startup), with the schema-cache module cherry-picked under their authorship and the wiring re-derived onto main's current connect machinery.
Context — what this changes for users
Every desktop/dashboard start spawns EVERY configured stdio MCP child (Playwright, etc.) and fetches schemas, even for servers the session never touches — main's idle recycle only reclaims them after opt-in idle windows, never avoids the initial spawn. With mcp_servers..lazy: true (default OFF), a server whose config fingerprint matches a valid on-disk schema-cache entry registers its tools WITHOUT spawning; the child starts on first actual tool use.
Scope honesty — the full 4-group map of the original PR
Design (from #56832) + re-derivation notes
Review follow-ups folded (simplify pass)
Verification
Attribution mapping for Vansh5632 landed in #77492.
Closes #56832.