From 45c10fa16626c4bf6fe54dfea55a0aef53b72f51 Mon Sep 17 00:00:00 2001 From: kangfenmao Date: Sun, 16 Mar 2025 21:58:36 +0800 Subject: [PATCH] feat: add server restart functionality to MCPService - Implemented a new method to restart MCP servers, enhancing server management capabilities. - Updated the existing server activation logic to include a restart option when necessary. - Ensured that server state is properly managed during the restart process. --- src/main/services/MCPService.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/services/MCPService.ts b/src/main/services/MCPService.ts index d5785060..ebc5e298 100644 --- a/src/main/services/MCPService.ts +++ b/src/main/services/MCPService.ts @@ -224,15 +224,31 @@ export default class MCPService extends EventEmitter { await this.deactivate(server.name) } else if (!wasActive && server.isActive) { await this.activate(server) + } else { + await this.restartServer(server) } // Update servers list const updatedServers = [...this.servers] updatedServers[index] = server this.servers = updatedServers + + // Notify Redux this.notifyReduxServersChanged(updatedServers) } + public async restartServer(_server: MCPServer): Promise { + await this.ensureInitialized() + + const server = this.servers.find((s) => s.name === _server.name) + + if (server) { + if (server.isActive) { + await this.deactivate(server.name) + } + await this.activate(server) + } + } /** * Delete an MCP server */