Skip to main content
Glama

list_file_symbols

Extract all symbols defined in a Python file to analyze code structure and identify functions, classes, and variables for navigation and refactoring.

Instructions

List all symbols defined in a file.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The list_file_symbols function implements the logic for listing symbols in a file, including symbol parsing and error handling.
    async def list_file_symbols(file_path: str) -> str:
        """List all symbols defined in a file."""
        client = _get_client()
    
        path = Path(file_path).resolve()
        if not path.exists():
            return _error(f"File not found: {file_path}")
    
        try:
            await client.open_document(path)
            symbols = await client.search_document_symbols(path)
    
            if not symbols:
                return _not_found(f"No symbols in {path.name}")
    
            def parse_symbol(sym: dict) -> dict:
                name = sym.get("name", "?")
                kind = SYMBOL_KINDS.get(sym.get("kind", 0), "Symbol")
    
                if "range" in sym:
                    range_info = sym.get("range", {}).get("start", {})
                else:
                    range_info = sym.get("location", {}).get("range", {}).get("start", {})
    
                line = range_info.get("line", 0) + 1
                children = [parse_symbol(c) for c in sym.get("children", [])]
    
                result = {"name": name, "kind": kind, "line": line}
                if children:
                    result["children"] = children
                return result
    
            parsed = [parse_symbol(sym) for sym in symbols]
            return _ok({"file": path.name, "path": str(path), "count": len(symbols), "symbols": parsed})
  • The list_file_symbols tool is registered using the @mcp.tool() decorator.
    @mcp.tool()
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description must carry the full burden of behavioral disclosure. While 'List' implies a read-only operation, the description omits what constitutes a 'symbol' (classes, functions, variables), the output format, and whether the operation is expensive or cached. It mentions an output schema exists but adds no context about what it contains.

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?

Extremely brief at 7 words. While appropriately front-loaded, it's arguably too terse given the lack of schema documentation and annotations. However, no words are wasted, and the structure is efficient.

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

Completeness3/5

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

Minimally viable for a single-parameter tool with an output schema. The description covers the basic operation but leaves significant gaps regarding symbol types, output structure, and sibling differentiation that would help an agent invoke it correctly versus alternatives.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0% with no parameter descriptions. The description mentions 'in a file' which implies the file_path parameter, but provides no semantic details: whether paths should be absolute or relative, supported languages/file types, or error behavior when files don't exist. Insufficient compensation for zero schema coverage.

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 provides a clear verb (List), resource (symbols), and scope (defined in a file). However, it fails to differentiate from sibling symbol-related tools like 'search_symbol', 'get_definition', or 'find_usages', which all interact with code symbols in different ways.

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

Usage Guidelines2/5

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

No guidance provided on when to use this tool versus alternatives. Given siblings like 'search_symbol' (cross-file search) and 'get_definition' (specific symbol lookup), the description should clarify that this enumerates all symbols within a single specified file.

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/qinsehm1128/mcp-ty'

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