Skip to content
Back to search

rust-docs-mcp-server

🦀 Prevents outdated Rust code suggestions from AI assistants. This MCP server fetches current crate docs, uses embeddings/LLMs, and provides accurate context via a tool call.

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today
Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/govcraft--rust-docs-mcp-server/badge.svg)](/listings/govcraft--rust-docs-mcp-server)

HTML

<a href="/listings/govcraft--rust-docs-mcp-server"><img src="/api/listings/govcraft--rust-docs-mcp-server/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

Install instructions from the README

As written by the repo's author. findsafeskills has not verified these steps.

The recommended way to install is to download the pre-compiled binary for your operating system from the [GitHub Releases page](https://github.com/Govcraft/rust-docs-mcp-server/releases).

1. Go to the [Releases page](https://github.com/Govcraft/rust-docs-mcp-server/releases). 2. Download the appropriate archive (`.zip` for Windows, `.tar.gz` for Linux/macOS) for your system. 3. Extract the `rustdocs_mcp_server` (or `rustdocs_mcp_server.exe`) binary. 4. Place the binary in a directory included in your system's `PATH` environment variable (e.g., `/usr/local/bin`, `~/bin`).

Building from Source (Alternative)

If you prefer to build from source, you will need the [Rust Toolchain](https://rustup.rs/) installed.

1. **Clone the repository:**

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

2. **Build the server:**

   cargo build --release

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

README.md · README · 346 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. # Rust Docs MCP Server
  2. [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
  3. ⭐ **Like this project? Please
  4. [star the repository](https://github.com/Govcraft/rust-docs-mcp-server) on
  5. GitHub to show your support and stay updated!** ⭐
  6. ## Motivation
  7. Modern AI-powered coding assistants (like Cursor, Cline, Roo Code, etc.) excel
  8. at understanding code structure and syntax but often struggle with the specifics
  9. of rapidly evolving libraries and frameworks, especially in ecosystems like Rust
  10. where crates are updated frequently. Their training data cutoff means they may
  11. lack knowledge of the latest APIs, leading to incorrect or outdated code
  12. suggestions.
  13. This MCP server addresses this challenge by providing a focused, up-to-date
  14. knowledge source for a specific Rust crate. By running an instance of this
  15. server for a crate (e.g., `serde`, `tokio`, `reqwest`), you give your LLM coding
  16. assistant a tool (`query_rust_docs`) it can use _before_ writing code related to
  17. that crate.
  18. When instructed to use this tool, the LLM can ask specific questions about the
  19. crate's API or usage and receive answers derived directly from the _current_
  20. documentation. This significantly improves the accuracy and relevance of the
  21. generated code, reducing the need for manual correction and speeding up
  22. development.
  23. Multiple instances of this server can be run concurrently, allowing the LLM
  24. assistant to access documentation for several different crates during a coding
  25. session.
  26. This server fetches the documentation for a specified Rust crate, generates
  27. embeddings for the content, and provides an MCP tool to answer questions about
  28. the crate based on the documentation context.
  29. ## Features
  30. - **Targeted Documentation:** Focuses on a single Rust crate per server
  31. instance.
  32. - **Feature Support:** Allows specifying required crate features for
  33. documentation generation.
  34. - **Semantic Search:** Uses OpenAI's `text-embedding-3-small` model to find the
  35. most relevant documentation sections for a given question.
  36. - **LLM Summarization:** Leverages OpenAI's `gpt-4o-mini-2024-07-18` model to
  37. generate concise answers based _only_ on the retrieved documentation context.
  38. - **Caching:** Caches generated documentation content and embeddings in the
  39. user's XDG data directory (`~/.local/share/rustdocs-mcp-server/` or similar)
  40. based on crate, version, _and_ requested features to speed up subsequent
  41. launches.
  42. - **MCP Integration:** Runs as a standard MCP server over stdio, exposing tools
  43. and resources.
  44. ## Prerequisites
  45. - **OpenAI API Key:** Needed for generating embeddings and summarizing answers.
  46. The server expects this key to be available in the `OPENAI_API_KEY`
  47. environment variable. (The server also requires network access to download
  48. crate dependencies and interact with the OpenAI API).
  49. ## Installation
  50. The recommended way to install is to download the pre-compiled binary for your
  51. operating system from the
  52. [GitHub Releases page](https://github.com/Govcraft/rust-docs-mcp-server/releases).
  53. 1. Go to the
  54. [Releases page](https://github.com/Govcraft/rust-docs-mcp-server/releases).
  55. 2. Download the appropriate archive (`.zip` for Windows, `.tar.gz` for
  56. Linux/macOS) for your system.
  57. 3. Extract the `rustdocs_mcp_server` (or `rustdocs_mcp_server.exe`) binary.
  58. 4. Place the binary in a directory included in your system's `PATH` environment
  59. variable (e.g., `/usr/local/bin`, `~/bin`).
  60. ### Building from Source (Alternative)
  61. If you prefer to build from source, you will need the
  62. [Rust Toolchain](https://rustup.rs/) installed.
  63. 1. **Clone the repository:**
  64. ```bash
  65. git clone https://github.com/Govcraft/rust-docs-mcp-server.git
  66. cd rust-docs-mcp-server
  67. ```
  68. 2. **Build the server:**
  69. ```bash
  70. cargo build --release
  71. ```
  72. ## Usage
  73. **Important Note for New Crates:**
  74. When 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.
  75. It 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.
  76. ### Running the Server
  77. The server is launched from the command line and requires the **Package ID
  78. Specification** for the target crate. This specification follows the format used
  79. by Cargo (e.g., `crate_name`, `crate_name@version_req`). For the full
  80. specification details, see `man cargo-pkgid` or the
  81. [Cargo documentation](https://doc.rust-lang.org/cargo/reference/pkgid-spec.html).
  82. Optionally, you can specify required crate features using the `-F` or
  83. `--features` flag, followed by a comma-separated list of features. This is
  84. necessary for crates that require specific features to be enabled for
  85. `cargo doc` to succeed (e.g., crates requiring a runtime feature like
  86. `async-stripe`).
  87. ```bash
  88. # Set the API key (replace with your actual key)
  89. export OPENAI_API_KEY="sk-..."
  90. # Example: Run server for the latest 1.x version of serde
  91. rustdocs_mcp_server "serde@^1.0"
  92. # Example: Run server for a specific version of reqwest
  93. rustdocs_mcp_server "reqwest@0.12.0"
  94. # Example: Run server for the latest version of tokio
  95. rustdocs_mcp_server tokio
  96. # Example: Run server for async-stripe, enabling a required runtime feature
  97. rustdocs_mcp_server "async-stripe@0.40" -F runtime-tokio-hyper-rustls
  98. # Example: Run server for another crate with multiple features
  99. rustdocs_mcp_server "some-crate@1.2" --features feat1,feat2
  100. ```
  101. On the first run for a specific crate version _and feature set_, the server
  102. will:
  103. 1. Download the crate documentation using `cargo doc` (with specified features).
  104. 2. Parse the HTML documentation.
  105. 3. Generate embeddings for the documentation content using the OpenAI API (this
  106. may take some time and incur costs, though typically only fractions of a US
  107. penny for most crates; even a large crate like `async-stripe` with over 5000
  108. documentation pages cost only $0.18 USD for embedding generation during
  109. testing).
  110. 4. Cache the documentation content and embeddings so that the cost isn't
  111. incurred again.
  112. 5. Start the MCP server.
  113. Subsequent runs for the same crate version _and feature set_ will load the data
  114. from the cache, making startup much faster.
  115. ### MCP Interaction
  116. The server communicates using the Model Context Protocol over standard
  117. input/output (stdio). It exposes the following:
  118. - **Tool: `query_rust_docs`**
  119. - **Description:** Query documentation for the specific Rust crate the server
  120. was started for, using semantic search and LLM summarization.
  121. - **Input Schema:**
  122. ```json
  123. {
  124. "type": "object",
  125. "properties": {
  126. "question": {
  127. "type": "string",
  128. "description": "The specific question about the crate's API or usage."
  129. }
  130. },
  131. "required": ["question"]
  132. }
  133. ```
  134. - **Output:** A text response containing the answer generated by the LLM based
  135. on the relevant documentation context, prefixed with
  136. `From <crate_name> docs:`.
  137. - **Example MCP Call:**
  138. ```json
  139. {
  140. "jsonrpc": "2.0",
  141. "method": "callTool",
  142. "params": {
  143. "tool_name": "query_rust_docs",
  144. "arguments": {
  145. "question": "How do I make a simple GET request with reqwest?"
  146. }
  147. },
  148. "id": 1
  149. }
  150. ```
  151. - **Resource: `crate://<crate_name>`**
  152. - **Description:** Provides the name of the Rust crate this server instance is
  153. configured for.
  154. - **URI:** `crate://<crate_name>` (e.g., `crate://serde`, `crate://reqwest`)
  155. - **Content:** Plain text containing the crate name.
  156. - **Logging:** The server sends informational logs (startup messages, query
  157. processing steps) back to the MCP client via `logging/message` notifications.
  158. ### Example Client Configuration (Roo Code)
  159. You can configure MCP clients like Roo Code to run multiple instances of this
  160. server, each targeting a different crate. Here's an example snippet for Roo
  161. Code's `mcp_settings.json` file, configuring servers for `reqwest` and
  162. `async-stripe` (note the added features argument for `async-stripe`):
  163. ```json
  164. {
  165. "mcpServers": {
  166. "rust-docs-reqwest": {
  167. "command": "/path/to/your/rustdocs_mcp_server",
  168. "args": [
  169. "reqwest@0.12"
  170. ],
  171. "env": {
  172. "OPENAI_API_KEY": "YOUR_OPENAI_API_KEY_HERE"
  173. },
  174. "disabled": false,
  175. "alwaysAllow": []
  176. },
  177. "rust-docs-async-stripe": {
  178. "command": "rustdocs_mcp_server",
  179. "args": [
  180. "async-stripe@0.40",
  181. "-F",
  182. " runtime-tokio-hyper-rustls"
  183. ],
  184. "env": {
  185. "OPENAI_API_KEY": "YOUR_OPENAI_API_KEY_HERE"
  186. },
  187. "disabled": false,
  188. "alwaysAllow": []
  189. }
  190. }
  191. }
  192. ```
  193. **Note:**
  194. - Replace `/path/to/your/rustdocs_mcp_server` with the actual path to the
  195. compiled binary on your system if it isn't in your PATH.
  196. - Replace `YOUR_OPENAI_API_KEY_HERE` with your actual OpenAI API key.
  197. - The keys (`rust-docs-reqwest`, `rust-docs-async-stripe`) are arbitrary names
  198. you choose to identify the server instances within Roo Code.
  199. ### Example Client Configuration (Claude Desktop)
  200. For Claude Desktop users, you can configure the server in the MCP settings.
  201. Here's an example configuring servers for `serde` and `async-stripe`:
  202. ```json
  203. {
  204. "mcpServers": {
  205. "rust-docs-serde": {
  206. "command": "/path/to/your/rustdocs_mcp_server",
  207. "args": [
  208. "serde@^1.0"
  209. ]
  210. },
  211. "rust-docs-async-stripe-rt": {
  212. "command": "rustdocs_mcp_server",
  213. "args": [
  214. "async-stripe@0.40",
  215. "-F",
  216. "runtime-tokio-hyper-rustls"
  217. ]
  218. }
  219. }
  220. }
  221. ```
  222. **Note:**
  223. - Ensure `rustdocs_mcp_server` is in your system's PATH or provide the full path
  224. (e.g., `/path/to/your/rustdocs_mcp_server`).
  225. - The keys (`rust-docs-serde`, `rust-docs-async-stripe-rt`) are arbitrary names
  226. you choose to identify the server instances.
  227. - Remember to set the `OPENAI_API_KEY` environment variable where Claude Desktop
  228. can access it (this might be system-wide or via how you launch Claude
  229. Desktop). Claude Desktop's MCP configuration might not directly support
  230. setting environment variables per-server like Roo Code.
  231. - The example shows how to add the `-F` argument for crates like `async-stripe`
  232. that require specific features.
  233. ### Caching
  234. - **Location:** Cached documentation and embeddings are stored in the XDG data
  235. directory, typically under
  236. `~/.local/share/rustdocs-mcp-server/<crate_name>/<sanitized_version_req>/<features_hash>/embeddings.bin`.
  237. The `sanitized_version_req` is derived from the version requirement, and
  238. `features_hash` is a hash representing the specific combination of features
  239. requested at startup. This ensures different feature sets are cached
  240. separately.
  241. - **Format:** Data is cached using `bincode` serialization.
  242. - **Regeneration:** If the cache file is missing, corrupted, or cannot be
  243. decoded, the server will automatically regenerate the documentation and
  244. embeddings.
  245. ## How it Works
  246. 1. **Initialization:** Parses the crate specification and optional features from
  247. the command line using `clap`.
  248. 2. **Cache Check:** Looks for a pre-existing cache file for the specific crate,
  249. version requirement, and feature set.
  250. 3. **Documentation Generation (if cache miss):**
  251. - Creates a temporary Rust project depending only on the target crate,
  252. enabling the specified features in its `Cargo.toml`.
  253. - Runs `cargo doc` using the `cargo` library API to generate HTML
  254. documentation in the temporary directory.
  255. - Dynamically locates the correct output directory within `target/doc` by
  256. searching for the subdirectory containing `index.html`.
  257. 4. **Content Extraction (if cache miss):**
  258. - Walks the generated HTML files within the located documentation directory.
  259. - Uses the `scraper` crate to parse each HTML file and extract text content
  260. from the main content area (`<section id="main-content">`).
  261. 5. **Embedding Generation (if cache miss):**
  262. - Uses the `async-openai` crate and `tiktoken-rs` to generate embeddings for
  263. each extracted document chunk using the `text-embedding-3-small` model.
  264. - Calculates the estimated cost based on the number of tokens processed.
  265. 6. **Caching (if cache miss):** Saves the extracted document content and their
  266. corresponding embeddings to the cache file (path includes features hash)
  267. using `bincode`.
  268. 7. **Server Startup:** Initializes the `RustDocsServer` with the
  269. loaded/generated documents and embeddings.
  270. 8. **MCP Serving:** Starts the MCP server using `rmcp` over stdio.
  271. 9. **Query Handling (`query_rust_docs` tool):**
  272. - Generates an embedding for the user's question.
  273. - Calculates the cosine similarity between the question embedding and all
  274. cached document embeddings.
  275. - Identifies the document chunk with the highest similarity.
  276. - Sends the user's question and the content of the best-matching document
  277. chunk to the `gpt-4o-mini-2024-07-18` model via the OpenAI API.
  278. - The LLM is prompted to answer the question based _only_ on the provided
  279. context.
  280. - Returns the LLM's response to the MCP client.
  281. ## License
  282. This project is licensed under the MIT License.
  283. Copyright (c) 2025 Govcraft
  284. ## Sponsor
  285. Govcraft 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.
  286. [![Sponsor on GitHub](https://img.shields.io/badge/Sponsor-%E2%9D%A4-%23db61a2?logo=GitHub)](https://github.com/sponsors/Govcraft)

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.