execute_menu_item
Performs actions in Unity Editor by triggering menu items via specified paths, enabling automation and integration with AI model clients.
Instructions
Executes a Unity menu item by path
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| menuPath | Yes | The path to the menu item to execute (e.g. "GameObject/Create Empty") |
Implementation Reference
- Server~/src/tools/menuItemTool.ts:53-73 (handler)The core handler function that executes the tool logic: destructures menuPath, sends request to mcpUnity with method 'execute_menu_item', handles response success/error, returns CallToolResult.async function toolHandler(mcpUnity: McpUnity, params: any): Promise<CallToolResult> { const { menuPath } = params; const response = await mcpUnity.sendRequest({ method: toolName, params: { menuPath } }); if (!response.success) { throw new McpUnityError( ErrorType.TOOL_EXECUTION, response.message || `Failed to execute menu item: ${menuPath}` ); } return { content: [{ type: response.type, text: response.message || `Successfully executed menu item: ${menuPath}` }] }; }
- Server~/src/tools/menuItemTool.ts:27-42 (registration)Registers the 'execute_menu_item' tool with the MCP server using server.tool(), providing name, description, schema, and a wrapper handler that calls the core toolHandler.server.tool( toolName, toolDescription, paramsSchema.shape, async (params: any) => { try { logger.info(`Executing tool: ${toolName}`, params); const result = await toolHandler(mcpUnity, params); logger.info(`Tool execution successful: ${toolName}`); return result; } catch (error) { logger.error(`Tool execution failed: ${toolName}`, error); throw error; } } );
- Zod schema defining the single input parameter 'menuPath' as a string with description.const paramsSchema = z.object({ menuPath: z.string().describe('The path to the menu item to execute (e.g. "GameObject/Create Empty")') });
- Server~/src/index.ts:54-54 (registration)Calls the registerMenuItemTool function to register the tool during server initialization.registerMenuItemTool(server, mcpUnity, toolLogger);