@@ -70,7 +70,22 @@ static McpServerManager()
7070 EditorApplication . quitting += OnEditorQuitting ;
7171
7272 // Check if server process is still running (e.g., after domain reload)
73- CheckExistingProcess ( ) ;
73+ EditorApplication . update += CheckExistingProcess ;
74+
75+ DownloadServerBinaryIfNeeded ( )
76+ . ContinueWith ( task =>
77+ {
78+ if ( task . IsFaulted || ! task . Result )
79+ return ; // Failed to download binaries, skip auto-start
80+
81+ if ( ! task . Result )
82+ return ; // No binaries available (either in CI or failed to download), skip auto-start
83+
84+ if ( EnvironmentUtils . IsCi ( ) )
85+ return ; // Skip auto-start in CI environment
86+
87+ EditorApplication . update += StartServerIfNeeded ;
88+ } ) ;
7489 }
7590
7691 #region Binary Metadata
@@ -467,6 +482,7 @@ public static string DockerRunCommand()
467482
468483 static void CheckExistingProcess ( )
469484 {
485+ EditorApplication . update -= CheckExistingProcess ;
470486 // Try to find an existing server process by checking if our tracked PID is still running
471487 // This helps maintain state across domain reloads
472488 var savedPid = EditorPrefs . GetInt ( ProcessIdKey , - 1 ) ;
@@ -1055,21 +1071,15 @@ static void CleanupProcess()
10551071 }
10561072 }
10571073
1058- public static void ToggleServer ( )
1059- {
1060- if ( IsRunning )
1061- StopServer ( ) ;
1062- else
1063- StartServer ( ) ;
1064- }
1065-
10661074 /// <summary>
10671075 /// Starts the MCP server if KeepServerRunning is enabled and no external server is detected.
10681076 /// This method is called during Unity Editor startup to auto-start the server based on user preference.
10691077 /// The external server check is performed asynchronously to avoid blocking the main thread.
10701078 /// </summary>
10711079 public static void StartServerIfNeeded ( )
10721080 {
1081+ EditorApplication . update -= StartServerIfNeeded ;
1082+
10731083 // Check if user wants the server to keep running
10741084 if ( ! UnityMcpPlugin . KeepServerRunning )
10751085 {
@@ -1126,10 +1136,9 @@ static void CheckExternalServerAsync(int port, Action<bool> onResult)
11261136 {
11271137 _logger . LogDebug ( "CheckExternalServerAsync: No server detected on port {port} ({message})" , port , ex . Message ) ;
11281138 }
1129-
1130- // Marshal callback back to the main thread
1131- EditorApplication . delayCall += ( ) => onResult ( result ) ;
1132- } ) ;
1139+ return result ;
1140+ } )
1141+ . ContinueWith ( task => onResult ( task . Result ) , TaskScheduler . FromCurrentSynchronizationContext ( ) ) ;
11331142 }
11341143
11351144 #endregion // Process Lifecycle
0 commit comments