MCP Tauri自动化
使用人工智能自动化Tauri桌面应用程序。 一个MCP服务器,允许Claude Code通过自然语言测试、调试和与Tauri应用程序交互。
这是什么?
测试Tauri应用程序通常意味着:
- ❌ 手动点击UI以进行每次更改
- ❌ 为简单的交互编写复杂的测试脚本
- ❌ 手动截取屏幕截图以调试视觉问题
- ❌ 在代码编辑器和正在运行的应用程序之间不断切换
使用此MCP服务器:
- ✅ 让克劳德“点击提交按钮并检查结果”
- ✅ 获取应用程序状态的即时屏幕截图
- ✅ 测试UI通过自然语言流动
- ✅ 在编写代码时自动化重复测试
快速开始
1.安装tauri驱动器
cargo install tauri-driver2.安装此MCP服务器
git clone
cd mcp-tauri-automation
npm install && npm run build3.添加到MCP配置中
Claude Code (Recommended)
使用Claude Code CLI注册服务器:
# Simplest setup - works with any Tauri app
# (you'll specify which app to launch when you ask Claude)
claude mcp add --transport stdio tauri-automation \
--scope user \
-- node /absolute/path/to/mcp-tauri-automation/dist/index.js替换 /absolute/path/to/mcp-tauri-automation 使用您克隆此仓库的实际路径。例如:
- Linux/macOS:
~/projects/mcp-tauri-automation/dist/index.js - 窗户:
C:/Users/YourName/projects/mcp-tauri-automation/dist/index.js
可选:设置默认应用程序路径
如果你主要使用一个Tauri应用程序,你可以将其设置为默认值:
claude mcp add --transport stdio tauri-automation \
--env TAURI_APP_PATH=/path/to/your-app/src-tauri/target/debug/your-app \
--scope user \
-- node /absolute/path/to/mcp-tauri-automation/dist/index.js💡 我可以测试多个应用程序吗? 对!这 TAURI_APP_PATH 这只是一个方便的默认设置。当你询问Claude时,你仍然可以通过指定路径来启动任何其他Tauri应用程序(例如,“在~/projects/calculator app/target/debug/calculator上启动我的计算器应用程序”)。高级:自定义默认值
claude mcp add --transport stdio tauri-automation \
--env TAURI_SCREENSHOT_DIR=./my-screenshots \
--env TAURI_DEFAULT_TIMEOUT=10000 \
--scope user \
-- node /absolute/path/to/mcp-tauri-automation/dist/index.js所有环境变量都有合理的默认值,并且是可选的:
TAURI_APP_PATH:无默认值(启动时指定,或为方便起见在此处设置)TAURI_SCREENSHOT_DIR:./screenshots(相对于运行Claude Code的位置)TAURI_WEBDRIVER_PORT:4444(金牛座司机在听)TAURI_DEFAULT_TIMEOUT:5000ms(等待UI元素的时间)
管理服务器:
# List all configured servers
claude mcp list
# Get details for a specific server
claude mcp get tauri-automation
# Remove a server
claude mcp remove tauri-automation
# Inside Claude Code, check server status
/mcp替代:JSON格式
Click to see JSON configuration format
claude mcp add-json tauri-automation '{
"type": "stdio",
"command": "node",
"args": ["/absolute/path/to/mcp-tauri-automation/dist/index.js"],
"env": {
"TAURI_APP_PATH": "/optional/default/app/path"
}
}'范围选项:
--scope user:适用于所有项目(推荐)--scope local(默认):仅在当前项目中对您可用--scope project:通过与项目中的每个人共享.mcp.json文件
Claude Desktop
编辑 ~/Library/Application Support/Claude/claude_desktop_config.json:
{
"mcpServers": {
"tauri-automation": {
"command": "node",
"args": ["/absolute/path/to/mcp-tauri-automation/dist/index.js"]
}
}
}可选:添加环境变量
{
"mcpServers": {
"tauri-automation": {
"command": "node",
"args": ["/absolute/path/to/mcp-tauri-automation/dist/index.js"],
"env": {
"TAURI_APP_PATH": "/path/to/your/default/app"
}
}
}
}Claude Code (Manual Config)
编辑 ~/.config/claude-code/mcp_config.json:
{
"mcpServers": {
"tauri-automation": {
"command": "node",
"args": ["/absolute/path/to/mcp-tauri-automation/dist/index.js"]
}
}
}可选:添加环境变量
{
"mcpServers": {
"tauri-automation": {
"command": "node",
"args": ["/absolute/path/to/mcp-tauri-automation/dist/index.js"],
"env": {
"TAURI_APP_PATH": "/path/to/your/default/app"
}
}
}
}备注:使用 claude mcp add 命令(见上面的“克劳德代码(推荐)”)比手动编辑更容易,更不容易出错。
Other MCP Clients
任何支持stdio传输的MCP客户端都可以使用此服务器。通过客户端的配置机制传递环境变量。
4.启动tauri驱动程序
在使用MCP服务器之前,请启动 tauri-driver 在单独的终端中:
# In a separate terminal, keep this running
tauri-driver为什么金牛座的司机是分开的? tauri-driver 是一个独立的WebDriver服务器,用于控制Tauri应用程序。保持独立意味着: - ✅ 您可以在不丢失应用程序状态的情况下重新启动MCP服务器 - ✅ 多个工具可以连接到同一个驱动程序实例 - ✅ 它在易于配置的已知端口(4444)上运行 未来改进:如果此MCP服务器未运行,则可以将其增强为自动启动tauri驱动程序。有兴趣贡献吗?看 贡献 在......下面5.与Claude一起使用
Launch my Tauri app, click the "Start" button, and take a screenshot或者,如果您没有设置默认应用程序路径:
Launch my calculator app at ~/projects/calculator/target/debug/calculator and test addition可用工具
| 工具 | 说明 |
|---|---|
launch_app | 启动您的Tauri应用程序 |
close_app | 关闭正在运行的应用程序 |
capture_screenshot | 截图(返回base64 PNG) |
click_element | 通过CSS选择器单击UI元素 |
type_text | 在输入字段中键入 |
wait_for_element | 等待元素出现 |
get_element_text | 从元素中读取文本 |
execute_tauri_command | 调用Tauri IPC命令 |
get_app_state | 检查应用程序是否正在运行并获取会话信息 |
配置
所有环境变量都是可选的 有合理的默认值:
| 变量 | 描述 | 默认值 | 何时设置 |
|---|---|---|---|
TAURI_APP_PATH | Tauri应用程序二进制文件的路径 | 无 | 如果你主要使用一个应用程序(但你仍然可以启动其他应用程序),则设置 |
TAURI_SCREENSHOT_DIR | 在哪里保存截图 | ./screenshots | 如果你想在不同的位置截图,请更改 |
TAURI_WEBDRIVER_PORT | tauri司机奔跑的港口 | 4444 | 只有当你在自定义港口运行tauri驱动程序时 |
TAURI_DEFAULT_TIMEOUT | 元素等待超时(毫秒) | 5000 | 加载速度较慢的应用程序增加,反馈速度较快的应用程序减少 |
TAURI_DRIVER_PATH | tauri驱动程序二进制文件的路径 | tauri-driver | 只有当tauri司机不在您的路径中时 |
查找您的Tauri应用程序二进制文件
构建Tauri应用程序后,二进制文件位于:
- 开发建设:
your-tauri-project/src-tauri/target/debug/your-app-name - 发布版本:
your-tauri-project/src-tauri/target/release/your-app-name - macOS应用程序:添加
.app扩展(例如。,your-app-name.app) - Windows应用程序:添加
.exe扩展
先构建你的应用程序:
cd your-tauri-project
cargo build # or: cargo build --release用法示例
基本测试工作流程
You: Launch my calculator app and test the addition feature
Claude will:
1. Launch the app using launch_app
2. Wait for the UI to load with wait_for_element
3. Click buttons and type numbers
4. Capture screenshots to verify results
5. Report back with findings调试UI问题
You: Take a screenshot of my app's settings page
Claude will:
1. Check if app is running (or launch it)
2. Navigate to settings (if needed)
3. Capture and display the screenshot测试Tauri命令
You: Call the save_preferences command with theme='dark' and verify it worked
Claude will:
1. Use execute_tauri_command to call your Rust backend
2. Verify the response
3. Optionally check the UI updated correctly建筑
┌─────────────────┐
│ Claude Code │ Ask in natural language
└────────┬────────┘
│ MCP Protocol (stdio)
┌────────▼────────────────┐
│ MCP Tauri Automation │ Translate to automation commands
│ Server │
└────────┬────────────────┘
│ WebDriver Protocol
┌────────▼────────┐
│ tauri-driver │ Control the application
└────────┬────────┘
│
┌────────▼────────┐
│ Your Tauri │ Desktop app being tested
│ App │
└─────────────────┘故障排除
“启动应用程序失败:连接ECONNREFUSED”
解决方案:确保 tauri-driver 在使用MCP服务器之前正在运行。
# In a separate terminal
tauri-driver“找不到元素:#我的按钮”
解决方案:
- 使用
wait_for_element首先用于动态加载的内容 - 验证浏览器DevTools中的选择器(Tauri应用程序使用web技术)
- 增加慢速加载UI的超时时间
“找不到应用程序路径”
解决方案:
- 首先构建您的Tauri应用程序:
cargo build - 使用二进制文件的绝对路径
- 确保二进制文件可执行:
chmod +x /path/to/app - 在macOS上,使用
.app捆绑路径
端口冲突(端口4444已在使用中)
解决方案:使用自定义端口:
# Start tauri-driver on different port
tauri-driver --port 4445然后更新您的MCP配置:
{
"env": {
"TAURI_WEBDRIVER_PORT": "4445"
}
}屏幕截图未显示
解决方案:
- 确保应用程序确实在运行:让Claude检查
get_app_state - 检查屏幕截图目录是否存在并且可写
- 对于base64屏幕截图(默认),请确保您的MCP客户端支持图像显示
运作原理
此服务器使用WebDriver协议来控制Tauri应用程序。事情是这样的:
- 金牛座司机 充当Tauri应用程序的WebDriver服务器
- 此MCP服务器 将Claude的请求转换为WebDriver命令
- WebDriver IO 处理低级WebDriver通信
- 您的Tauri应用程序 响应自动化命令
服务器维护一个活动会话,并确保在关闭应用程序或关机时进行适当的清理。
高级用法
调用自定义Tauri命令
首先,在您的 src-tauri/src/main.rs:
#[tauri::command]
fn get_user_data(user_id: i32) -> Result {
Ok(format!("User {}", user_id))
}
fn main() {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![get_user_data])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}然后问克劳德:
Execute the get_user_data command with user_id 123多次试运行
服务器可以在会话中多次启动和关闭应用程序:
Launch the app, test feature A, close it.
Launch again, test feature B, close it.发展
# Build
npm run build
# Watch mode
npm run watch
# Project structure
src/
├── index.ts # MCP server entry point
├── tauri-driver.ts # WebDriver wrapper
├── types.ts # TypeScript types
└── tools/
├── launch.ts # App lifecycle
├── screenshot.ts # Screenshot capture
├── interact.ts # UI interaction
└── state.ts # State & IPC commands需求
- Node.js 18+
- 锈蚀/货物 (适用于金牛座司机)
- 金牛座司机 已安装并正在运行
- A. 构建Tauri应用程序 测试
许可证
麻省理工学院
致谢
- 内置于 @模型上下文协议/sdk
- 由...驱动 WebDriver IO
- 专为 涛瑞 应用
