MCP Hub
Back to servers

Rust Documentation

A documentation-focused MCP server providing hybrid semantic and keyword search across core Rust language resources like The Book, Reference, and Rustronomicon.

Stars
1
Tools
4
Updated
Dec 16, 2025

rust-lang-mcp

An MCP (Model Context Protocol) server that provides AI assistants with access to Rust language documentation through hybrid search (keyword + semantic).

Features

  • Full-text search using Tantivy (BM25 ranking)
  • Semantic search using local ONNX embeddings (all-MiniLM-L6-v2)
  • Hybrid search combining both methods with Reciprocal Rank Fusion (RRF)
  • Multiple documentation sources: The Rust Book, Rust Reference, Rust by Example, Design Patterns, API Guidelines, and Rustonomicon

Setup

1. Build the server

cargo build --release

2. Run the server

./target/release/rust-lang-mcp

On first run, the server will automatically:

  1. Clone all documentation repositories (shallow clone, ~50MB total)
  2. Index all markdown files for search

This takes about 1-2 minutes on first startup. Subsequent runs are instant.

Manual documentation setup (optional)

If you prefer to clone the repositories manually or the auto-clone fails:

mkdir -p data
cd data

git clone --depth 1 https://github.com/rust-lang/book.git
git clone --depth 1 https://github.com/rust-lang/reference.git
git clone --depth 1 https://github.com/rust-lang/rust-by-example.git
git clone --depth 1 https://github.com/rust-unofficial/patterns.git
git clone --depth 1 https://github.com/rust-lang/api-guidelines.git
git clone --depth 1 https://github.com/rust-lang/nomicon.git

MCP Client Configuration

Claude Desktop

Add to ~/.config/claude/claude_desktop_config.json (Linux) or ~/Library/Application Support/Claude/claude_desktop_config.json (macOS):

{
  "mcpServers": {
    "rust-lang-mcp": {
      "command": "/absolute/path/to/rust-lang-mcp/target/release/rust-lang-mcp"
    }
  }
}

Claude Code (CLI)

Global configuration (recommended)

Add to ~/.claude.json to make the MCP available in all projects:

{
  "mcpServers": {
    "rust-lang-mcp": {
      "command": "/absolute/path/to/rust-lang-mcp/target/release/rust-lang-mcp"
    }
  }
}

Note: Add the mcpServers key at the top level of the existing ~/.claude.json file (don't replace the whole file).

Project-level configuration

For project-specific setup, create a .mcp.json file in the project root:

{
  "mcpServers": {
    "rust-lang-mcp": {
      "command": "cargo",
      "args": ["run", "--release"],
      "cwd": "/absolute/path/to/rust-lang-mcp"
    }
  }
}

This runs the MCP server directly from source, useful during development.

Note: You can check your MCP config locations by running /mcp in Claude Code. User-level config is at ~/.claude.json, project-level at .mcp.json.

Cursor

Add to Cursor's MCP settings:

{
  "mcpServers": {
    "rust-lang-mcp": {
      "command": "/absolute/path/to/rust-lang-mcp/target/release/rust-lang-mcp"
    }
  }
}

Tools

search_rust_docs

Search the indexed Rust documentation for concepts, syntax, and best practices.

Parameters:

ParameterTypeRequiredDefaultDescription
querystringYes-Keywords or phrases to search for
limitnumberNo5Maximum results to return (max: 20)
modestringNo"hybrid"Search mode: "hybrid", "keyword", or "semantic"

Search Modes:

  • hybrid (default): Combines keyword and semantic search using RRF score fusion. Best for most queries.
  • keyword: Traditional BM25 keyword search. Best for exact term matching.
  • semantic: Embedding-based similarity search. Best for conceptual queries.

Example:

{
  "query": "how to handle errors with Result",
  "limit": 5,
  "mode": "hybrid"
}

Response:

[
  {
    "title": "Recoverable Errors with Result",
    "snippet": "Most errors aren't serious enough to require the program to stop entirely...",
    "path": "ch09-02-recoverable-errors-with-result.md",
    "source": "rust-book",
    "score": 0.032
  }
]

explain_concept

Get detailed explanations of Rust concepts from The Rust Book and Rust Reference.

Parameters:

ParameterTypeRequiredDefaultDescription
conceptstringYes-The Rust concept to explain (e.g., "ownership", "lifetimes", "traits")
limitnumberNo3Maximum documentation sections to return (max: 10)

Example:

{
  "concept": "ownership",
  "limit": 3
}

get_best_practice

Get Rust best practices and idiomatic patterns from Design Patterns and API Guidelines.

Parameters:

ParameterTypeRequiredDefaultDescription
topicstringYes-The topic to get best practices for (e.g., "error handling", "API design")
limitnumberNo5Maximum results to return (max: 15)

Example:

{
  "topic": "error handling",
  "limit": 5
}

show_example

Get code examples from Rust by Example for practical demonstrations.

Parameters:

ParameterTypeRequiredDefaultDescription
topicstringYes-The topic to show examples for (e.g., "iterators", "closures", "match")
limitnumberNo3Maximum examples to return (max: 10)

Example:

{
  "topic": "iterators",
  "limit": 3
}

Documentation Sources

SourceRepositoryDescription
The Rust Bookrust-lang/bookOfficial Rust programming language book
Rust Referencerust-lang/referenceDetailed language reference
Rust by Examplerust-lang/rust-by-exampleLearn Rust through examples
Design Patternsrust-unofficial/patternsCommon Rust design patterns and idioms
API Guidelinesrust-lang/api-guidelinesRust API design recommendations
Rustonomiconrust-lang/nomiconThe Dark Arts of Unsafe Rust

Environment Variables

VariableDefaultDescription
RUST_MCP_DATA_DIR./dataDirectory containing documentation and index
RUST_LOG-Logging level (e.g., info, debug, trace)

How It Works

  1. Indexing: On first run, the server parses all Markdown files from the documentation sources and builds a Tantivy full-text index.

  2. Keyword Search: Uses Tantivy's BM25 algorithm to find documents matching query terms.

  3. Semantic Search (when enabled):

    • Generates 384-dimensional embeddings using the all-MiniLM-L6-v2 ONNX model
    • Stores embeddings in an HNSW (Hierarchical Navigable Small World) index
    • Finds semantically similar documents even without exact keyword matches
  4. Hybrid Search: Runs both searches in parallel and merges results using Reciprocal Rank Fusion (RRF), which combines rankings from multiple sources effectively.

Development

# Run tests
cargo test

# Run with logging
RUST_LOG=info cargo run --release

# Build debug version
cargo build

Troubleshooting

Search returns no results or errors

If the search index becomes corrupted or out of sync, you can rebuild it:

# Delete the index (keeps documentation sources)
rm -rf data/index

# Restart the server to trigger re-indexing
./target/release/rust-lang-mcp

The server will automatically rebuild the index on startup if it's empty or missing.

MCP connection issues

If Claude Code or other clients can't connect to the server:

  1. Verify the path in your MCP config is absolute and correct
  2. Check that the binary exists: ls -la /path/to/rust-lang-mcp/target/release/rust-lang-mcp
  3. Test the server manually: RUST_LOG=info /path/to/rust-lang-mcp/target/release/rust-lang-mcp
  4. Check Claude Code's MCP status with the /mcp command

License

MIT

Reviews

No reviews yet

Sign in to write a review