summaryrefslogtreecommitdiff
path: root/packages/core
diff options
context:
space:
mode:
authorRamón Medrano Llamas <[email protected]>2025-07-25 03:14:45 +0200
committerGitHub <[email protected]>2025-07-25 01:14:45 +0000
commit273e74c09da89492d16fc076cfbff4d043eafa4c (patch)
treed68076b1139ac909b43eb9ba402e62238044d8d2 /packages/core
parente9ee686ab6c5c99d895d80951336613f248f6560 (diff)
feat: add /mcp refresh command (#4566)
Diffstat (limited to 'packages/core')
-rw-r--r--packages/core/src/config/config.test.ts2
-rw-r--r--packages/core/src/config/config.ts2
-rw-r--r--packages/core/src/tools/tool-registry.test.ts6
-rw-r--r--packages/core/src/tools/tool-registry.ts25
4 files changed, 29 insertions, 6 deletions
diff --git a/packages/core/src/config/config.test.ts b/packages/core/src/config/config.test.ts
index 9fec505f..3f0b3db5 100644
--- a/packages/core/src/config/config.test.ts
+++ b/packages/core/src/config/config.test.ts
@@ -23,7 +23,7 @@ import { GitService } from '../services/gitService.js';
vi.mock('../tools/tool-registry', () => {
const ToolRegistryMock = vi.fn();
ToolRegistryMock.prototype.registerTool = vi.fn();
- ToolRegistryMock.prototype.discoverTools = vi.fn();
+ ToolRegistryMock.prototype.discoverAllTools = vi.fn();
ToolRegistryMock.prototype.getAllTools = vi.fn(() => []); // Mock methods if needed
ToolRegistryMock.prototype.getTool = vi.fn();
ToolRegistryMock.prototype.getFunctionDeclarations = vi.fn(() => []);
diff --git a/packages/core/src/config/config.ts b/packages/core/src/config/config.ts
index 231bbcd5..485a56c4 100644
--- a/packages/core/src/config/config.ts
+++ b/packages/core/src/config/config.ts
@@ -630,7 +630,7 @@ export class Config {
registerCoreTool(MemoryTool);
registerCoreTool(WebSearchTool, this);
- await registry.discoverTools();
+ await registry.discoverAllTools();
return registry;
}
}
diff --git a/packages/core/src/tools/tool-registry.test.ts b/packages/core/src/tools/tool-registry.test.ts
index ab337252..de355a98 100644
--- a/packages/core/src/tools/tool-registry.test.ts
+++ b/packages/core/src/tools/tool-registry.test.ts
@@ -312,7 +312,7 @@ describe('ToolRegistry', () => {
return mockChildProcess as any;
});
- await toolRegistry.discoverTools();
+ await toolRegistry.discoverAllTools();
const discoveredTool = toolRegistry.getTool('tool-with-bad-format');
expect(discoveredTool).toBeDefined();
@@ -338,7 +338,7 @@ describe('ToolRegistry', () => {
};
vi.spyOn(config, 'getMcpServers').mockReturnValue(mcpServerConfigVal);
- await toolRegistry.discoverTools();
+ await toolRegistry.discoverAllTools();
expect(mockDiscoverMcpTools).toHaveBeenCalledWith(
mcpServerConfigVal,
@@ -360,7 +360,7 @@ describe('ToolRegistry', () => {
};
vi.spyOn(config, 'getMcpServers').mockReturnValue(mcpServerConfigVal);
- await toolRegistry.discoverTools();
+ await toolRegistry.discoverAllTools();
expect(mockDiscoverMcpTools).toHaveBeenCalledWith(
mcpServerConfigVal,
diff --git a/packages/core/src/tools/tool-registry.ts b/packages/core/src/tools/tool-registry.ts
index a6742c06..b72ed9a5 100644
--- a/packages/core/src/tools/tool-registry.ts
+++ b/packages/core/src/tools/tool-registry.ts
@@ -153,8 +153,9 @@ export class ToolRegistry {
/**
* Discovers tools from project (if available and configured).
* Can be called multiple times to update discovered tools.
+ * This will discover tools from the command line and from MCP servers.
*/
- async discoverTools(): Promise<void> {
+ async discoverAllTools(): Promise<void> {
// remove any previously discovered tools
for (const tool of this.tools.values()) {
if (tool instanceof DiscoveredTool || tool instanceof DiscoveredMCPTool) {
@@ -174,6 +175,28 @@ export class ToolRegistry {
}
/**
+ * Discovers tools from project (if available and configured).
+ * Can be called multiple times to update discovered tools.
+ * This will NOT discover tools from the command line, only from MCP servers.
+ */
+ 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);
+ }
+ }
+
+ // discover tools using MCP servers, if configured
+ await discoverMcpTools(
+ this.config.getMcpServers() ?? {},
+ this.config.getMcpServerCommand(),
+ this,
+ this.config.getDebugMode(),
+ );
+ }
+
+ /**
* Discover or re-discover tools for a single MCP server.
* @param serverName - The name of the server to discover tools from.
*/