内容
<p align="center">
<img src="./rust.png" alt="Rust logo" width="180" />
</p>
# Rust 调试 MCP
[](https://www.typescriptlang.org/)
[](https://www.rust-lang.org/)
[](https://tauri.app/)
[](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API)
[](https://modelcontextprotocol.ai/)
用于调试和操作 Rust Tauri 应用程序的模型上下文协议(MCP)服务器,通过 WebSocket 进行通信。
## 目录
- [概述](#概述)
- [功能](#功能)
- [安装](#安装)
- [使用](#使用)
- [工具 API](#工具-api)
- [示例](#示例)
- [开发](#开发)
- [贡献](#贡献)
- [许可证](#许可证)
## 概述
`rust-debug-mcp` 连接 MCP 客户端和 Tauri 调试后端。它提供了一个工具 (`tauri_debug_command`),该工具将命令路由到专门的处理器,用于应用程序生命周期操作、核心调试、指标/任务检查、前端操作和 UI 自动化。
它通过 `configs/apps.json` 支持多个目标应用程序,包括在执行命令之前对每个应用程序进行功能检查。
## 功能
### 核心功能
- 多应用程序注册,支持每个应用程序的命令功能控制
- 应用程序生命周期管理(`start_app`、`kill_app`)
- 通过类型化的 WebSocket 桥接进行核心调试命令转发
- 响应详细程度控制(`concise` 和 `detailed`)
### 调试和检查
- 用于 Commander 风格后端的任务/会话/指标命令
- 前端广播支持,用于应用程序端操作
- UI 自动化命令(`click`、`fill`、`select`、`type`、`press_key`、快照、截图、等待/悬停/滚动、控制台日志)
### 可靠性
- 桥接管理器中的连接状态检查和重新连接行为
- 桥接调用的请求超时处理
- 有序的处理程序路由和干净的命令到处理程序解析
## 安装
### 快速设置
```bash
# 克隆仓库
git clone https://github.com/ruizrica/rust-debug-mcp.git
# 进入项目
cd rust-debug-mcp
# 安装依赖
npm install
# 构建
npm run build
```
### 在 MCP 客户端中安装
添加到您的 MCP 配置(示例):
```json
{
"mcpServers": {
"tauri-debug": {
"command": "node",
"args": ["/absolute/path/to/rust-debug-mcp/dist/server.js"],
"env": {
"LOG_LEVEL": "info",
"TAURI_WS_URL": "ws://localhost:9002",
"COMMANDER_WS_URL": "ws://localhost:9002"
}
}
}
}
```
有关更深入的设置和故障排除,请参阅 `docs/RUNBOOK.md`。
## 使用
### 启动服务器
```bash
npm run dev
# 或
npm start
```
服务器通过标准输入输出进行通信,旨在由 MCP 客户端启动。
### 多应用程序配置
`configs/apps.json` 控制默认应用程序、应用程序端点和命令功能集:
```json
{
"default": "commander",
"apps": {
"commander": {
"name": "Commander",
"wsUrl": "ws://localhost:9002",
"commands": ["all"]
},
"photon": {
"name": "Photon CLI",
"wsUrl": "ws://localhost:9847",
"commands": ["core", "ui_automation"]
}
}
}
```
## 工具 API
服务器公开了一个 MCP 工具:
| 工具 | 描述 |
|------|-------------|
| `tauri_debug_command` | 对选定的应用程序执行调试命令(`command`,可选 `params`,可选 `app`,可选 `response_format`) |
### 命令类别
- 应用程序生命周期:`start_app`、`kill_app`
- 核心:`test_connection`、`get_debug_mode`、`set_debug_mode`、`get_app_dir`、`get_logs`、`get_system_metrics`、`test_command`、`simple_test`
- 任务/会话/指标:`get_session_metrics`、`get_task_metrics`、`get_all_tasks`、`get_task`、`get_tasks_by_status`、`get_task_groups`、`list_windows`
- 前端操作:`broadcast_to_frontend`
- UI 自动化:`click`、`fill`、`select`、`type`、`press_key`、`get_snapshot`、`take_screenshot`、`wait_for`、`hover`、`scroll`、`get_console_logs`
有关完整的有效载荷详细信息,请参阅 `docs/COMMAND_REFERENCE.md`。
## 示例
### 最小命令
```json
{
"command": "test_connection"
}
```
### 针对特定应用程序
```json
{
"command": "get_debug_mode",
"app": "commander"
}
```
### UI 交互
```json
{
"command": "click",
"app": "photon",
"params": {
"uid": "e5"
}
}
```
## 开发
### 项目结构
```text
rust-debug-mcp/
├── src/
│ ├── server.ts # MCP 服务器入口点
│ ├── bridge-manager.ts # WebSocket 桥接和管理
│ ├── app-registry.ts # 多应用程序注册和功能检查
│ ├── handlers/ # 命令处理程序和路由器
│ ├── response-formatter.ts # 简洁/详细输出格式化
│ └── types.ts # 类型定义
├── configs/
│ └── apps.json
├── docs/
├── tests/
├── package.json
└── tsconfig.json
```
### 构建
```bash
npm run build
```
### 类型检查
```bash
npm run typecheck
```
### 测试
```bash
npm test
npm run test:unit
npm run test:integration
```
## 贡献
欢迎贡献。
1. 分叉仓库
2. 创建功能分支
3. 进行更改并测试
4. 打开拉取请求
## 许可证
MIT
---
使用 TypeScript、Rust、Tauri 和 MCP 构建。