MCP Server Tauri

repository·main·Indexed 42 days ago

https://github.com/hypothesi/mcp-server-tauri

A Model Context Protocol (MCP) server that enables AI assistants like Claude, Cursor, and Windsurf to build, test, and debug Tauri v2 applications. It provides tools for UI automation, IPC monitoring, log streaming, and webview interaction via the tauri-plugin-mcp-bridge Rust plugin.

Tokens
45.7K
Snippets
153
Records
206
Agent score
55%

What's inside MCP Server Tauri

  1. Overview of the @hypothesi/tauri-mcp-cli skill

    main

    The @hypothesi/tauri-mcp-cli package is a bundled skill designed for AI coding agents to automate or test Tauri v2 desktop and mobile applications. It provides a comprehensive surface covering session management, UI interaction, inspection, IPC debugging, and mobile workflows.

    Covered Domains:

    • Session and daemon management
    • UI interaction
    • Inspection and capture
    • IPC and backend debugging
    • Mobile and remote device workflows
  2. Understand Prompts (Slash Commands) in Tauri MCP

    main

    Prompts are pre-built templates that appear as slash commands in MCP-compatible AI assistants (like Claude Desktop or Cursor). Unlike tools, which the AI calls automatically, prompts are user-controlled workflows.

    Key Differences

    • Tools: Single actions called automatically by the AI (e.g., webview_screenshot).
    • Prompts: Guided, multi-step workflows initiated by the user (e.g., /fix-webview-errors).

    Use prompts when you need a guided debugging session, a testing flow, or a complex task that requires multiple tools working together in a specific sequence.

    Note: Some MCP clients (like Windsurf) may not support slash commands yet. If they don't work, you can manually instruct the AI to follow the prompt's logic.

  3. Understand Test App integration with MCP Server

    main

    The Test App is specifically configured to support the MCP server's native automation through several key mechanisms:

    • WebSocket Port: Automatically allocated within the 9223-9322 range for UI automation.
    • MCP Bridge Plugin: Integrated as a workspace dependency from packages/tauri-plugin-mcp-bridge/. It provides IPC monitoring and direct command execution.
    • Window Management: The app exposes window information to allow the MCP server to verify the application state.
  4. Choosing between webview_select_element and webview_get_pointed_element

    main

    When performing UI automation or element inspection, choose the tool based on who initiates the selection workflow:

    • webview_select_element: Use this when the agent initiates the picker. This is best when the AI wants to actively ask the user to select something specific.
    • webview_get_pointed_element: Use this when the user initiates the selection. This is best when the user has already used the Alt+Shift+Click shortcut and tells the agent to look at what they pointed at.
  5. Understand driver-session vs daemon management

    main

    The CLI distinguishes between the background process and the active driver connection:

    • daemon stop: Kills the background process entirely.
    • driver-session stop: Only ends the current connection to the application; the daemon may still be running.

    Best Practice: Because driver-session start might report success even if the app is not live, always verify the connection immediately after starting with:

    driver-session status --json

    Verify that the output contains "connected": true.

  6. How multi-app support works

    main

    The MCP server can connect to multiple Tauri applications simultaneously. Each application must run on a unique port.

    Key behaviors:

    • The most recently connected app becomes the default app.
    • You can target a specific app using its port number or bundleId via the appIdentifier parameter.
    • You can stop individual sessions or all active sessions at once.
    // Connect to first app
    await driver_session({ action: "start", port: 9223 })
    
    // Connect to second app
    await driver_session({ action: "start", port: 9224 })
    
    // Check status - shows both apps with default indicator
    await driver_session({ action: "status" })
    
    // Use default app (the most recent one, e.g., port 9224)
    await webview_screenshot()
    
    // Target a specific app by its port
    await webview_screenshot({ appIdentifier: 9223 })
    
    // Stop a specific app session
    await driver_session({ action: "stop", appIdentifier: 9223 })
    
    // Stop all active app sessions
    await driver_session({ action: "stop" })
  7. How the MCP Bridge architecture works

    main

    The MCP Bridge acts as a communication layer between a Node.js-based MCP Server and a Tauri application.

    1. The MCP Server communicates with the Tauri App via a WebSocket server running on port 9223 (or the next available port in the 9223-9322 range).
    2. The mcp-bridge Plugin (Rust backend) receives these WebSocket commands and executes them against the Tauri application's internals (IPC, Window management, etc.).
    3. This enables the MCP server to perform UI automation, inspect backend state, and monitor IPC traffic as if it were a native part of the application environment.
  8. How the MCP Server Tauri architecture works

    main

    The system uses a three-tier architecture to bridge AI assistants with Tauri applications:

    1. MCP Server (Node.js/TypeScript): Implements the Model Context Protocol. It acts as the entry point for AI assistants (via stdio) and communicates with the Tauri application via WebSockets.
    2. Tauri Plugin (Rust): Runs inside the Tauri app. It hosts a WebSocket server, monitors IPC events, and manages a script registry for persistent JavaScript injection.
    3. Tauri Application (Webview): The target application where JavaScript is executed in the webview to interact with the UI.

    Communication Flow: AI Assistant $\rightarrow$ MCP Protocol (stdio) $\rightarrow$ MCP Server $\rightarrow$ WebSocket (port 9223) $\rightarrow$ Tauri Plugin $\rightarrow$ Webview (JavaScript)

  9. What are Prompts (Slash Commands)?

    main

    In the context of the Tauri MCP server, Prompts are pre-built templates that guide your AI assistant through multi-step, structured workflows. While Tools are individual actions (e.g., taking a single screenshot), Prompts combine multiple tools into a cohesive experience.

    AspectToolsPrompts
    ControlAI-controlledUser-controlled
    ScopeSingle actionMulti-step workflow
    InvocationAI decides when to useYou type a slash command
    Exampletauri_webview_screenshot/fix-webview-errors

    In MCP clients like Claude Desktop, Cursor, and VS Code, these appear as slash commands (e.g., /command-name).

  10. How the MCP Server architecture works

    main

    The MCP Server for Tauri acts as a bridge between your AI assistant and your running Tauri application.

    Communication Flow:

    • The AI assistant communicates with the MCP Server via the Model Context Protocol.
    • The MCP Server communicates with your Tauri application via a Plugin Client using a WebSocket port (9223).
    • This connection enables native IPC for UI automation, DOM interaction, and direct command execution through the mcp-bridge plugin installed in your app.
  11. Use the /fix-webview-errors prompt for debugging

    main

    The /fix-webview-errors prompt initiates a complete debugging workflow to find and fix JavaScript errors in your Tauri app's webview.

    Workflow Steps

    1. Connects to your running app via driver_session.
    2. Retrieves console logs and errors using read_logs.
    3. Analyzes stack traces and identifies root causes.
    4. Locates the problematic source code.
    5. Proposes concrete fixes.
    6. Cleans up the session.

    Prerequisites

    • Your Tauri app must be running.
    • The MCP bridge plugin must be installed.
    • withGlobalTauri must be enabled in tauri.conf.json.

    Example usage:

    /fix-webview-errors
  12. Configure your AI Assistant to use MCP Server Tauri

    main

    To enable AI-powered development for your Tauri app, you must first register the MCP server with your AI assistant (e.g., Claude Code, Cursor, Windsurf, VS Code).

    Run the following command to automatically add the server:

    npx -y @a1st/aix add mcp tauri --command 'npx @hypothesi/tauri-mcp-server' --user

    Using the companion CLI

    For a direct terminal workflow, install and use the CLI:

    npm install -g @hypothesi/tauri-mcp-cli
    tauri-mcp driver-session start --port 9223

    Manual Configuration

    Add the following to your MCP configuration file:

    {
      "mcpServers": {
        "tauri": {
          "command": "npx",
          "args": ["-y", "@hypothesi/tauri-mcp-server"]
        }
      }
    }

    Config file locations:

    • Claude Code: Cmd/Ctrl+Shift+P → "MCP: Edit Config"
    • Cursor: Cursor Settings → MCP → New MCP Server
    • VS Code: Add to settings.json under mcp.servers
    • Windsurf: Cascade pane → MCPs icon → settings icon
    • Cline: See Cline MCP configuration guide

    Note: Restart your AI assistant after making these changes.