execute_tauri_command
Execute Tauri IPC commands to automate desktop application testing and functionality without manual interaction or complex scripting.
Instructions
Execute a Tauri IPC command. The command must be exposed in the Tauri app's src-tauri/src/main.rs file.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| command | Yes | Name of the Tauri command to execute | |
| args | No | Arguments to pass to the command |
Input Schema (JSON Schema)
{
"properties": {
"args": {
"additionalProperties": true,
"description": "Arguments to pass to the command",
"type": "object"
},
"command": {
"description": "Name of the Tauri command to execute",
"type": "string"
}
},
"required": [
"command"
],
"type": "object"
}
Implementation Reference
- src/tools/state.ts:11-30 (handler)MCP tool handler function that calls the TauriDriver's executeTauriCommand and formats the ToolResponse.export async function executeTauriCommand( driver: TauriDriver, params: ExecuteTauriCommandParams ): Promise<ToolResponse<{ result: unknown }>> { try { const result = await driver.executeTauriCommand(params.command, params.args); return { success: true, data: { result, }, }; } catch (error) { return { success: false, error: error instanceof Error ? error.message : String(error), }; } }
- src/tauri-driver.ts:181-199 (helper)Core implementation in TauriDriver class that executes Tauri IPC commands via injected JavaScript invoking window.__TAURI__.invoke.async executeTauriCommand(command: string, args: Record<string, unknown> = {}): Promise<unknown> { this.ensureAppRunning(); try { // Execute JavaScript in the Tauri window to call the command const result = await this.appState.browser!.execute( (cmd: string, cmdArgs: Record<string, unknown>) => { // @ts-ignore - Tauri's invoke function is injected globally return window.__TAURI__?.invoke(cmd, cmdArgs); }, command, args ); return result; } catch (error) { throw new Error(`Failed to execute Tauri command '${command}': ${error instanceof Error ? error.message : String(error)}`); } }
- src/index.ts:172-190 (registration)Tool registration in the ListToolsRequestSchema handler, defining the tool's name, description, and input schema for MCP.{ name: 'execute_tauri_command', description: 'Execute a Tauri IPC command. The command must be exposed in the Tauri app\'s src-tauri/src/main.rs file.', inputSchema: { type: 'object', properties: { command: { type: 'string', description: 'Name of the Tauri command to execute', }, args: { type: 'object', description: 'Arguments to pass to the command', additionalProperties: true, }, }, required: ['command'], }, },
- src/index.ts:310-320 (handler)Dispatch handler in the central CallToolRequestSchema switch statement that invokes the tool handler and formats the MCP response.case 'execute_tauri_command': { const result = await executeTauriCommand(driver, args as any); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; }
- src/types.ts:94-99 (schema)TypeScript type definition for the tool's input parameters.export interface ExecuteTauriCommandParams { /** Command name to execute */ command: string; /** Arguments to pass to the command */ args?: Record<string, unknown>; }