Skip to main content
Glama
nuskey8

docs.rs MCP

by nuskey8

docs_rs_search_in_crate

Search for traits, structs, methods, and other items within a specific Rust crate's documentation on docs.rs to find required functionality.

Instructions

Search for traits, structs, methods, etc. from the crate's all.html page. To get a module, use docs_rs_get_item instead.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
crate_nameYesName of the crate to search
queryYesSearch keyword (trait name, struct name, function name, etc.)
versionNoSpecific version (optional, defaults to latest)
item_typeNoFilter by item type (struct | trait | fn | enum| union | macro | constant)

Implementation Reference

  • The `searchInCrate` function is the main handler that executes the tool's logic. It scrapes the crate's all.html page on docs.rs, identifies item links by type, filters by query and optional item_type, deduplicates, and returns formatted markdown results with documentation links.
    private async searchInCrate(args: any) {
        const { crate_name, query, version = "latest", item_type } = args;
    
        try {
            const url = `https://docs.rs/${crate_name}/${version}/${crate_name}/all.html`;
            const response = await axios.get<string>(url);
            const $ = cheerio.load(response.data);
    
            const items: Array<{
                name: string;
                type: string;
                link: string;
            }> = [];
    
            $("#main-content a").each((_, element) => {
                const $link = $(element);
                const itemName = $link.text().trim();
                const itemLink = $link.attr("href") || "";
    
                if (!itemName || !itemLink) return;
    
                let type = "unknown";
                if (itemLink.includes("struct.")) type = "struct";
                else if (itemLink.includes("trait.")) type = "trait";
                else if (itemLink.includes("fn.")) type = "function";
                else if (itemLink.includes("enum.")) type = "enum";
                else if (itemLink.includes("type.")) type = "type";
                else if (itemLink.includes("const.")) type = "constant";
                else if (itemLink.includes("static.")) type = "static";
                else if (itemLink.includes("macro.")) type = "macro";
    
                const matchesQuery = !query || query == "" || itemName.toLowerCase().includes(query.toLowerCase());
                const matchesType = !item_type || item_type == "" || type === item_type || itemName.toLowerCase().includes(item_type.toLowerCase());
    
                if (matchesQuery && matchesType && type !== "unknown") {
                    items.push({
                        name: itemName,
                        type,
                        link: itemLink.startsWith("http") ? itemLink : `https://docs.rs/${crate_name}/${version}/${crate_name}/${itemLink}`,
                    });
                }
            });
    
            const uniqueItems = items.filter((item, index, self) =>
                index === self.findIndex(i => i.name === item.name && i.type === item.type)
            );
    
            const searchTerm = query || "all items";
            return {
                content: [
                    {
                        type: "text",
                        text: `# Search Results for "${searchTerm}" in ${crate_name}\n\n` +
                            `Found ${uniqueItems.length} items\n\n` +
                            (uniqueItems.length === 0
                                ? "No matching items found."
                                : uniqueItems
                                    .map(
                                        (item) =>
                                            `## ${item.name} (${item.type})\n\n` +
                                            `**Description:** ${item.type}\n\n` +
                                            `**Link:** [View Documentation](${item.link})\n\n` +
                                            `---\n`
                                    )
                                    .join("\n")
                            ),
                    },
                ],
            };
        } catch (error) {
            throw new Error(`Failed to search items in ${crate_name}: ${error}`);
        }
  • Input schema defining the parameters for the `docs_rs_search_in_crate` tool: crate_name (required), query (required), version (optional), item_type (optional).
    inputSchema: {
        type: "object",
        properties: {
            crate_name: {
                type: "string",
                description: "Name of the crate to search",
            },
            query: {
                type: "string",
                description: "Search keyword (trait name, struct name, function name, etc.)",
            },
            version: {
                type: "string",
                description: "Specific version (optional, defaults to latest)",
            },
            item_type: {
                type: "string",
                description: "Filter by item type (struct | trait | fn | enum| union | macro | constant)",
            },
        },
        required: ["crate_name", "query"],
  • src/index.ts:116-141 (registration)
    Tool registration in the ListToolsRequestHandler response, including name, description, and input schema.
    {
        name: "docs_rs_search_in_crate",
        description: "Search for traits, structs, methods, etc. from the crate's all.html page. To get a module, use docs_rs_get_item instead.",
        inputSchema: {
            type: "object",
            properties: {
                crate_name: {
                    type: "string",
                    description: "Name of the crate to search",
                },
                query: {
                    type: "string",
                    description: "Search keyword (trait name, struct name, function name, etc.)",
                },
                version: {
                    type: "string",
                    description: "Specific version (optional, defaults to latest)",
                },
                item_type: {
                    type: "string",
                    description: "Filter by item type (struct | trait | fn | enum| union | macro | constant)",
                },
            },
            required: ["crate_name", "query"],
        },
    },
  • src/index.ts:155-156 (registration)
    Dispatch case in the CallToolRequestHandler switch statement that routes calls to the searchInCrate handler.
    case "docs_rs_search_in_crate":
        return await this.searchInCrate(request.params.arguments);
Behavior3/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. It mentions the source ('from the crate's all.html page') which adds useful context about where the search is performed, but doesn't disclose behavioral aspects like rate limits, authentication needs, pagination, or what happens when no results are found. The description is neutral about mutation/safety but doesn't explicitly state it's read-only.

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 perfectly concise with two sentences that each serve a clear purpose: the first states what the tool does, and the second provides crucial sibling differentiation. There's zero wasted language and it's front-loaded with the core functionality.

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

Completeness4/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 (search operation with 4 parameters), 100% schema coverage, and no output schema, the description provides good contextual completeness. It clearly states the purpose and sibling differentiation, though it could benefit from mentioning what the search returns (e.g., list of matching items) since there's no output schema.

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?

Schema description coverage is 100%, so the schema already documents all four parameters thoroughly. The description doesn't add any parameter-specific details beyond what's in the schema (like explaining search semantics or item_type usage). It meets the baseline for high schema coverage but doesn't enhance parameter understanding.

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

Purpose5/5

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

The description clearly states the specific action ('Search for traits, structs, methods, etc.') and resource ('from the crate's all.html page'), with explicit differentiation from the sibling tool docs_rs_get_item. It uses precise terminology that distinguishes it from other search tools like docs_rs_search_crates.

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

Usage Guidelines5/5

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

The description provides explicit guidance on when to use this tool versus alternatives: 'To get a module, use docs_rs_get_item instead.' This clearly delineates the boundary between searching within a crate versus retrieving specific module items, though it doesn't mention docs_rs_search_crates or docs_rs_readme.

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