Skip to main content
Glama
spacemeowx2

Cargo Doc MCP Server

by spacemeowx2

list_symbols

List all symbols in a Rust crate to implement traits or explore available types, including structs, enums, and traits with their paths.

Instructions

List all symbols in a crate. Use when implementing traits or exploring available types. Shows structs, enums, traits with their paths.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_pathYesPath to the Rust project (must be absolute path)
crate_nameYesName of the crate to list symbols for

Implementation Reference

  • Core handler function that traverses the Rust documentation directory, parses symbol files, and returns a list of SymbolInfo objects including name, type, path, and URL.
    public async listSymbols(projectPath: string, crateName: string): Promise<SymbolInfo[]> {
        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 symbols: SymbolInfo[] = [];
    
            // 定义符号收集处理函数
            const symbolHandler = async (fileName: string, filePath: string, modulePath: string) => {
                const symbol = this.parseSymbolFromFile(fileName, modulePath, crateName, filePath);
                if (symbol) {
                    symbols.push(symbol);
                }
            };
    
            // 使用通用的traverseDirectory收集符号
            await this.traverseDirectory(docDir, crateName, '', symbolHandler);
    
            return symbols.sort((a, b) => a.path.localeCompare(b.path));
        } catch (error) {
            throw new DocError(
                DocErrorCode.SEARCH_FAILED,
                'Failed to list symbols',
                error
            );
        }
    }
  • Input schema definition for the list_symbols tool, specifying project_path and crate_name as required string parameters.
    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 list symbols for",
        },
      },
      required: ["project_path", "crate_name"],
    },
  • src/index.ts:106-123 (registration)
    Tool registration in the ListTools response, defining name, description, and input schema.
    {
      name: "list_symbols",
      description: "List all symbols in a crate. Use when implementing traits or exploring available types. Shows structs, enums, traits with their paths.",
      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 list symbols for",
          },
        },
        required: ["project_path", "crate_name"],
      },
    },
  • Type definition for SymbolInfo, used as the return type of listSymbols.
    export interface SymbolInfo {
        name: string;
        type: SymbolType;
        path: string;
        url: string;
    }
  • Helper function to parse individual symbol information from documentation HTML file names.
    private parseSymbolFromFile(fileName: string, modulePath: string, crateName: string, filePath: string): SymbolInfo | null {
        const match = fileName.match(/^(struct|enum|trait|fn|const|type|macro|mod)\.(.+)\.html$/);
        if (!match) {
            return null;
        }
    
        const [, type, name] = match;
        const symbolName = name.replace(/-/g, '::');
        const fullPath = modulePath
            ? `${crateName}::${modulePath}::${symbolName}`
            : `${crateName}::${symbolName}`;
    
        return {
            name: symbolName,
            type: type as SymbolType,
            path: fullPath,
            url: RustdocUrl.create(filePath)
        };
    }
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 what the tool shows (structs, enums, traits with paths), but doesn't cover critical aspects like whether it's read-only, safe, requires specific permissions, handles errors, or provides pagination/formatting details. For a tool with zero annotation coverage, this is a significant gap in transparency.

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 appropriately sized and front-loaded, with two sentences that efficiently convey purpose and usage. It avoids unnecessary details, though it could be slightly more structured (e.g., separating purpose from guidance). Overall, it's concise with minimal waste.

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 tool's complexity (2 parameters, no output schema, no annotations), the description is incomplete. It lacks information on behavioral traits (e.g., safety, error handling), output format, and explicit usage boundaries. Without annotations or an output schema, the description should do more to compensate, but it falls short.

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 schema description coverage is 100%, with both parameters ('project_path' and 'crate_name') fully documented in the schema. The description doesn't add any parameter-specific details beyond what the schema provides, such as format examples or constraints. This meets the baseline for high schema coverage, but doesn't enhance understanding.

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 with a specific verb ('List') and resource ('symbols in a crate'), and distinguishes the types of symbols included (structs, enums, traits with paths). However, it doesn't explicitly differentiate from sibling tools like 'get_crate_doc' or 'search_doc', which prevents a perfect score.

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 ('Use when implementing traits or exploring available types'), which gives some context for when to invoke the tool. However, it lacks explicit guidance on when not to use it or alternatives (e.g., compared to 'search_doc'), and doesn't mention prerequisites like needing a valid Rust project, leaving room for improvement.

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