summaryrefslogtreecommitdiff
path: root/packages/core/src/tools/tool-registry.ts
diff options
context:
space:
mode:
authorRamón Medrano Llamas <[email protected]>2025-08-19 21:03:19 +0200
committerGitHub <[email protected]>2025-08-19 19:03:19 +0000
commitb24c5887c45edde8690b4d73d8961e63eee13a34 (patch)
tree6136f1f6bcc61801edb9f6d6411966b3b6678984 /packages/core/src/tools/tool-registry.ts
parent4828e4daf198a675ce118cec08dcfbd0bfbb28a6 (diff)
feat: restart MCP servers on /mcp refresh (#5479)
Co-authored-by: Brian Ray <[email protected]> Co-authored-by: N. Taylor Mullen <[email protected]>
Diffstat (limited to 'packages/core/src/tools/tool-registry.ts')
-rw-r--r--packages/core/src/tools/tool-registry.ts43
1 files changed, 23 insertions, 20 deletions
diff --git a/packages/core/src/tools/tool-registry.ts b/packages/core/src/tools/tool-registry.ts
index ff155679..90531742 100644
--- a/packages/core/src/tools/tool-registry.ts
+++ b/packages/core/src/tools/tool-registry.ts
@@ -16,7 +16,8 @@ import {
import { Config } from '../config/config.js';
import { spawn } from 'node:child_process';
import { StringDecoder } from 'node:string_decoder';
-import { discoverMcpTools } from './mcp-client.js';
+import { connectAndDiscover } from './mcp-client.js';
+import { McpClientManager } from './mcp-client-manager.js';
import { DiscoveredMCPTool } from './mcp-tool.js';
import { parse } from 'shell-quote';
@@ -163,9 +164,18 @@ Signal: Signal number or \`(none)\` if no signal was received.
export class ToolRegistry {
private tools: Map<string, AnyDeclarativeTool> = new Map();
private config: Config;
+ private mcpClientManager: McpClientManager;
constructor(config: Config) {
this.config = config;
+ this.mcpClientManager = new McpClientManager(
+ this.config.getMcpServers() ?? {},
+ this.config.getMcpServerCommand(),
+ this,
+ this.config.getPromptRegistry(),
+ this.config.getDebugMode(),
+ this.config.getWorkspaceContext(),
+ );
}
/**
@@ -220,14 +230,7 @@ export class ToolRegistry {
await this.discoverAndRegisterToolsFromCommand();
// discover tools using MCP servers, if configured
- await discoverMcpTools(
- this.config.getMcpServers() ?? {},
- this.config.getMcpServerCommand(),
- this,
- this.config.getPromptRegistry(),
- this.config.getDebugMode(),
- this.config.getWorkspaceContext(),
- );
+ await this.mcpClientManager.discoverAllMcpTools();
}
/**
@@ -242,14 +245,14 @@ export class ToolRegistry {
this.config.getPromptRegistry().clear();
// discover tools using MCP servers, if configured
- await discoverMcpTools(
- this.config.getMcpServers() ?? {},
- this.config.getMcpServerCommand(),
- this,
- this.config.getPromptRegistry(),
- this.config.getDebugMode(),
- this.config.getWorkspaceContext(),
- );
+ await this.mcpClientManager.discoverAllMcpTools();
+ }
+
+ /**
+ * Restarts all MCP servers and re-discovers tools.
+ */
+ async restartMcpServers(): Promise<void> {
+ await this.discoverMcpTools();
}
/**
@@ -269,9 +272,9 @@ export class ToolRegistry {
const mcpServers = this.config.getMcpServers() ?? {};
const serverConfig = mcpServers[serverName];
if (serverConfig) {
- await discoverMcpTools(
- { [serverName]: serverConfig },
- undefined,
+ await connectAndDiscover(
+ serverName,
+ serverConfig,
this,
this.config.getPromptRegistry(),
this.config.getDebugMode(),