关于 tauri-mcp-cli
用于通过 `tauri-mcp` 操作 Tauri 应用的命令行工作流技能,涵盖驱动会话、Webview 交互与检查、IPC 命令及设备流程,并提供会话和守护进程故障排查指引。
主要功能
- 01启动并验证驱动会话
- 02交互和检查 Webview
- 03截取屏幕并执行 JavaScript
- 04运行后端 IPC 命令并检查状态
- 05列出设备并处理移动端连接
- 06排查会话和守护进程故障
适用场景
- 01自动化运行中的 Tauri 应用 Webview
- 02截取屏幕并检查页面内容
- 03调用后端命令并检查状态
- 04连接 Android 或 iOS 测试目标
MCP 相关
通过 `tauri-mcp` 访问 Tauri MCP bridge 插件。命令行工作流会启动驱动会话,并通过命令提供 Webview、IPC 和设备操作。
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ hypothesi/ mcp-server-tauri --skill tauri-mcp-cli安装后在 Claude Code 中输入/tauri-mcp-cli确认已加载。
详细介绍
Tauri MCP CLI
在整个 CLI 工作流中使用此技能。此软件包特意只提供一个捆绑技能,因此 Agent 无需在重叠的领域专用技能之间做选择。
前提条件
- 应用正在开发模式下运行,通常使用
cargo tauri dev。 - 已安装并注册
tauri-plugin-mcp-bridge插件。 src-tauri/tauri.conf.json设置了withGlobalTauri: true。
核心规则
在调用几乎所有其他工具之前,先启动或验证驱动程序会话:
tauri-mcp driver-session start --port 9223
tauri-mcp driver-session status --json
即使无法连接到任何应用,driver-session start 也可能成功,因此务必检查状态输出中的 connected: true。
会话与守护进程生命周期
# Start a session
tauri-mcp driver-session start --port 9223
# Run one or more commands in separate shell invocations
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
CLI 使用 MCPorter 保持活动模式,因此后台守护进程会在多个独立的 tauri-mcp ... 命令之间保留会话状态。
仅当后台进程本身运行异常时,才使用守护进程命令:
tauri-mcp daemon status
tauri-mcp daemon restart
tauri-mcp driver-session start --port 9223
UI 交互
# Click or focus an element
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 "[email protected]"
# Wait before interacting with async UI
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
所有 CLI 标志都采用 kebab-case,而非 camelCase。例如,使用 --window-id,而不是 --windowId。
检查与捕获
# 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
# Run JavaScript in the webview
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"]'
# Read logs and inspect windows
tauri-mcp read-logs --source console --filter "error" --lines 100
tauri-mcp manage-window --action list --json
如果内容位于屏幕之外,请先滚动到可见区域,再截取屏幕截图。CLI 不会在标准输出中返回 base64 图像数据。
IPC 与后端
# Verify the bridge plugin is active
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
# Capture IPC traffic around an interaction
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"}'
如果 driver-session status --json 返回 identifier: null,则应视为桥接插件缺失或未激活。
移动设备与远程设备
# List targets
tauri-mcp list-devices --json
# Android emulator or iOS simulator
tauri-mcp driver-session start --port 9223
# Real Android device
adb reverse tcp:9223 tcp:9223
tauri-mcp driver-session start --port 9223
# Real iOS device or direct network connection
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"
对于真实的 Android 设备,不要假设无需 adb reverse 或显式指定 --host 就能使用 localhost。
高优先级故障模式
没有活动会话
tauri-mcp driver-session start --port 9223
tauri-mcp driver-session status --json
守护进程过期或应用重启
tauri-mcp daemon restart
tauri-mcp driver-session start --port 9223
tauri-mcp driver-session status --json
端口错误
tauri-mcp driver-session start --port 9225
截图使用不当
# Wrong: captures a file path string, not image bytes
IMG=$(tauri-mcp webview-screenshot)
# Right
tauri-mcp webview-screenshot --file shot.png
JavaScript 返回值形状
# Wrong: returns null
tauri-mcp webview-execute-js --script "() => { return document.title; }"
# Right
tauri-mcp webview-execute-js --script "document.title"
输入文本时缺少选择器
# Wrong
tauri-mcp webview-keyboard --action type --text "hello"
# Right
tauri-mcp webview-keyboard --action type --selector "#email" --text "hello"
决策清单
操作前,请确认:
- 应用正在运行。
driver-session status --json显示connected: true。- 命令使用 kebab-case 标志。
- 如果截图结果很重要,截图命令会将其写入明确指定的文件路径。
- 移动端工作流指定了正确的连接路径和日志来源。
评论
支持 Markdown