kill unused mcp servers

This commit is contained in:
Dallin Romney 2025-03-17 00:17:05 -07:00
parent 432221b87d
commit d11ed7da53
2 changed files with 12 additions and 0 deletions

View file

@ -369,6 +369,11 @@ async function configYamlToContinueConfig(
// Apply MCP if specified
const mcpManager = MCPManagerSingleton.getInstance();
if (config.mcpServers) {
await mcpManager.removeUnusedConnections(
config.mcpServers.map((s) => s.name),
);
}
await Promise.allSettled(
config.mcpServers?.map(async (server) => {
const abortController = new AbortController();

View file

@ -46,6 +46,13 @@ export class MCPManagerSingleton {
this.connections.delete(id);
}
async removeUnusedConnections(keepIds: string[]) {
const toRemove = this.connections
.keys()
.filter((k) => !keepIds.includes(k));
await Promise.all(toRemove.map(this.removeConnection));
}
}
class MCPConnection {