File tree Expand file tree Collapse file tree 2 files changed +6
-29
lines changed
UnityMcpServer~/src/tools Expand file tree Collapse file tree 2 files changed +6
-29
lines changed Original file line number Diff line number Diff 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 )
Original file line number Diff line number Diff line change 1313def 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 ,
You can’t perform that action at this time.
0 commit comments