Skip to main content
Glama
spacemeowx2

Cargo Doc MCP Server

by spacemeowx2

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;
    }
Behavior2/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 of behavioral disclosure. It mentions the tool's purpose and use cases but fails to describe key behavioral traits like whether it requires specific permissions, how results are returned (e.g., format, pagination), or any rate limits. This leaves significant gaps for an agent to understand how to invoke it effectively.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is concise and well-structured in two sentences: the first states the purpose, and the second provides usage context. There is no wasted text, and it is front-loaded with the core functionality. However, it could be slightly more efficient by integrating the use cases more seamlessly.

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

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of a search tool with 3 parameters, no annotations, and no output schema, the description is incomplete. It lacks details on behavioral aspects (e.g., result format, error handling) and doesn't compensate for the absence of structured output information, making it insufficient for an agent to fully understand the tool's operation.

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?

The input schema has 100% description coverage, providing clear details for all three parameters (project_path, crate_name, query). The description adds no additional parameter semantics beyond what the schema already states, such as examples of valid queries or constraints on crate names. With high schema coverage, the baseline score of 3 is appropriate as the schema handles the heavy lifting.

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

Purpose4/5

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

The description clearly states the tool's purpose: 'Search crate docs for specific features, error messages, or usage examples.' It specifies the verb ('Search') and resource ('crate docs'), and mentions the target content types. However, it doesn't explicitly differentiate from sibling tools like 'get_crate_doc' or 'list_symbols', which likely have related but distinct functions.

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

Usage Guidelines3/5

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

The description provides implied usage guidance by stating it 'Helps debug compilation issues or learn new APIs,' suggesting contexts where this tool is appropriate. However, it lacks explicit guidance on when to use this tool versus its siblings (e.g., 'get_crate_doc' and 'list_symbols'), such as comparing search functionality to direct documentation retrieval or symbol listing.

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/spacemeowx2/cargo-doc-mcp'

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