docs_rs_search_crates
Search for Rust crates on crates.io using keywords to find relevant packages for your project needs.
Instructions
Search for Rust crates by keywords on crates.io.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"query": "<query>"
},
"name": "docs_rs_search_crates"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | Search keywords for finding relevant crates. Keywords should be in English. | |
| per_page | No | Number of results per page (default: 10, max: 100) | |
| sort | No | Sort order: 'relevance', 'downloads', 'recent-downloads', 'recent-updates', 'new' (default: relevance) |
Implementation Reference
- src/index.ts:172-211 (handler)The primary handler function that executes the tool logic: searches crates.io API with the given query, processes results into a formatted markdown response.
private async searchCrates(args: any) { const { query, per_page = 10, sort = "relevance" } = args; try { const response = await axios.get<{ crates: any[] }>("https://crates.io/api/v1/crates", { params: { q: query, per_page: Math.min(per_page, 100), sort, }, }); const crates = response.data.crates.map((crate: any) => ({ name: crate.name, description: crate.description || "No description available", downloads: crate.downloads, version: crate.newest_version, documentation: crate.documentation, })); return { content: [ { type: "text", text: `# Crate Search Results for "${query}"\n\n${crates .map( (crate: CrateSearchResult) => `## ${crate.name} (${crate.version})\n\n` + `**Description:** ${crate.description}\n\n` + `**Downloads:** ${crate.downloads.toLocaleString()}\n\n` + `**Documentation:** ${crate.documentation || "N/A"}\n\n---\n` ) .join("\n")}`, }, ], }; } catch (error) { throw new Error(`Failed to search crates: ${error}`); } } - src/index.ts:54-70 (schema)Defines the input schema for the tool, specifying parameters like query, per_page, and sort.
type: "object", properties: { query: { type: "string", description: "Search keywords for finding relevant crates. Keywords should be in English.", }, per_page: { type: "number", description: "Number of results per page (default: 10, max: 100)", }, sort: { type: "string", description: "Sort order: 'relevance', 'downloads', 'recent-downloads', 'recent-updates', 'new' (default: relevance)", }, }, required: ["query"], }, - src/index.ts:50-71 (registration)Tool registration in the ListTools response, including name, description, and schema.
{ name: "docs_rs_search_crates", description: "Search for Rust crates by keywords on crates.io.", inputSchema: { type: "object", properties: { query: { type: "string", description: "Search keywords for finding relevant crates. Keywords should be in English.", }, per_page: { type: "number", description: "Number of results per page (default: 10, max: 100)", }, sort: { type: "string", description: "Sort order: 'relevance', 'downloads', 'recent-downloads', 'recent-updates', 'new' (default: relevance)", }, }, required: ["query"], }, }, - src/index.ts:149-150 (registration)Dispatches the tool call to the searchCrates handler in the CallToolRequestSchema switch.
case "docs_rs_search_crates": return await this.searchCrates(request.params.arguments);