Skip to content

Commit f37981e

Browse files
checkpoint 1, broken
1 parent 34f5e7a commit f37981e

File tree

3 files changed

+92
-68
lines changed

3 files changed

+92
-68
lines changed

README.md

Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -189,47 +189,38 @@ in `mcp_settings.json`
189189
```
190190

191191

192-
## License
193-
194-
MIT License
195192

196-
## MCP Tool: `list_crate_items`
193+
### 4. `list_crate_items`
197194

198-
The `list_crate_items` tool enumerates all items in a specified Rust crate and version, optionally filtering by item type, visibility, or module path. This is useful for quickly exploring the structure of a crate, generating concise listings for LLMs, or programmatically analyzing crate APIs.
195+
Enumerates all items in a specified Rust crate and version, optionally filtering by item type, visibility, or module path. Useful for exploring crate structure, generating concise listings for LLMs, or programmatically analyzing crate APIs.
199196

200-
### Usage
197+
**Parameters:**
198+
- `crate_name` (required): The name of the crate
199+
- `version` (required): The version of the crate
200+
- `item_type` (optional): Filter by item type (struct, enum, trait, fn, macro, mod)
201+
- `visibility` (optional): Filter by visibility (pub, private)
202+
- `module` (optional): Filter by module path (e.g., serde::de)
201203

202-
```sh
203-
cargo run --bin cratedocs -- list-crate-items --crate-name serde --version 1.0.0
204+
**Example:**
205+
```json
206+
{
207+
"name": "list_crate_items",
208+
"arguments": {
209+
"crate_name": "serde",
210+
"version": "1.0.0",
211+
"item_type": "struct"
212+
}
213+
}
204214
```
205215

206-
#### With filters:
207-
208-
- Filter by item type (e.g., struct, enum, trait, fn, macro, mod):
209-
210-
```sh
211-
cargo run --bin cratedocs -- list-crate-items --crate-name serde --version 1.0.0 --item-type struct
212-
```
213-
214-
- Filter by visibility (e.g., pub, private):
215-
216-
```sh
217-
cargo run --bin cratedocs -- list-crate-items --crate-name serde --version 1.0.0 --visibility pub
218-
```
219-
220-
- Filter by module path:
221-
222-
```sh
223-
cargo run --bin cratedocs -- list-crate-items --crate-name serde --version 1.0.0 --module serde::de
224-
```
225-
226-
### Output
227-
228-
The output is a concise, categorized list (JSON or markdown) showing each item's name, type, visibility, and module path.
229-
230-
**Example (stub output):**
216+
**Example Output (stub):**
231217
```
232218
Stub: list_crate_items for crate: serde, version: 1.0.0, filters: Some(ItemListFilters { item_type: Some("struct"), visibility: None, module: None })
233219
```
234220

235221
When implemented, the output will be a structured list of items matching the filters.
222+
223+
224+
## License
225+
226+
MIT License

src/bin/cratedocs.rs

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -84,24 +84,6 @@ enum Commands {
8484
#[arg(short, long)]
8585
debug: bool,
8686
},
87-
/// List all items in a crate (using rust-analyzer)
88-
ListCrateItems {
89-
/// Crate name (e.g., serde)
90-
#[arg(long)]
91-
crate_name: String,
92-
/// Crate version (e.g., 1.0.0)
93-
#[arg(long)]
94-
version: String,
95-
/// Filter by item type (struct, enum, trait, fn, macro, mod)
96-
#[arg(long)]
97-
item_type: Option<String>,
98-
/// Filter by visibility (pub, private)
99-
#[arg(long)]
100-
visibility: Option<String>,
101-
/// Filter by module path (e.g., serde::de)
102-
#[arg(long)]
103-
module: Option<String>,
104-
},
10587
}
10688

10789
#[tokio::main]
@@ -136,23 +118,6 @@ async fn main() -> Result<()> {
136118
max_tokens,
137119
debug
138120
}).await,
139-
Commands::ListCrateItems {
140-
crate_name,
141-
version,
142-
item_type,
143-
visibility,
144-
module,
145-
} => {
146-
use cratedocs_mcp::tools::item_list::{list_crate_items, ItemListFilters};
147-
let filters = ItemListFilters {
148-
item_type,
149-
visibility,
150-
module,
151-
};
152-
let result = list_crate_items(&crate_name, &version, Some(filters)).await?;
153-
println!("{}", result);
154-
Ok(())
155-
}
156121
}
157122
}
158123

src/tools/docs/docs.rs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::tools::item_list;
12
use std::{future::Future, pin::Pin, sync::Arc};
23

34
use mcp_core::{
@@ -321,6 +322,36 @@ impl mcp_server::Router for DocRouter {
321322
"required": ["crate_name", "item_path"]
322323
}),
323324
),
325+
Tool::new(
326+
"list_crate_items".to_string(),
327+
"Enumerate all items in a Rust crate (optionally filtered by type, visibility, or module). Returns a concise, categorized list.".to_string(),
328+
json!({
329+
"type": "object",
330+
"properties": {
331+
"crate_name": {
332+
"type": "string",
333+
"description": "The name of the crate"
334+
},
335+
"version": {
336+
"type": "string",
337+
"description": "The version of the crate"
338+
},
339+
"item_type": {
340+
"type": "string",
341+
"description": "Filter by item type (struct, enum, trait, fn, macro, mod)"
342+
},
343+
"visibility": {
344+
"type": "string",
345+
"description": "Filter by visibility (pub, private)"
346+
},
347+
"module": {
348+
"type": "string",
349+
"description": "Filter by module path (e.g., serde::de)"
350+
}
351+
},
352+
"required": ["crate_name", "version"]
353+
}),
354+
),
324355
]
325356
}
326357

@@ -386,6 +417,43 @@ impl mcp_server::Router for DocRouter {
386417
let doc = this.lookup_item(crate_name, item_path, version).await?;
387418
Ok(vec![Content::text(doc)])
388419
}
420+
"list_crate_items" => {
421+
let crate_name = arguments
422+
.get("crate_name")
423+
.and_then(|v| v.as_str())
424+
.ok_or_else(|| ToolError::InvalidParameters("crate_name is required".to_string()))?
425+
.to_string();
426+
let version = arguments
427+
.get("version")
428+
.and_then(|v| v.as_str())
429+
.ok_or_else(|| ToolError::InvalidParameters("version is required".to_string()))?
430+
.to_string();
431+
let item_type = arguments
432+
.get("item_type")
433+
.and_then(|v| v.as_str())
434+
.map(|s| s.to_string());
435+
let visibility = arguments
436+
.get("visibility")
437+
.and_then(|v| v.as_str())
438+
.map(|s| s.to_string());
439+
let module = arguments
440+
.get("module")
441+
.and_then(|v| v.as_str())
442+
.map(|s| s.to_string());
443+
let filters = cratedocs_mcp::tools::item_list::ItemListFilters {
444+
item_type,
445+
visibility,
446+
module,
447+
};
448+
let result = cratedocs_mcp::tools::item_list::list_crate_items(
449+
&crate_name,
450+
&version,
451+
Some(filters),
452+
)
453+
.await
454+
.map_err(|e| ToolError::ExecutionError(format!("list_crate_items failed: {}", e)))?;
455+
Ok(vec![Content::text(result)])
456+
}
389457
_ => Err(ToolError::NotFound(format!("Tool {} not found", tool_name))),
390458
}
391459
})

0 commit comments

Comments
 (0)