⭐ Like this project? Please star the repository on GitHub to show your support and stay updated! ⭐ Modern AI-powered coding assistants (like Cursor, Cline, Roo Code, etc.) excel at understanding code structure and syntax but often struggle with the specifics of rapidly evolving libraries and frameworks, especially in ecosystems like Rust where crates are updated frequently. Their training data cut
Add this skill
npx mdskills install Govcraft/rust-docs-mcp-serverWell-documented MCP server providing semantic search over Rust crate documentation with OpenAI integration
1# Rust Docs MCP Server23[](https://opensource.org/licenses/MIT)45⭐ **Like this project? Please6[star the repository](https://github.com/Govcraft/rust-docs-mcp-server) on7GitHub to show your support and stay updated!** ⭐89## Motivation1011Modern AI-powered coding assistants (like Cursor, Cline, Roo Code, etc.) excel12at understanding code structure and syntax but often struggle with the specifics13of rapidly evolving libraries and frameworks, especially in ecosystems like Rust14where crates are updated frequently. Their training data cutoff means they may15lack knowledge of the latest APIs, leading to incorrect or outdated code16suggestions.1718This MCP server addresses this challenge by providing a focused, up-to-date19knowledge source for a specific Rust crate. By running an instance of this20server for a crate (e.g., `serde`, `tokio`, `reqwest`), you give your LLM coding21assistant a tool (`query_rust_docs`) it can use _before_ writing code related to22that crate.2324When instructed to use this tool, the LLM can ask specific questions about the25crate's API or usage and receive answers derived directly from the _current_26documentation. This significantly improves the accuracy and relevance of the27generated code, reducing the need for manual correction and speeding up28development.2930Multiple instances of this server can be run concurrently, allowing the LLM31assistant to access documentation for several different crates during a coding32session.3334This server fetches the documentation for a specified Rust crate, generates35embeddings for the content, and provides an MCP tool to answer questions about36the crate based on the documentation context.3738## Features3940- **Targeted Documentation:** Focuses on a single Rust crate per server41 instance.42- **Feature Support:** Allows specifying required crate features for43 documentation generation.44- **Semantic Search:** Uses OpenAI's `text-embedding-3-small` model to find the45 most relevant documentation sections for a given question.46- **LLM Summarization:** Leverages OpenAI's `gpt-4o-mini-2024-07-18` model to47 generate concise answers based _only_ on the retrieved documentation context.48- **Caching:** Caches generated documentation content and embeddings in the49 user's XDG data directory (`~/.local/share/rustdocs-mcp-server/` or similar)50 based on crate, version, _and_ requested features to speed up subsequent51 launches.52- **MCP Integration:** Runs as a standard MCP server over stdio, exposing tools53 and resources.5455## Prerequisites5657- **OpenAI API Key:** Needed for generating embeddings and summarizing answers.58 The server expects this key to be available in the `OPENAI_API_KEY`59 environment variable. (The server also requires network access to download60 crate dependencies and interact with the OpenAI API).6162## Installation6364The recommended way to install is to download the pre-compiled binary for your65operating system from the66[GitHub Releases page](https://github.com/Govcraft/rust-docs-mcp-server/releases).67681. Go to the69 [Releases page](https://github.com/Govcraft/rust-docs-mcp-server/releases).702. Download the appropriate archive (`.zip` for Windows, `.tar.gz` for71 Linux/macOS) for your system.723. Extract the `rustdocs_mcp_server` (or `rustdocs_mcp_server.exe`) binary.734. Place the binary in a directory included in your system's `PATH` environment74 variable (e.g., `/usr/local/bin`, `~/bin`).7576### Building from Source (Alternative)7778If you prefer to build from source, you will need the79[Rust Toolchain](https://rustup.rs/) installed.80811. **Clone the repository:**82 ```bash83 git clone https://github.com/Govcraft/rust-docs-mcp-server.git84 cd rust-docs-mcp-server85 ```862. **Build the server:**87 ```bash88 cargo build --release89 ```9091## Usage9293**Important Note for New Crates:**9495When using the server with a crate for the first time (or with a new version/feature set), it needs to download the documentation and generate embeddings. This process can take some time, especially for crates with extensive documentation, and requires an active internet connection and OpenAI API key.9697It is recommended to run the server once directly from your command line for any new crate configuration *before* adding it to your AI coding assistant (like Roo Code, Cursor, etc.). This allows the initial embedding generation and caching to complete. Once you see the server startup messages indicating it's ready (e.g., "MCP Server listening on stdio"), you can shut it down (Ctrl+C). Subsequent launches, including those initiated by your coding assistant, will use the cached data and start much faster.9899100### Running the Server101102The server is launched from the command line and requires the **Package ID103Specification** for the target crate. This specification follows the format used104by Cargo (e.g., `crate_name`, `crate_name@version_req`). For the full105specification details, see `man cargo-pkgid` or the106[Cargo documentation](https://doc.rust-lang.org/cargo/reference/pkgid-spec.html).107108Optionally, you can specify required crate features using the `-F` or109`--features` flag, followed by a comma-separated list of features. This is110necessary for crates that require specific features to be enabled for111`cargo doc` to succeed (e.g., crates requiring a runtime feature like112`async-stripe`).113114```bash115# Set the API key (replace with your actual key)116export OPENAI_API_KEY="sk-..."117118# Example: Run server for the latest 1.x version of serde119rustdocs_mcp_server "serde@^1.0"120121# Example: Run server for a specific version of reqwest122rustdocs_mcp_server "reqwest@0.12.0"123124# Example: Run server for the latest version of tokio125rustdocs_mcp_server tokio126127# Example: Run server for async-stripe, enabling a required runtime feature128rustdocs_mcp_server "async-stripe@0.40" -F runtime-tokio-hyper-rustls129130# Example: Run server for another crate with multiple features131rustdocs_mcp_server "some-crate@1.2" --features feat1,feat2132```133134On the first run for a specific crate version _and feature set_, the server135will:1361371. Download the crate documentation using `cargo doc` (with specified features).1382. Parse the HTML documentation.1393. Generate embeddings for the documentation content using the OpenAI API (this140 may take some time and incur costs, though typically only fractions of a US141 penny for most crates; even a large crate like `async-stripe` with over 5000142 documentation pages cost only $0.18 USD for embedding generation during143 testing).1444. Cache the documentation content and embeddings so that the cost isn't145 incurred again.1465. Start the MCP server.147148Subsequent runs for the same crate version _and feature set_ will load the data149from the cache, making startup much faster.150151### MCP Interaction152153The server communicates using the Model Context Protocol over standard154input/output (stdio). It exposes the following:155156- **Tool: `query_rust_docs`**157 - **Description:** Query documentation for the specific Rust crate the server158 was started for, using semantic search and LLM summarization.159 - **Input Schema:**160 ```json161 {162 "type": "object",163 "properties": {164 "question": {165 "type": "string",166 "description": "The specific question about the crate's API or usage."167 }168 },169 "required": ["question"]170 }171 ```172 - **Output:** A text response containing the answer generated by the LLM based173 on the relevant documentation context, prefixed with174 `From <crate_name> docs:`.175 - **Example MCP Call:**176 ```json177 {178 "jsonrpc": "2.0",179 "method": "callTool",180 "params": {181 "tool_name": "query_rust_docs",182 "arguments": {183 "question": "How do I make a simple GET request with reqwest?"184 }185 },186 "id": 1187 }188 ```189190- **Resource: `crate://<crate_name>`**191 - **Description:** Provides the name of the Rust crate this server instance is192 configured for.193 - **URI:** `crate://<crate_name>` (e.g., `crate://serde`, `crate://reqwest`)194 - **Content:** Plain text containing the crate name.195196- **Logging:** The server sends informational logs (startup messages, query197 processing steps) back to the MCP client via `logging/message` notifications.198199### Example Client Configuration (Roo Code)200201You can configure MCP clients like Roo Code to run multiple instances of this202server, each targeting a different crate. Here's an example snippet for Roo203Code's `mcp_settings.json` file, configuring servers for `reqwest` and204`async-stripe` (note the added features argument for `async-stripe`):205206```json207{208 "mcpServers": {209 "rust-docs-reqwest": {210 "command": "/path/to/your/rustdocs_mcp_server",211 "args": [212 "reqwest@0.12"213 ],214 "env": {215 "OPENAI_API_KEY": "YOUR_OPENAI_API_KEY_HERE"216 },217 "disabled": false,218 "alwaysAllow": []219 },220 "rust-docs-async-stripe": {221 "command": "rustdocs_mcp_server",222 "args": [223 "async-stripe@0.40",224 "-F",225 " runtime-tokio-hyper-rustls"226 ],227 "env": {228 "OPENAI_API_KEY": "YOUR_OPENAI_API_KEY_HERE"229 },230 "disabled": false,231 "alwaysAllow": []232 }233 }234}235```236237**Note:**238239- Replace `/path/to/your/rustdocs_mcp_server` with the actual path to the240 compiled binary on your system if it isn't in your PATH.241- Replace `YOUR_OPENAI_API_KEY_HERE` with your actual OpenAI API key.242- The keys (`rust-docs-reqwest`, `rust-docs-async-stripe`) are arbitrary names243 you choose to identify the server instances within Roo Code.244245### Example Client Configuration (Claude Desktop)246247For Claude Desktop users, you can configure the server in the MCP settings.248Here's an example configuring servers for `serde` and `async-stripe`:249250```json251{252 "mcpServers": {253 "rust-docs-serde": {254 "command": "/path/to/your/rustdocs_mcp_server",255 "args": [256 "serde@^1.0"257 ]258 },259 "rust-docs-async-stripe-rt": {260 "command": "rustdocs_mcp_server",261 "args": [262 "async-stripe@0.40",263 "-F",264 "runtime-tokio-hyper-rustls"265 ]266 }267 }268}269```270271**Note:**272273- Ensure `rustdocs_mcp_server` is in your system's PATH or provide the full path274 (e.g., `/path/to/your/rustdocs_mcp_server`).275- The keys (`rust-docs-serde`, `rust-docs-async-stripe-rt`) are arbitrary names276 you choose to identify the server instances.277- Remember to set the `OPENAI_API_KEY` environment variable where Claude Desktop278 can access it (this might be system-wide or via how you launch Claude279 Desktop). Claude Desktop's MCP configuration might not directly support280 setting environment variables per-server like Roo Code.281- The example shows how to add the `-F` argument for crates like `async-stripe`282 that require specific features.283284### Caching285286- **Location:** Cached documentation and embeddings are stored in the XDG data287 directory, typically under288 `~/.local/share/rustdocs-mcp-server/<crate_name>/<sanitized_version_req>/<features_hash>/embeddings.bin`.289 The `sanitized_version_req` is derived from the version requirement, and290 `features_hash` is a hash representing the specific combination of features291 requested at startup. This ensures different feature sets are cached292 separately.293- **Format:** Data is cached using `bincode` serialization.294- **Regeneration:** If the cache file is missing, corrupted, or cannot be295 decoded, the server will automatically regenerate the documentation and296 embeddings.297298## How it Works2993001. **Initialization:** Parses the crate specification and optional features from301 the command line using `clap`.3022. **Cache Check:** Looks for a pre-existing cache file for the specific crate,303 version requirement, and feature set.3043. **Documentation Generation (if cache miss):**305 - Creates a temporary Rust project depending only on the target crate,306 enabling the specified features in its `Cargo.toml`.307 - Runs `cargo doc` using the `cargo` library API to generate HTML308 documentation in the temporary directory.309 - Dynamically locates the correct output directory within `target/doc` by310 searching for the subdirectory containing `index.html`.3114. **Content Extraction (if cache miss):**312 - Walks the generated HTML files within the located documentation directory.313 - Uses the `scraper` crate to parse each HTML file and extract text content314 from the main content area (`<section id="main-content">`).3155. **Embedding Generation (if cache miss):**316 - Uses the `async-openai` crate and `tiktoken-rs` to generate embeddings for317 each extracted document chunk using the `text-embedding-3-small` model.318 - Calculates the estimated cost based on the number of tokens processed.3196. **Caching (if cache miss):** Saves the extracted document content and their320 corresponding embeddings to the cache file (path includes features hash)321 using `bincode`.3227. **Server Startup:** Initializes the `RustDocsServer` with the323 loaded/generated documents and embeddings.3248. **MCP Serving:** Starts the MCP server using `rmcp` over stdio.3259. **Query Handling (`query_rust_docs` tool):**326 - Generates an embedding for the user's question.327 - Calculates the cosine similarity between the question embedding and all328 cached document embeddings.329 - Identifies the document chunk with the highest similarity.330 - Sends the user's question and the content of the best-matching document331 chunk to the `gpt-4o-mini-2024-07-18` model via the OpenAI API.332 - The LLM is prompted to answer the question based _only_ on the provided333 context.334 - Returns the LLM's response to the MCP client.335336## License337338This project is licensed under the MIT License.339340Copyright (c) 2025 Govcraft341342## Sponsor343344Govcraft is a one-person shop—no corporate backing, no investors, just me building useful tools. If this project helps you, [sponsoring](https://github.com/sponsors/Govcraft) keeps the work going.345346[](https://github.com/sponsors/Govcraft)347
Full transparency — inspect the skill content before installing.