Skip to content

Commit ec69103

Browse files
committed
ack commetns
1 parent f844e25 commit ec69103

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed

apps/sim/lib/mcp/connection-manager.ts

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -305,20 +305,21 @@ class McpConnectionManager {
305305

306306
if (this.disposed) return
307307

308-
try {
309-
this.connections.delete(serverId)
310-
this.states.delete(serverId)
308+
const attempts = state.reconnectAttempts
309+
this.connections.delete(serverId)
310+
this.states.delete(serverId)
311311

312+
try {
312313
const result = await this.connect(config, userId, workspaceId)
313314
if (result.supportsListChanged) {
314-
const newState = this.states.get(serverId)
315-
if (newState) {
316-
newState.reconnectAttempts = 0
317-
}
318315
logger.info(`[${config.name}] Reconnected successfully`)
316+
} else {
317+
this.restoreReconnectState(config, userId, workspaceId, attempts)
318+
this.scheduleReconnect(config, userId, workspaceId)
319319
}
320320
} catch (error) {
321321
logger.error(`[${config.name}] Reconnect failed:`, error)
322+
this.restoreReconnectState(config, userId, workspaceId, attempts)
322323
this.scheduleReconnect(config, userId, workspaceId)
323324
}
324325
}, delay)
@@ -334,6 +335,29 @@ class McpConnectionManager {
334335
}
335336
}
336337

338+
/**
339+
* Restore minimal state so `scheduleReconnect` can check attempts and continue the retry loop.
340+
*/
341+
private restoreReconnectState(
342+
config: McpServerConfig,
343+
userId: string,
344+
workspaceId: string,
345+
reconnectAttempts: number
346+
): void {
347+
if (!this.states.has(config.id)) {
348+
this.states.set(config.id, {
349+
serverId: config.id,
350+
serverName: config.name,
351+
workspaceId,
352+
userId,
353+
connected: false,
354+
supportsListChanged: false,
355+
reconnectAttempts,
356+
lastActivity: Date.now(),
357+
})
358+
}
359+
}
360+
337361
private ensureIdleCheck(): void {
338362
if (this.idleCheckTimer) return
339363

0 commit comments

Comments
 (0)