diff options
| author | Ramón Medrano Llamas <[email protected]> | 2025-08-05 23:59:31 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-08-05 21:59:31 +0000 |
| commit | 29c3825604fdc82b483902bf79f204673e2dfdae (patch) | |
| tree | 5c73f8937ad4ee52948b66f558136dddf5a9c86e /packages/core/src/tools/tool-registry.ts | |
| parent | faf6a5497a7fd902edb4dfd0941c4157edb62dd5 (diff) | |
fix(mcp): clear prompt registry on refresh to prevent duplicates (#5385)
Co-authored-by: Jacob Richman <[email protected]>
Co-authored-by: Sandy Tao <[email protected]>
Diffstat (limited to 'packages/core/src/tools/tool-registry.ts')
| -rw-r--r-- | packages/core/src/tools/tool-registry.ts | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/packages/core/src/tools/tool-registry.ts b/packages/core/src/tools/tool-registry.ts index 57627ee0..e60b8f74 100644 --- a/packages/core/src/tools/tool-registry.ts +++ b/packages/core/src/tools/tool-registry.ts @@ -150,6 +150,14 @@ export class ToolRegistry { this.tools.set(tool.name, tool); } + private removeDiscoveredTools(): void { + for (const tool of this.tools.values()) { + if (tool instanceof DiscoveredTool || tool instanceof DiscoveredMCPTool) { + this.tools.delete(tool.name); + } + } + } + /** * Discovers tools from project (if available and configured). * Can be called multiple times to update discovered tools. @@ -157,11 +165,9 @@ export class ToolRegistry { */ async discoverAllTools(): Promise<void> { // remove any previously discovered tools - for (const tool of this.tools.values()) { - if (tool instanceof DiscoveredTool || tool instanceof DiscoveredMCPTool) { - this.tools.delete(tool.name); - } - } + this.removeDiscoveredTools(); + + this.config.getPromptRegistry().clear(); await this.discoverAndRegisterToolsFromCommand(); @@ -182,11 +188,9 @@ export class ToolRegistry { */ async discoverMcpTools(): Promise<void> { // remove any previously discovered tools - for (const tool of this.tools.values()) { - if (tool instanceof DiscoveredMCPTool) { - this.tools.delete(tool.name); - } - } + this.removeDiscoveredTools(); + + this.config.getPromptRegistry().clear(); // discover tools using MCP servers, if configured await discoverMcpTools( @@ -210,6 +214,8 @@ export class ToolRegistry { } } + this.config.getPromptRegistry().removePromptsByServer(serverName); + const mcpServers = this.config.getMcpServers() ?? {}; const serverConfig = mcpServers[serverName]; if (serverConfig) { |
