@@ -133,7 +133,6 @@ export class McpHub {
133133 connections : McpConnection [ ] = [ ]
134134 isConnecting : boolean = false
135135 private configChangeDebounceTimers : Map < string , NodeJS . Timeout > = new Map ( )
136- private toggleOperations : Map < string , Promise < void > > = new Map ( ) // Track ongoing toggle operations
137136 private isInitializing : boolean = true // Flag to prevent duplicate connections during initialization
138137
139138 constructor ( provider : ClineProvider ) {
@@ -315,19 +314,7 @@ export class McpHub {
315314 return
316315 }
317316
318- // Check if any servers have toggle operations in progress
319- const servers = result . data . mcpServers || { }
320- const hasActiveToggleOperations = Object . keys ( servers ) . some ( ( serverName ) => {
321- const operationKey = `${ serverName } -${ source } `
322- return this . toggleOperations . has ( operationKey )
323- } )
324-
325- if ( hasActiveToggleOperations ) {
326- console . log ( `Skipping config file change for ${ source } - toggle operations in progress` )
327- return
328- }
329-
330- await this . updateServerConnections ( servers , source )
317+ await this . updateServerConnections ( result . data . mcpServers || { } , source )
331318 } catch ( error ) {
332319 // Check if the error is because the file doesn't exist
333320 if ( error . code === "ENOENT" && source === "project" ) {
@@ -953,8 +940,13 @@ export class McpHub {
953940
954941 for ( const connection of connections ) {
955942 try {
956- await connection . transport . close ( )
957- await connection . client . close ( )
943+ // Only try to close transport and client if they exist (not null for disabled servers)
944+ if ( connection . transport ) {
945+ await connection . transport . close ( )
946+ }
947+ if ( connection . client ) {
948+ await connection . client . close ( )
949+ }
958950 } catch ( error ) {
959951 console . error ( `Failed to close transport for ${ name } :` , error )
960952 }
@@ -1347,33 +1339,6 @@ export class McpHub {
13471339 serverName : string ,
13481340 disabled : boolean ,
13491341 source ?: "global" | "project" ,
1350- ) : Promise < void > {
1351- // Check if there's already a toggle operation in progress for this server
1352- const operationKey = `${ serverName } -${ source || "global" } `
1353- const existingOperation = this . toggleOperations . get ( operationKey )
1354-
1355- if ( existingOperation ) {
1356- console . log ( `Toggle operation already in progress for ${ operationKey } , waiting...` )
1357- await existingOperation
1358- return
1359- }
1360-
1361- // Create a new toggle operation
1362- const toggleOperation = this . _performToggleServerDisabled ( serverName , disabled , source )
1363- this . toggleOperations . set ( operationKey , toggleOperation )
1364-
1365- try {
1366- await toggleOperation
1367- } finally {
1368- // Clean up the operation from the map
1369- this . toggleOperations . delete ( operationKey )
1370- }
1371- }
1372-
1373- private async _performToggleServerDisabled (
1374- serverName : string ,
1375- disabled : boolean ,
1376- source ?: "global" | "project" ,
13771342 ) : Promise < void > {
13781343 try {
13791344 // Find the connection to determine if it's a global or project server
0 commit comments