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.
This commit is contained in:
kangfenmao 2025-03-16 21:58:36 +08:00
parent 295454a85e
commit 45c10fa166

View File

@ -224,15 +224,31 @@ export default class MCPService extends EventEmitter {
await this.deactivate(server.name) await this.deactivate(server.name)
} else if (!wasActive && server.isActive) { } else if (!wasActive && server.isActive) {
await this.activate(server) await this.activate(server)
} else {
await this.restartServer(server)
} }
// Update servers list // Update servers list
const updatedServers = [...this.servers] const updatedServers = [...this.servers]
updatedServers[index] = server updatedServers[index] = server
this.servers = updatedServers this.servers = updatedServers
// Notify Redux
this.notifyReduxServersChanged(updatedServers) this.notifyReduxServersChanged(updatedServers)
} }
public async restartServer(_server: MCPServer): Promise<void> {
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 * Delete an MCP server
*/ */