rust-mcp
A Model Context Protocol (MCP) server for Rust development. It gives AI assistants (e.g. Cursor, Claude Code) compiler-accurate tools—Cargo commands, rust-analyzer semantics, refactors, Mermaid diagrams, sandbox execution—with token-efficient output and path safety.
Use it as your daily Rust MCP server, or fork it as a template to build your own MCP server. See Creating your own MCP server.
Features
- Cargo:
cargo_workspace_action— check, clippy, test, build (with optional TOON output; build requires approval). - Semantics:
analyze_codebase_symbol— hover, references, definition, type, traits, borrow_graph, doc (rust-analyzer-backed). - Structure:
inspect_codebase_structure— diagnostics, items, snapshot, diff (withdetail: "summary"or"full"). - Diagrams:
generate_mermaid_diagram— crate graph, file structure, trait hierarchy. - Refactor:
refactor— rename symbol (with optional apply + cargo check); extract/change-signature stubs. - Security:
security_ops— validate MCP config, scan invisible Unicode, TOON encode. - Sandbox:
sandbox_run— run scripts with timeout and output caps (approval required). - Cursor:
cursor_init_rules— seed.cursor/rules/for Rust projects. - State DB (optional):
manage_shared_memory,find_crate_usages; knowledge feature:search_docs(RAG).
Resources: skills via skill://<name>. Path guard blocks .env, .ssh, and other sensitive paths.
Requirements
- Rust 1.70+ (rustup)
- Cursor (or any MCP client) using stdio transport
Install & run
git clone https://github.com/YOUR_ORG/rust-mcp.git # replace YOUR_ORG with the repo owner
cd rust-mcp
cargo build --release
Binary: target/release/rust-mcp.
Cursor (this repo): Open this folder in Cursor. The project .cursor/mcp.json starts the server (e.g. cargo run --release or the binary). Restart Cursor after changing config.
Cursor (another project): Add to that project’s .cursor/mcp.json (or ~/.cursor/mcp.json):
{
"mcpServers": {
"rust-mcp": {
"command": "/path/to/rust-mcp/target/release/rust-mcp",
"args": ["--client=cursor"]
}
}
}
Use the absolute path to the binary. --client=cursor skips server-side confirmation prompts and lets Cursor handle approvals.
CLI & env
Subcommands (no server):
rust-mcp index-workspaces <path>...— index workspaces forfind_crate_usages.rust-mcp index-docs <path>...— index docs forsearch_docs(requires--features knowledge, Ollama with embedding model).
Optional features
cargo build --release --features "wasm" # sandbox_run: run WASI .wasm
cargo build --release --features "knowledge" # search_docs (LanceDB + Ollama)
See FEATURES.md for the full list (some tool names there reflect an older API; the server uses consolidated tools as in this README).
Documentation
- SETUP.md — Build, Cursor config, troubleshooting.
- FEATURES.md — Capabilities and options.
- documentation/ — Proposals, architecture, HITL, sandbox, creating your own server.
- documentation/PUBLISHING-CHECKLIST.md — Pre-publish steps before going public.
License
Dual-licensed under MIT and Apache-2.0; you may use either. See LICENSE-MIT and LICENSE-APACHE.
Contributing
See CONTRIBUTING.md.