Skip to content

[Bug] disconnectMCP() permanently wipes all custom tools from the registry #1034

Description

@akramcodez

Description

Whenever an MCP server disconnects (due to a restart, shutdown, or crash), tool-manager.ts handles the cleanup by completely resetting the tool registry back to static defaults. It calls this.customTools.clear(), completely wiping out all user-defined custom tools. The only way to recover them is to restart Nanocoder.

Environment

  • OS: Any
  • Node version: Node 18+
  • Nanocoder version: 1.30.0
  • Provider: N/A
  • Model: N/A

Steps to Reproduce

  1. Start Nanocoder and ensure you have custom tools loaded in your workspace.
  2. Connect to an MCP server.
  3. Have the MCP server disconnect or explicitly disconnect it.
  4. Try to use your custom tools—they are gone.

Expected Behavior

Disconnecting from an MCP server should only unregister the MCP-provided tools, leaving workspace custom tools intact.

Actual Behavior

disconnectMCP() resets the entire registry to allToolExports (built-ins only) and clears this.customTools.

Additional Context

  • 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

Implementation Notes

Fix in source/tools/tool-manager.ts lines 370-385. Remove this.registry = ToolRegistry.fromToolExports(...) and this.customTools.clear(). Only call this.registry.unregisterMany(mcpToolNames).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions