内容
<p align="center">
<img src="divlensmainlogo.png" width="120" alt="DivLens Logo" />
</p>
<h1 align="center">DivLens MCP</h1>
<p align="center">
<strong>AI 代理的实时系统智能</strong><br/>
为 Claude、Cursor 和 Windsurf 提供机器的眼睛 — CPU、RAM、磁盘、网络、进程、硬件健康等。
</p>
<p align="center">
<a href="https://opensource.org/licenses/Apache-2.0">
<img src="https://img.shields.io/badge/License-Apache%202.0-orange.svg" alt="License: Apache 2.0" />
</a>
<a href="https://www.rust-lang.org">
<img src="https://img.shields.io/badge/Built%20with-Rust-orange.svg?logo=rust" alt="Built with Rust" />
</a>
<img src="https://img.shields.io/badge/MCP-Compatible-orange.svg" alt="MCP Compatible" />
<img src="https://img.shields.io/badge/Platform-macOS%20%7C%20Windows%20%7C%20Linux-orange.svg" alt="Platform" />
<img src="https://img.shields.io/badge/Version-0.1.0-orange.svg" alt="Version" />
</p>
<p align="center">
<img src="https://img.shields.io/badge/Claude-Compatible-blueviolet?logo=anthropic" alt="Claude" />
<img src="https://img.shields.io/badge/Cursor-Compatible-blue?logo=cursor" alt="Cursor" />
<img src="https://img.shields.io/badge/Windsurf-Compatible-teal" alt="Windsurf" />
<img src="https://img.shields.io/badge/Zero%20Cloud-100%25%20Local-brightgreen" alt="Zero Cloud" />
</p>
---
## 什么是 DivLens MCP?
**DivLens MCP** 是一个高性能的 [模型上下文协议(MCP)](https://modelcontextprotocol.io) 服务器,使用 Rust 编写。
它弥合了 AI 助手和您的机器之间的差距,为 Claude、Cursor、Windsurf 以及其他任何 MCP 兼容的代理提供 **实时、结构化的访问** 到硬件传感器、存储指标、网络诊断、进程树、开发运行时、系统日志等。
无需云服务。无需 API 密钥。无需配置。只需构建并运行。
```
"为什么我的 Mac 很慢?" → Claude 调用 get_live_metrics() → 立即得到答案。
"我的 SSD 健康吗?" → Claude 调用 get_hardware_diagnostics() → 返回 SMART 数据。
"什么占用了磁盘?" → Claude 调用 get_advanced_storage_stats() → 列出最大的文件。
```
---
## ✦ 17 个诊断工具
| 类别 | 工具 | 返回内容 |
| :--- | :--- | :--- |
| ⚡ **性能** | `get_live_metrics` | CPU 使用率、RAM、交换内存、阻塞进程、运行时间 |
| ⚡ **性能** | `get_process_list` | 按 CPU/RAM 排序的进程列表,附带 PID |
| 💾 **存储** | `get_storage_health` | 每个挂载点的可用/已用/总大小 |
| 💾 **存储** | `scan_storage_inventory` | 完整的按文件类型分类的库存,附带大小 |
| 💾 **存储** | `get_file_type_summary` | 按扩展名分类的文件数量和大小 |
| 💾 **存储** | `get_specific_file_type` | 所有匹配特定扩展名的文件 |
| 💾 **存储** | `get_advanced_storage_stats` | 50 个最大的文件 + 陈旧数据分析 |
| 💾 **存储** | `get_storage_diagnostics` | IOPS、读写延迟、SMART 状态 |
| 🖥️ **硬件** | `get_hardware_diagnostics` | CPU/GPU 规格、电池百分比、温度、SMART |
| 🌐 **网络** | `get_network_diagnostics` | 吞吐量、活动连接、信号 |
| 🌐 **网络** | `get_network_config` | IP、DNS、接口配置(每个适配器) |
| 🔬 **身份** | `get_system_dna` | 操作系统、主机名、运行时间、机器指纹 |
| 🛠️ **开发栈** | `get_dev_stack` | Node、Python、Rust、Go、Java 运行环境 + 包 |
| 🛠️ **开发栈** | `get_drivers` | 内核模块和设备驱动程序 |
| 📂 **实用工具** | `scan_directory` | 递归目录列表,附带大小 |
| 🧠 **内存** | `recall_memory` | 过去 AI 诊断的语义搜索 |
| 📋 **日志** | `get_system_logs` | 最近的操作系统/内核错误,按模式分类 |
---
## 🚀 安装 — 一个命令,任何平台
> **无需 Rust。不需要编译。不需要手动编辑配置。**
> 安装程序下载预构建的二进制文件并自动配置您的 AI 客户端。
### macOS 和 Linux
```bash
curl -fsSL https://raw.githubusercontent.com/Lohithry/divlens-mcp/main/install.sh | bash
```
### Windows(PowerShell — 无需管理员权限)
```powershell
irm https://raw.githubusercontent.com/Lohithry/divlens-mcp/main/install.ps1 | iex
```
安装程序将:
- ✅ 检测您的操作系统和芯片(Apple Silicon / Intel / Linux / Windows)
- ✅ 从 GitHub Releases 下载正确的预构建二进制文件
- ✅ 验证 SHA-256 校验和
- ✅ 安装到您的 PATH,无需管理员权限
- ✅ 自动配置 **Claude Desktop**、**Cursor**、**Windsurf** 和 **Antigravity**
- ✅ 在完成前测试服务器是否正常工作
然后只需 **重启您的 AI 客户端** 并询问 *"现在我的 CPU 占用率是多少?"*
---
### 从源代码构建(高级)
需要 [Rust](https://rustup.rs/) 1.82+。
```bash
git clone https://github.com/Lohithry/divlens-mcp.git
cd divlens-mcp/apps/core
cargo build --release
./target/release/divlens-core --mcp
```
---
## 连接到您的 AI
### Claude Desktop
> 配置文件:`~/Library/Application Support/Claude/claude_desktop_config.json`(macOS)
> 或 `%APPDATA%\Claude\claude_desktop_config.json`(Windows)
```jsonc
{
"mcpServers": {
"divlens": {
"command": "/usr/local/bin/divlens-core",
"args": ["--mcp"]
}
}
}
```
退出并重新启动 Claude Desktop。🔌 插件图标确认连接。
### Cursor
> 配置文件:`~/.cursor/mcp.json`
```jsonc
{
"mcpServers": {
"divlens": {
"command": "/usr/local/bin/divlens-core",
"args": ["--mcp"]
}
}
}
```
`Cmd+Shift+P` → *Reload Window*
### Windsurf
> 配置文件:`~/.codeium/windsurf/mcp_config.json`
```jsonc
{
"mcpServers": {
"divlens": {
"command": "/usr/local/bin/divlens-core",
"args": ["--mcp"]
}
}
}
```
有关完整的设置详情,请参阅 **[DEPLOYMENT.md](DEPLOYMENT.md)**。
---
## 工作原理
```
┌─────────────────────────────────────────┐
│ AI 客户端 (Claude / Cursor / 等) │
│ LLM 推理在此进行 │
└──────────────────┬──────────────────────┘
│ JSON-RPC 2.0 (stdio)
▼
┌─────────────────────────────────────────┐
│ divlens-core (Rust) │
│ │
│ ┌───────────────┐ ┌───────────────┐ │
│ │ MCP 层 │ │ 17 个工具 │ │
│ │ (JSON-RPC) │ │ (Rust + 操作系统) │ │
│ └───────────────┘ └───────────────┘ │
│ ┌───────────────┐ ┌───────────────┐ │
│ │ SQLite 缓存 │ │ 原始 API │ │
│ │ (系统信息/操作系统) │ │ (IOKit/WMI) │ │
│ └───────────────┘ └───────────────┘ │
└─────────────────────────────────────────┘
零云。零 API 密钥。100% 本地。
```
**传输:** 每个 MCP 消息都是一个换行符分隔的 JSON-RPC 2.0 对象,通过 stdio 传输。
**AI 逻辑:** DivLens 从不运行 LLM 推理 — 它只收集和返回原始系统数据。
**隐私:** 所有数据都保留在您的机器上。没有任何数据被发送到其他地方。
---
## 项目结构
```
divlens-mcp/
└── apps/
└── core/ # Rust MCP 引擎
├── src/
│ ├── tools/ # 17 个工具的实现
│ ├── mcp/ # JSON-RPC 2.0 协议处理程序
│ ├── mcp_server.rs # stdio 传输循环
│ ├── collectors/ # 原始操作系统数据收集器
│ │ ├── volatile/ # CPU、RAM、网络(实时)
│ │ ├── persistent/ # 存储、硬件(缓存)
│ │ └── ondemand/ # 驱动程序、日志、包
│ ├── modules/ # 核心业务逻辑
│ ├── db/ # SQLite 缓存层
│ ├── models/ # 共享数据类型
│ └── utils/ # Shell 环境恢复
├── Cargo.toml
└── env.example
```
---
## 可选:语义内存
启用 `vector-memory` 功能,以使用本地 ONNX 嵌入模型(无云,无 API 密钥)为 `recall_memory` 提供真正的语义搜索:
```bash
cargo build --release --features vector-memory
```
启用后,DivLens 创建一个本地 [LanceDB](https://lancedb.github.io/lancedb/) 矩阵存储,并使用 [fastembed](https://github.com/Anush008/fastembed-rs) 来嵌入和语义召回过去的诊断。
禁用时(默认),`recall_memory` 返回一个空列表 — 不会破坏任何功能。
---
## 验证服务器
在没有客户端的情况下测试 MCP 线路协议:
```bash
# 初始化握手
echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","clientInfo":{"name":"test","version":"0.1"}}}' \
| divlens-core --mcp
# 直接调用工具
echo '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"get_live_metrics","arguments":{}}}' \
| divlens-core --mcp
```
---
## 许可证
在 **Apache License, Version 2.0** 下许可。
请参阅 [LICENSE](LICENSE) 以获取完整文本。
版权所有 © 2024 DivLens Contributors。
---
<p align="center">
<img src="divlensmainlogo.png" width="48" alt="DivLens" /><br/>
<sub>使用 ❤️ 在 Rust 中构建 · 零云 · AI 原生诊断</sub>
</p>