Skip to content

Commit 5df6f8e

Browse files
committed
Start MCP server after binary download
Wait for DownloadServerBinaryIfNeeded() to complete before scheduling the MCP server auto-start. Adds a ContinueWith-based check and a new ActionStartServerIfNeeded helper that subscribes to EditorApplication.update only when binaries are available (skipping auto-start in CI or on download failure). Moves the auto-start logic into McpServerManager and removes the previous EnvironmentUtils.IsCi gating and delayed ConnectIfNeeded scheduling in Startup to centralize async startup and avoid blocking during domain reloads.
1 parent cc2e4b7 commit 5df6f8e

2 files changed

Lines changed: 23 additions & 13 deletions

File tree

Unity-MCP-Plugin/Assets/root/Editor/Scripts/McpServerManager.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,25 @@ static McpServerManager()
6969
// Register for editor quit to clean up the server process
7070
EditorApplication.quitting += OnEditorQuitting;
7171

72+
DownloadServerBinaryIfNeeded()
73+
.ContinueWith(task =>
74+
{
75+
if (!task.Result)
76+
return; // No binaries available (either in CI or failed to download), skip auto-start
77+
78+
EditorApplication.update += ActionStartServerIfNeeded;
79+
});
80+
7281
// Check if server process is still running (e.g., after domain reload)
7382
CheckExistingProcess();
7483
}
7584

85+
static void ActionStartServerIfNeeded()
86+
{
87+
EditorApplication.update -= ActionStartServerIfNeeded;
88+
StartServerIfNeeded();
89+
}
90+
7691
#region Binary Metadata
7792

7893
public const string ExecutableName = "unity-mcp-server";

Unity-MCP-Plugin/Assets/root/Editor/Scripts/Startup.cs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,14 @@ static Startup()
2828
UnityMcpPlugin.Instance.BuildMcpPluginIfNeeded();
2929
UnityMcpPlugin.Instance.AddUnityLogCollectorIfNeeded(() => new BufferedFileLogStorage());
3030

31-
// Defer connection to avoid blocking during domain reload.
32-
// Starting async SignalR connections during [InitializeOnLoad] can cause
33-
// Unity to freeze because async continuations may run on the main thread
34-
// while it's still processing the domain reload.
35-
if (!EnvironmentUtils.IsCi())
36-
EditorApplication.delayCall += () => UnityMcpPlugin.ConnectIfNeeded();
37-
38-
McpServerManager.DownloadServerBinaryIfNeeded();
39-
40-
// Defer MCP server auto-start to avoid blocking during domain reload
41-
// and to ensure configuration is fully loaded
42-
if (!EnvironmentUtils.IsCi())
43-
EditorApplication.update += ActionStartServerIfNeeded;
31+
McpServerManager.DownloadServerBinaryIfNeeded()
32+
.ContinueWith(task =>
33+
{
34+
if (!task.Result)
35+
return; // No binaries available (either in CI or already exist), skip auto-start
36+
37+
EditorApplication.update += ActionStartServerIfNeeded;
38+
});
4439

4540
if (Application.dataPath.Contains(" "))
4641
Debug.LogError("The project path contains spaces, which may cause issues during usage of AI Game Developer. Please consider the move the project to a folder without spaces.");

0 commit comments

Comments
 (0)