Rust库API参考服务

Amari MCP Server是一个配置驱动的MCP服务器,为Rust库生态系统提供准确的API参考,通过直接解析源代码来消除幻觉,并通过模型上下文协议提供准确的类型签名、文档和模块结构。

  • by justinelliottcobb
  • Rust
  • 本地部署
  • 更新于
在 GitHub 查看 justinelliottcobb/Amari-mcp

使用说明

阿玛瑞MCP服务器

配置驱动的MCP服务器,为Rust提供最新的API参考 图书馆生态系统。通过直接解析源代码消除幻觉 随着 syn 并提供准确的类型签名、文档和模块 通过模型上下文协议构建。

当前配置为 阿玛里 数学计算库(21个板条箱,约161K行),但设计用于工作 通过TOML清单文件使用任何Rust工作区。

快速开始

# Build
cargo build --release

# Validate that the library source is parseable
cargo run --release -- check

# Start the MCP server
cargo run --release -- serve

配置Claude代码

添加到您的Claude Code MCP设置中(使用绝对路径):

{
  "amari-mcp": {
    "command": "/absolute/path/to/amari-mcp/target/release/amari-mcp",
    "args": ["--manifest", "/absolute/path/to/amari-mcp/manifests/amari.toml"]
  }
}

或者通过CLI添加它:

claude mcp add amari-mcp -- /path/to/amari-mcp/target/release/amari-mcp \
  --manifest /path/to/amari-mcp/manifests/amari.toml

这 --manifest 路径必须是绝对的,因为服务器可以从以下位置启动 任何工作目录。

MCP工具

工具 说明
api_search 使用kind/crate过滤器按名称搜索类型、功能、特征
type_info 完整类型详细信息:签名、字段、方法、trait impls、文档
module_overview 列出机箱或模块中的所有公共项目
feature_map 哪些货物功能支持哪些板条箱和类型
dependency_graph 机箱间依赖关系
browse_docs 模块级和项目级文档
usage_examples 从文档注释中提取代码示例

命令行界面

amari-mcp [OPTIONS] [COMMAND]

Commands:
  serve   Start the MCP server (default)
  check   Validate that the manifest and source are parseable

Options:
  -m, --manifest <PATH>  Path to library manifest [default: manifests/amari.toml]
      --log-level <LVL>  Log level [default: info]

检查模式

这 check 子命令解析所有配置的板条箱并报告统计信息:

$ cargo run -- check
Library: amari
Parsed 19 crates, 579 modules, 5796 items
  amari-core (312 items)
  amari-tropical (129 items)
  amari-dual (169 items)
  ...
  amari-dynamics (973 items) [feature: dynamics]

Check passed.

在CI中使用此项可以捕获库和MCP服务器之间的API漂移。

索引不同的库

创建描述库工作区的清单文件:

[library]
name = "mylib"
display_name = "My Library"
version = "1.0.0"
description = "Description of the library"
source_path = "../path/to/mylib"  # relative to this manifest file

[workspace]
root_cargo_toml = "Cargo.toml"
umbrella_crate = "src/lib.rs"

[crates.default]
members = ["mylib-core", "mylib-utils"]

[crates.optional]
gpu = "mylib-gpu"

[crates.internal]
members = []

[aliases]
mylib-core = "core"

然后运行:

amari-mcp --manifest manifests/mylib.toml serve

看 设计.md 对于完整的清单格式规范。

发展

# Run all tests (66 tests: 60 unit + 6 integration)
cargo test

# Clippy with warnings as errors
cargo clippy -- -D warnings

# Format check
cargo fmt --check

预提交钩子在每次提交时强制执行fmt、clippy和test。

建筑

manifest (TOML) --> parser (syn) --> ApiIndex<Validated> --> MCP tools --> Claude Code
  • 配置模块:加载TOML清单,解析路径,将板条箱映射到特征
  • 解析器: syn-基于人造丝平行度的AST行走(19箱约1秒)
  • 索引:幻影型状态机(Unvalidated -> Validated)
  • 工具:7个MCP处理程序共享 Arc<SharedState> 超过已验证的指数

看 设计.md 详细的架构和 ROADMAP.md 计划工作。

许可证

麻省理工学院或阿帕奇-2.0

相关项目