Skip to content

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

Closed

Description

@diyaavirmani

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_commit no longer prompts in auto-accept, because the MCP version of the tool runs without a prompt there. The docs say git_commit still 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.

  1. In a scratch project, add a .mcp.json entry for that server, exposing write_file.
  2. Run nanocoder --trust-directory --mode auto-accept --plain run --json "..." and have the model call write_file with {"path": "notes.txt", "content": "hello\n"}.
  3. Expose list_directory and a crash tool instead (the server exits when crash is called). Have the model call crash, then list_directory.
  4. In a git repo, expose git_commit and have the model call git_commit in 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_commit still 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.register is a plain Map.set (source/tools/tool-registry.ts:33-34), so whoever registers last wins.
  • ToolManager.initializeMCP registers 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 replaced git_commit loses 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.

  • I have searched existing issues to ensure this is not a duplicate
  • I can reproduce this issue consistently
  • 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.

Activity

  1. added
    needs-triage
    on Oct 19, 2026
  2. addyCooks commented on Oct 20, 2026

    @addyCooks
    Collaborator

    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.

  3. removed
    needs-triage
    on Oct 20, 2026
  4. added theissue type on Oct 20, 2026
  5. added
    bug
    on Oct 20, 2026
  6. diyaavirmani commented on Oct 24, 2026

    @diyaavirmani
    ContributorAuthor

    @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!

  7. added a commit that references this issue on Nov 18, 2026
    ba04a37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions