Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/daemon/src/daemon/mcp-client-pool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,17 @@ describe('syncWithConfig', () => {
await pool.syncWithConfig({});
expect(pool.getStatus('dyn')?.connected).toBe(true);
});

it('should drop a server whose only connection attempt failed once removed from config', async () => {
mockCreateMCPClient.mockRejectedValueOnce(new Error('connection closed'));
await pool.connect('bad', { transport: 'stdio', command: 'bad', enabled: true }).catch(() => {});
// Status exists (with error) even though it never made it into `clients`.
expect(pool.getStatus('bad')?.error).toBeTruthy();

await pool.syncWithConfig({});

expect(pool.getStatus('bad')).toBeUndefined();
});
});

// ── getStatuses ───────────────────────────────────────────────────────────
Expand Down
5 changes: 4 additions & 1 deletion packages/daemon/src/daemon/mcp-client-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,10 @@ export class McpClientPool {
*/
async syncWithConfig(configs: Record<string, McpServerConfig>): Promise<void> {
const newIds = new Set(Object.keys(configs));
const currentIds = new Set(this.clients.keys());
// Union of connected clients and tracked statuses — a server whose last
// connect attempt failed has a status entry but no client, and must still
// be reconciled (and dropped) when removed from config.
const currentIds = new Set([...this.clients.keys(), ...this.statuses.keys()]);

// Disconnect removed config-based servers (skip dynamic)
for (const id of currentIds) {
Expand Down
Loading
Loading