[Bug] An MCP tool with the same name as a built-in silently replaces it, and a server crash then removes the built-in
Description
When an MCP server exposes a tool with the same name as a built-in (write_file, list_directory, git_status, git_commit, ...), the MCP tool silently replaces the built-in: its handler, its schema and its approval policy. There's no warning. Custom tools that collide with a built-in are already skipped with an error, but MCP tools aren't checked.
This is easy to hit. The filesystem server in the MCP Quick Start (docs/configuration/mcp-configuration.md) exposes write_file and list_directory, and the official git server exposes git_status, git_diff, git_log, git_add and git_commit.
What the user sees:
- Calls to the built-in go to the MCP server instead.
git_commitno longer prompts in auto-accept, because the MCP version of the tool runs without a prompt there. The docs saygit_commitstill prompts in auto-accept (docs/features/development-modes.md:59).- On main, if that server later goes unhealthy (crash, failed ping), nanocoder removes its tools by name, and that deletes the built-in for the rest of the session. The model gets
Unknown tool: list_directory, and the tool is no longer offered.
Environment
- OS: macOS (Darwin 25.6.0, x86_64)
- Node version: 22.23.3
- Nanocoder version: main at
ef4e79ec, and v1.31.0 - Provider: a local OpenAI-compatible test server with scripted responses
- Model: n/a (scripted)
Steps to Reproduce
I used a small stdio MCP server built on @modelcontextprotocol/sdk. It exposes whichever tool names I give it, logs each call, and never touches the disk.
- In a scratch project, add a
.mcp.jsonentry for that server, exposingwrite_file. - Run
nanocoder --trust-directory --mode auto-accept --plain run --json "..."and have the model callwrite_filewith{"path": "notes.txt", "content": "hello\n"}. - Expose
list_directoryand acrashtool instead (the server exits whencrashis called). Have the model callcrash, thenlist_directory. - In a git repo, expose
git_commitand have the model callgit_commitin auto-accept.
Expected Behavior
- Built-in tools keep working. A colliding MCP tool is skipped or namespaced with a warning, the way colliding custom tools are skipped (
source/tools/tool-manager.ts:229-246). - An unhealthy server only loses its own tools. The docs say a failed ping "marks the server unhealthy and removes its tools" (
docs/configuration/mcp-configuration.md:203). git_commitstill prompts in auto-accept.
Actual Behavior
| Case | Result |
|---|---|
| no MCP (control) | write_file writes notes.txt |
MCP exposes write_file |
the model is sent the MCP definition ([MCP:fixture] ...), the call goes to the MCP server, and notes.txt is never written |
MCP exposes echo_tool + crash (control) |
after the crash, the built-in list_directory still works |
MCP exposes list_directory + crash |
after the crash, main returns Unknown tool: list_directory and stops offering the tool. v1.31.0 returns MCP tool execution failed: Not connected |
git_commit, no MCP (control) |
the run stops with kind: "tool-approval-required" (exit 2) |
MCP exposes git_commit |
the MCP tool runs with no prompt, kind: "success" |
Each case gave the same result on main ef4e79ec and on v1.31.0, except the crash case noted in the table.
Logs/Screenshots
What I think is going on:
ToolRegistry.registeris a plainMap.set(source/tools/tool-registry.ts:33-34), so whoever registers last wins.ToolManager.initializeMCPregisters the MCP entries after the built-ins (source/tools/tool-manager.ts:214), so a same-named MCP entry overwrites the built-in.- MCP tools don't need approval in auto-accept (
source/mcp/mcp-client.ts:861-862), so the replacedgit_commitloses its prompt. - When a server goes unhealthy, the health handler calls
registry.unregisterMany(toolNames)by name (source/tools/tool-manager.ts:180-188). That removes the shadowed built-in, and it isn't restored.
Additional Context
Proposed fix (happy to adjust): check for name collisions when registering MCP tools. Either skip the MCP tool with a warning, like custom tools, or register it under a namespaced name. Then make the unhealthy and disconnect paths remove only entries that belong to the MCP client, so a built-in can never be unregistered. One open question for you: should a deliberate override (someone who wants the MCP write_file) be possible through config, or is "built-ins always win" fine?
For tests: an MCP entry named like a built-in leaves the built-in in the registry (with a warning), an unhealthy server leaves built-ins registered, and git_commit still needs approval in auto-accept with a colliding server configured.
- [x] I have searched existing issues to ensure this is not a duplicate
- [x] I can reproduce this issue consistently
- [x] This issue occurs with the latest version of nanocoder
@addyCooks could you take a look when you have a moment? I'd like to work on this one, so please assign it to me if that works for you.
Thanks @diyaavirmani, this is a clear report and I reproduced it at unit level on current main. An MCP entry with a built-in's name overwrites it in the registry, and both the unhealthy handler and disconnectMCP then unregister that name, which removes the built-in.
On your open question: let's go with "built-ins always win". Skip the colliding MCP tool with a warning, the same way custom tools are skipped, and track which names the MCP client actually registered so the unhealthy and disconnect paths only remove those. We can add an opt-in override later if someone needs it.
One extra case for the tests: disconnectMCP has the same by-name unregister, and the "connected" recovery path calls registerMany, so it needs the same collision check.
I'll assign this to you, go ahead whenever you're ready.
@addyCooks the fix for this is up in #1863 (all checks green, no conflicts). Would you be able to take a look when you have a moment? Thanks!