@@ -1207,6 +1207,15 @@ export class McpHub {
12071207 }
12081208 }
12091209
1210+ // Store disabled state before clearing connections
1211+ const disabledServers = new Map < string , boolean > ( )
1212+ for ( const conn of this . connections ) {
1213+ if ( conn . server . disabled ) {
1214+ const key = `${ conn . server . name } -${ conn . server . source || "global" } `
1215+ disabledServers . set ( key , true )
1216+ }
1217+ }
1218+
12101219 // Clear all existing connections first
12111220 const existingConnections = [ ...this . connections ]
12121221 for ( const conn of existingConnections ) {
@@ -1218,6 +1227,15 @@ export class McpHub {
12181227 await this . initializeMcpServers ( "global" )
12191228 await this . initializeMcpServers ( "project" )
12201229
1230+ // Re-apply disabled state to servers that were disabled before refresh
1231+ for ( const conn of this . connections ) {
1232+ const key = `${ conn . server . name } -${ conn . server . source || "global" } `
1233+ if ( disabledServers . has ( key ) && ! conn . server . disabled ) {
1234+ // Server was disabled before refresh but got re-enabled, disable it again
1235+ await this . toggleServerDisabled ( conn . server . name , true , conn . server . source )
1236+ }
1237+ }
1238+
12211239 await delay ( 100 )
12221240
12231241 await this . notifyWebviewOfServerChanges ( )
@@ -1339,8 +1357,35 @@ export class McpHub {
13391357
13401358 // If disabling the server, update the connection state and disconnect
13411359 if ( disabled ) {
1360+ // First update the config file
13421361 connection . server . disabled = true
1362+
1363+ // Store the config before deleting the connection
1364+ const storedConfig = connection . server . config
1365+
1366+ // Delete the connection (this closes transport and client)
13431367 await this . deleteConnection ( serverName , serverSource )
1368+
1369+ // Create a placeholder connection for disabled servers
1370+ // This is needed so the server still appears in the UI
1371+ const parsedConfig = JSON . parse ( storedConfig )
1372+ parsedConfig . disabled = true
1373+
1374+ const placeholderConnection : McpConnection = {
1375+ server : {
1376+ name : serverName ,
1377+ config : JSON . stringify ( parsedConfig ) ,
1378+ status : "disconnected" ,
1379+ disabled : true ,
1380+ source : serverSource ,
1381+ projectPath :
1382+ serverSource === "project" ? vscode . workspace . workspaceFolders ?. [ 0 ] ?. uri . fsPath : undefined ,
1383+ errorHistory : [ ] ,
1384+ } ,
1385+ client : null as any ,
1386+ transport : null as any ,
1387+ }
1388+ this . connections . push ( placeholderConnection )
13441389 } else {
13451390 // If enabling the server, we need to re-read the config and reconnect
13461391 // Get the updated config from the file
0 commit comments