Tools: Menu Interaction
Relevant source files
The following files were used as context for generating this wiki page:- Packages/src/Editor/Api/McpTools/ExecuteMenuItem/ExecuteMenuItemTool.cs
- Packages/src/Editor/Api/McpTools/GetMenuItems/GetMenuItemsTool.cs
- Packages/src/Editor/Api/McpTools/ExecuteMenuItem/SKILL.md
- Packages/src/Editor/Api/McpTools/GetMenuItems/MenuItemInfo.cs
- Packages/src/Editor/Api/McpTools/UseCases/Tools/ExecuteMenuItemUseCase.cs
- Packages/src/Editor/UI/McpEditorWindow.cs
- Packages/src/TOOL_REFERENCE.md
- README.md
The Menu Interaction tools are a core component of uLoopMCP's "Unity Editor Automation & Discovery Tools". They provide an interface for AI agents to discover and execute Unity Editor menu items programmatically. This allows the AI to perform actions that are typically handled manually by a developer, such as running project-specific tools, creating objects, or triggering builds.
This functionality is exposed through two primary tools: get-menu-items for discovery and execute-menu-item for execution. Together, they form a powerful mechanism for automating complex workflows within the Unity Editor, aligning with the project's goal of enabling an AI to drive development with minimal human intervention.
Sources: README.md, TOOL_REFERENCE.md
get-menu-items Tool
This tool retrieves a list of menu items defined in the Unity project using the [MenuItem("...")] attribute. It allows an AI agent to discover what actions are available through the editor's menu system.
Sources: Packages/src/Editor/Api/McpTools/GetMenuItems/GetMenuItemsTool.cs, TOOL_REFERENCE.md
Parameters
The get-menu-items tool can be customized with the following parameters:
| Parameter | Type | Description | Default |
|---|---|---|---|
FilterText | string | Text to filter MenuItem paths. An empty string returns all items. | "" |
FilterType | enum | The type of filter to apply: contains, exact, startswith. | contains |
IncludeValidation | bool | If true, includes validation functions in the results. | false |
MaxCount | number | The maximum number of menu items to retrieve. | 200 |
Sources: TOOL_REFERENCE.md
Response Data: MenuItemInfo
The tool returns a list of MenuItemInfo objects, each representing a discovered menu item.
This diagram shows the structure of the MenuItemInfo class.
The properties of the MenuItemInfo object provide detailed metadata about each menu item:
| Property | Type | Description |
|---|---|---|
Path | string | The menu item path (e.g., "GameObject/Create Empty"). |
Priority | int | The priority used for ordering the menu item. |
IsValidateFunction | bool | true if the method is a validation function for a menu item. |
MethodName | string | The name of the C# method that implements the menu item. |
TypeName | string | The full name of the class containing the method. |
AssemblyName | string | The name of the assembly where the method is defined. |
CanExecuteViaEditorApplication | bool | Indicates if the item can be run with EditorApplication.ExecuteMenuItem. |
WarningMessage | string | Contains a warning if issues like duplicate attributes are detected. |
Sources: Packages/src/Editor/Api/McpTools/GetMenuItems/MenuItemInfo.cs:8-40
execute-menu-item Tool
This tool executes a Unity menu item specified by its path. It is a critical tool for enabling AI-driven actions within the editor.
Sources: Packages/src/Editor/Api/McpTools/ExecuteMenuItem/ExecuteMenuItemTool.cs, TOOL_REFERENCE.md
Parameters
| Parameter | Type | Description | Default |
|---|---|---|---|
MenuItemPath | string | The path of the menu item to execute (e.g., "GameObject/Create Empty"). | "" |
UseReflectionFallback | boolean | If true, attempts to use reflection if EditorApplication.ExecuteMenuItem fails. | true |
Sources: TOOL_REFERENCE.md
Execution Flow
The execution logic is managed by the ExecuteMenuItemUseCase class, which provides a robust, two-stage execution process to ensure reliability.
- Primary Method: It first attempts to execute the menu item using the standard
EditorApplication.ExecuteMenuItemmethod. - Fallback Method: If the primary method fails and
UseReflectionFallbackis enabled, it searches for the menu item's underlying method using theMenuItemDiscoveryServiceand invokes it directly via reflection.
This flow is illustrated below:
The following sequence diagram shows the interaction between the tool, its use case, and other services during execution.
Response
The tool returns a JSON object indicating the outcome of the execution.
| Property | Type | Description |
|---|---|---|
MenuItemPath | string | The path of the menu item that was targeted for execution. |
Success | boolean | true if the execution was successful. |
ExecutionMethod | string | The method used for execution (EditorApplication or Reflection). |
ErrorMessage | string | An error message if the execution failed. |
Details | string | Additional information about the execution result. |
MenuItemFound | boolean | true if the menu item was found in the system. |
WarningMessage | string | A warning if the menu item has issues (e.g., duplicate definitions). |
Sources: TOOL_REFERENCE.md, Packages/src/Editor/Api/McpTools/UseCases/Tools/ExecuteMenuItemUseCase.cs
Security
Executing arbitrary menu items, especially via reflection, carries security risks. uLoopMCP implements several safeguards.
Tool-Level Security Setting
The execute-menu-item tool is disabled by default. It must be explicitly enabled by checking "Allow Menu Item Execution" in the Window > uLoopMCP > Security Settings panel.
Sources: Packages/src/Editor/UI/McpEditorWindow.cs:81, 301, README.md
Reflection Fallback Security
The reflection-based fallback mechanism in ExecuteMenuItemUseCase includes a validation step (IsValidMenuItemTypeName) to prevent the execution of potentially dangerous code. This check ensures that the method being invoked belongs to an allowed namespace.
The validation logic is as follows:
- Check against a denylist of system types (
McpConstants.DENIED_SYSTEM_TYPES). - If not denied, check if the type's namespace is on an allowlist (
McpConstants.ALLOWED_NAMESPACES). - Execution is permitted only if the type is in an allowed namespace and not on the denylist.
Skills Integration
For integration with LLM tools like Claude Code, the execute-menu-item tool is exposed as a "Skill". A SKILL.md file defines its name and description for the LLM.
---
name: uloop-execute-menu-item
description: Execute a Unity menu item by its path. Use 'uloop-get-menu-items' to discover available menu items first.
---
This allows an AI agent to understand when and how to use the tool by invoking /uloop-execute-menu-item.
Sources: Packages/src/Editor/Api/McpTools/ExecuteMenuItem/SKILL.md, README.md