You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+59-15
Original file line number
Diff line number
Diff line change
@@ -20,9 +20,10 @@ This server fetches the documentation for a specified Rust crate, generates embe
20
20
## Features
21
21
22
22
***Targeted Documentation:** Focuses on a single Rust crate per server instance.
23
+
***Feature Support:** Allows specifying required crate features for documentation generation.
23
24
***Semantic Search:** Uses OpenAI's `text-embedding-3-small` model to find the most relevant documentation sections for a given question.
24
25
***LLM Summarization:** Leverages OpenAI's `gpt-4o-mini-2024-07-18` model to generate concise answers based *only* on the retrieved documentation context.
25
-
***Caching:** Caches generated documentation content and embeddings in the user's XDG data directory (`~/.local/share/rustdocs-mcp-server/` or similar) to speed up subsequent launches for the same crate and version.
26
+
***Caching:** Caches generated documentation content and embeddings in the user's XDG data directory (`~/.local/share/rustdocs-mcp-server/` or similar) based on crate, version, *and* requested features to speed up subsequent launches.
26
27
***MCP Integration:** Runs as a standard MCP server over stdio, exposing tools and resources.
27
28
28
29
## Prerequisites
@@ -55,7 +56,9 @@ If you prefer to build from source, you will need the [Rust Toolchain](https://r
55
56
56
57
### Running the Server
57
58
58
-
The server is launched from the command line and requires a single argument: the **Package ID Specification**for the target crate. This specification follows the format used by Cargo (e.g., `crate_name`, `crate_name@version_req`). For the full specification details, see `man cargo-pkgid` or the [Cargo documentation](https://doc.rust-lang.org/cargo/reference/pkgid-spec.html).
59
+
The server is launched from the command line and requires the **Package ID Specification**for the target crate. This specification follows the format used by Cargo (e.g., `crate_name`, `crate_name@version_req`). For the full specification details, see `man cargo-pkgid` or the [Cargo documentation](https://doc.rust-lang.org/cargo/reference/pkgid-spec.html).
60
+
61
+
Optionally, you can specify required crate features using the `-F` or `--features` flag, followed by a comma-separated list of features. This is necessary for crates that require specific features to be enabled for`cargo doc` to succeed (e.g., crates requiring a runtime feature like `async-stripe`).
On the first run for a specific crate version, the server will:
75
-
1. Download the crate documentation using `cargo doc`.
83
+
On the first run for a specific crate version*and feature set*, the server will:
84
+
1. Download the crate documentation using `cargo doc` (with specified features).
76
85
2. Parse the HTML documentation.
77
86
3. Generate embeddings for the documentation content using the OpenAI API (this may take some time and incur costs, though typically only fractions of a US penny for most crates, potentially a few pennies for crates with exceptionally large documentation).
78
87
4. Cache the documentation content and embeddings.
79
88
5. Start the MCP server.
80
89
81
-
Subsequent runs for the same crate version will load the data from the cache, making startup much faster.
90
+
Subsequent runs for the same crate version *and feature set*will load the data from the cache, making startup much faster.
82
91
83
92
### MCP Interaction
84
93
@@ -125,7 +134,7 @@ The server communicates using the Model Context Protocol over standard input/out
125
134
126
135
### Example Client Configuration (Roo Code)
127
136
128
-
You can configure MCP clients like Roo Code to run multiple instances of this server, each targeting a different crate. Here's an example snippet for Roo Code's `mcp_settings.json` file, configuring servers for`reqwest` and `sqlx`:
137
+
You can configure MCP clients like Roo Code to run multiple instances of this server, each targeting a different crate. Here's an example snippet for Roo Code's `mcp_settings.json` file, configuring servers for`reqwest` and `async-stripe` (note the added features argument for`async-stripe`):
129
138
130
139
```json
131
140
{
@@ -141,10 +150,12 @@ You can configure MCP clients like Roo Code to run multiple instances of this se
* Ensure `rustdocs_mcp_server` is in your system's PATH or provide the full path (e.g., `/path/to/your/rustdocs_mcp_server`).
203
+
* The keys (`rust-docs-serde`, `rust-docs-async-stripe-rt`) are arbitrary names you choose to identify the server instances.
204
+
* Remember to set the `OPENAI_API_KEY` environment variable where Claude Desktop can access it (this might be system-wide or via how you launch Claude Desktop). Claude Desktop's MCP configuration might not directly support setting environment variables per-server like Roo Code.
205
+
* The example shows how to add the `-F` argument for crates like `async-stripe` that require specific features.
163
206
164
207
### Caching
165
208
166
-
* **Location:** Cached documentation and embeddings are stored in the XDG data directory, typically under `~/.local/share/rustdocs-mcp-server/<crate_name>/<sanitized_version_req>/embeddings.bin`. The `sanitized_version_req` is derived from the version requirement provided at startup.
209
+
***Location:** Cached documentation and embeddings are stored in the XDG data directory, typically under `~/.local/share/rustdocs-mcp-server/<crate_name>/<sanitized_version_req>/<features_hash>/embeddings.bin`. The `sanitized_version_req` is derived from the version requirement, and `features_hash` is a hash representing the specific combination of features requested at startup. This ensures different feature sets are cached separately.
167
210
***Format:** Data is cached using `bincode` serialization.
168
211
***Regeneration:** If the cache file is missing, corrupted, or cannot be decoded, the server will automatically regenerate the documentation and embeddings.
169
212
170
213
## How it Works
171
214
172
-
1. **Initialization:** Takes the crate specification from the command line.
173
-
2. **Cache Check:** Looks for a pre-existing cache file for the specific crate and version requirement.
215
+
1. **Initialization:**Parses the crate specification and optional features from the command line using `clap`.
216
+
2. **Cache Check:** Looks for a pre-existing cache file for the specific crate, version requirement, and feature set.
174
217
3. **Documentation Generation (if cache miss):**
175
-
* Creates a temporary Rust project depending only on the target crate.
218
+
* Creates a temporary Rust project depending only on the target crate, enabling the specified features in its `Cargo.toml`.
176
219
* Runs `cargo doc` using the `cargo` library API to generate HTML documentation in the temporary directory.
220
+
* Dynamically locates the correct output directory within `target/doc` by searching for the subdirectory containing `index.html`.
177
221
4. **Content Extraction (if cache miss):**
178
-
* Walks the generated HTML files.
222
+
* Walks the generated HTML files within the located documentation directory.
179
223
* Uses the `scraper` crate to parse each HTML file and extract text content from the main content area (`<section id="main-content">`).
180
224
5. **Embedding Generation (if cache miss):**
181
225
* Uses the `async-openai` crate and `tiktoken-rs` to generate embeddings for each extracted document chunk using the `text-embedding-3-small` model.
182
226
* Calculates the estimated cost based on the number of tokens processed.
183
-
6. **Caching (if cache miss):** Saves the extracted document content and their corresponding embeddings to the cache file using `bincode`.
227
+
6. **Caching (if cache miss):** Saves the extracted document content and their corresponding embeddings to the cache file (path includes features hash) using `bincode`.
184
228
7. **Server Startup:** Initializes the `RustDocsServer` with the loaded/generated documents and embeddings.
185
229
8. **MCP Serving:** Starts the MCP server using `rmcp` over stdio.
0 commit comments