Tauri应用调试服务器

Tauri MCP是一个用于调试和自动化Tauri桌面应用程序的模型上下文协议服务器,提供UI树访问、DOM交互、JavaScript执行等功能。

  • by Lumither
  • Rust
  • 本地部署
  • 4 星标
  • 更新于
在 GitHub 查看 Lumither/tauri-mcp

使用说明

Tauri MCP

MCP(模型上下文协议)服务器,用于调试和自动化Tauri应用程序。

类似于 剧作家 MCP 对于浏览器,Tauri MCP使AI代理能够 与Tauri桌面应用程序交互、检查和调试。

备注:vibe编码,使用风险自负。

备注:仅在macOS上测试。

特性

  • 辅助功能快照:获取结构化UI树(如浏览器DevTools可访问性树)
  • DOM交互:单击、填充输入、导航-所有这些都可以通过CSS选择器或元素引用来实现
  • JavaScript评估:在webview中执行任意JavaScript
  • Tauri集成:调用Tauri命令,检查应用程序状态,列出窗口
  • IPC跟踪:捕获和分析命令调用和事件
  • 截图:捕获窗口截图

建筑

┌─────────────────┐        stdio         ┌──────────────────┐
│   AI Agent      │◄────────────────────►│ tauri-mcp-server │
│ (Claude/Cursor) │        (MCP)         │   (Rust binary)  │
└─────────────────┘                      └────────┬─────────┘
                                                  │
                                            HTTP (localhost)
                                                  │
                                          ┌───────▼──────────┐
                                          │   Tauri App      │
                                          │   + MCP Plugin   │
                                          │                  │
                                          │ localhost:9223   │
                                          └──────────────────┘

快速开始

1.将插件添加到您的Tauri应用程序中

[dependencies]
tauri-mcp-plugin = { git = "https://github.com/lumither/tauri-mcp", tag = "v0.1.3" }
use tauri_mcp_plugin::McpPlugin;

fn main() {
    tauri::Builder::default()
        .plugin(McpPlugin::new().build())
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}
// capabilities/default.json
{
  "permissions": [
    // ..
    "tauri-mcp:allow-js-result",
    "tauri-mcp:allow-invoke-command"
  ]
}

2.配置您的MCP客户端

添加到您的MCP客户端配置(Claude Desktop、Claude Code、Cursor等):

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

或者,如果您在本地安装了二进制文件:

{
  "mcpServers": {
    "tauri": {
      "command": "/path/to/tauri-mcp-server"
    }
  }
}

或者,如果您正在使用克劳德代码

claude mcp add tauri -- npx -y @lumither/tauri-mcp

可用工具

导航

工具 说明
tauri_navigate 导航到Web视图中的URL
tauri_click 通过CSS选择器或ref单击元素
tauri_fill 填写输入字段
tauri_scroll 滚动页面或元素进入视图
tauri_screenshot 截图
tauri_screenshot_full 进行全屏截图

检查

工具 说明
tauri_snapshot 获取可访问性树快照
tauri_query 按CSS选择器查询元素
tauri_eval 执行JavaScript代码

牛磺酸特异性

工具 说明
tauri_windows 列出所有窗口
tauri_state 获取应用程序状态和命令
tauri_invoke 调用Tauri命令

追踪

工具 说明
tauri_start_trace 开始捕获IPC事件
tauri_stop_trace 停止跟踪并获取事件

配置

插件选项

McpPlugin::new()
.port(9223)              // HTTP server port (0 = auto)
.discovery(true)         // Write discovery file for auto-connect
.max_snapshot_depth(10)  // Max accessibility tree depth
.build()

环境变量

变量 描述
TAURI_MCP_URL 覆盖插件URL(例如。, http://localhost:9223)

发展

建筑

# Build all crates
cargo build --release

# Build just the server
cargo build --release -p tauri-mcp-server

# Build just the plugin
cargo build --release -p tauri-mcp-plugin

项目结构

tauri-mcp/
├── crates/
│   ├── tauri-mcp-types/    # Shared types
│   ├── tauri-mcp-plugin/   # Tauri plugin
│   └── tauri-mcp-server/   # MCP server binary
├── npm/
│   └── tauri-mcp/          # npm distribution package
├── examples/
│   └── demo-app/           # Example Tauri app
└── README.md

安全

  • 插件服务器仅绑定到 127.0.0.1 (本地主机)
  • 无身份验证(信任本地主机连接)
  • 设计用于开发/调试,而非生产使用

许可证

根据以下任一方式获得许可:

实施状态

工作

  • [x] 使用CORS插件HTTP服务器
  • [x] 基于stdio的JSON-RPC MCP服务器
  • [x] 应用程序状态检查(tauri_state)
  • [x] 窗口列表(tauri_windows)
  • [x] JavaScript评估(tauri_eval)
  • [x] IPC事件跟踪框架
  • [x] 通过配置文件发现应用程序
  • [x] 点击、填充、导航(JS注入)
  • [x] 异步JavaScript结果检索(用于快照、查询结果)
  • [x] 屏幕截图
  • [x] 带有元素引用的完整可访问性树

计划的

  • []WebSocket/SSE用于实时事件
  • []本机可访问性API集成
  • []多窗口协调
  • []测试记录/回放
  • [ ] tauri_resize --调整窗口大小(宽度、高度)
  • [ ] tauri_get_size --获取当前窗口大小
  • [ ] tauri_move --移动窗口(x,y)
  • [ ] tauri_get_position --获取当前窗口位置
  • [ ] tauri_minimize --最小化窗口
  • [ ] tauri_maximize --最大化窗口
  • [ ] tauri_fullscreen --在窗口上切换全屏
  • [ ] tauri_is_fullscreen --检查窗口是否处于全屏状态
  • [ ] tauri_refresh --刷新/重新加载Web视图
  • [ ] tauri_monitors --列出可用监视器(id、名称、大小、位置、比例因子)
  • [ ] tauri_current_monitor --获取窗口当前打开的监视器
  • [ ] tauri_move_to_monitor --将窗口移动到特定监视器

MCP设置

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

手动测试

# Test HTTP API directly
curl http://localhost:9223/api/state

# Test MCP server
echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}}}
{"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}' | ./target/release/tauri-mcp-server