Skip to main content
Glama

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);

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