docs_rs_get_item
Retrieve detailed documentation for specific Rust crate items like modules, structs, traits, enums, and functions from docs.rs to understand implementation details and usage.
Instructions
Get documentation content of a specific item (module, struct, trait, enum, function, etc.) within a crate
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| crate_name | Yes | Name of the crate | |
| item_type | Yes | Type of item: 'module' for modules, 'struct', 'trait', 'enum', 'type', 'fn', etc. | |
| item_path | Yes | The full path of the item, including the module name (e.g. wasmtime::component::Component) | |
| version | No | Specific version (optional, defaults to latest) |
Implementation Reference
- src/index.ts:254-323 (handler)The handler function that constructs the docs.rs URL based on crate_name, item_type, and item_path, fetches the HTML using axios and cheerio, extracts the main content, converts it to markdown using turndownService, and returns it as MCP content.private async getItem(args: any) { const { crate_name, item_type, item_path, version = "latest" } = args; const item_name = item_path.split("::").pop(); try { let url: string; if (item_type === "module") { url = `https://docs.rs/${crate_name}/${version}/${item_path.replaceAll("::", "/")}/index.html`; } else { const pathParts = item_path.split("::"); const modulePath = pathParts.slice(0, -1).join("/"); url = `https://docs.rs/${crate_name}/${version}/${modulePath}/${item_type}.${item_name}.html`; } const response = await axios.get<string>(url); const $ = cheerio.load(response.data); const mainContentSection = $("#main-content"); let contentHtml = ""; if (mainContentSection.length > 0) { contentHtml = mainContentSection.html() || ""; } else { const itemDecl = $(".rustdoc .item-decl").first(); const mainContent = $(".rustdoc .docblock").first(); if (itemDecl.length > 0) { contentHtml += itemDecl.html() || ""; } if (mainContent.length === 0) { const alternativeContent = $(".rustdoc-main .item-decl").first(); if (alternativeContent.length > 0) { contentHtml += alternativeContent.html() || ""; } } else { contentHtml += mainContent.html() || ""; } } if (!contentHtml) { const fullItemName = item_path; return { content: [ { type: "text", text: `# ${fullItemName} (${item_type})\n\nNo documentation content found at ${url}`, }, ], }; } const markdownContent = turndownService.turndown(contentHtml); const fullItemName = item_path; return { content: [ { type: "text", text: `# ${fullItemName} (${item_type})\n\n**Documentation URL:** ${url}\n\n${markdownContent}`, }, ], }; } catch (error) { const fullItemName = item_path; throw new Error(`Failed to get item documentation for ${fullItemName}: ${error}`); } }
- src/index.ts:90-115 (schema)The input schema definition for the tool, specifying parameters like crate_name, item_type, item_path, and optional version.{ name: "docs_rs_get_item", description: "Get documentation content of a specific item (module, struct, trait, enum, function, etc.) within a crate", inputSchema: { type: "object", properties: { crate_name: { type: "string", description: "Name of the crate", }, item_type: { type: "string", description: "Type of item: 'module' for modules, 'struct', 'trait', 'enum', 'type', 'fn', etc.", }, item_path: { type: "string", description: "The full path of the item, including the module name (e.g. wasmtime::component::Component)", }, version: { type: "string", description: "Specific version (optional, defaults to latest)", }, }, required: ["crate_name", "item_type", "item_path"], }, },
- src/index.ts:153-154 (registration)The switch case in the CallToolRequestSchema handler that routes the tool call to the getItem method.case "docs_rs_get_item": return await this.getItem(request.params.arguments);