Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion MCPForUnity/Editor/Tools/ManageEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Comment on lines +90 to +92
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Checking CompilationPipeline.isCompiling immediately after RequestScriptCompilation() may not accurately reflect the compilation state due to async nature. Consider delaying the check or using EditorApplication.update callback.

Prompt To Fix With AI
This is a comment left during a code review.
Path: MCPForUnity/Editor/Tools/ManageEditor.cs
Line: 90:92

Comment:
**style:** Checking `CompilationPipeline.isCompiling` immediately after `RequestScriptCompilation()` may not accurately reflect the compilation state due to async nature. Consider delaying the check or using EditorApplication.update callback.

How can I resolve this? If you propose a fix, please make it concise.

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}");
}
Comment on lines +87 to +109
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

RequestScriptCompilation timing may not reflect actual compilation state.

The nowCompiling check on line 92 occurs immediately after calling RequestScriptCompilation(). Since this operation runs asynchronously, the state may not immediately reflect whether compilation will begin. The current note acknowledges the no-op case but doesn't document this async behavior.

For more reliable state tracking, consider using the CompilationPipeline.compilationStarted event instead of polling isCompiling immediately after the request.

🤖 Prompt for AI Agents
In MCPForUnity/Editor/Tools/ManageEditor.cs around lines 87 to 109, the code
reads CompilationPipeline.isCompiling immediately after
RequestScriptCompilation(), which can be misleading because compilation starts
asynchronously; replace the immediate check with a reliable approach by
subscribing to CompilationPipeline.compilationStarted (and optionally
compilationFinished) to detect when compilation actually begins, update the
success response to either return immediately with a clear note that compilation
is asynchronous or defer returning until compilationStarted fires (or provide a
follow-up callback/notification), and remove the immediate nowCompiling polling
logic so the response accurately reflects true compilation state.


// Tool Control
case "set_active_tool":
Expand Down Expand Up @@ -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."
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Server/src/services/tools/manage_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down