Skip to content

fix(mcp): don't let an MCP tool replace or remove a built-in (#1853) - #1863

Merged
addyCooks merged 4 commits into
Nano-Collective:mainfrom
diyaavirmani:fix/mcp-tool-shadows-builtin
Nov 18, 2026
Merged

addyCooks merged 4 commits into
Nano-Collective:mainfrom
diyaavirmani:fix/mcp-tool-shadows-builtin

Conversation

@diyaavirmani

Copy link
Copy Markdown
Contributor

Description

Closes #1853.

The tool registry is a plain name-keyed map, and MCP tools were registered after the built-ins. So an MCP tool with a built-in's name silently replaced it: handler, schema and approval policy. The filesystem server's write_file and list_directory, and the git server's git_commit, are common examples. git_commit then ran without a prompt in auto-accept. When the server later went unhealthy or disconnected, its tools were removed by name, which deleted the built-in for the rest of the session.

As agreed in the issue, built-ins always win.

Change (source/tools/tool-manager.ts):

  • ToolManager tracks the names the MCP client registered.
  • An MCP tool whose name is already taken by a built-in, custom or skill tool is skipped, the same way a colliding custom tool is. It's listed on that server's init result (MCPInitResult.skippedTools).
  • The unhealthy path, the recovery to connected, and disconnectMCP only add or remove names that MCP itself registered. A built-in can no longer be replaced on recovery or removed on disconnect.
  • The MCP lookups also only apply to those names. That covers getMCPToolInfo, used by /tools and the confirmation prompt, and plan mode's read-only filter. So a skipped tool can't relabel the built-in as an MCP tool, and its missing readOnlyHint can't hide the built-in in plan mode. I found the plan-mode case while working on this: an unannotated MCP list_directory was hiding the built-in list_directory in plan mode.

Warning: describeSkippedMCPTools() builds one message, and the TUI (a WarningMessage), --plain (writeStatus) and the daemon (console.error) all print it at startup:

MCP server "fixture" offers tools that a built-in or custom tool already uses, so they were skipped: write_file

Docs: a short "Tool Name Collisions" section in docs/configuration/mcp-configuration.md.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Changeset

  • Added a changeset (pnpm changeset) describing this change for the changelog

Testing

Automated Tests

  • New features include passing tests in .spec.ts/tsx files
  • All existing tests pass (pnpm test:all completes successfully): see below; the only failures also happen without this change
  • Tests cover both success and error scenarios

New tests in source/tools/tool-manager.spec.ts. They use a fake client through the existing createMCPClient() seam:

  • an MCP tool named like a built-in is skipped, the built-in's entry is untouched, skippedTools lists it, and the server's other tool still registers
  • skippedTools is unset when nothing collides
  • an MCP tool named like a skill tool is skipped
  • an unhealthy server removes only its own tools, not a built-in it collided with (the maintainer's case)
  • a server recovering to connected doesn't replace the built-in, and its own tool comes back (the maintainer's extra case)
  • disconnectMCP removes only MCP tools (the maintainer's extra case)
  • git_commit still needs approval in auto-accept with a server offering git_commit
  • plan mode keeps a built-in that an unannotated MCP tool is named like
  • describeSkippedMCPTools formatting

With only tool-manager.ts reverted (plus a stub for the new formatter), 7 of these fail. The other two, the "nothing collides" case and the formatter, are expected to pass there.

Two existing tests created their "MCP" tools with registerSkillTool and set the private mcpClient field, so as far as ToolManager is concerned those tools were never registered by MCP. They now connect a fake client through initializeMCP, with the same assertions:

  • "plan mode hides MCP tools unless the server annotates them read-only" (tool-manager.spec.ts)
  • "custom tools survive an MCP disconnect" (custom-tools/end-to-end.spec.ts)

Format, lint, types and knip pass. On macOS the full AVA suite passed 9,711 tests (20 skipped). The only 2 failures are the gh-pr-worktree tests that fail the same way on upstream main (/var vs /private/var tmpdir paths on macOS).

Manual Testing

  • Tested with Ollama
  • Tested with OpenRouter
  • Tested with OpenAI-compatible API
  • Tested MCP integration (if applicable)

End to end through the real CLI, on macOS with Node 22.23.3:

  • --plain run --json, auto-accept,
  • a scripted local OpenAI-compatible model,
  • a real stdio MCP server built on @modelcontextprotocol/sdk that logs each call and never writes to disk.

These are the cases from the issue. The source of truth is notes.txt on disk, the MCP server's own call log, and the CLI's JSON report.

Case v1.31.0 (npm, latest release) upstream main 9a244b89 v1.32.0 release PR (257b95e2) this branch v1.32.0 release PR + this fix
no MCP, write_file (control) written written written written written
MCP offers write_file MCP handles it, not written not written not written warning, built-in writes notes.txt, MCP never called same as this branch
MCP offers echo_tool + crash (control) list_directory works works works works works
MCP offers list_directory + crash Not connected Unknown tool: list_directory, no longer offered same as main warning, built-in list_directory works and stays offered same as this branch
no MCP, git_commit (control) approval required (exit 2) same same same same
MCP offers git_commit runs with no prompt no prompt no prompt approval required (exit 2) same as this branch

In the interactive TUI, I started in a project whose server offers write_file and echo_tool, accepted the trust prompt, and ran /tools:

  • upstream main: no warning, and /tools lists write_file (fixture).
  • This branch: the warning shows, /tools lists echo_tool (fixture), and write_file is listed with the built-ins.

The fix cherry-picks cleanly onto the v1.32.0 release PR, and the branch merges cleanly with current main.

Checklist

  • If this was for an open issue, I was assigned to it
  • Code follows project style guidelines
  • Self-review completed
  • Documentation updated (if needed)
  • No breaking changes (or clearly documented)
  • Appropriate logging added using structured logging (startup warnings go through the existing per-surface output: WarningMessage, writeStatus and console.error, the same as MCP connection failures)

The tool registry is a plain name-keyed map, and MCP entries were
registered after the built-ins, so an MCP tool named like a built-in
(the filesystem server's write_file and list_directory, the git server's
git_commit) silently replaced it: handler, schema and approval policy.
git_commit stopped prompting in auto-accept. The unhealthy and disconnect
paths then removed MCP tools by name, which deleted the built-in for the
rest of the session.

ToolManager now tracks the names the MCP client registered. An MCP tool
whose name is already taken by a built-in, custom or skill tool is
skipped, the same way a colliding custom tool is, and is reported on the
server's init result. The TUI, --plain and the daemon print a startup
warning for it. The unhealthy path, the recovery to connected and
disconnectMCP only add or remove names MCP holds. The MCP lookups behind
/tools, the confirmation prompt and plan mode's read-only filter also
only apply to those names, so a skipped tool's annotation can't hide or
relabel the built-in.

Two existing specs planted "MCP" tools with registerSkillTool and set the
private mcpClient field; they now connect a fake client through
initializeMCP instead.

Closes Nano-Collective#1853.
@github-actions github-actions Bot added area:tools Tool implementations and tool-calling area:tui Terminal UI area:docs Documentation labels Oct 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

nc-review: comments — 1 nit

@diyaavirmani — a few things worth a look, none blocking.

Closes #1853 cleanly. ToolManager now tracks names registered by MCP and treats any name collision with a built-in/custom/skill tool as an MCP skip (parallel to the existing custom-tool collision handling). Unhealthy/recovery/disconnect paths now mutate only MCP-owned names; the MCP lookups (getMCPToolInfo, plan-mode getMcpReadOnly) are gated on the same set, so an unannotated MCP list_directory can no longer hide the read-only built-in. A unified startup warning is wired into the TUI (WarningMessage), --plain (writeStatus), and the daemon (console.error). Tests cover all three collision surfaces and the unhealthy/reconnect/disconnect paths; two legacy tests were migrated off the mcpClient field-seam to the existing createMCPClient seam. Ready to merge.

⚪ nit · tests · source/tools/tool-manager.spec.ts:409

The recovery test covers echo_tool coming back and list_directory (a built-in shadowed by an unannotated MCP name) staying registered, which is the right shape. One edge it doesn't exercise: the recovered path's registerMCPEntries should call mcpClient.getToolEntries(change.serverName). If a future change drops the forServerName filter, every server's tools would land on every health-flip, and this test would still pass. A second server with ephemeral_tool would catch that and is cheap to add, but the omission is not load-bearing.


🔴 blocking · 🟠 a reviewer would ask for a change · ⚪ optional

Automated code review — correctness, security, design, tests, plus duplicates and scope. A human still decides; this is not a substitute for review and is not exhaustive. The required status checks separately cover lint, formatting, types, unused dependencies, the test suite and the build. This bot never merges. Maintainers can rerun with /re-review.

@github-actions

Copy link
Copy Markdown
Contributor

Hi @diyaavirmani, thanks for this PR! It looks like a maintainer has left feedback
or review activity and there are still some outstanding items to wrap up.

Whenever you get a chance, could you take a look at the open comments?
If anything is unclear or you'd like a hand, just reply here and we'll help you get it across the line.

Resolves the conflicts with Nano-Collective#1914, which gives each ACP session a
ToolManager layered over the shared one and skips a session MCP tool
whose name the parent already offers.

- registerMCPEntries replaces registerMcpTools. The layered registry's
  hasTool already sees the parent's tools, so a name the parent offers
  is skipped by the same check as a built-in, and is also reported in
  skippedTools. Upstream's warning log is kept for every skip.
- mcpReadOnly reads only names this manager's MCP client registered,
  then falls back to the parent. Upstream's version read the client's
  mapping for any name, which let a skipped tool's annotation decide
  whether plan mode offers the built-in ("plan mode keeps a built-in
  that an unannotated MCP tool is named like" fails without this).
- getMCPToolInfo keeps the registered-name lookup and upstream's parent
  fallback.
- New spec: a session's skipped MCP tool is reported and does not mark
  the existing tool as an MCP tool.
@diyaavirmani

Copy link
Copy Markdown
Contributor Author

Merged main to clear the conflicts with #1914 (68628ea). #1914's per-session ToolManager overlaps with this PR, so the merge combines the two rather than taking one side:

  • registerMCPEntries replaces registerMcpTools. The layered registry's hasTool already sees the parent's tools, so a name the parent offers is skipped by the same check as a built-in and is reported in skippedTools. feat(acp): honour client-supplied mcpServers with a per-session tool registry #1914's warning log is kept for every skip.
  • mcpReadOnly reads only names this manager's MCP client registered, then falls back to the parent. Taking main's version as is breaks this PR's "plan mode keeps a built-in that an unannotated MCP tool is named like" test, since a skipped tool's annotation would again decide whether plan mode offers the built-in.
  • getMCPToolInfo keeps the registered-name lookup plus feat(acp): honour client-supplied mcpServers with a per-session tool registry #1914's parent fallback.
  • New spec: a session's skipped MCP tool is reported and doesn't mark the existing tool as an MCP tool.

Testing on Node 22: tsc, Biome and the full AVA suite. The two failures in the full run don't involve this PR: trust-cli › a record from another fingerprint version needs re-approval also fails on an untouched main checkout here (macOS), and settings-tabs › left/right arrows move the selected-tab failed once under load and passes on rerun.

@addyCooks could you take another look when you get a chance?

@addyCooks addyCooks left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks good. The tests cover the cases we discussed in #1853 and CI is green. One thing before merge:

The branch now conflicts with main in tool-manager.ts (initializeMCP). Main added the warning for two MCP servers exposing the same tool name (getToolNameConflicts). Please rebase and keep both warnings. Note the early return results when nothing is skipped would skip that conflicts warning, so move it, and add a test that both warnings still fire. Then I'll merge.

Resolve the initializeMCP conflict with main's duplicate MCP tool name
warning (getToolNameConflicts) and keep both warnings:

- The duplicate-name warning now runs before the early return taken when
  no tool was skipped, so it fires in the common case of two servers
  sharing a name that no built-in uses.
- A skipped name is left out of the duplicate-name warning: when two
  servers offer a built-in's name, the built-in handles the calls, so
  naming a server they "go to" would be wrong.
- Skipped names are reported for every server that offers them, not
  only for the server the tool mapping routes the name to.

Specs cover a shared name with nothing skipped, a skip alongside a
shared name (both warnings), and a built-in name two servers share.
The fakes the PR added for initializeMCP now provide
getToolNameConflicts.
@diyaavirmani

diyaavirmani commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks @addyCooks, done. I merged main in (6829401) rather than rebasing, and kept both warnings. The duplicate-name warning now runs before the early return, so it fires even when nothing is skipped. A name that a built-in already uses is left out of it and reported as skipped for each server that offers it.
New tests check that both warnings fire together, and CI is green.

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.
@diyaavirmani

Copy link
Copy Markdown
Contributor Author

@addyCooks main moved again, so I merged it in once more (51bcdb9). This time the conflict was on-demand MCP discovery (#1651, with #2052 and #2057). It gives MCP tools a second way into the registry, so it needed more than a text merge:

  • Catalog: an MCP tool named like a built-in, custom or skill tool is now left out of the discovery catalog too, and still reported in skippedTools. Otherwise load_tool_schema would offer the MCP schema for a name that calls the built-in.
  • loadMcpTool: it won't claim a name another tool holds, and it records what it registers. So an outage or disconnectMCP removes tools loaded on demand and never the built-in. Without that record, upstream's own outage test fails on this branch.
  • Recovery: restoreServerTools skips the same names when it rebuilds the catalog and re-registers the loaded tools.
  • getMCPToolInfo: a tool that's only in the catalog still counts as MCP, as upstream has it, so the server's alwaysAllow and the confirmation's server label still apply to it.
  • Callers: daemon/entry.ts and plain/initialize.ts pass upstream's tune config and keep the skipped-tools warning.

Three new tests cover discovery mode. The shadowed name stays out of the catalog. A tool loaded on demand is removed on disconnect while the built-in stays. An outage and recovery restore the loaded tool without touching the built-in. All three fail without these changes. Format, types, lint and knip pass, and the tools, MCP, ACP, daemon, plain-mode, hooks and conversation specs pass locally. CI is green (18/18). Could you take another look?

@addyCooks addyCooks left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work as always @diyaavirmani !

Approving 🎉

@addyCooks
addyCooks merged commit ba04a37 into Nano-Collective:main Nov 18, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent:comments nc-review left non-blocking findings area:docs Documentation area:tools Tool implementations and tool-calling area:tui Terminal UI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] An MCP tool with the same name as a built-in silently replaces it, and a server crash then removes the built-in

2 participants