Skip to main content
Glama
nuskey8

docs.rs MCP

by nuskey8

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
NameRequiredDescriptionDefault
crate_nameYesName of the crate
item_typeYesType of item: 'module' for modules, 'struct', 'trait', 'enum', 'type', 'fn', etc.
item_pathYesThe full path of the item, including the module name (e.g. wasmtime::component::Component)
versionNoSpecific version (optional, defaults to latest)

Implementation Reference

  • 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}`);
        }
    }
  • 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);
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool 'Get[s] documentation content,' implying a read-only operation, but does not cover aspects like authentication needs, rate limits, error handling, or response format. For a tool with no annotations, this leaves significant behavioral gaps.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that directly states the tool's purpose without unnecessary words. It is front-loaded with the core action and resource, making it easy to parse and understand quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (4 parameters, no output schema, no annotations), the description is minimally adequate. It covers the basic purpose but lacks details on behavioral traits, usage guidelines, and output expectations, which are important for effective tool invocation by an AI agent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 100%, so the schema already documents all parameters (crate_name, item_type, item_path, version). The description adds minimal value by listing item types (e.g., 'module, struct, trait, enum, function, etc.') and implying retrieval scope, but does not provide additional syntax or usage details beyond what the schema offers, aligning with the baseline for high coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Get documentation content of a specific item (module, struct, trait, enum, function, etc.) within a crate.' It specifies the verb ('Get'), resource ('documentation content'), and scope ('within a crate'), but does not explicitly differentiate it from sibling tools like docs_rs_search_in_crate, which might search within a crate rather than retrieve specific item documentation.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It does not mention sibling tools such as docs_rs_search_in_crate or docs_rs_search_crates, nor does it specify prerequisites, exclusions, or contexts for usage, leaving the agent to infer based on tool names alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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