From 7307ef2e5fa509dc281c31b14546f5539aa0effd Mon Sep 17 00:00:00 2001 From: dsarno Date: Sun, 21 Dec 2025 23:26:00 -0800 Subject: [PATCH] Add compilation status details to manage_editor response --- MCPForUnity/Editor/Tools/ManageEditor.cs | 26 +++++++++++++++++++++- Server/src/services/tools/manage_editor.py | 2 +- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/MCPForUnity/Editor/Tools/ManageEditor.cs b/MCPForUnity/Editor/Tools/ManageEditor.cs index 0c9411eb8..21f536b7f 100644 --- a/MCPForUnity/Editor/Tools/ManageEditor.cs +++ b/MCPForUnity/Editor/Tools/ManageEditor.cs @@ -2,6 +2,7 @@ using MCPForUnity.Editor.Helpers; using Newtonsoft.Json.Linq; using UnityEditor; +using UnityEditor.Compilation; using UnityEditorInternal; // Required for tag management namespace MCPForUnity.Editor.Tools @@ -83,6 +84,29 @@ public static object HandleCommand(JObject @params) { return new ErrorResponse($"Error stopping play mode: {e.Message}"); } + case "request_script_compilation": + try + { + bool wasCompiling = CompilationPipeline.isCompiling; + CompilationPipeline.RequestScriptCompilation(); + bool nowCompiling = CompilationPipeline.isCompiling; + string detail = nowCompiling + ? "Unity reports compilation in progress." + : "Unity is not currently compiling; if no pending script changes exist, the request may be a no-op."; + return new SuccessResponse( + "Script compilation request sent.", + new + { + wasCompiling, + nowCompiling, + note = detail + } + ); + } + catch (Exception e) + { + return new ErrorResponse($"Error requesting script compilation: {e.Message}"); + } // Tool Control case "set_active_tool": @@ -121,7 +145,7 @@ public static object HandleCommand(JObject @params) default: return new ErrorResponse( - $"Unknown action: '{action}'. Supported actions: play, pause, stop, set_active_tool, add_tag, remove_tag, add_layer, remove_layer. Use MCP resources for reading editor state, project info, tags, layers, selection, windows, prefab stage, and active tool." + $"Unknown action: '{action}'. Supported actions: play, pause, stop, request_script_compilation, set_active_tool, add_tag, remove_tag, add_layer, remove_layer. Use MCP resources for reading editor state, project info, tags, layers, selection, windows, prefab stage, and active tool." ); } } diff --git a/Server/src/services/tools/manage_editor.py b/Server/src/services/tools/manage_editor.py index e6e95292c..698cc3ab5 100644 --- a/Server/src/services/tools/manage_editor.py +++ b/Server/src/services/tools/manage_editor.py @@ -14,7 +14,7 @@ ) async def manage_editor( ctx: Context, - action: Annotated[Literal["telemetry_status", "telemetry_ping", "play", "pause", "stop", "set_active_tool", "add_tag", "remove_tag", "add_layer", "remove_layer"], "Get and update the Unity Editor state."], + action: Annotated[Literal["telemetry_status", "telemetry_ping", "play", "pause", "stop", "request_script_compilation", "set_active_tool", "add_tag", "remove_tag", "add_layer", "remove_layer"], "Get and update the Unity Editor state."], wait_for_completion: Annotated[bool | str, "Optional. If True, waits for certain actions (accepts true/false or 'true'/'false')"] | None = None, tool_name: Annotated[str,