Skip to content

Commit 4d70f93

Browse files
authored
Merge pull request #1 from msanatan/menu-item-fix
Remove delayed execution of executing menu item, fixing #279
2 parents 63b1a42 + 745aa32 commit 4d70f93

File tree

2 files changed

+6
-29
lines changed

2 files changed

+6
-29
lines changed

UnityMcpBridge/Editor/Tools/MenuItems/MenuItemExecutor.cs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,12 @@ public static object Execute(JObject @params)
3636

3737
try
3838
{
39-
// Execute on main thread using delayCall
40-
EditorApplication.delayCall += () =>
39+
bool executed = EditorApplication.ExecuteMenuItem(menuPath);
40+
if (!executed)
4141
{
42-
try
43-
{
44-
bool executed = EditorApplication.ExecuteMenuItem(menuPath);
45-
if (!executed)
46-
{
47-
McpLog.Error($"[MenuItemExecutor] Failed to execute menu item via delayCall: '{menuPath}'. It might be invalid, disabled, or context-dependent.");
48-
}
49-
}
50-
catch (Exception delayEx)
51-
{
52-
McpLog.Error($"[MenuItemExecutor] Exception during delayed execution of '{menuPath}': {delayEx}");
53-
}
54-
};
55-
42+
McpLog.Error($"[MenuItemExecutor] Failed to execute menu item via delayCall: '{menuPath}'. It might be invalid, disabled, or context-dependent.");
43+
return Response.Error($"Failed to execute menu item '{menuPath}'. It might be invalid, disabled, or context-dependent.");
44+
}
5645
return Response.Success($"Attempted to execute menu item: '{menuPath}'. Check Unity logs for confirmation or errors.");
5746
}
5847
catch (Exception e)

UnityMcpBridge/UnityMcpServer~/src/tools/manage_menu_item.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
def register_manage_menu_item_tools(mcp: FastMCP):
1414
"""Registers the manage_menu_item tool with the MCP server."""
1515

16-
@mcp.tool()
16+
@mcp.tool(description="Manage Unity menu items (execute/list/exists)")
1717
@telemetry_tool("manage_menu_item")
1818
async def manage_menu_item(
1919
ctx: Context,
@@ -25,18 +25,6 @@ async def manage_menu_item(
2525
refresh: Annotated[bool | None,
2626
"Optional flag to force refresh of the menu cache when listing"] = None,
2727
) -> dict[str, Any]:
28-
"""Manage Unity menu items (execute/list/exists).
29-
30-
Args:
31-
ctx: The MCP context.
32-
action: One of 'execute', 'list', 'exists'.
33-
menu_path: Menu path for 'execute' or 'exists' (e.g., "File/Save Project").
34-
search: Optional filter string for 'list'.
35-
refresh: Optional flag to force refresh of the menu cache when listing.
36-
37-
Returns:
38-
A dictionary with operation results ('success', 'data', 'error').
39-
"""
4028
# Prepare parameters for the C# handler
4129
params_dict: dict[str, Any] = {
4230
"action": action,

0 commit comments

Comments
 (0)