Skip to main content
Glama

search_doc

Search Rust crate documentation to find features, error messages, and usage examples for debugging compilation issues or learning APIs.

Instructions

Search crate docs for specific features, error messages, or usage examples. Helps debug compilation issues or learn new APIs.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_pathYesPath to the Rust project (must be absolute path)
crate_nameYesName of the crate to search in
queryYesSearch query (keyword or symbol)

Implementation Reference

  • Core handler function that performs the search by traversing the documentation directory, reading HTML files, and matching the query string case-insensitively.
    public async searchDoc( projectPath: string, crateName: string, query: string, options: SearchOptions = {} ): Promise<SearchResult[]> { const isBuilt = await this.checkDoc(projectPath, crateName); if (!isBuilt) { throw new DocError( DocErrorCode.SEARCH_FAILED, 'Failed to access documentation' ); } const cached = await this.cache.get(projectPath, crateName); if (!cached) { throw new DocError( DocErrorCode.CACHE_ERROR, 'Cache error: Documentation entry not found' ); } try { const { docPath } = cached; const docDir = path.dirname(docPath); const results: SearchResult[] = []; // 定义搜索处理函数 const searchHandler = async (fileName: string, filePath: string, modulePath: string) => { if (options.limit && results.length >= options.limit) { return; } const content = await fs.readFile(filePath, 'utf-8'); if (content.toLowerCase().includes(query.toLowerCase())) { const symbol = this.parseSymbolFromFile(fileName, modulePath, crateName, filePath); results.push({ title: symbol ? symbol.path : path.basename(fileName, '.html'), url: RustdocUrl.create(filePath) }); } }; // 使用通用的traverseDirectory进行搜索 await this.traverseDirectory(docDir, crateName, '', searchHandler); return results.sort((a, b) => a.title.localeCompare(b.title)); } catch (error) { throw new DocError( DocErrorCode.SEARCH_FAILED, 'Failed to search documentation', error ); } }
  • Input schema definition for the search_doc tool, specifying required parameters: project_path, crate_name, query.
    inputSchema: { type: "object", properties: { project_path: { type: "string", description: "Path to the Rust project (must be absolute path)", }, crate_name: { type: "string", description: "Name of the crate to search in", }, query: { type: "string", description: "Search query (keyword or symbol)", }, }, required: ["project_path", "crate_name", "query"], },
  • src/index.ts:124-145 (registration)
    Tool registration in ListToolsRequestHandler, defining name, description, and input schema for search_doc.
    { name: "search_doc", description: "Search crate docs for specific features, error messages, or usage examples. Helps debug compilation issues or learn new APIs.", inputSchema: { type: "object", properties: { project_path: { type: "string", description: "Path to the Rust project (must be absolute path)", }, crate_name: { type: "string", description: "Name of the crate to search in", }, query: { type: "string", description: "Search query (keyword or symbol)", }, }, required: ["project_path", "crate_name", "query"], }, },
  • MCP CallTool handler case that extracts arguments, calls DocManager.searchDoc, and formats results as text content.
    case "search_doc": { const { project_path, crate_name, query } = request.params .arguments as { project_path: string; crate_name: string; query: string; }; const results = await docManager.searchDoc(project_path, crate_name, query, { limit: 50, }); return { content: [ { type: "text", text: `Found ${results.length} results:`, }, ...results.map((result) => ({ type: "text" as const, text: `\n- ${result.title}\n URL: ${result.url}`, })), ], }; }
  • Type definitions for SearchOptions (used in handler) and SearchResult (return type).
    export interface SearchOptions { limit?: number; } /** * Search result item */ export interface SearchResult { title: string; url: string; }
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/spacemeowx2/cargo-doc-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server