Skip to main content
Glama

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
NameRequiredDescriptionDefault
menuPathYesThe path to the menu item to execute (e.g. "GameObject/Create Empty")

Implementation Reference

  • 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}` 
        }]
      };
    }
  • 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")')
    });
  • Calls the registerMenuItemTool function to register the tool during server initialization.
    registerMenuItemTool(server, mcpUnity, toolLogger);
Install Server

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/CoderGamester/mcp-unity'

If you have feedback or need assistance with the MCP directory API, please join our Discord server