mcp-rustdoc 4.0.0 → 4.0.2

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 +41 -428
  2. package/dist/index.js +25 -1126
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,39 +1,28 @@
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
+ MCP server for browsing Rust crate documentation. Scrapes docs.rs, doc.rust-lang.org (`std`/`core`/`alloc`), and the crates.io API. Zero HTTP dependencies native `fetch` only.
4
4
 
5
5
  ## Tools
6
6
 
7
- | Tool | What it returns |
7
+ | Tool | Description |
8
8
  |---|---|
9
- | `get_crate_metadata` | Version, features, default features, optional/required deps, links (crates.io API) |
10
- | `get_crate_brief` | One-shot bundle: metadata + overview + re-exports + module list + focused module items |
11
- | `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
- | `search_crate` | Ranked symbol search (exact > prefix > substring) with canonical paths |
15
- | `search_crates` | Search crates.io by keyword — returns name, description, downloads, version |
16
- | `get_crate_versions` | All published versions with dates and yanked status (crates.io API) |
17
- | `get_source_code` | Raw source code of a file from docs.rs or doc.rust-lang.org |
18
-
19
- Every tool accepts an optional `version` parameter to pin a specific crate version instead of `latest`.
20
-
21
- ### Standard library support
22
-
23
- All documentation tools work with `std`, `core`, and `alloc` — the Rust standard library crates hosted at `doc.rust-lang.org`. Use them exactly like any other crate:
24
-
25
- ```
26
- > lookup_crate_docs({ crateName: "std" })
27
- > get_crate_items({ crateName: "std", modulePath: "collections" })
28
- > search_crate({ crateName: "core", query: "Option" })
29
- ```
30
-
31
- `get_crate_metadata` returns a helpful message for std crates since they aren't published on crates.io.
9
+ | `get_crate_metadata` | Version, features, deps, MSRV, links |
10
+ | `get_crate_brief` | Metadata + overview + modules + focused module items in one call |
11
+ | `lookup_crate_docs` | Crate overview, version, sections, re-exports |
12
+ | `get_crate_items` | Items in a module. Filter by type and feature gate. |
13
+ | `lookup_crate_item` | Full item docs: signature, methods, variants, impls, examples. Auto-discovers module path. |
14
+ | `search_crate` | Ranked symbol search within a crate |
15
+ | `search_crates` | Search crates.io by keyword |
16
+ | `get_crate_versions` | All published versions with dates and yanked status |
17
+ | `get_source_code` | Raw source code from docs.rs |
18
+ | `batch_lookup` | Multiple item lookups in one call (up to 20) |
19
+ | `get_crate_changelog` | GitHub releases for a crate |
20
+ | `resolve_type` | Resolve a type path like `tokio::sync::Mutex` to its docs |
21
+
22
+ All tools accept an optional `version` parameter.
32
23
 
33
24
  ## Install
34
25
 
35
- No clone needed. Just configure your AI coding assistant with `npx`:
36
-
37
26
  ```
38
27
  npx -y mcp-rustdoc
39
28
  ```
@@ -44,33 +33,10 @@ npx -y mcp-rustdoc
44
33
  claude mcp add mcp-rustdoc -- npx -y mcp-rustdoc
45
34
  ```
46
35
 
47
- Or add to your project's `.mcp.json`:
48
-
49
- ```json
50
- {
51
- "mcpServers": {
52
- "mcp-rustdoc": {
53
- "type": "stdio",
54
- "command": "npx",
55
- "args": ["-y", "mcp-rustdoc"]
56
- }
57
- }
58
- }
59
- ```
60
-
61
36
  ### Gemini CLI
62
37
 
63
- Add to `~/.gemini/settings.json` (global) or `.gemini/settings.json` (project):
64
-
65
38
  ```json
66
- {
67
- "mcpServers": {
68
- "mcp-rustdoc": {
69
- "command": "npx",
70
- "args": ["-y", "mcp-rustdoc"]
71
- }
72
- }
73
- }
39
+ { "mcpServers": { "mcp-rustdoc": { "command": "npx", "args": ["-y", "mcp-rustdoc"] } } }
74
40
  ```
75
41
 
76
42
  ### OpenAI Codex CLI
@@ -79,402 +45,49 @@ Add to `~/.gemini/settings.json` (global) or `.gemini/settings.json` (project):
79
45
  codex mcp add mcp-rustdoc -- npx -y mcp-rustdoc
80
46
  ```
81
47
 
82
- Or add to `~/.codex/config.toml`:
83
-
84
- ```toml
85
- [mcp_servers.mcp-rustdoc]
86
- command = "npx"
87
- args = ["-y", "mcp-rustdoc"]
88
- ```
89
-
90
48
  ### Claude Desktop
91
49
 
92
- Add to your `claude_desktop_config.json`:
93
-
94
50
  ```json
95
- {
96
- "mcpServers": {
97
- "mcp-rustdoc": {
98
- "command": "npx",
99
- "args": ["-y", "mcp-rustdoc"]
100
- }
101
- }
102
- }
51
+ { "mcpServers": { "mcp-rustdoc": { "command": "npx", "args": ["-y", "mcp-rustdoc"] } } }
103
52
  ```
104
53
 
105
- ### MCP Inspector (testing)
54
+ ## Parameters
106
55
 
107
- ```bash
108
- npx @modelcontextprotocol/inspector -- npx -y mcp-rustdoc
109
- ```
56
+ Every tool takes `crateName` (string, required) and `version` (string, optional). Additional parameters:
110
57
 
111
- ---
58
+ | Tool | Extra parameters |
59
+ |---|---|
60
+ | `get_crate_brief` | `focusModules` — comma-separated modules to expand |
61
+ | `get_crate_items` | `modulePath`, `itemType`, `feature` |
62
+ | `lookup_crate_item` | `itemType` (required), `itemName` (required), `modulePath`, `includeImpls`, `includeExamples` |
63
+ | `search_crate` | `query` (required) |
64
+ | `search_crates` | `query` (required), `page`, `perPage` |
65
+ | `get_source_code` | `path` (required) |
66
+ | `batch_lookup` | `items` (required) — array of `{ itemType, itemName, modulePath? }`, max 20 |
67
+ | `get_crate_changelog` | `count` — number of releases (default 5) |
68
+ | `resolve_type` | `typePath` (required) — e.g. `"tokio::sync::Mutex"` |
112
69
 
113
70
  ## Development
114
71
 
115
72
  ```bash
116
73
  git clone https://github.com/kieled/mcp-rustdoc.git
117
- cd mcp-rustdoc
118
- bun install
119
- ```
120
-
121
- ### Run with bun (no build step)
122
-
123
- ```bash
124
- bun run dev
125
- ```
126
-
127
- ### Build with Vite and run with Node.js
128
-
129
- ```bash
130
- bun run build # vite build → dist/index.js (single bundled ESM file)
131
- node dist/index.js
74
+ cd mcp-rustdoc && npm install
132
75
  ```
133
76
 
134
- ### Build with tsc
135
-
136
77
  ```bash
137
- bun run build:tsc # tsc dist/ (one .js per source file)
138
- node dist/index.js
139
- ```
140
-
141
- ### Type check only
142
-
143
- ```bash
144
- bun run typecheck # tsc --noEmit
145
- ```
146
-
147
- ### Publish
148
-
149
- ```bash
150
- npm publish # runs vite build via prepublishOnly, then publishes
151
- ```
152
-
153
- ---
154
-
155
- ## Tool reference
156
-
157
- ### `get_crate_metadata`
158
-
159
- Fetches structured metadata from the crates.io API.
160
-
161
- | Parameter | Type | Required | Description |
162
- |---|---|---|---|
163
- | `crateName` | string | yes | Crate name |
164
- | `version` | string | no | Pinned version |
165
-
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
- ```
192
-
193
- ---
194
-
195
- ### `get_crate_brief`
196
-
197
- Single call to bootstrap context for a crate. Combines metadata, overview docs, re-exports, module list, and optionally expands focused modules.
198
-
199
- | Parameter | Type | Required | Description |
200
- |---|---|---|---|
201
- | `crateName` | string | yes | Crate name |
202
- | `version` | string | no | Pinned version |
203
- | `focusModules` | string | no | Comma-separated modules to expand (e.g. `"sync,task"`) |
204
-
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
- ---
237
-
238
- ### `lookup_crate_docs`
239
-
240
- Fetches the main documentation page for a crate.
241
-
242
- | Parameter | Type | Required | Description |
243
- |---|---|---|---|
244
- | `crateName` | string | yes | Crate name |
245
- | `version` | string | no | Pinned version |
246
-
247
- Returns: crate version, overview documentation text, re-exports, and section list with item counts.
248
-
249
- ---
250
-
251
- ### `get_crate_items`
252
-
253
- Lists all public items in a crate root or specific module.
254
-
255
- | Parameter | Type | Required | Description |
256
- |---|---|---|---|
257
- | `crateName` | string | yes | Crate name |
258
- | `modulePath` | string | no | Dot-separated path (e.g. `"sync"`, `"io.util"`) |
259
- | `itemType` | enum | no | Filter: `mod` `struct` `enum` `trait` `fn` `macro` `type` `constant` `static` `union` `attr` `derive` |
260
- | `version` | string | no | Pinned version |
261
-
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
- ---
276
-
277
- ### `lookup_crate_item`
278
-
279
- Retrieves full documentation for a single item.
280
-
281
- | Parameter | Type | Required | Description |
282
- |---|---|---|---|
283
- | `crateName` | string | yes | Crate name |
284
- | `itemType` | enum | yes | Item type (see `get_crate_items`) |
285
- | `itemName` | string | yes | Item name (e.g. `"Mutex"`, `"spawn"`) |
286
- | `modulePath` | string | no | Dot-separated module path |
287
- | `version` | string | no | Pinned version |
288
- | `includeImpls` | boolean | no | Include trait implementation list |
289
- | `includeExamples` | boolean | no | Include code examples |
290
-
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
- ---
327
-
328
- ### `search_crate`
329
-
330
- Searches all items in a crate by name. Results are ranked: exact match on the bare item name scores highest, then prefix matches, then substring matches.
331
-
332
- | Parameter | Type | Required | Description |
333
- |---|---|---|---|
334
- | `crateName` | string | yes | Crate name |
335
- | `query` | string | yes | Search query (case-insensitive) |
336
- | `version` | string | no | Pinned version |
337
-
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
- ...
78
+ bun run dev # run with bun (no build)
79
+ npm run build # vite build → dist/index.js
80
+ npm run typecheck # tsc --noEmit
81
+ npm publish # build + publish
349
82
  ```
350
83
 
351
- ---
352
-
353
- ### `search_crates`
354
-
355
- Search for Rust crates on crates.io by keyword.
356
-
357
- | Parameter | Type | Required | Description |
358
- |---|---|---|---|
359
- | `query` | string | yes | Search keywords |
360
- | `page` | number | no | Page number (default 1) |
361
- | `perPage` | number | no | Results per page (default 10, max 50) |
362
-
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
- ---
375
-
376
- ### `get_crate_versions`
377
-
378
- List all published versions of a crate from crates.io.
379
-
380
- | Parameter | Type | Required | Description |
381
- |---|---|---|---|
382
- | `crateName` | string | yes | Crate name |
383
-
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
- ---
397
-
398
- ### `get_source_code`
399
-
400
- Fetch the raw source code of a file from docs.rs (or doc.rust-lang.org for std crates).
401
-
402
- | Parameter | Type | Required | Description |
403
- |---|---|---|---|
404
- | `crateName` | string | yes | Crate name |
405
- | `path` | string | yes | Source path relative to crate root (e.g. `"src/lib.rs"`, `"src/sync/mutex.rs"`) |
406
- | `version` | string | no | Pinned version |
407
-
408
- ```
409
- > get_source_code({ crateName: "tokio", path: "src/sync/mutex.rs" })
410
-
411
- # Source: tokio/src/sync/mutex.rs
412
- https://docs.rs/tokio/latest/src/tokio/sync/mutex.rs
413
-
414
- \`\`\`rust
415
- use crate::sync::batch_semaphore as semaphore;
416
- ...
417
- \`\`\`
418
- ```
419
-
420
- ---
421
-
422
- ## Recommended workflows
423
-
424
- ### Exploring a new crate
425
-
426
- 1. `get_crate_brief` with `focusModules` targeting the modules you care about
427
- 2. `search_crate` to find specific types or functions
428
- 3. `lookup_crate_item` for detailed signatures and docs
429
-
430
- ### Understanding feature flags
431
-
432
- 1. `get_crate_metadata` to see all features and their activations
433
- 2. `get_crate_items` to see which items require which features
434
-
435
- ### Finding the right type
436
-
437
- 1. `search_crate` with a keyword
438
- 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
440
-
441
- ---
442
-
443
84
  ## Architecture
444
85
 
445
- ```
446
- src/
447
- index.ts Entry pointregisters 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
452
- tools/
453
- shared.ts Shared Zod schemas (itemTypeEnum, versionParam)
454
- lookup-docs.ts lookup_crate_docs
455
- get-items.ts get_crate_items
456
- lookup-item.ts lookup_crate_item
457
- search.ts search_crate
458
- search-crates.ts search_crates
459
- crate-versions.ts get_crate_versions
460
- source-code.ts get_source_code
461
- crate-metadata.ts get_crate_metadata
462
- crate-brief.ts get_crate_brief
463
- ```
464
-
465
- ### Data sources
466
-
467
- - **docs.rs** — HTML pages parsed with cheerio for surgical DOM extraction (only the elements needed, not full-page conversion)
468
- - **doc.rust-lang.org** — Same rustdoc HTML format, used for `std`, `core`, and `alloc`
469
- - **crates.io API** — JSON endpoints for metadata, features, dependencies, and search
470
-
471
- ### Design decisions
472
-
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
86
+ - **cheerio** — surgical DOM extraction from rustdoc HTML
87
+ - **Native fetch** — `AbortController` timeouts, retry with backoff on 5xx
88
+ - **LRU cache** 500 entries, 5-min TTL, 15-min stale-while-revalidate
89
+ - **Ranked search** exact > prefix > substring scoring on `all.html`
90
+ - **Auto-discovery** `lookup_crate_item` finds module paths via `all.html`, fuzzy fallback on miss
478
91
 
479
92
  ## License
480
93