Skip to content

Commit f3d8b7b

Browse files
committed
docs: update readme regarding features arg
1 parent 4cc9eeb commit f3d8b7b

File tree

1 file changed

+59
-15
lines changed

1 file changed

+59
-15
lines changed

Diff for: README.md

+59-15
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ This server fetches the documentation for a specified Rust crate, generates embe
2020
## Features
2121

2222
* **Targeted Documentation:** Focuses on a single Rust crate per server instance.
23+
* **Feature Support:** Allows specifying required crate features for documentation generation.
2324
* **Semantic Search:** Uses OpenAI's `text-embedding-3-small` model to find the most relevant documentation sections for a given question.
2425
* **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.
2627
* **MCP Integration:** Runs as a standard MCP server over stdio, exposing tools and resources.
2728

2829
## Prerequisites
@@ -55,7 +56,9 @@ If you prefer to build from source, you will need the [Rust Toolchain](https://r
5556

5657
### Running the Server
5758

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`).
5962

6063
```bash
6164
# Set the API key (replace with your actual key)
@@ -69,16 +72,22 @@ export OPENAI_API_KEY="sk-..."
6972
7073
# Example: Run server for the latest version of tokio
7174
./target/release/rustdocs_mcp_server tokio
75+
76+
# Example: Run server for async-stripe, enabling a required runtime feature
77+
./target/release/rustdocs_mcp_server "[email protected]" -F runtime-tokio-hyper-rustls
78+
79+
# Example: Run server for another crate with multiple features
80+
./target/release/rustdocs_mcp_server "[email protected]" --features feat1,feat2
7281
```
7382

74-
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).
7685
2. Parse the HTML documentation.
7786
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).
7887
4. Cache the documentation content and embeddings.
7988
5. Start the MCP server.
8089

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.
8291

8392
### MCP Interaction
8493

@@ -125,7 +134,7 @@ The server communicates using the Model Context Protocol over standard input/out
125134

126135
### Example Client Configuration (Roo Code)
127136

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`):
129138

130139
```json
131140
{
@@ -141,10 +150,12 @@ You can configure MCP clients like Roo Code to run multiple instances of this se
141150
"disabled": false,
142151
"alwaysAllow": []
143152
},
144-
"rust-docs-sqlx": {
153+
"rust-docs-async-stripe": {
145154
"command": "rustdocs_mcp_server",
146155
"args": [
147-
156+
157+
"-F",
158+
"runtime-tokio-hyper-rustls"
148159
],
149160
"env": {
150161
"OPENAI_API_KEY": "YOUR_OPENAI_API_KEY_HERE"
@@ -159,28 +170,61 @@ You can configure MCP clients like Roo Code to run multiple instances of this se
159170
**Note:**
160171
* Replace `/path/to/your/rustdocs_mcp_server` with the actual path to the compiled binary on your system if it isn't in your PATH.
161172
* Replace `YOUR_OPENAI_API_KEY_HERE` with your actual OpenAI API key.
162-
* The keys (`rust-docs-reqwest`, `rust-docs-sqlx`) are arbitrary names you choose to identify the server instances within Roo Code.
173+
* The keys (`rust-docs-reqwest`, `rust-docs-async-stripe`) are arbitrary names you choose to identify the server instances within Roo Code.
174+
175+
176+
### Example Client Configuration (Claude Desktop)
177+
178+
For Claude Desktop users, you can configure the server in the MCP settings. Here's an example configuring servers for `serde` and `async-stripe`:
179+
180+
```json
181+
{
182+
"mcpServers": {
183+
"rust-docs-serde": {
184+
"command": "/path/to/your/rustdocs_mcp_server",
185+
"args": [
186+
"serde@^1.0"
187+
]
188+
},
189+
"rust-docs-async-stripe-rt": {
190+
"command": "rustdocs_mcp_server",
191+
"args": [
192+
193+
"-F",
194+
"runtime-tokio-hyper-rustls"
195+
]
196+
}
197+
}
198+
}
199+
```
200+
201+
**Note:**
202+
* 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.
163206

164207
### Caching
165208

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.
167210
* **Format:** Data is cached using `bincode` serialization.
168211
* **Regeneration:** If the cache file is missing, corrupted, or cannot be decoded, the server will automatically regenerate the documentation and embeddings.
169212

170213
## How it Works
171214

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.
174217
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`.
176219
* 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`.
177221
4. **Content Extraction (if cache miss):**
178-
* Walks the generated HTML files.
222+
* Walks the generated HTML files within the located documentation directory.
179223
* Uses the `scraper` crate to parse each HTML file and extract text content from the main content area (`<section id="main-content">`).
180224
5. **Embedding Generation (if cache miss):**
181225
* Uses the `async-openai` crate and `tiktoken-rs` to generate embeddings for each extracted document chunk using the `text-embedding-3-small` model.
182226
* 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`.
184228
7. **Server Startup:** Initializes the `RustDocsServer` with the loaded/generated documents and embeddings.
185229
8. **MCP Serving:** Starts the MCP server using `rmcp` over stdio.
186230
9. **Query Handling (`query_rust_docs` tool):**

0 commit comments

Comments
 (0)