Skip to content

Conversation

@Adancurusul
Copy link

Replace global mcpClient with Map to store separate client instances for each MCP server. Previously all servers shared one client and showed identical tools.

TLDR

Fixed MCP servers all showing the same tools instead of their unique toolsets. Changed from global variable to Map-based storage so each server gets its own client instance.

Dive Deeper

The issue was in `packages/core/src/tools/mcp-client.ts` where a global `mcpClient` variable was being overwritten by each new connection. This meant the last connected server's tools would appear for all servers.

Solution:

  • Replaced `let mcpClient: Client | null = null` with `const mcpClients: Map<string, Client> = new Map()`
  • Each server now gets its own client instance stored in the Map
  • Added proper cleanup when connections fail to prevent memory leaks

Reviewer Test Plan

  1. Configure multiple MCP servers in settings
  2. Start the CLI and verify each server shows different tools (not identical ones)

Testing Matrix

🍏 🪟 🐧
npm run
npx
Docker
Podman - -
Seatbelt - -

Linked issues / bugs

Replace global mcpClient with Map to store separate client instances
for each MCP server. Previously all servers shared one client and
showed identical tools.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant