Skip to main content
Glama

docs_rs_search_in_crate

Search crate documentation on docs.rs for specific traits, structs, methods, or other items. Filter by type or version to locate relevant Rust documentation efficiently.

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

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

Input Schema (JSON Schema)

{ "properties": { "crate_name": { "description": "Name of the crate to search", "type": "string" }, "item_type": { "description": "Filter by item type (struct | trait | fn | enum| union | macro | constant)", "type": "string" }, "query": { "description": "Search keyword (trait name, struct name, function name, etc.)", "type": "string" }, "version": { "description": "Specific version (optional, defaults to latest)", "type": "string" } }, "required": [ "crate_name", "query" ], "type": "object" }

Implementation Reference

  • The main handler function that implements the logic for searching items (traits, structs, etc.) in a crate's documentation by scraping the all.html page, filtering by query and type, and returning markdown-formatted results.
    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}`); } } async run() {
  • Input schema definition for the tool, specifying parameters like crate_name, query, version, and optional item_type.
    { 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)
    Switch case in the CallToolRequestSchema handler that dispatches to the searchInCrate method.
    case "docs_rs_search_in_crate": return await this.searchInCrate(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