@@ -44,6 +44,8 @@ private enum TransportProtocol
4444 private Button testConnectionButton ;
4545
4646 private bool connectionToggleInProgress ;
47+ private Task verificationTask ;
48+ private string lastHealthStatus ;
4749
4850 // Events
4951 public event Action OnManualConfigUpdateRequested ;
@@ -408,15 +410,34 @@ private async void OnTestConnectionClicked()
408410 }
409411
410412 public async Task VerifyBridgeConnectionAsync ( )
413+ {
414+ // Prevent concurrent verification calls
415+ if ( verificationTask != null && ! verificationTask . IsCompleted )
416+ {
417+ return ;
418+ }
419+
420+ verificationTask = VerifyBridgeConnectionInternalAsync ( ) ;
421+ await verificationTask ;
422+ }
423+
424+ private async Task VerifyBridgeConnectionInternalAsync ( )
411425 {
412426 var bridgeService = MCPServiceLocator . Bridge ;
413427 if ( ! bridgeService . IsRunning )
414428 {
415429 healthStatusLabel . text = "Disconnected" ;
416430 healthIndicator . RemoveFromClassList ( "healthy" ) ;
417431 healthIndicator . RemoveFromClassList ( "warning" ) ;
432+ healthIndicator . RemoveFromClassList ( "unknown" ) ;
418433 healthIndicator . AddToClassList ( "unknown" ) ;
419- McpLog . Warn ( "Cannot verify connection: Bridge is not running" ) ;
434+
435+ // Only log if state changed
436+ if ( lastHealthStatus != "Disconnected" )
437+ {
438+ McpLog . Warn ( "Cannot verify connection: Bridge is not running" ) ;
439+ lastHealthStatus = "Disconnected" ;
440+ }
420441 return ;
421442 }
422443
@@ -426,23 +447,45 @@ public async Task VerifyBridgeConnectionAsync()
426447 healthIndicator . RemoveFromClassList ( "warning" ) ;
427448 healthIndicator . RemoveFromClassList ( "unknown" ) ;
428449
450+ string newStatus ;
429451 if ( result . Success && result . PingSucceeded )
430452 {
431- healthStatusLabel . text = "Healthy" ;
453+ newStatus = "Healthy" ;
454+ healthStatusLabel . text = newStatus ;
432455 healthIndicator . AddToClassList ( "healthy" ) ;
433- McpLog . Debug ( $ "Connection verification successful: { result . Message } ") ;
456+
457+ // Only log if state changed
458+ if ( lastHealthStatus != newStatus )
459+ {
460+ McpLog . Debug ( $ "Connection verification successful: { result . Message } ") ;
461+ lastHealthStatus = newStatus ;
462+ }
434463 }
435464 else if ( result . HandshakeValid )
436465 {
437- healthStatusLabel . text = "Ping Failed" ;
466+ newStatus = "Ping Failed" ;
467+ healthStatusLabel . text = newStatus ;
438468 healthIndicator . AddToClassList ( "warning" ) ;
439- McpLog . Warn ( $ "Connection verification warning: { result . Message } ") ;
469+
470+ // Always log warnings/errors
471+ if ( lastHealthStatus != newStatus )
472+ {
473+ McpLog . Warn ( $ "Connection verification warning: { result . Message } ") ;
474+ lastHealthStatus = newStatus ;
475+ }
440476 }
441477 else
442478 {
443- healthStatusLabel . text = "Unhealthy" ;
479+ newStatus = "Unhealthy" ;
480+ healthStatusLabel . text = newStatus ;
444481 healthIndicator . AddToClassList ( "warning" ) ;
445- McpLog . Error ( $ "Connection verification failed: { result . Message } ") ;
482+
483+ // Always log errors
484+ if ( lastHealthStatus != newStatus )
485+ {
486+ McpLog . Error ( $ "Connection verification failed: { result . Message } ") ;
487+ lastHealthStatus = newStatus ;
488+ }
446489 }
447490 }
448491 }
0 commit comments