mcp-rustdoc 4.0.0 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +73 -175
  2. package/dist/index.js +25 -1126
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,20 +1,25 @@
1
1
  # mcp-rustdoc
2
2
 
3
- An MCP server that gives AI assistants deep access to the Rust ecosystem. It scrapes docs.rs (and `doc.rust-lang.org` for `std`/`core`/`alloc`) with surgical DOM extraction (cheerio) and queries the crates.io API, exposing nine tools that cover everything from high-level crate overviews to individual method signatures, feature gates, trait impls, and code examples. Responses are cached in memory (5-minute TTL) to avoid redundant fetches.
3
+ An MCP server that gives AI assistants deep access to the Rust ecosystem. It scrapes docs.rs (and `doc.rust-lang.org` for `std`/`core`/`alloc`) with surgical DOM extraction (cheerio) and queries the crates.io API, exposing twelve tools that cover everything from high-level crate overviews to individual method signatures, feature gates, trait impls, code examples, changelogs, and source code.
4
+
5
+ Zero external HTTP dependencies — uses native `fetch` (Node.js >= 20). Responses are cached with LRU eviction (500 entries, 5-minute TTL, stale-while-revalidate) and all HTTP calls retry on transient failures.
4
6
 
5
7
  ## Tools
6
8
 
7
9
  | Tool | What it returns |
8
10
  |---|---|
9
- | `get_crate_metadata` | Version, features, default features, optional/required deps, links (crates.io API) |
11
+ | `get_crate_metadata` | Version, features, deps, MSRV, links (crates.io API) |
10
12
  | `get_crate_brief` | One-shot bundle: metadata + overview + re-exports + module list + focused module items |
11
13
  | `lookup_crate_docs` | Crate overview documentation, version, sections, re-exports |
12
- | `get_crate_items` | Items in a module with types, feature gates, and descriptions |
13
- | `lookup_crate_item` | Item detail: signature, docs, methods, variants, optionally trait impls + examples |
14
+ | `get_crate_items` | Items in a module with types, feature gates, and descriptions. Filterable by type and feature. |
15
+ | `lookup_crate_item` | Item detail: signature, docs, methods, variants, trait impls, examples. Auto-discovers module path. |
14
16
  | `search_crate` | Ranked symbol search (exact > prefix > substring) with canonical paths |
15
17
  | `search_crates` | Search crates.io by keyword — returns name, description, downloads, version |
16
18
  | `get_crate_versions` | All published versions with dates and yanked status (crates.io API) |
17
19
  | `get_source_code` | Raw source code of a file from docs.rs or doc.rust-lang.org |
20
+ | `batch_lookup` | Look up multiple items in one call (up to 20) — saves round-trips |
21
+ | `get_crate_changelog` | Recent GitHub releases for a crate |
22
+ | `resolve_type` | Resolve a full Rust type path (e.g. `tokio::sync::Mutex`) to its documentation |
18
23
 
19
24
  Every tool accepts an optional `version` parameter to pin a specific crate version instead of `latest`.
20
25
 
@@ -115,7 +120,7 @@ npx @modelcontextprotocol/inspector -- npx -y mcp-rustdoc
115
120
  ```bash
116
121
  git clone https://github.com/kieled/mcp-rustdoc.git
117
122
  cd mcp-rustdoc
118
- bun install
123
+ npm install
119
124
  ```
120
125
 
121
126
  ### Run with bun (no build step)
@@ -127,21 +132,21 @@ bun run dev
127
132
  ### Build with Vite and run with Node.js
128
133
 
129
134
  ```bash
130
- bun run build # vite build → dist/index.js (single bundled ESM file)
135
+ npm run build # vite build → dist/index.js (single bundled ESM file)
131
136
  node dist/index.js
132
137
  ```
133
138
 
134
139
  ### Build with tsc
135
140
 
136
141
  ```bash
137
- bun run build:tsc # tsc → dist/ (one .js per source file)
142
+ npm run build:tsc # tsc → dist/ (one .js per source file)
138
143
  node dist/index.js
139
144
  ```
140
145
 
141
146
  ### Type check only
142
147
 
143
148
  ```bash
144
- bun run typecheck # tsc --noEmit
149
+ npm run typecheck # tsc --noEmit
145
150
  ```
146
151
 
147
152
  ### Publish
@@ -163,32 +168,7 @@ Fetches structured metadata from the crates.io API.
163
168
  | `crateName` | string | yes | Crate name |
164
169
  | `version` | string | no | Pinned version |
165
170
 
166
- Returns: version, description, links (docs/repo/crates.io), license, download count, full feature list with activations, optional deps (feature-gated), required deps.
167
-
168
- ```
169
- > get_crate_metadata({ crateName: "tokio" })
170
-
171
- # tokio v1.49.0
172
-
173
- An event-driven, non-blocking I/O platform for writing asynchronous applications...
174
-
175
- ## Links
176
- docs: https://docs.rs/tokio
177
- repo: https://github.com/tokio-rs/tokio
178
- license: MIT
179
- downloads: 312,456,789
180
-
181
- ## Features
182
- default = [macros, rt-multi-thread]
183
- fs = []
184
- full = [fs, io-util, io-std, macros, net, ...]
185
- io-util = [bytes]
186
- ...
187
-
188
- ## Optional Dependencies
189
- bytes ^1 (feature-gated)
190
- ...
191
- ```
171
+ Returns: version, description, links (docs/repo/crates.io), license, download count, MSRV, full feature list with activations, optional deps (feature-gated), required deps.
192
172
 
193
173
  ---
194
174
 
@@ -202,37 +182,6 @@ Single call to bootstrap context for a crate. Combines metadata, overview docs,
202
182
  | `version` | string | no | Pinned version |
203
183
  | `focusModules` | string | no | Comma-separated modules to expand (e.g. `"sync,task"`) |
204
184
 
205
- ```
206
- > get_crate_brief({ crateName: "tokio", focusModules: "sync,task" })
207
-
208
- # tokio v1.49.0
209
- ...
210
- ## Features
211
- default = [macros, rt-multi-thread]
212
- all: bytes, fs, full, io-std, io-util, ...
213
-
214
- ## Overview
215
- [truncated crate doc]
216
-
217
- ## Re-exports
218
- pub use task::spawn;
219
- ...
220
-
221
- ## Modules
222
- fs io macros net runtime signal sync task time
223
-
224
- ## Focus: tokio::sync
225
- [struct] Barrier — ...
226
- [struct] Mutex [sync] — ...
227
- [struct] Notify [sync] — ...
228
- ...
229
-
230
- ## Focus: tokio::task
231
- [fn] spawn — ...
232
- [struct] JoinHandle — ...
233
- ...
234
- ```
235
-
236
185
  ---
237
186
 
238
187
  ### `lookup_crate_docs`
@@ -250,79 +199,32 @@ Returns: crate version, overview documentation text, re-exports, and section lis
250
199
 
251
200
  ### `get_crate_items`
252
201
 
253
- Lists all public items in a crate root or specific module.
202
+ Lists all public items in a crate root or specific module. Supports filtering by item type and feature gate.
254
203
 
255
204
  | Parameter | Type | Required | Description |
256
205
  |---|---|---|---|
257
206
  | `crateName` | string | yes | Crate name |
258
207
  | `modulePath` | string | no | Dot-separated path (e.g. `"sync"`, `"io.util"`) |
259
208
  | `itemType` | enum | no | Filter: `mod` `struct` `enum` `trait` `fn` `macro` `type` `constant` `static` `union` `attr` `derive` |
209
+ | `feature` | string | no | Filter to items behind this feature gate (e.g. `"sync"`, `"fs"`) |
260
210
  | `version` | string | no | Pinned version |
261
211
 
262
- Each item includes its type, name, feature gate (if any), and short description.
263
-
264
- ```
265
- > get_crate_items({ crateName: "tokio", modulePath: "sync", itemType: "struct" })
266
-
267
- # Items in tokio::sync [struct]
268
- [struct] Barrier — ...
269
- [struct] Mutex [feature: sync] — ...
270
- [struct] Notify [feature: sync] — ...
271
- [struct] OwnedMutexGuard [feature: sync] — ...
272
- ...
273
- ```
274
-
275
212
  ---
276
213
 
277
214
  ### `lookup_crate_item`
278
215
 
279
- Retrieves full documentation for a single item.
216
+ Retrieves full documentation for a single item. Auto-discovers the module path if omitted by searching `all.html`. Falls back to fuzzy suggestions if the exact item is not found.
280
217
 
281
218
  | Parameter | Type | Required | Description |
282
219
  |---|---|---|---|
283
220
  | `crateName` | string | yes | Crate name |
284
221
  | `itemType` | enum | yes | Item type (see `get_crate_items`) |
285
222
  | `itemName` | string | yes | Item name (e.g. `"Mutex"`, `"spawn"`) |
286
- | `modulePath` | string | no | Dot-separated module path |
223
+ | `modulePath` | string | no | Dot-separated module path. Auto-discovered if omitted. |
287
224
  | `version` | string | no | Pinned version |
288
225
  | `includeImpls` | boolean | no | Include trait implementation list |
289
226
  | `includeExamples` | boolean | no | Include code examples |
290
227
 
291
- Returns: feature gate (if any), type signature, documentation text, methods list, enum variants, required/provided trait methods. Optionally includes trait implementations and code examples.
292
-
293
- ```
294
- > lookup_crate_item({
295
- crateName: "tokio",
296
- itemType: "struct",
297
- itemName: "Mutex",
298
- modulePath: "sync",
299
- includeImpls: true
300
- })
301
-
302
- # struct tokio::sync::Mutex
303
- > Available on crate feature `sync` only.
304
-
305
- ## Signature
306
- pub struct Mutex<T: ?Sized> { ... }
307
-
308
- ## Documentation
309
- An asynchronous Mutex...
310
-
311
- ## Methods (12)
312
- pub fn new(t: T) -> Mutex<T>
313
- pub fn lock(&self) -> impl Future<Output = MutexGuard<'_, T>>
314
- pub fn try_lock(&self) -> Result<MutexGuard<'_, T>, TryLockError>
315
- ...
316
-
317
- ## Trait Implementations (15)
318
- impl<T: ?Sized + Debug> Debug for Mutex<T>
319
- impl<T> Default for Mutex<T>
320
- impl<T> From<T> for Mutex<T>
321
- impl<T: ?Sized> Send for Mutex<T>
322
- impl<T: ?Sized> Sync for Mutex<T>
323
- ...
324
- ```
325
-
326
228
  ---
327
229
 
328
230
  ### `search_crate`
@@ -335,19 +237,6 @@ Searches all items in a crate by name. Results are ranked: exact match on the ba
335
237
  | `query` | string | yes | Search query (case-insensitive) |
336
238
  | `version` | string | no | Pinned version |
337
239
 
338
- ```
339
- > search_crate({ crateName: "tokio", query: "Mutex" })
340
-
341
- # "Mutex" in tokio — 6 matches
342
-
343
- [struct] tokio::sync::Mutex
344
- [struct] tokio::sync::MutexGuard
345
- [struct] tokio::sync::OwnedMutexGuard
346
- [struct] tokio::sync::MappedMutexGuard
347
- [enum] tokio::sync::TryLockError
348
- ...
349
- ```
350
-
351
240
  ---
352
241
 
353
242
  ### `search_crates`
@@ -360,17 +249,6 @@ Search for Rust crates on crates.io by keyword.
360
249
  | `page` | number | no | Page number (default 1) |
361
250
  | `perPage` | number | no | Results per page (default 10, max 50) |
362
251
 
363
- ```
364
- > search_crates({ query: "http" })
365
-
366
- # Crate search: "http" — 1234 results (page 1)
367
-
368
- http v1.2.0 (50,000,000 downloads) — A set of types for representing HTTP requests and responses.
369
- hyper v1.5.2 (120,000,000 downloads) — A fast and correct HTTP library.
370
- reqwest v0.12.12 (100,000,000 downloads) — higher level HTTP client library
371
- ...
372
- ```
373
-
374
252
  ---
375
253
 
376
254
  ### `get_crate_versions`
@@ -381,18 +259,6 @@ List all published versions of a crate from crates.io.
381
259
  |---|---|---|---|
382
260
  | `crateName` | string | yes | Crate name |
383
261
 
384
- ```
385
- > get_crate_versions({ crateName: "serde" })
386
-
387
- # serde — 312 versions
388
-
389
- 1.0.219 2025-02-01
390
- 1.0.218 2025-01-12
391
- 1.0.217 2024-12-23
392
- ...
393
- 0.1.0 2014-12-09
394
- ```
395
-
396
262
  ---
397
263
 
398
264
  ### `get_source_code`
@@ -405,17 +271,39 @@ Fetch the raw source code of a file from docs.rs (or doc.rust-lang.org for std c
405
271
  | `path` | string | yes | Source path relative to crate root (e.g. `"src/lib.rs"`, `"src/sync/mutex.rs"`) |
406
272
  | `version` | string | no | Pinned version |
407
273
 
408
- ```
409
- > get_source_code({ crateName: "tokio", path: "src/sync/mutex.rs" })
274
+ ---
410
275
 
411
- # Source: tokio/src/sync/mutex.rs
412
- https://docs.rs/tokio/latest/src/tokio/sync/mutex.rs
276
+ ### `batch_lookup`
413
277
 
414
- \`\`\`rust
415
- use crate::sync::batch_semaphore as semaphore;
416
- ...
417
- \`\`\`
418
- ```
278
+ Look up multiple items in a single call. Returns a compact summary (signature + short doc) for each item. Saves round-trips when you need several items at once.
279
+
280
+ | Parameter | Type | Required | Description |
281
+ |---|---|---|---|
282
+ | `crateName` | string | yes | Crate name |
283
+ | `items` | array | yes | Items to look up (max 20). Each: `{ itemType, itemName, modulePath? }` |
284
+ | `version` | string | no | Pinned version |
285
+
286
+ ---
287
+
288
+ ### `get_crate_changelog`
289
+
290
+ Fetch recent GitHub releases for a crate. Requires the crate to have a GitHub repository link on crates.io.
291
+
292
+ | Parameter | Type | Required | Description |
293
+ |---|---|---|---|
294
+ | `crateName` | string | yes | Crate name |
295
+ | `count` | number | no | Number of releases (default 5, max 20) |
296
+
297
+ ---
298
+
299
+ ### `resolve_type`
300
+
301
+ Resolve a full Rust type path to its documentation. Parses the path to determine the crate, module, and item name automatically.
302
+
303
+ | Parameter | Type | Required | Description |
304
+ |---|---|---|---|
305
+ | `typePath` | string | yes | Full Rust type path (e.g. `"tokio::sync::Mutex"`, `"std::collections::HashMap"`) |
306
+ | `version` | string | no | Pinned version |
419
307
 
420
308
  ---
421
309
 
@@ -425,18 +313,23 @@ use crate::sync::batch_semaphore as semaphore;
425
313
 
426
314
  1. `get_crate_brief` with `focusModules` targeting the modules you care about
427
315
  2. `search_crate` to find specific types or functions
428
- 3. `lookup_crate_item` for detailed signatures and docs
316
+ 3. `lookup_crate_item` for detailed signatures and docs (no need to specify `modulePath` — it auto-discovers)
429
317
 
430
318
  ### Understanding feature flags
431
319
 
432
- 1. `get_crate_metadata` to see all features and their activations
433
- 2. `get_crate_items` to see which items require which features
320
+ 1. `get_crate_metadata` to see all features, their activations, and MSRV
321
+ 2. `get_crate_items` with the `feature` parameter to see items behind a specific feature gate
434
322
 
435
323
  ### Finding the right type
436
324
 
437
325
  1. `search_crate` with a keyword
438
326
  2. `lookup_crate_item` with `includeImpls: true` to see what traits it implements
439
- 3. `lookup_crate_item` on referenced types to chase cross-links
327
+ 3. `resolve_type` to chase cross-crate type paths (e.g. `tokio::sync::Mutex`)
328
+
329
+ ### Bulk lookups
330
+
331
+ 1. `batch_lookup` to fetch signatures and docs for multiple items in one call
332
+ 2. `get_crate_changelog` to see what changed in recent releases
440
333
 
441
334
  ---
442
335
 
@@ -444,11 +337,9 @@ use crate::sync::batch_semaphore as semaphore;
444
337
 
445
338
  ```
446
339
  src/
447
- index.ts Entry point — registers tools + prompt, starts stdio server
448
- lib.ts Shared: URL builders, HTTP/DOM helpers, crates.io API, extractors
449
- cache.ts In-memory TTL cache (5-minute default)
450
- types/
451
- html-to-text.d.ts Type declarations for html-to-text
340
+ index.ts Entry point — registers 12 tools + prompt, starts stdio server
341
+ lib.ts HTTP (native fetch), URL builders, DOM helpers, crates.io API, extractors
342
+ cache.ts LRU cache (500 entries, 5-min TTL, stale-while-revalidate)
452
343
  tools/
453
344
  shared.ts Shared Zod schemas (itemTypeEnum, versionParam)
454
345
  lookup-docs.ts lookup_crate_docs
@@ -460,6 +351,9 @@ src/
460
351
  source-code.ts get_source_code
461
352
  crate-metadata.ts get_crate_metadata
462
353
  crate-brief.ts get_crate_brief
354
+ batch-lookup.ts batch_lookup
355
+ crate-changelog.ts get_crate_changelog
356
+ resolve-type.ts resolve_type
463
357
  ```
464
358
 
465
359
  ### Data sources
@@ -467,14 +361,18 @@ src/
467
361
  - **docs.rs** — HTML pages parsed with cheerio for surgical DOM extraction (only the elements needed, not full-page conversion)
468
362
  - **doc.rust-lang.org** — Same rustdoc HTML format, used for `std`, `core`, and `alloc`
469
363
  - **crates.io API** — JSON endpoints for metadata, features, dependencies, and search
364
+ - **GitHub API** — Release notes for changelogs (via repository link from crates.io)
470
365
 
471
366
  ### Design decisions
472
367
 
473
- - **cheerio over full-page text conversion** — Extracts only specific DOM elements (`.item-decl`, `.top-doc`, `.code-header`, `.stab.portability`) to minimize token usage
474
- - **Ranked search** — `all.html` contains every public item; scoring by exact/prefix/substring gives better results than flat substring matching
475
- - **Version parameter everywhere** — Agents working on projects with pinned dependencies need to read docs for specific versions
476
- - **Optional sections** — `includeImpls` and `includeExamples` default to off so the base response stays compact; agents opt in when they need more detail
477
- - **In-memory cache** — All HTTP responses are cached for 5 minutes, avoiding redundant fetches when agents issue multiple related tool calls
368
+ - **Native fetch, zero HTTP deps** — Uses Node.js built-in `fetch` with `AbortController` timeouts. No axios, no node-fetch.
369
+ - **cheerio for DOM extraction** — Extracts only specific DOM elements (`.item-decl`, `.top-doc`, `.code-header`, `.stab.portability`) to minimize token usage. Also powers `cleanHtml()` as a replacement for `html-to-text`.
370
+ - **LRU cache with stale-while-revalidate** — 500-entry cap with LRU eviction. Stale entries (past 5-min TTL but within 15-min grace) are served immediately while a background refresh runs.
371
+ - **Retry with backoff** — Transient 5xx errors are retried up to 2 times with exponential backoff.
372
+ - **Ranked search** — `all.html` contains every public item; scoring by exact/prefix/substring gives better results than flat substring matching.
373
+ - **Auto-discovery** — `lookup_crate_item` searches `all.html` to find the module path when not provided, and falls back to fuzzy suggestions when an exact match fails.
374
+ - **Version parameter everywhere** — Agents working on projects with pinned dependencies can read docs for specific versions.
375
+ - **Optional sections** — `includeImpls` and `includeExamples` default to off so the base response stays compact; agents opt in when they need more detail.
478
376
 
479
377
  ## License
480
378