Skip to content

Commit 19e5a7f

Browse files
author
lu.jin
committed
first commit
0 parents  commit 19e5a7f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+12232
-0
lines changed

.github/workflows/build.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Build & Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
workflow_dispatch:
8+
9+
jobs:
10+
build:
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
include:
15+
- platform: 'macos-latest'
16+
args: '--target universal-apple-darwin'
17+
- platform: 'ubuntu-22.04'
18+
args: ''
19+
- platform: 'windows-latest'
20+
args: ''
21+
22+
runs-on: ${{ matrix.platform }}
23+
steps:
24+
- uses: actions/checkout@v4
25+
26+
- name: Setup Node
27+
uses: actions/setup-node@v4
28+
with:
29+
node-version: lts/*
30+
31+
- name: Install Rust stable
32+
uses: dtolnay/rust-action@stable
33+
34+
- name: Install dependencies (Ubuntu only)
35+
if: matrix.platform == 'ubuntu-22.04'
36+
run: |
37+
sudo apt-get update
38+
sudo apt-get install -y libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf
39+
40+
- name: Install frontend dependencies
41+
run: npm install && cd frontend && npm install
42+
43+
- name: Build Tauri app
44+
uses: tauri-apps/tauri-action@v0
45+
env:
46+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
47+
with:
48+
tagName: ${{ github.ref_name }}
49+
releaseName: 'MCP Inspector ${{ github.ref_name }}'
50+
releaseBody: 'See the assets to download and install this version.'
51+
releaseDraft: true
52+
prerelease: false
53+
args: ${{ matrix.args }}

.gitignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Rust
2+
/target/
3+
Cargo.lock
4+
5+
# IDE
6+
.vscode/
7+
.idea/
8+
*.swp
9+
*.swo
10+
*~
11+
12+
# OS
13+
.DS_Store
14+
Thumbs.db
15+
16+
# Logs
17+
*.log

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[workspace]
2+
members = ["src-tauri"]

DEVELOPMENT.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# 开发说明
2+
3+
## 项目架构
4+
5+
### 模块划分
6+
7+
```
8+
mcp-inspector
9+
├── main.rs - 应用入口,CLI 参数解析
10+
├── mcp/ - MCP 客户端模块
11+
│ ├── client.rs - 核心客户端实现
12+
│ └── ... - 各功能模块
13+
├── logging/ - 日志系统
14+
│ ├── collector.rs - 日志收集
15+
│ ├── formatter.rs - 日志格式化
16+
│ └── storage.rs - 日志存储
17+
└── ui/ - 用户界面
18+
├── app.rs - TUI 主应用
19+
└── components/ - UI 组件
20+
```
21+
22+
### 关键设计决策
23+
24+
1. **异步架构**: 使用 Tokio 异步运行时,支持高效的 I/O 操作
25+
2. **模块化设计**: 清晰的模块划分,便于维护和扩展
26+
3. **类型安全**: 充分利用 Rust 的类型系统,减少运行时错误
27+
4. **错误处理**: 使用 `anyhow``Result` 类型,统一错误处理
28+
29+
## 扩展指南
30+
31+
### 添加新的 MCP 功能
32+
33+
1.`src/mcp/client.rs` 中添加新方法
34+
2. 在 UI 中添加对应的显示逻辑
35+
3. 更新文档
36+
37+
### 添加新的 UI 组件
38+
39+
1.`src/ui/components/` 中创建新文件
40+
2.`src/ui/app.rs` 中集成组件
41+
3. 添加键盘快捷键支持
42+
43+
### 自定义日志格式
44+
45+
修改 `src/logging/formatter.rs` 中的 `format` 方法
46+
47+
## 性能优化建议
48+
49+
1. **日志缓冲**: 当前限制为 1000 条,可根据需要调整
50+
2. **UI 刷新率**: 当前为 100ms,可根据性能需求调整
51+
3. **发布构建**: 使用 `--release` 标志获得最佳性能
52+
53+
## 调试技巧
54+
55+
### 启用详细日志
56+
57+
```bash
58+
RUST_LOG=trace ./target/debug/mcp-inspector --server ...
59+
```
60+
61+
### 使用 Rust 调试器
62+
63+
```bash
64+
rust-gdb ./target/debug/mcp-inspector
65+
```
66+
67+
## 常见问题
68+
69+
### Q: 如何支持新的传输协议?
70+
71+
A: 在 `src/mcp/client.rs` 中的 `McpClient::new_from_command` 方法中添加新的传输类型支持。
72+
73+
### Q: 如何添加新的标签页?
74+
75+
A:
76+
1.`Tab` 枚举中添加新变体
77+
2. 更新 `titles()` 和转换方法
78+
3.`render()` 方法中添加渲染逻辑
79+
80+
### Q: 如何自定义 UI 主题?
81+
82+
A: 修改 `src/ui/app.rs` 中的 `Style` 定义,使用不同的颜色和样式。
83+
84+
## 贡献指南
85+
86+
1. Fork 项目
87+
2. 创建特性分支 (`git checkout -b feature/amazing-feature`)
88+
3. 提交更改 (`git commit -m 'Add amazing feature'`)
89+
4. 推送到分支 (`git push origin feature/amazing-feature`)
90+
5. 创建 Pull Request
91+
92+
## 代码风格
93+
94+
- 使用 `cargo fmt` 格式化代码
95+
- 使用 `cargo clippy` 检查代码质量
96+
- 遵循 Rust 官方风格指南

README.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# MCP Inspector
2+
3+
基于 Tauri 2 + Vue 3 重新实现的 MCP (Model Context Protocol) 检查器,前端由 Vue 负责渲染工具/资源/提示与日志面板,Rust 后端透过 Tauri 命令调用 `rmcp` 客户端并与 MCP 服务器交互。
4+
5+
## 目录结构
6+
7+
- `frontend/`:Vue 3 + Vite 单页应用,渲染界面并通过 `@tauri-apps/api/tauri``invoke` 调用 Rust 命令(`connect_mcp`, `list_tools`, `call_tool`, 等)。
8+
- `src-tauri/`:Tauri 2 Rust 后端,包含所有 MCP 通道逻辑,利用 `rmcp``reqwest` 向服务器发起请求,并返回 JSON 结构给前端。
9+
- `Cargo.toml`:工作区配置,仅包含 `src-tauri` crate。
10+
11+
## 运行
12+
13+
### 准备
14+
15+
1. 安装 Node.js 与 npm/yarn;
16+
2. 安装 Rust toolchain(stable)和 Tauri CLI(`cargo install tauri-cli`)。
17+
3. 若在 Linux 上构建,确保系统提供 [WebKitGTK](https://webkitgtk.org/),例如通过 `sudo apt install libwebkit2gtk-4.1-dev` 以满足 Tauri/Wry 的 C 依赖,否则 `cargo tauri build`/`cargo check` 会报缺少 `webkit2gtk-4.1`
18+
19+
### 开发模式
20+
21+
```bash
22+
cd frontend
23+
npm install
24+
npm run tauri
25+
```
26+
27+
该命令会先启动 Vite 开发服务器(`localhost:5173`),再通过 Tauri 打开桌面窗口。修改 Vue 文件会自动热更新。
28+
29+
### 构建发布
30+
31+
```bash
32+
cd frontend
33+
npm install
34+
npm run build
35+
cd ../src-tauri
36+
cargo tauri build
37+
```
38+
39+
Vue 资产会被打包到 `frontend/dist`,Tauri 会将其嵌入最终应用。
40+
41+
## 后端命令
42+
43+
Rust 侧提供以下 `tauri::command` 接口供 Vue 调用:
44+
45+
- `connect_mcp(payload)`:连接 MCP 服务器,可以传入 `url`(默认 `http://localhost:8000/mcp`)与一组 `HeaderPair`,命令会在结果里返回已经发送的 headers 以方便前端记录。
46+
- `list_tools()` / `list_resources()` / `list_prompts()`:返回简化的工具/资源/提示结构供前端渲染。
47+
- `call_tool({ name, args })`:调用工具时传入 optional JSON 对象(UI 会根据 schema 或 raw JSON 自动拼装),命令只接受对象类型以避免非结构化 payload。
48+
49+
这些命令都共享一个 `McpSession`,它在全局状态里维护 `rmcp::service::RunningService` 实例,确保前端调用期间连接不会被重建。
50+
51+
## 前端交互
52+
53+
- 顶部连接面板允许指定服务器 URL、维护一组 header 并展示最后一次连接的 URL/headers 与连接按钮,操作结果会写入日志流。
54+
- 左侧工具卡片展示名称/描述,并根据工具的 `input_schema.properties` 自动生成字段输入;若未提供 schema,则支持自由 JSON 并会校验是否为对象。
55+
- 右侧面板依次展示 Resources、Prompts 与日志信息,日志也会记录调用工具/连接的返回值与错误。
56+
- 顶部状态栏显示连接状态,Vue 插件 `@tauri-apps/api``invoke` 用于向 Rust 发送命令。
57+
58+
## 技术栈
59+
60+
- Rust + Tauri:负责 MCP 通信与命令暴露。
61+
- Vue 3 + Vite:提供响应式界面与表单控件。
62+
- rmcp:官方 MCP Rust SDK。
63+
- reqwest + sse-stream:实现可容忍省略 `Content-Type` 的 SSE transport。
64+
65+
## 贡献
66+
67+
欢迎提交 Issue 或 Pull Request;如果需要扩展工具调用、添加提示模板、或替换 UI 样式都可以在 frontend 里进行迭代。

frontend/.gitignore

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
.DS_Store
12+
dist
13+
dist-ssr
14+
coverage
15+
*.local
16+
17+
# Editor directories and files
18+
.vscode/*
19+
!.vscode/extensions.json
20+
.idea
21+
*.suo
22+
*.ntvs*
23+
*.njsproj
24+
*.sln
25+
*.sw?
26+
27+
*.tsbuildinfo
28+
29+
.eslintcache
30+
31+
# Cypress
32+
/cypress/videos/
33+
/cypress/screenshots/
34+
35+
# Vitest
36+
__screenshots__/

frontend/README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# frontend
2+
3+
This template should help get you started developing with Vue 3 in Vite.
4+
5+
## Recommended IDE Setup
6+
7+
[VS Code](https://code.visualstudio.com/) + [Vue (Official)](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur).
8+
9+
## Recommended Browser Setup
10+
11+
- Chromium-based browsers (Chrome, Edge, Brave, etc.):
12+
- [Vue.js devtools](https://chromewebstore.google.com/detail/vuejs-devtools/nhdogjmejiglipccpnnnanhbledajbpd)
13+
- [Turn on Custom Object Formatter in Chrome DevTools](http://bit.ly/object-formatters)
14+
- Firefox:
15+
- [Vue.js devtools](https://addons.mozilla.org/en-US/firefox/addon/vue-js-devtools/)
16+
- [Turn on Custom Object Formatter in Firefox DevTools](https://fxdx.dev/firefox-devtools-custom-object-formatters/)
17+
18+
## Customize configuration
19+
20+
See [Vite Configuration Reference](https://vite.dev/config/).
21+
22+
## Project Setup
23+
24+
```sh
25+
npm install
26+
```
27+
28+
### Compile and Hot-Reload for Development
29+
30+
```sh
31+
npm run dev
32+
```
33+
34+
### Compile and Minify for Production
35+
36+
```sh
37+
npm run build
38+
```

frontend/index.html

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!DOCTYPE html>
2+
<html lang="zh-CN">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" href="/favicon.ico" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<meta name="description" content="MCP Inspector - 探索和调试 MCP 服务器的工具、资源和提示" />
8+
<meta name="theme-color" content="#0a0e1a" />
9+
10+
<!-- Preconnect to Google Fonts -->
11+
<link rel="preconnect" href="https://fonts.googleapis.com">
12+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
13+
14+
<!-- Google Fonts -->
15+
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">
16+
17+
<title>MCP Inspector</title>
18+
19+
<style>
20+
/* Prevent FOUC */
21+
html {
22+
background: #0a0e1a;
23+
}
24+
</style>
25+
</head>
26+
<body>
27+
<div id="app"></div>
28+
<script type="module" src="/src/main.ts"></script>
29+
</body>
30+
</html>

frontend/jsconfig.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"compilerOptions": {
3+
"paths": {
4+
"@/*": ["./src/*"]
5+
}
6+
},
7+
"exclude": ["node_modules", "dist"]
8+
}

0 commit comments

Comments
 (0)