# systeminfo_rust_mcp **Repository Path**: awol2010ex/systeminfo_rust_mcp ## Basic Information - **Project Name**: systeminfo_rust_mcp - **Description**: A Model Context Protocol (MCP) server that provides comprehensive system information through stdio line mode communication. Built with Rust and the `sysinfo` crate for cross-platform compatibility. - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-12-17 - **Last Updated**: 2025-12-17 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # System Info MCP Server | 系统信息 MCP 服务器 **[English](#english) | [中文](#chinese)** --- ## English | 英文 A Model Context Protocol (MCP) server that provides comprehensive system information through stdio line mode communication. Built with Rust and the `sysinfo` crate for cross-platform compatibility. ## Features - **System Information**: Hostname, OS details, memory usage, uptime, boot time - **CPU Information**: CPU count, frequency, usage statistics per core - **Disk Information**: Disk space, mount points, file systems, removable status - **Network Information**: Network interface statistics, MAC addresses, traffic data - **Process Information**: Top 20 processes with resource usage and status - **MCP Protocol Compliance**: Full JSON-RPC 2.0 implementation over stdio - **Trae IDE Compatible**: Optimized for Trae IDE integration with proper error handling - **Cross-Platform**: Works on Windows, Linux, and macOS ## Prerequisites - Rust 1.70+ (install from [rustup.rs](https://rustup.rs/)) - Cargo (included with Rust) ## Building from Source ### Clone the Repository ```bash git clone cd systeminfo_rust_mcp ``` ### Build the Project ```bash cargo build --release ``` This will create an optimized binary at `target/release/systeminfo_rust_mcp.exe` (Windows) or `target/release/systeminfo_rust_mcp` (Linux/macOS). ### Development Build ```bash cargo build ``` Creates a debug binary at `target/debug/systeminfo_rust_mcp.exe` (Windows) or `target/debug/systeminfo_rust_mcp` (Linux/macOS). ## Installation Methods ### Method 1: Direct Binary Usage After building, you can use the binary directly: **Windows:** ```powershell .\target\release\systeminfo_rust_mcp.exe ``` **Linux/macOS:** ```bash ./target/release/systeminfo_rust_mcp ``` ### Method 2: Add to PATH Add the binary to your system PATH for global access: **Windows:** ```powershell # Copy to a directory in your PATH copy target\release\systeminfo_rust_mcp.exe C:\Windows\System32\ ``` **Linux/macOS:** ```bash # Copy to /usr/local/bin (requires sudo) sudo cp target/release/systeminfo_rust_mcp /usr/local/bin/ sudo chmod +x /usr/local/bin/systeminfo_rust_mcp ``` ### Method 3: Trae IDE Installation For Trae IDE users, you can install this MCP server directly: 1. **Build the project first:** ```bash cargo build --release ``` 2. **Add to Trae MCP configuration:** Create or edit the MCP configuration file in Trae: - **Windows**: `%APPDATA%\Trae\User\settings.json` - **macOS**: `~/Library/Application Support/Trae/User/settings.json` - **Linux**: `~/.config/Trae/User/settings.json` Add the following configuration: ```json { "mcp.servers": { "systeminfo": { "command": "path/to/your/systeminfo_rust_mcp.exe", "args": [], "env": {} } } } ``` Replace `path/to/your/systeminfo_rust_mcp.exe` with the actual path to your built binary. 3. **Restart Trae IDE** to load the new MCP server. ### Method 4: Cargo Install (if published) If the crate is published to crates.io: ```bash cargo install systeminfo_rust_mcp ``` ## Usage The server communicates via stdio using JSON-RPC 2.0 protocol. Send requests as JSON lines (newline-delimited). ### Starting the Server ```bash cargo run ``` ### Example Requests #### Initialize Connection ```json {"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": null} ``` #### List Available Tools ```json {"jsonrpc": "2.0", "id": 2, "method": "tools/list", "params": null} ``` #### Get System Information ```json {"jsonrpc": "2.0", "id": 3, "method": "tools/call", "params": {"name": "get_system_info", "arguments": {}}} ``` #### Get CPU Information ```json {"jsonrpc": "2.0", "id": 4, "method": "tools/call", "params": {"name": "get_cpu_info", "arguments": {}}} ``` #### Get Disk Information ```json {"jsonrpc": "2.0", "id": 5, "method": "tools/call", "params": {"name": "get_disk_info", "arguments": {}}} ``` #### Get Network Information ```json {"jsonrpc": "2.0", "id": 6, "method": "tools/call", "params": {"name": "get_network_info", "arguments": {}}} ``` #### Get Process Information ```json {"jsonrpc": "2.0", "id": 7, "method": "tools/call", "params": {"name": "get_process_info", "arguments": {}}} ``` ### Testing with Python Create a simple test script: ```python #!/usr/bin/env python3 import json import subprocess # Start the server process = subprocess.Popen( ["cargo", "run"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True ) # Send a request request = json.dumps({ "jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": {"name": "get_system_info", "arguments": {}} }) + "\n" process.stdin.write(request) process.stdin.flush() # Read response response = process.stdout.readline() print("Response:", response) # Terminate process.terminate() ``` ## Available Tools | Tool Name | Description | |-----------|-------------| | `get_system_info` | Basic system information including hostname, OS, memory, etc. | | `get_cpu_info` | Detailed CPU information including usage and frequency | | `get_disk_info` | Disk information including space and mount points | | `get_network_info` | Network interface information including traffic statistics | | `get_process_info` | Top processes information sorted by resource usage | ## Response Format All tool calls return responses in this format: ```json { "jsonrpc": "2.0", "id": , "result": { "content": [ { "type": "text", "text": "", "mime_type": "application/json" } ], "is_error": false }, "error": null } ``` ## Development ### Project Structure ``` systeminfo_rust_mcp/ ├── Cargo.toml # Project dependencies ├── src/ │ └── main.rs # Main server implementation └── README.md # This file ``` ### Dependencies - `serde` & `serde_json`: JSON serialization - `sysinfo`: Cross-platform system information ### Running Tests ```bash cargo test ``` ### Building Documentation ```bash cargo doc --open ``` ## Cross-Platform Support This server works on: - **Windows**: Full support with all features - **Linux**: Full support with all features - **macOS**: Full support with all features - **Other platforms**: Limited support depending on `sysinfo` crate capabilities ## Troubleshooting ### Common Issues 1. **JSON Parse Errors**: Ensure the server only outputs JSON-RPC messages to stdout 2. **ID Field Validation**: The server properly handles requests with/without ID fields 3. **InputSchema Validation**: Tools use correct `inputSchema` field format 4. **Port Already in Use**: This server uses stdio, not network ports 5. **Permission Denied**: Ensure you have proper file system permissions 6. **Missing Dependencies**: Run `cargo build` to download dependencies ### Trae IDE Specific Issues 1. **"Unrecognized key(s) in object: 'error'"**: Fixed - server now conditionally serializes error field 2. **"Expected string, received null"**: Fixed - server properly handles requests without ID 3. **"InputSchema validation errors"**: Fixed - tools use correct camelCase field names ### Debug Mode Run with debug output: ```bash RUST_LOG=debug cargo run ``` ## Contributing 1. Fork the repository 2. Create a feature branch 3. Make your changes 4. Add tests if applicable 5. Submit a pull request ## License This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details. Copyright 2024 [Your Name or Organization] ## Acknowledgments - Built with the excellent [sysinfo](https://crates.io/crates/sysinfo) crate - Follows the Model Context Protocol specification - Inspired by the Rust MCP SDK project --- ## 中文 | Chinese ### 功能特性 - **系统信息**: 主机名、操作系统详情、内存使用、运行时间 - **CPU信息**: CPU数量、频率、每个核心的使用统计 - **磁盘信息**: 磁盘空间、挂载点、文件系统、可移动状态 - **网络信息**: 网络接口统计、MAC地址、流量数据 - **进程信息**: 前20个进程的资源使用和状态 - **MCP协议兼容**: 基于stdio的完整JSON-RPC 2.0实现 - **Trae IDE兼容**: 针对Trae IDE集成优化,具备正确的错误处理 - **跨平台**: 支持Windows、Linux和macOS ### 前提条件 - Rust 1.70+ (从 [rustup.rs](https://rustup.rs/) 安装) - Cargo (随Rust一起提供) ### 从源码构建 #### 克隆仓库 ```bash git clone cd systeminfo_rust_mcp ``` #### 构建项目 ```bash cargo build --release ``` 这将在 `target/release/systeminfo_rust_mcp.exe` (Windows) 或 `target/release/systeminfo_rust_mcp` (Linux/macOS) 创建优化的二进制文件。 #### 开发构建 ```bash cargo build ``` 在 `target/debug/systeminfo_rust_mcp.exe` (Windows) 或 `target/debug/systeminfo_rust_mcp` (Linux/macOS) 创建调试二进制文件。 ### 安装方法 #### 方法1:直接使用二进制文件 构建后,您可以直接使用二进制文件: **Windows:** ```powershell .\target\release\systeminfo_rust_mcp.exe ``` **Linux/macOS:** ```bash ./target/release/systeminfo_rust_mcp ``` #### 方法2:添加到PATH 将二进制文件添加到系统PATH以实现全局访问: **Windows:** ```powershell # 复制到PATH中的目录 copy target\release\systeminfo_rust_mcp.exe C:\Windows\System32\ ``` **Linux/macOS:** ```bash # 复制到/usr/local/bin (需要sudo) sudo cp target/release/systeminfo_rust_mcp /usr/local/bin/ sudo chmod +x /usr/local/bin/systeminfo_rust_mcp ``` #### 方法3:Trae IDE安装 对于Trae IDE用户,您可以直接安装此MCP服务器: 1. **首先构建项目:** ```bash cargo build --release ``` 2. **添加到Trae MCP配置:** 在Trae中创建或编辑MCP配置文件: - **Windows**: `%APPDATA%\Trae\User\settings.json` - **macOS**: `~/Library/Application Support/Trae/User/settings.json` - **Linux**: `~/.config/Trae/User/settings.json` 添加以下配置: ```json { "mcp.servers": { "systeminfo": { "command": "path/to/your/systeminfo_rust_mcp.exe", "args": [], "env": {} } } } ``` 将 `path/to/your/systeminfo_rust_mcp.exe` 替换为您构建的二进制文件的实际路径。 3. **重启Trae IDE** 以加载新的MCP服务器。 #### 方法4:Cargo安装(如果发布) 如果crate发布到crates.io: ```bash cargo install systeminfo_rust_mcp ``` ### 使用方法 服务器通过stdio使用JSON-RPC 2.0协议进行通信。以JSON行(换行分隔)的形式发送请求。 #### 启动服务器 ```bash cargo run ``` #### 示例请求 ##### 初始化连接 ```json {"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": null} ``` ##### 列出可用工具 ```json {"jsonrpc": "2.0", "id": 2, "method": "tools/list", "params": null} ``` ##### 获取系统信息 ```json {"jsonrpc": "2.0", "id": 3, "method": "tools/call", "params": {"name": "get_system_info", "arguments": {}}} ``` ##### 获取CPU信息 ```json {"jsonrpc": "2.0", "id": 4, "method": "tools/call", "params": {"name": "get_cpu_info", "arguments": {}}} ``` ##### 获取磁盘信息 ```json {"jsonrpc": "2.0", "id": 5, "method": "tools/call", "params": {"name": "get_disk_info", "arguments": {}}} ``` ##### 获取网络信息 ```json {"jsonrpc": "2.0", "id": 6, "method": "tools/call", "params": {"name": "get_network_info", "arguments": {}}} ``` ##### 获取进程信息 ```json {"jsonrpc": "2.0", "id": 7, "method": "tools/call", "params": {"name": "get_process_info", "arguments": {}}} ``` #### 使用Python测试 创建简单的测试脚本: ```python #!/usr/bin/env python3 import json import subprocess # 启动服务器 process = subprocess.Popen( ["cargo", "run"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True ) # 发送请求 request = json.dumps({ "jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": {"name": "get_system_info", "arguments": {}} }) + "\n" process.stdin.write(request) process.stdin.flush() # 读取响应 response = process.stdout.readline() print("响应:", response) # 终止 process.terminate() ``` ### 可用工具 | 工具名称 | 描述 | |-----------|-------------| | `get_system_info` | 基本系统信息,包括主机名、操作系统、内存等 | | `get_cpu_info` | 详细的CPU信息,包括使用率和频率 | | `get_disk_info` | 磁盘信息,包括空间和挂载点 | | `get_network_info` | 网络接口信息,包括流量统计 | | `get_process_info` | 按资源使用排序的顶级进程信息 | ### 响应格式 所有工具调用都返回以下格式的响应: ```json { "jsonrpc": "2.0", "id": <请求ID>, "result": { "content": [ { "type": "text", "text": "", "mime_type": "application/json" } ], "is_error": false }, "error": null } ``` ### 开发 #### 项目结构 ``` systeminfo_rust_mcp/ ├── Cargo.toml # 项目依赖 ├── src/ │ └── main.rs # 主服务器实现 └── README.md # 此文件 ``` #### 依赖项 - `serde` & `serde_json`: JSON序列化 - `sysinfo`: 跨平台系统信息 #### 运行测试 ```bash cargo test ``` #### 构建文档 ```bash cargo doc --open ``` ### 跨平台支持 此服务器适用于: - **Windows**: 完全支持所有功能 - **Linux**: 完全支持所有功能 - **macOS**: 完全支持所有功能 - **其他平台**: 根据`sysinfo`crate的功能提供有限支持 ### 故障排除 #### 常见问题 1. **JSON解析错误**: 确保服务器只向stdout输出JSON-RPC消息 2. **ID字段验证**: 服务器正确处理带/不带ID字段的请求 3. **InputSchema验证**: 工具使用正确的`inputSchema`字段格式 4. **端口已在使用**: 此服务器使用stdio,不使用网络端口 5. **权限被拒绝**: 确保您具有适当的文件系统权限 6. **缺少依赖项**: 运行`cargo build`下载依赖项 #### Trae IDE特定问题 1. **"对象中存在无法识别的键:'error'"**: 已修复 - 服务器现在有条件地序列化错误字段 2. **"应为字符串,接收到null"**: 已修复 - 服务器正确处理没有ID的请求 3. **"InputSchema验证错误"**: 已修复 - 工具使用正确的驼峰命名字段名 #### 调试模式 使用调试输出运行: ```bash RUST_LOG=debug cargo run ``` ### 贡献 1. Fork仓库 2. 创建功能分支 3. 进行更改 4. 如适用,添加测试 5. 提交拉取请求 ### 许可证 本项目采用Apache License 2.0许可证 - 详见 [LICENSE](LICENSE) 文件。 版权所有 2024 [awol2005ex] ### 致谢 - 使用优秀的[sysinfo](https://crates.io/crates/sysinfo)crate构建 - 遵循模型上下文协议规范