MCP (Model Context Protocol) server for exhaustive Rust code analysis.
MCP server written in Rust that analyzes Rust projects via syn + toml and rust-analyzer (ra_ap_* as semantic ASG). Exposes that return ready for consumption by LLMs.
MCP Server For Deterministic Rust Analysis
Stars
1
Tools
—
Uptime
—
37 tools
deterministic Markdown
It is the Rust counterpart of cobol-mcp-server, java-mcp-server and python-mcp-server: same philosophy ("ground truth", no hallucination), different domain and different parser (syn/toml/ra_ap_* instead of ProLeap/Spoon/LibCST).
Quick start
Prerequisites
Rust 1.85+ (tested with 1.96.0 via brew and rustup)
macOS / Linux (Windows not tested)
Optional, for cross-compile to musl: zig + cargo-zigbuild + rustup with targets x86_64-unknown-linux-musl and aarch64-unknown-linux-musl
The script performs the full JSON-RPC handshake: initialize → tools/list → loads the fixture → invokes 11 tools → verifies outputs → exit. Verifies the server works end-to-end with a real MCP client.
CI and container
The project has a GitHub Actions workflow at .github/workflows/ci.yml with 3 jobs:
test-native: cargo test on Ubuntu.
cross-compile-musl: cargo zigbuild + verification with docker run alpine.
lint: cargo fmt --check + cargo clippy (without -D warnings due to minor doc list warnings).
And a multi-stage Dockerfile that produces the rust-mcp-server:test image (~42 MB):
The project includes two example Rust crates in tests/fixtures/, designed so the tools have real material to work with (instead of empty fixtures):
sample_crate/ — the main fixture. Has 3 real and used deps:
cfg-if = "1" (normal) — used in is_release() with the cfg_if! macro (verifies cfg-if is processed correctly).
once_cell = "1" (normal) — used in cached_value() (verifies sync::OnceCell).
pretty_assertions = "1" (dev-dep) — used in tests (verifies dev-deps).
The fixture has 4 passing tests: test_add, test_multiply, test_is_release, test_cached_value.
sample_crate_with_deps/ — fixture for find_unused_dependencies. Has 3 UNUSED deps (serde, unused_dep, unused_dev_dep) that the tool must report.
rust-mcp-server can be compiled as a static Linux binary using zig as linker (via cargo-zigbuild). The resulting binary does not depend on glibc and runs on any modern Linux distro (Alpine, Ubuntu, RHEL, etc.) without external dependencies.
Prerequisites
# zig — linker used by cargo-zigbuild
brew install zig
# rustup — the Rust toolchain manager
brew install rustup-init
rustup-init -y --default-toolchain stable
rustup target add x86_64-unknown-linux-musl
rustup target add aarch64-unknown-linux-musl
# cargo-zigbuild — the wrapper that invokes zig as linker
cargo install cargo-zigbuild
Note on dual toolchain: if you have Rust installed via Homebrew (brew install rust), rustup target add only affects the rustup toolchain. The default cargo resolves to the Homebrew binary, which does NOT see the musl targets. Solution (recommended): brew uninstall rust to have a single toolchain. If you do not want to uninstall, you need to create rustup shims manually (next section).
Shims setup if you have toolchain conflict
If after brew install rustup-init the default cargo is not from rustup, you need to create shims:
RUSTUP_REAL=$(find /Users/alejandro.ferreira/homebrew/Cellar/rustup -name rustup -type f 2>/dev/null | head -1)
for cmd in cargo rustc rustup rustdoc rustfmt cargo-clippy clippy-driver; do
cp "$RUSTUP_REAL" "$HOME/.cargo/bin/$cmd"
done
chmod +x "$HOME/.cargo/bin/"{cargo,rustc,rustup,rustdoc,rustfmt,cargo-clippy,clippy-driver}
cargo --version
Why cp and not ln -s: the rustup binary detects its name via argv[0]. Symlinks preserve argv[0] pointing to rustup, not cargo, so dispatch fails. cp breaks the link, giving each shim its own argv[0].
ureq (HTTP client) may not work on musl for some URLs (TLS). We don't use it for real I/O, so it does not matter.
gix is included but resolve_git uses git CLI (not gix::clone), so it requires git installed on the target system (not a problem for our use case).
cargo-zigbuild emits a warning during build: linker stderr: ignoring deprecated linker optimization setting '1'. Comes from the interaction with zig 0.16. Does not affect the binary — it builds and works correctly.
MCP tool reference (37 tools)
Source management (5)
load_rust_project — loads a local path, Git URL, or archive URL
unload_rust_project — removes from cache
project_metadata — name, alias, kind, path, package info
Verbose tool pattern: one struct per tool, explicit registration in RustMcpServer::build_tools(). Inspired by BaseCobolTool / BaseJavaTool.
Stable McpTool trait: tool contract. Do NOT change without reviewing all tools.
Thread-safe ProjectManager: tokio::sync::RwLock<HashMap>, 10 min expiry, same shape as java-mcp-server.
Deterministic Markdown: byte-for-byte output, no timestamps. Golden snapshots in tests/snapshots/.
Version from version.txt: build.rs injects it into OUT_DIR/version.rs, lib.rs includes it with include!. Equivalent to Maven filtering of version.properties in Java.
Dual-engine bug-hunt: 4 sweeps use syn (static, parse-only), 1 sweep (find_dead_code) uses ra_ap_* (semantic with find_all_refs). SymbolLocation includes implicit_references: { test, derive, no_mangle, cfg, allow } to avoid false positives.