tauri-mcp-cli

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Tauri MCP CLI

Tauri MCP CLI

Use this skill for the entire CLI workflow. The package intentionally ships a single bundled skill so agents do not need to pick between overlapping domain-specific skills.
使用该技能完成完整的CLI工作流。本包特意提供了一个捆绑的单一技能,因此Agent无需在重叠的领域特定技能中进行选择。

Prerequisites

前提条件

  • The app is running in development mode, usually with
    cargo tauri dev
    .
  • The
    tauri-plugin-mcp-bridge
    plugin is installed and registered.
  • src-tauri/tauri.conf.json
    sets
    withGlobalTauri: true
    .
  • 应用处于开发模式运行,通常使用
    cargo tauri dev
    命令。
  • 已安装并注册
    tauri-plugin-mcp-bridge
    插件。
  • src-tauri/tauri.conf.json
    中设置
    withGlobalTauri: true

Core Rule

核心规则

Start or verify a driver session before calling almost any other tool:
bash
tauri-mcp driver-session start --port 9223
tauri-mcp driver-session status --json
driver-session start
can succeed even when no app is reachable, so always check
connected: true
in the status output.
在调用几乎所有其他工具之前,先启动或验证驱动会话:
bash
tauri-mcp driver-session start --port 9223
tauri-mcp driver-session status --json
即使无法连接到应用,
driver-session start
也可能执行成功,因此务必检查状态输出中的
connected: true

Session and Daemon Lifecycle

会话与守护进程生命周期

bash
undefined
bash
undefined

Start a session

启动会话

tauri-mcp driver-session start --port 9223
tauri-mcp driver-session start --port 9223

Run one or more commands in separate shell invocations

在单独的Shell调用中运行一个或多个命令

tauri-mcp webview-screenshot --file before.png tauri-mcp webview-interact --action click --selector "#submit-btn" tauri-mcp webview-screenshot --file after.png
tauri-mcp webview-screenshot --file before.png tauri-mcp webview-interact --action click --selector "#submit-btn" tauri-mcp webview-screenshot --file after.png

End the session

结束会话

tauri-mcp driver-session stop

The CLI uses MCPorter keep-alive mode, so the background daemon preserves session state across separate `tauri-mcp ...` commands.

Use daemon commands only when the background process itself is unhealthy:

```bash
tauri-mcp daemon status
tauri-mcp daemon restart
tauri-mcp driver-session start --port 9223
tauri-mcp driver-session stop

CLI使用MCPorter保活模式,因此后台守护进程会在多个独立的`tauri-mcp ...`命令之间保留会话状态。

仅当后台进程本身出现异常时,才使用守护进程命令:

```bash
tauri-mcp daemon status
tauri-mcp daemon restart
tauri-mcp driver-session start --port 9223

UI Interaction

UI交互

bash
undefined
bash
undefined

Click or focus an element

点击或聚焦元素

tauri-mcp webview-interact --action click --selector "#submit-btn" tauri-mcp webview-interact --action focus --selector "#search"
tauri-mcp webview-interact --action click --selector "#submit-btn" tauri-mcp webview-interact --action focus --selector "#search"

Type into a field

在输入框中输入内容

tauri-mcp webview-keyboard --action type --selector "#email" --text "hello@example.com"
tauri-mcp webview-keyboard --action type --selector "#email" --text "hello@example.com"

Wait before interacting with async UI

等待异步UI加载完成后再交互

tauri-mcp webview-wait-for --type selector --value "#success-msg" --timeout 5000 tauri-mcp webview-interact --action click --selector "#success-msg"
tauri-mcp webview-wait-for --type selector --value "#success-msg" --timeout 5000 tauri-mcp webview-interact --action click --selector "#success-msg"

Keyboard shortcuts and scrolling

快捷键与滚动操作

tauri-mcp webview-keyboard --action press --key "s" --modifiers '["Control"]' tauri-mcp webview-interact --action scroll --selector ".content" --scroll-y 300

All CLI flags are kebab-case, not camelCase. For example, use `--window-id`, not `--windowId`.
tauri-mcp webview-keyboard --action press --key "s" --modifiers '["Control"]' tauri-mcp webview-interact --action scroll --selector ".content" --scroll-y 300

所有CLI参数均使用短横线命名法(kebab-case),而非驼峰命名法(camelCase)。例如,使用`--window-id`而非`--windowId`。

Inspection and Capture

检查与捕获

bash
undefined
bash
undefined

Screenshots always write files to disk

截图始终将文件写入磁盘

tauri-mcp webview-screenshot --file shot.png tauri-mcp webview-screenshot --format jpeg --quality 80 --file shot.jpg tauri-mcp webview-screenshot --json
tauri-mcp webview-screenshot --file shot.png tauri-mcp webview-screenshot --format jpeg --quality 80 --file shot.jpg tauri-mcp webview-screenshot --json

Run JavaScript in the webview

在webview中运行JavaScript代码

tauri-mcp webview-execute-js --script "document.title" tauri-mcp webview-execute-js --script "(() => { return document.querySelectorAll('li').length; })()"
tauri-mcp webview-execute-js --script "document.title" tauri-mcp webview-execute-js --script "(() => { return document.querySelectorAll('li').length; })()"

Find elements and inspect styles

查找元素并检查样式

tauri-mcp webview-find-element --selector "#hero" tauri-mcp webview-get-styles --selector "#hero" --properties '["color","font-size"]'
tauri-mcp webview-find-element --selector "#hero" tauri-mcp webview-get-styles --selector "#hero" --properties '["color","font-size"]'

Read logs and inspect windows

读取日志并检查窗口

tauri-mcp read-logs --source console --filter "error" --lines 100 tauri-mcp manage-window --action list --json

If content is off-screen, scroll it into view before taking a screenshot. The CLI does not return base64 image data on stdout.
tauri-mcp read-logs --source console --filter "error" --lines 100 tauri-mcp manage-window --action list --json

如果内容不在屏幕可视区域内,请先将其滚动到视图中再截图。CLI不会在标准输出中返回base64格式的图片数据。

IPC and Backend

IPC与后端

bash
undefined
bash
undefined

Verify the bridge plugin is active

验证桥接插件是否激活

tauri-mcp driver-session status --json
tauri-mcp driver-session status --json

Run backend commands

运行后端命令

tauri-mcp ipc-execute-command --command "greet" --args '{"name":"World"}' tauri-mcp ipc-get-backend-state --json
tauri-mcp ipc-execute-command --command "greet" --args '{"name":"World"}' tauri-mcp ipc-get-backend-state --json

Capture IPC traffic around an interaction

捕获交互过程中的IPC流量

tauri-mcp ipc-monitor --action stop tauri-mcp ipc-monitor --action start tauri-mcp webview-interact --action click --selector "#refresh" tauri-mcp ipc-get-captured --json tauri-mcp ipc-monitor --action stop
tauri-mcp ipc-monitor --action stop tauri-mcp ipc-monitor --action start tauri-mcp webview-interact --action click --selector "#refresh" tauri-mcp ipc-get-captured --json tauri-mcp ipc-monitor --action stop

Emit synthetic events

触发合成事件

tauri-mcp ipc-emit-event --event-name "user-action" --payload '{"action":"button-clicked"}'

If `driver-session status --json` returns `identifier: null`, treat that as a missing or inactive bridge plugin.
tauri-mcp ipc-emit-event --event-name "user-action" --payload '{"action":"button-clicked"}'

如果`driver-session status --json`返回`identifier: null`,则表示桥接插件缺失或未激活。

Mobile and Remote Devices

移动与远程设备

bash
undefined
bash
undefined

List targets

列出目标设备

tauri-mcp list-devices --json
tauri-mcp list-devices --json

Android emulator or iOS simulator

Android模拟器或iOS模拟器

tauri-mcp driver-session start --port 9223
tauri-mcp driver-session start --port 9223

Real Android device

真实Android设备

adb reverse tcp:9223 tcp:9223 tauri-mcp driver-session start --port 9223
adb reverse tcp:9223 tcp:9223 tauri-mcp driver-session start --port 9223

Real iOS device or direct network connection

真实iOS设备或直接网络连接

tauri-mcp driver-session start --host 192.168.1.101 --port 9223
tauri-mcp driver-session start --host 192.168.1.101 --port 9223

Mobile logs

移动设备日志

tauri-mcp read-logs --source android --filter "com.myapp" tauri-mcp read-logs --source ios --filter "MyApp"

For real Android devices, do not assume localhost works without `adb reverse` or an explicit `--host`.
tauri-mcp read-logs --source android --filter "com.myapp" tauri-mcp read-logs --source ios --filter "MyApp"

对于真实Android设备,请勿假设无需`adb reverse`或显式指定`--host`即可使用localhost连接。

High-Value Failure Modes

常见高风险故障场景

No active session

无活跃会话

bash
tauri-mcp driver-session start --port 9223
tauri-mcp driver-session status --json
bash
tauri-mcp driver-session start --port 9223
tauri-mcp driver-session status --json

Stale daemon or app restart

守护进程过期或应用重启

bash
tauri-mcp daemon restart
tauri-mcp driver-session start --port 9223
tauri-mcp driver-session status --json
bash
tauri-mcp daemon restart
tauri-mcp driver-session start --port 9223
tauri-mcp driver-session status --json

Wrong port

端口错误

bash
tauri-mcp driver-session start --port 9225
bash
tauri-mcp driver-session start --port 9225

Screenshot misuse

截图使用错误

bash
undefined
bash
undefined

Wrong: captures a file path string, not image bytes

错误:捕获的是文件路径字符串,而非图片字节

IMG=$(tauri-mcp webview-screenshot)
IMG=$(tauri-mcp webview-screenshot)

Right

正确做法

tauri-mcp webview-screenshot --file shot.png
undefined
tauri-mcp webview-screenshot --file shot.png
undefined

JavaScript return shape

JavaScript返回格式错误

bash
undefined
bash
undefined

Wrong: returns null

错误:返回null

tauri-mcp webview-execute-js --script "() => { return document.title; }"
tauri-mcp webview-execute-js --script "() => { return document.title; }"

Right

正确做法

tauri-mcp webview-execute-js --script "document.title"
undefined
tauri-mcp webview-execute-js --script "document.title"
undefined

Missing selector for typed input

输入操作缺少选择器

bash
undefined
bash
undefined

Wrong

错误

tauri-mcp webview-keyboard --action type --text "hello"
tauri-mcp webview-keyboard --action type --text "hello"

Right

正确做法

tauri-mcp webview-keyboard --action type --selector "#email" --text "hello"
undefined
tauri-mcp webview-keyboard --action type --selector "#email" --text "hello"
undefined

Decision Checklist

操作前检查清单

Before acting, verify:
  1. The app is running.
  2. driver-session status --json
    shows
    connected: true
    .
  3. The command uses kebab-case flags.
  4. Screenshot commands write to explicit file paths when the result matters.
  5. Mobile workflows specify the correct connection path and log source.
执行操作前,请验证以下内容:
  1. 应用正在运行。
  2. driver-session status --json
    显示
    connected: true
  3. 命令使用短横线命名法(kebab-case)的参数。
  4. 当截图结果重要时,截图命令需指定明确的文件路径。
  5. 移动设备工作流指定了正确的连接路径和日志来源。