tauri-connector
A Tauri v2 plugin with embedded MCP server + Rust CLI for deep inspection and interaction with Tauri desktop applications. Drop-in replacement for tauri-plugin-mcp-bridge that fixes the __TAURI__ not available bug on macOS.
The Problem
tauri-plugin-mcp-bridge injects JavaScript into the webview that relies on window.__TAURI__ to send execution results back to Rust. On macOS with WKWebView, the injected scripts run in an isolated content world where window.__TAURI__ doesn't exist -- causing all JS-based tools (execute_js, dom_snapshot, console logs) to time out.
The Fix
tauri-connector uses a dual-path JS execution strategy:
-
WS Bridge (primary) -- A small JS client injected into the webview connects back to the plugin via
ws://127.0.0.1:{port}. Scripts and results flow through this dedicated WebSocket channel. -
Eval+Event fallback -- If the WS bridge times out (2s), the plugin falls back to injecting JS via Tauri's
window.eval()and receiving results through Tauri's event system. This path requireswithGlobalTauri: true.
The fallback is transparent -- callers get the same result regardless of which path succeeds. The MCP server runs inside the plugin -- when your Tauri app starts, it starts automatically.
Frontend JS (app context)
|-- invoke('plugin:connector|push_dom') --> Rust state (cached DOM)
|-- invoke('plugin:connector|push_logs') -> Rust state (cached logs)
'-- WebSocket ws://127.0.0.1:9300 --------> Bridge (JS execution, path 1)
Plugin (Rust)
|-- bridge.execute_js()
| |-- try WS bridge (2s timeout) --------> webview JS via WebSocket
| '-- fallback: window.eval() + event ---> webview JS via Tauri IPC
|-- xcap native capture (cross-platform) --> PNG/JPEG/WebP with resize
'-- snapdom fallback ---------------------> DOM-to-image via @zumer/snapdom
Claude Code -------- SSE http://host:9556/sse -----> Embedded MCP server
|-- handlers (direct, in-process)
|-- bridge.execute_js() -> JS result
'-- state.get_dom() -> cached DOM
CLI (Rust) -------- WebSocket ws://host:9555 -----> Plugin WS server
Components
| Component | Description |
|---|---|
plugin/ |
Rust Tauri v2 plugin with embedded MCP server (tauri-plugin-connector on crates.io) |
crates/cli/ |
Rust CLI binary with ref-based element addressing |
crates/mcp-server/ |
Standalone Rust MCP server (alternative to embedded, connects via WebSocket) |
crates/client/ |
Shared Rust WebSocket client library |
Features
25 Tools (MCP + CLI)
Every tool is available via both the embedded MCP server (for Claude Code) and the Rust CLI (for terminal use). The CLI uses ref-based element addressing inspired by vercel-labs/agent-browser.
| Category | MCP Tool | CLI Command |
|---|---|---|
| JavaScript | webview_execute_js |
eval <script> |
| DOM | webview_dom_snapshot |
snapshot [-i] [-c] [--mode ai|accessibility|structure] |
| DOM (cached) | get_cached_dom |
dom |
| Elements | webview_find_element |
find <selector> [-s css|xpath|text] |
| Styles | webview_get_styles |
get styles <@ref|selector> |
| Picker | webview_get_pointed_element |
pointed |
| Select | webview_select_element |
(visual picker, not yet implemented) |
| Interact | webview_interact |
click, dblclick, hover, focus, fill, type, check, uncheck, select, scroll, scrollintoview |
| Keyboard | webview_keyboard |
press <key> |
| Wait | webview_wait_for |
wait <selector> [--text] [--timeout] |
| Screenshot | webview_screenshot |
screenshot <path> [-f png|jpeg|webp] [-m maxWidth] |
| Windows | manage_window |
windows, resize <w> <h> |
| State | ipc_get_backend_state |
state |
| IPC | ipc_execute_command |
ipc exec <cmd> [-a '{...}'] |
| Monitor | ipc_monitor |
ipc monitor / ipc unmonitor |
| Captured | ipc_get_captured |
ipc captured [-f filter] |
| Events | ipc_emit_event |
emit <event> [-p '{...}'] |
| Logs | read_logs |
logs [-n 20] [-f filter] |
| Logs | clear_logs |
clear logs|ipc|events|all |
| Logs | read_log_file |
(via MCP only) |
| Events | ipc_listen |
events listen|captured|stop |
| Events | event_get_captured |
events captured [-p regex] |
| DOM | webview_search_snapshot |
(via MCP only) |
| Setup | get_setup_instructions |
examples |
| Devices | list_devices |
(info only) |
CLI Ref-Based Addressing
Take a DOM snapshot with stable ref IDs, then interact with elements using those refs:
# Take snapshot -- assigns ref IDs, enriches with React component names, stitches portals
# Interact using refs (persist across CLI invocations)
Unified Snapshot Engine (v0.5)
The DOM snapshot engine uses a single window.__CONNECTOR_SNAPSHOT__() function with three modes:
| Mode | Output | Use case |
|---|---|---|
ai (default) |
Role, name, ARIA states, ref=eN IDs, component=Name, portal stitching |
Claude interaction |
accessibility |
Role, accessible name, ARIA states | Semantic understanding |
structure |
Tag, id, classes, data-testid | Layout debugging |
Key capabilities:
- TreeWalker API for ~78x faster traversal (no stack overflow on deep React trees)
- Portal stitching -- Ant Design modals/drawers/dropdowns are logically re-parented under their trigger via
aria-controls/aria-owns - React fiber enrichment -- Component names (
component=AppointmentModal) via__reactFiber$on DOM nodes - Visibility pruning --
aria-hidden,display:none,visibility:hidden,role=presentation/noneautomatically excluded - Virtual scroll detection --
rc-virtual-list-holdercontainers annotated with visible item count - Token budgeting --
maxDepthandmaxElementsfor graceful truncation on large DOMs
The plugin also auto-pushes DOM snapshots via Tauri IPC. The get_cached_dom tool returns this pre-cached snapshot instantly.
Quick Start
Using Claude Code? Install the skill for automated setup -- see Claude Code Skill below.
1. Add the plugin
# src-tauri/Cargo.toml
[]
= "0.6"
2. Register it (debug-only)
// src-tauri/src/lib.rs -- place BEFORE .invoke_handler()
3. Add permission
// src-tauri/capabilities/default.json -- add to permissions array
"connector:default"
4. Set withGlobalTauri (required)
// src-tauri/tauri.conf.json
5. Install snapdom (screenshot fallback)
# In your frontend project
If your project uses Vite/webpack, no extra setup needed. Otherwise expose on window:
import { snapdom } from '@zumer/snapdom';
window.snapdom = snapdom;
6. Configure Claude Code
// .mcp.json -- the MCP server starts automatically with the app
7. Run
Look for:
[connector][mcp] MCP ready for 'MyApp' -- url: http://0.0.0.0:9556/sse
[connector] Plugin ready for 'MyApp' (com.example.app) -- WS on 0.0.0.0:9555
The MCP server is now live. Claude Code connects automatically via the URL in .mcp.json.
WebSocket API via Bun
Connect directly to the plugin WebSocket on port 9555 using bun -e. No build step or extra dependencies -- bun has native WebSocket support.
Execute JavaScript
Take Screenshot
DOM Snapshot / Click / Type
# AI snapshot (default mode -- includes refs, component names, portal stitching)
# Click an element
# Type text into focused element
App State / Logs / Windows
# App metadata (no bridge needed)
# Console logs
WS Command Reference
All commands use { id, type, ...params } with snake_case types:
| Type | Key Params |
|---|---|
ping |
-- |
execute_js |
script, window_id |
screenshot |
format, quality, max_width, window_id |
dom_snapshot |
mode (ai/accessibility/structure), selector, max_depth, max_elements, react_enrich, follow_portals, shadow_dom, window_id |
find_element |
selector, strategy, window_id |
get_styles |
selector, properties, window_id |
interact |
action, selector, strategy, x, y, window_id |
keyboard |
action, text, key, modifiers, window_id |
wait_for |
selector, strategy, text, timeout, window_id |
window_list / window_info / window_resize |
window_id, width, height |
backend_state |
-- |
ipc_execute_command |
command, args |
ipc_monitor |
action |
ipc_get_captured |
filter, limit, pattern, since |
ipc_emit_event |
event_name, payload |
console_logs |
lines, filter, level, pattern, since, window_id |
clear_logs |
source |
read_log_file |
source, lines, level, pattern, since, window_id |
ipc_listen |
action, events |
event_get_captured |
event, pattern, limit, since |
search_snapshot |
pattern, context, mode, window_id |
Rust CLI (Alternative)
A Rust CLI with ref-based element addressing is also available:
# Homebrew (macOS/Linux)
# Or build from source
# Binary at target/release/tauri-connector
Environment: TAURI_CONNECTOR_HOST (default 127.0.0.1), TAURI_CONNECTOR_PORT (default 9555).
Claude Code Skill (Recommended)
Install the included skill to let Claude Code automatically set up and use tauri-connector.
Install
What It Does
Once installed, Claude will automatically:
- Set up the plugin in any Tauri project when asked
- Use the CLI for DOM snapshots and element interactions
- Debug issues using console logs, app state, and JS execution
- Automate testing with snapshot -> click/fill/verify workflows
For contributors: The release workflow skill is at
.claude/skills/tauri-connector-release/SKILL.md— it triggers automatically when you say "release" or "bump version" inside this repo.
MCP Server
Embedded (Default)
The MCP server starts automatically inside the Tauri plugin when the app runs. Configure Claude Code with:
No separate process, no Node.js, no install step. Just run your Tauri app.
Standalone (Alternative)
A standalone Rust MCP binary is also available for cases where you can't modify the Tauri app:
# Binary at target/release/tauri-connector-mcp
Plugin Configuration
use ConnectorBuilder;
// Or disable the embedded MCP server:
new
.disable_mcp
.build
Frontend Integration (Optional)
Push DOM snapshots from your frontend for instant LLM access:
import { invoke } from '@tauri-apps/api/core';
// The bridge auto-pushes DOM snapshots on page load and significant mutations.
// For manual push (e.g. after a custom state change):
const result = window.__CONNECTOR_SNAPSHOT__({ mode: 'ai', maxElements: 5000 });
await invoke('plugin:connector|push_dom', {
payload: {
windowId: 'main',
html: document.body.innerHTML.substring(0, 500000),
textContent: document.body.innerText.substring(0, 200000),
snapshot: result.snapshot,
snapshotMode: 'ai',
refs: JSON.stringify(result.refs),
meta: JSON.stringify(result.meta),
}
});
The bridge JS auto-pushes DOM on page load and significant mutations (5s debounce) when window.__TAURI_INTERNALS__ is available.
Alt+Shift+Click Element Picker
Alt+Shift+Click any element in the app to capture its metadata. Retrieve via webview_get_pointed_element MCP tool.
Project Structure
tauri-connector/
|-- Cargo.toml # Workspace root
|-- plugin/ # Rust Tauri v2 plugin (crates.io)
| |-- Cargo.toml
| '-- src/
| |-- lib.rs # Plugin entry + Tauri IPC commands
| |-- bridge.rs # Internal WebSocket bridge (the fix)
| |-- server.rs # External WebSocket server (for CLI)
| |-- mcp.rs # Embedded MCP SSE server
| |-- mcp_tools.rs # MCP tool definitions + dispatch
| |-- handlers.rs # All command handlers
| |-- protocol.rs # Message types
| '-- state.rs # Shared state (DOM cache, logs, IPC)
|-- crates/
| |-- client/ # Shared Rust WebSocket client
| | '-- src/lib.rs
| |-- mcp-server/ # Standalone MCP server (alternative)
| | '-- src/
| | |-- main.rs # Stdio JSON-RPC loop
| | |-- protocol.rs # JSON-RPC types
| | '-- tools.rs # Tool definitions + dispatch
| '-- cli/ # Rust CLI binary
| '-- src/
| |-- main.rs # Clap CLI entry point
| |-- commands.rs # Command implementations
| '-- snapshot.rs # Ref system + DOM snapshot builder
|-- skill/ # Claude Code skill + bun scripts
| |-- SKILL.md # Usage guide (loaded by Claude Code)
| |-- SETUP.md # Setup instructions
| '-- scripts/ # Bun scripts for WS interaction
| |-- connector.ts # Shared helper (auto-discovers ports via PID file)
| |-- state.ts, eval.ts, screenshot.ts, snapshot.ts
| |-- click.ts, fill.ts, find.ts, wait.ts
| '-- logs.ts, windows.ts
|-- LICENSE
'-- README.md
How It Works
JS Execution (Dual Path)
The bridge uses two execution paths for maximum reliability:
-
WS Bridge (primary, 2s timeout): Internal WebSocket on
127.0.0.1:9300-9400. Bridge JS injected into the webview connects back, executes scripts viaAsyncFunction, and returns results through the WebSocket. Usestokio::select!for multiplexed read/write on a single stream. -
Eval+Event fallback: If the WS bridge times out, the plugin injects JS via Tauri's
window.eval()and receives results through Tauri's event system (plugin:event|emit). RequireswithGlobalTauri: true. Handles double-serialized event payloads automatically.
The fallback is transparent -- bridge.execute_js() returns the same result regardless of which path succeeded.
Screenshot
The webview_screenshot tool uses a tiered approach:
-
xcap native capture (cross-platform): Uses the xcap crate for pixel-accurate window capture on Windows, macOS, and Linux. Matches the window by title, captures via native OS APIs, then resizes (
maxWidth) and encodes to PNG/JPEG/WebP via theimagecrate. Runs on a blocking thread to avoid stalling the Tokio runtime. -
snapdom fallback: When xcap is unavailable (e.g. Wayland without permissions, CI environments), falls back to snapdom (
@zumer/snapdom) — a fast DOM-to-image library that captures exactly what the web engine renders. Loaded via dynamicimport()orwindow.snapdomglobal. No CDN dependency, works fully offline.
PID File Auto-Discovery
When the plugin starts, it writes target/.connector.json with all port info:
The bun scripts in skill/scripts/ auto-discover this file, verify the PID is alive, and connect without any env vars. If the Tauri app is already running in another terminal, the scripts connect directly -- no need to start a new instance.
Embedded MCP Server
- Plugin starts an SSE HTTP server on port 9556 (configurable)
- Claude Code connects via
GET /sseand receives an SSE event stream - Tool calls arrive via
POST /messagewith JSON-RPC bodies - Handlers call the bridge and plugin state directly -- zero WebSocket overhead
Console Log Capture
The bridge intercepts console.log/warn/error/info/debug, storing entries in file-backed JSONL storage at {app_data_dir}/.tauri-connector/console.log. Logs persist across app restarts. Accessible via read_logs, read_log_file, or auto-pushed to Rust via invoke().
Ref System
The unified snapshot engine assigns sequential ref IDs (e0, e1, ...) to interactive elements (buttons, links, inputs, checkboxes, etc.) and elements with onclick, tabindex, or cursor:pointer. Three ref formats are accepted: @e1, ref=e1, or e1. Refs are persisted to disk and used across subsequent CLI invocations until the next snapshot refreshes them. The ref resolution uses a three-strategy fallback: CSS selector, then role+name text matching, then [role="..."] attribute matching.
Requirements
- Tauri v2.x
- Rust 2024 edition
- Bun (for skill scripts / WebSocket API examples)
@zumer/snapdomin frontend (optional, for screenshot fallback when xcap is unavailable)
License
MIT