Skip to main content
Glama

docs_rs_get_item

Retrieve detailed documentation for specific items (modules, structs, traits, enums, functions, etc.) within Rust crates on docs.rs. Specify crate name, item type, and path to access precise content.

Instructions

Get documentation content of a specific item (module, struct, trait, enum, function, etc.) within a crate

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
crate_nameYesName of the crate
item_pathYesThe full path of the item, including the module name (e.g. wasmtime::component::Component)
item_typeYesType of item: 'module' for modules, 'struct', 'trait', 'enum', 'type', 'fn', etc.
versionNoSpecific version (optional, defaults to latest)

Implementation Reference

  • The handler function that executes the tool logic: constructs the docs.rs URL based on item_type and item_path, fetches the HTML, parses with cheerio to extract content, converts to markdown with turndown, and returns formatted text 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}`); } }
  • The input schema defining parameters: crate_name (required), item_type (required), item_path (required), version (optional).
    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:90-115 (registration)
    Tool registration in the listTools response, including name, description, and inputSchema.
    { 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)
    Registration of the handler in the CallToolRequestSchema switch statement.
    case "docs_rs_get_item": return await this.getItem(request.params.arguments);

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/nuskey8/docs-rs-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server