Rust is the language of AI
An MCP (Model Context Protocol) server that provides comprehensive access to Rust crate documentation, source code analysis, dependency trees, and module structure visualization. Built for agents to gain quality insights into Rust projects and build with confidence.
The rise of AI agents has revolutionized software development, with new tools and libraries emerging at an unprecedented pace. However, this rapid evolution creates a critical challenge: agents cannot reliably build with tools they weren't trained on.
When an agent tries to use a new Rust crate:
- π« Training data is outdated β The model hasn't seen recent crates or API changes
- π« Documentation scraping is inefficient β Web scraping GitHub or docs.rs is slow and unreliable
- π« Examples aren't enough β Copy-pasting README examples provides surface-level understanding
- π« Internal structure is opaque β Agents can't explore how modules, traits, and types interconnect
This leads to frustrated developers watching their agents fail repeatedly, guessing at APIs, and producing broken code.
This MCP server gives agents the tools they need to truly understand Rust crates:
- π Explore internal structure β Navigate module hierarchies and type relationships
- π Access complete documentation β Full rustdoc with signatures, fields, and methods
- π Trace dependencies β Understand what a crate depends on and why
- πΎ Work offline β Cache crates locally for instant, reliable access
- π― Query precisely β Search by pattern, kind, or path to find exactly what's needed
With these capabilities, agents can build confidently with any Rust crate β even ones released yesterday.
- Multi-source caching β crates.io, GitHub repositories, local filesystem paths
- Workspace support β Individual member analysis and caching for cargo workspaces
- Documentation search β Pattern matching with kind/path filtering and preview modes
- Item inspection β Detailed signatures, fields, methods, and documentation strings
- Source code access β Line-level precision with parameterized surrounding context
- Dependency analysis β Direct and transitive dependency trees with metadata
- Module structure β Hierarchical tree generation via cargo-modules integration
- Offline operation β Full functionality after initial crate caching
- Token management β Response truncation and preview modes for LLM compatibility
cache_crate- Download and cache a crate from various sources. Setsource_typeto one of:cratesio,github, orlocal- For cratesio: Provide
version(e.g.,{crate_name: "serde", source_type: "cratesio", version: "1.0.215"}) - For github: Provide
github_urland eitherbranchORtag(e.g.,{crate_name: "my-crate", source_type: "github", github_url: "https://github.com/user/repo", tag: "v1.0.0"}) - For local: Provide
path, optionalversion(e.g.,{crate_name: "my-crate", source_type: "local", path: "~/projects/my-crate"})
- For cratesio: Provide
remove_crate- Remove cached crate versions to free disk spacelist_cached_crates- View all cached crates with versions and sizeslist_crate_versions- List cached versions for a specific crateget_crates_metadata- Batch metadata queries for multiple crates
list_crate_items- Browse all items in a crate with optional filteringsearch_items- Full search with complete documentation (may hit token limits)search_items_preview- Lightweight search returning only IDs, names, and typesget_item_details- Detailed information about specific items (signatures, fields, etc.)get_item_docs- Extract just the documentation string for an itemget_item_source- View source code with configurable context lines
get_dependencies- Analyze direct and transitive dependencies with filtering
structure- Generate hierarchical module tree using integrated cargo-modules
search_items_fuzzy- Fuzzy search with typo tolerance and semantic similarity
By default, crates are cached in ~/.rust-docs-mcp/cache/. You can customize
this location using:
# Command line option
rust-docs-mcp --cache-dir /custom/path/to/cache
# or set the environment variable
export RUST_DOCS_MCP_CACHE_DIR=/custom/path/to/cache
rust-docs-mcpTo access private repositories or increase GitHub API rate limits, set the
GITHUB_TOKEN environment variable:
export GITHUB_TOKEN=your_github_personal_access_tokenBenefits of authentication:
- Access private repositories β Cache and analyze private Rust crates
- Higher rate limits β 5,000 requests/hour (vs 60 unauthenticated)
- Avoid rate limit errors β Essential for caching multiple GitHub-hosted crates
- Complete source code in
source/directory - Cache metadata and timestamps in
metadata.json - For workspace crates, individual members in
members/directory:members/{member-name}/docs.json- Rustdoc JSON documentationmembers/{member-name}/dependencies.json- Cargo dependency metadatamembers/{member-name}/metadata.json- Member-specific cache metadata
- For single crates:
docs.json- Rustdoc JSON documentationdependencies.json- Cargo dependency metadata
curl -sSL https://raw.githubusercontent.com/snowmead/rust-docs-mcp/main/install.sh | bashcurl -sSL https://raw.githubusercontent.com/snowmead/rust-docs-mcp/main/install.sh | bashcurl -sSL https://raw.githubusercontent.com/snowmead/rust-docs-mcp/main/install.sh | bash -s -- --install-dir /usr/local/bincargo install rust-docs-mcp-
Rust nightly toolchain (for Rustdoc JSON generation)
rustup toolchain install nightly
-
Network access to download crates from crates.io
git clone https://github.com/snowmead/rust-docs-mcp
cd rust-docs-mcp/rust-docs-mcp
cargo build --release
./target/release/rust-docs-mcp installrust-docs-mcp # Start MCP server
rust-docs-mcp install # Install to ~/.local/bin
rust-docs-mcp install --force # Force overwrite existing installation
rust-docs-mcp doctor # Verify system environment and dependencies
rust-docs-mcp doctor --json # Output diagnostic results in JSON format
rust-docs-mcp update # Update to latest version from GitHub
rust-docs-mcp --help # Show helpIf you encounter issues during installation or runtime, run the doctor command to diagnose common problems:
rust-docs-mcp doctorThe doctor command checks:
- Rust toolchain availability (stable + nightly)
- Git installation
- Network connectivity to crates.io and GitHub
- Cache directory permissions and disk space
- Rustdoc JSON generation capability
- Optional dependencies (e.g., codesign on macOS)
For programmatic integration, use --json flag to get structured output.
Add the server to your MCP configuration:
{
"rust-docs": {
"command": "/path/to/rust-docs-mcp/target/release/rust-docs-mcp",
"transport": "stdio"
}
}