SuperAPI AI Directory

rust-docs-mcp-server

Up-to-date documentation for a specific Rust crate via semantic search and LLM summarization.

Open website

About this tool

Purpose

rust-docs-mcp-server is used to prevent AI programming assistants (such as Cursor, Cline, Roo Code, etc.) from giving outdated Rust code suggestions. It establishes a knowledge source of the latest documentation for a specific Rust crate, allowing the LLM to query accurate API usage before writing code, thereby improving the accuracy and relevance of the generated code.

Main Capabilities

  • Targeted documentation: Each server instance focuses on a single Rust crate (for example, serde, tokio, reqwest).
  • Feature support: Allows specifying the required features of the crate to generate the corresponding documentation.
  • Semantic search: Uses OpenAI's text-embedding-3-small model to generate embeddings for the documentation content and find the most relevant documentation fragments based on the question.
  • LLM summarization: Uses OpenAI's gpt-4o-mini-2024-07-18 model to generate concise answers based only on the retrieved documentation context.
  • Caching: Caches the generated documentation content and embeddings in the user's XDG data directory (such as ~/.local/share/rustdocs-mcp-server/), keyed by crate, version, and feature combination, to speed up subsequent startups.
  • MCP integration: Runs as a standard MCP server over stdio, exposing tools and resources.

Usage

Installation

It is recommended to download the precompiled binary from the GitHub Releases page:

  1. Go to the Releases page.
  2. Download the archive file for your system (Windows is .zip, Linux/macOS is .tar.gz).
  3. Extract it to obtain the rustdocs_mcp_server (or rustdocs_mcp_server.exe) executable file.
  4. Place the binary in a directory in the system PATH (such as /usr/local/bin, ~/bin).

Alternative: Build from source, which requires installing the Rust Toolchain.

git clone https://github.com/Govcraft/rust-docs-mcp-server.git
cd rust-docs-mcp-server
cargo build --release

Running

The server is started via the command line and requires the Package ID Specification of the target crate (same format as Cargo, such as crate_name, crate_name@version_req). Optionally use -F or --features to specify a comma-separated list of features.

When running for the first time for a specific crate version and feature set, the server will:

  1. Use cargo doc (with the specified features) to download the crate documentation.
  2. Parse the HTML documentation.
  3. Use the OpenAI API to generate embeddings for the documentation content (this may take time and incur costs; most crates only need a few cents; in testing, generating embeddings for async-stripe's more than 5000 pages of documentation cost $0.18).
  4. Cache the documentation content and embeddings.
  5. Start the MCP server.

Subsequent startups with the same configuration will load directly from the cache and be faster. It is recommended that the first time you configure any new crate, run the server directly from the command line once, wait until you see a startup-ready message (such as "MCP Server listening on stdio"), then close it (Ctrl+C), and then add it to the AI coding assistant. In this way, the cache has already been generated, and subsequent startups will be faster.

MCP Interaction

The server communicates through standard input/output (stdio) and exposes the following:

  • Tool: query_rust_docs

    • Description: For the Rust crate specified when the server starts, query the documentation using semantic search and LLM summarization.
    • Input schema: { "type": "object", "properties": { "question": { "type": "string", "description": "The specific question about the crate's API or usage." } }, "required": ["question"] }
    • Output: A text answer generated by the LLM based on the relevant documentation context, prefixed with "From <crate_name> docs: ".
    • Example call: { "jsonrpc": "2.0", "method": "callTool", "params": { "tool_name": "query_rust_docs", "arguments": { "question": "How do I make a simple GET request with reqwest?" } }, "id": 1 }
  • Resource: crate://<crate_name>

    • Description: Provides the Rust crate name configured for this server instance.
    • URI: crate://<crate_name> (e.g., crate://serde, crate://reqwest)
    • Content: Plain text containing the crate name.
  • Logs: The server sends informational logs (startup messages, query processing steps) to the MCP client via logging/message notifications.

Client Configuration Example (Roo Code)

Multiple server instances can be configured in Roo Code's mcp_settings.json, each targeting a different crate. The example configures reqwest and async-stripe (note that async-stripe adds a features parameter). You need to replace the binary path and OpenAI API key; key names can be customized.

Client Configuration Example (Claude Desktop)

Configure in Claude Desktop's MCP settings; the example configures serde and async-stripe. You need to ensure the binary is in PATH or provide the full path; key names can be customized. Note to set the OPENAI_API_KEY environment variable, and Claude Desktop's MCP configuration may not support setting environment variables per server.

How It Works

  1. Initialization: Use clap to parse the crate specification and optional features from the command line.
  2. Cache Check: Look for a cache file for the specific crate, version requirement, and feature set.
  3. Documentation Generation (on cache miss): Create a temporary Rust project that depends only on the target crate, enabling the specified features in Cargo.toml. Use the cargo library API to run cargo doc to generate HTML documentation, and dynamicallylocate the output directory containing index.html.
  4. Content Extraction (on cache miss): Use the scraper crate to traverse HTML files and extract text from the main content area (<section id="main-content">).
  5. Embedding Generation (on cache miss): Use async-openai and tiktoken-rs to generate embeddings for each documentation chunk, estimating cost based on token count.
  6. Caching (on cache miss): Save the documentation content and embeddings to a cache file using bincode serialization (the path includes a feature hash).
  7. Server Startup: Initialize RustDocsServer and load/generate documentation and embeddings.
  8. MCP Service: Start the MCP server over stdio via rmcp.
  9. Query Processing: Generate an embedding for the question, compute cosine similarity with all cached document embeddings, find the most similar documentation chunk, send the question and that chunk's content to gpt-4o-mini-2024-07-18, require it to answer based only on the given context, and return the LLM response.

Use Cases

  • When an AI programming assistant needs up-to-date Rust crate API information.
  • When development frequently uses rapidly iterating Rust libraries.
  • In multi-instance scenarios where accurate context needs to be provided for multiple different crates.

Limitations

  • Requires an OpenAI API key (OPENAI_API_KEY environment variable).
  • Requires a network connection to download crate dependencies and interact with the OpenAI API.
  • The first run of a new crate configuration requires downloading documentation and generating embeddings, which may take a long time and incur API costs.
  • Each server instance targets only one Rust crate.
  • More details regarding platform support, specific pricing, performance metrics, etc. are not yet provided.

License

MIT License, Copyright (c) 2025 Govcraft.