systeminfo_rust_mcp

Crates.iosysteminfo_rust_mcp
lib.rssysteminfo_rust_mcp
version0.0.1
created_at2025-12-17 03:00:08.460784+00
updated_at2025-12-17 03:00:08.460784+00
descriptionA Model Context Protocol (MCP) server for system information retrieval
homepage
repositoryhttps://gitee.com/awol20101ex/systeminfo_rust_mcp
max_upload_size
id1989226
size51,436
(awol2005ex)

documentation

README

System Info MCP Server | 系统信息 MCP 服务器

English | 中文


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)
  • Cargo (included with Rust)

Building from Source

Clone the Repository

git clone <repository-url>
cd systeminfo_rust_mcp

Build the Project

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

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:

.\target\release\systeminfo_rust_mcp.exe

Linux/macOS:

./target/release/systeminfo_rust_mcp

Method 2: Add to PATH

Add the binary to your system PATH for global access:

Windows:

# Copy to a directory in your PATH
copy target\release\systeminfo_rust_mcp.exe C:\Windows\System32\

Linux/macOS:

# 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:

    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:

    {
      "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:

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

cargo run

Example Requests

Initialize Connection

{"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": null}

List Available Tools

{"jsonrpc": "2.0", "id": 2, "method": "tools/list", "params": null}

Get System Information

{"jsonrpc": "2.0", "id": 3, "method": "tools/call", "params": {"name": "get_system_info", "arguments": {}}}

Get CPU Information

{"jsonrpc": "2.0", "id": 4, "method": "tools/call", "params": {"name": "get_cpu_info", "arguments": {}}}

Get Disk Information

{"jsonrpc": "2.0", "id": 5, "method": "tools/call", "params": {"name": "get_disk_info", "arguments": {}}}

Get Network Information

{"jsonrpc": "2.0", "id": 6, "method": "tools/call", "params": {"name": "get_network_info", "arguments": {}}}

Get Process Information

{"jsonrpc": "2.0", "id": 7, "method": "tools/call", "params": {"name": "get_process_info", "arguments": {}}}

Testing with Python

Create a simple test script:

#!/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:

{
  "jsonrpc": "2.0",
  "id": <request_id>,
  "result": {
    "content": [
      {
        "type": "text",
        "text": "<json_formatted_data>",
        "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

cargo test

Building Documentation

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:

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 file for details.

Copyright 2024 [Your Name or Organization]

Acknowledgments

  • Built with the excellent 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 安装)
  • Cargo (随Rust一起提供)

从源码构建

克隆仓库

git clone <repository-url>
cd systeminfo_rust_mcp

构建项目

cargo build --release

这将在 target/release/systeminfo_rust_mcp.exe (Windows) 或 target/release/systeminfo_rust_mcp (Linux/macOS) 创建优化的二进制文件。

开发构建

cargo build

target/debug/systeminfo_rust_mcp.exe (Windows) 或 target/debug/systeminfo_rust_mcp (Linux/macOS) 创建调试二进制文件。

安装方法

方法1:直接使用二进制文件

构建后,您可以直接使用二进制文件:

Windows:

.\target\release\systeminfo_rust_mcp.exe

Linux/macOS:

./target/release/systeminfo_rust_mcp

方法2:添加到PATH

将二进制文件添加到系统PATH以实现全局访问:

Windows:

# 复制到PATH中的目录
copy target\release\systeminfo_rust_mcp.exe C:\Windows\System32\

Linux/macOS:

# 复制到/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. 首先构建项目:

    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

    添加以下配置:

    {
      "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:

cargo install systeminfo_rust_mcp

使用方法

服务器通过stdio使用JSON-RPC 2.0协议进行通信。以JSON行(换行分隔)的形式发送请求。

启动服务器

cargo run

示例请求

初始化连接
{"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": null}
列出可用工具
{"jsonrpc": "2.0", "id": 2, "method": "tools/list", "params": null}
获取系统信息
{"jsonrpc": "2.0", "id": 3, "method": "tools/call", "params": {"name": "get_system_info", "arguments": {}}}
获取CPU信息
{"jsonrpc": "2.0", "id": 4, "method": "tools/call", "params": {"name": "get_cpu_info", "arguments": {}}}
获取磁盘信息
{"jsonrpc": "2.0", "id": 5, "method": "tools/call", "params": {"name": "get_disk_info", "arguments": {}}}
获取网络信息
{"jsonrpc": "2.0", "id": 6, "method": "tools/call", "params": {"name": "get_network_info", "arguments": {}}}
获取进程信息
{"jsonrpc": "2.0", "id": 7, "method": "tools/call", "params": {"name": "get_process_info", "arguments": {}}}

使用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 按资源使用排序的顶级进程信息

响应格式

所有工具调用都返回以下格式的响应:

{
  "jsonrpc": "2.0",
  "id": <请求ID>,
  "result": {
    "content": [
      {
        "type": "text",
        "text": "<JSON格式化的数据>",
        "mime_type": "application/json"
      }
    ],
    "is_error": false
  },
  "error": null
}

开发

项目结构

systeminfo_rust_mcp/
├── Cargo.toml          # 项目依赖
├── src/
│   └── main.rs        # 主服务器实现
└── README.md          # 此文件

依赖项

  • serde & serde_json: JSON序列化
  • sysinfo: 跨平台系统信息

运行测试

cargo test

构建文档

cargo doc --open

跨平台支持

此服务器适用于:

  • Windows: 完全支持所有功能
  • Linux: 完全支持所有功能
  • macOS: 完全支持所有功能
  • 其他平台: 根据sysinfocrate的功能提供有限支持

故障排除

常见问题

  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验证错误": 已修复 - 工具使用正确的驼峰命名字段名

调试模式

使用调试输出运行:

RUST_LOG=debug cargo run

贡献

  1. Fork仓库
  2. 创建功能分支
  3. 进行更改
  4. 如适用,添加测试
  5. 提交拉取请求

许可证

本项目采用Apache License 2.0许可证 - 详见 LICENSE 文件。

版权所有 2024 [awol2005ex]

致谢

  • 使用优秀的sysinfocrate构建
  • 遵循模型上下文协议规范
Commit count: 0

cargo fmt