mcp-stama: 面向 AI Agent 的高性能 Rust MCP Server

mcp-stama 是一个使用 Rust 编写的高性能 Model Context Protocol (MCP) server,旨在通过单个静态二进制文件为 AI 编程 agent 提供本地上下文。它消除了与 Node.js 或 Python 运行时相关的开销,将冷启动时间从秒级降低到 2 毫秒以下,并将内存占用从数百兆降低到 10MB 以下。

Performance Benchmarks

在所有主要资源指标上,mcp-stama 的表现都显著优于基于 Node.js 或 Python 构建的传统 MCP server。

Metric Legacy MCP Servers (Node / Python) mcp-stama (Rust)
Cold Startup Time 1,500ms – 3,000ms < 2ms
p50 Execution Latency 150ms – 800ms 300µs – 5ms
Memory Footprint (RSS) 180 MB – 350 MB < 10 MB
Dependencies 100+ packages Zero external runtimes
Installation Requires Node.js / Python setup Single static binary

针对特定工具的内部微基准测试进一步证明了这种效率:

Tool Name Invocations p50 Latency p99 Latency Memory Footprint (RSS)
docker_watcher 100 327 µs 1.66 ms < 10 MB
git_snapshot 100 462 µs 1.36 ms < 10 MB
fast_grep 100 5.05 ms 8.72 ms < 10 MB

Built-in High-Performance Tools

mcp-stama 包含几个专门设计的工具,旨在为 AI agent 提供深度的本地上下文,而无需启动沉重的子进程或浪费 prompt token。

fast_grep

该工具提供亚毫秒级的文件搜索和正则扫描。它利用 ignore::WalkBuilder 来自动遵循 .gitignore.ignore 文件,同时跳过二进制文件和隐藏文件。

git_snapshot

gix (gitoxide) 提供支持,这是一个纯 Rust 的 Git 检查器。它能够原生获取 HEAD commit、分支信息、行差异以及文件状态,从而无需调用外部 git 可执行文件。

docker_watcher

该工具使用 bollardsysinfo 提供即时的宿主机和容器诊断。它能让 AI agent 洞察正在运行的 Docker 容器、系统内存、CPU 核心以及映射端口。

Installation and Configuration

mcp-stama 以单个静态二进制文件形式分发,并包含一个自动配置器,以简化与 AI 编辑器的集成。

Installation

  • macOS / Linux: curl -fsSL https://raw.githubusercontent.com/StamManif/mcp-stama/main/install.sh | sh
  • Windows (PowerShell): iwr -useb https://raw.githubusercontent.com/StamManif/mcp-stama/main/install.ps1 | iex
  • Cargo: cargo install mcp-stama

Auto-Configuration

用户可以使用以下标志位自动将 server 注入到编辑器设置中:

  • Claude Desktop: mcp-stama --install-claude
  • Cursor: mcp-stama --install-cursor

Manual Configuration

对于手动设置,请将以下内容添加到相应的配置文件中(Cursor 使用 ~/.cursor/mcp.json,Claude Desktop 使用 claude_desktop_config.json):

{
  "mcpServers": {
    "mcp-stama": {
      "command": "mcp-stama",
      "args": []
    }
  }
}

Technical Architecture

mcp-stama 实现了一个纯 Stdio JSON-RPC 2.0 接口。为了严格遵守 JSON-RPC 帧协议,所有的诊断和日志输出都会被路由到 stderr,以确保 stdout 仅专门用于协议流量。

请求流遵循线性路径:AI Client (Cursor/Claude) $\rightarrow$ StdioTransport $\rightarrow$ JsonRpcRequest/Response $
ightarrow$ ToolRegistry $\rightarrow$ Specific Tool (fast_grep, git_snapshot, or docker_watcher)

Sources

相关

  • 项目
  • 项目
  • 项目
  • 项目
  • 项目