Repository navigation
fix(mcp): keep on-demand discovery working after a server reconnects - #2052
Merged
Merged
Conversation
When a server recovered, the health listener registered every tool it has, whatever the discovery mode, and never put them back in the catalog. A discovery-mode session then sent every schema in every request. Recovery now refills the catalog and registers only the tools that were loaded before the outage (or every tool when discovery is off). A call to a catalog tool whose schema isn't loaded was rejected as "does not exist" / "Unknown tool"; it now tells the model to call load_tool_schema first. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 task done
Contributor
|
nc-review could not produce a verdict this run (agent exit |
This was referenced Nov 11, 2026
jay23606
added a commit
to jay23606/nanocoder
that referenced
this pull request
Nov 12, 2026
…ano-Collective#2052) When a server recovered, the health listener registered every tool it has, whatever the discovery mode, and never put them back in the catalog. A discovery-mode session then sent every schema in every request. Recovery now refills the catalog and registers only the tools that were loaded before the outage (or every tool when discovery is off). A call to a catalog tool whose schema isn't loaded was rejected as "does not exist" / "Unknown tool"; it now tells the model to call load_tool_schema first. Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
diyaavirmani
added a commit
to diyaavirmani/nanocoder
that referenced
this pull request
Nov 16, 2026
Conflicts with on-demand MCP discovery (Nano-Collective#1651, Nano-Collective#2052, Nano-Collective#2057): - tool-manager.ts: kept discovery, the catalog and outage recovery, with this branch's registration rule on every path. A name a built-in, custom or skill tool has is skipped from the catalog too, so load_tool_schema can't offer the MCP schema for it, and loadMcpTool won't claim it. Tools loaded on demand are tracked, so an outage or a disconnect removes them and never the built-in. - daemon/entry.ts, plain/initialize.ts: pass upstream's tune config and keep the skipped-tools warning. - Specs: kept both sides; setGlobalMessageQueue moved to @/components/message-queue (Nano-Collective#2155), and the custom-tools stand-in client now maps its tool, which initializeMCP reads.
11 of 18 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.
Description
On-demand MCP discovery (
load_tool_schemaand the catalog, which turns on at 8 or more MCP tools or withmcpDiscovery: "always") breaks after a server outage. It also sends the model a misleading error.1. Reconnect loads every schema. When a server went unhealthy,
ToolManagerremoved its tools from both the registry and the catalog. When it recovered toconnected, the listener calledregisterMcpTools(getToolEntries(server))whatever the discovery mode, and didn't put the tools back in the catalog. Example: a 40-tool GitHub server in a discovery session blips once. After that every request carries all 40 schemas, which is exactly what discovery exists to prevent, and the catalog section in the prompt is empty.Fix:
initializeMCPrecords whether it chose discovery. When a server goes unhealthy, the manager remembers which of that server's tools were registered. On recovery,restoreServerTools():2. Calling a catalog tool before loading it gave the wrong error. The catalog shows each tool's name, so models often call one directly. It isn't registered until its schema is loaded, so
partitionToolCallsrejected it asdoes not exist … Available tools are: …(interactive loop) orUnknown tool:(plain/ACP). The mode check had the same gap ("not available in the current mode"). Nothing told the model it only had to load the schema. Now a call to an unloaded catalog tool is refused with:… is an on-demand MCP tool whose schema is not loaded yet. Call load_tool_schema with tool_name "X" first …. This only applies whenload_tool_schemais offered. Otherwise the existing message stays.The related
isReadOnlyissue (it trusts an unloaded tool'sreadOnlyHint) is a separate PR.Overlap: #1863 also edits the unhealthy/recovery listener in
initializeMCP, so whichever merges second will need a small rebase. The two changes don't conflict in intent: #1863 limits which names MCP can add or remove, and this PR decides which of those names are registered and which stay in the catalog.Type of Change
Changeset
patch)Testing
New tests in
source/tools/tool-manager.spec.ts. They use a fake client through the existingcreateMCPClient()seam and drive its health listener:load_tool_schemahint by bothfilterValidToolCallsandpartitionUnknownToolCalls, and the same call is valid once loaded.With
tool-manager.tsandtool-filters.tsreverted to main, all three fail.tsc --noEmitand biome are clean. AVA passes forsource/tools/**,source/hooks/chat-handler/**,source/acp,source/plain,source/mcp, the custom-tools end-to-end spec andprompt-builder(1267 tests).🤖 Generated with Claude Code