feat: add /mcp refresh command (#4566)

This commit is contained in:
Ramón Medrano Llamas
2025-07-25 03:14:45 +02:00
committed by GitHub
parent e9ee686ab6
commit 273e74c09d
6 changed files with 155 additions and 7 deletions

View File

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

View File

@@ -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) {
@@ -173,6 +174,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.