Add support for the crate name in the item-path

This commit is contained in:
Danielle Jenkins 2025-03-13 17:53:41 +09:00
parent 704c7333b6
commit 9bdd25e4a5

View file

@ -147,7 +147,13 @@ impl DocRouter {
} }
// Get documentation for a specific item in a crate // Get documentation for a specific item in a crate
async fn lookup_item(&self, crate_name: String, item_path: String, version: Option<String>) -> Result<String, ToolError> { async fn lookup_item(&self, crate_name: String, mut item_path: String, version: Option<String>) -> Result<String, ToolError> {
// Strip crate name prefix from the item path if it exists
let crate_prefix = format!("{}::", crate_name);
if item_path.starts_with(&crate_prefix) {
item_path = item_path[crate_prefix.len()..].to_string();
}
// Check cache first // Check cache first
let cache_key = if let Some(ver) = &version { let cache_key = if let Some(ver) = &version {
format!("{}:{}:{}", crate_name, ver, item_path) format!("{}:{}:{}", crate_name, ver, item_path)
@ -305,7 +311,7 @@ impl mcp_server::Router for DocRouter {
}, },
"item_path": { "item_path": {
"type": "string", "type": "string",
"description": "Path to the item (e.g., 'std::vec::Vec')" "description": "Path to the item (e.g., 'vec::Vec' or 'crate_name::vec::Vec' - crate prefix will be automatically stripped)"
}, },
"version": { "version": {
"type": "string", "type": "string",