Skip to main content
Glama
Preston-Harrison

Filesystem MCP Server

list_directory

Display directory contents with clear file and folder identification. Use this tool to view organized listings of files and directories within specified paths.

Instructions

List the contents of a directory with type annotations.

Args: path (str): Directory path to list (absolute or relative to allowed directories)

Returns: str: Newline-separated list of entries with '[DIR]' or '[FILE]' prefixes, or error message if failed

Note: - Path must be within allowed directory roots - Fails if path is not a directory - Entries are sorted alphabetically - Format: '[DIR] dirname' or '[FILE] filename'

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • main.py:404-431 (handler)
    The core handler function for the 'list_directory' tool. It resolves the path using _resolve, checks if it's a directory, iterates over contents, tags them as [DIR] or [FILE], sorts alphabetically, and joins with newlines. Errors are handled gracefully with human-readable messages.
    @mcp.tool
    def list_directory(path: str) -> str:
        """List the contents of a directory with type annotations.
    
        Args:
            path (str): Directory path to list (absolute or relative to allowed directories)
    
        Returns:
            str: Newline-separated list of entries with '[DIR]' or '[FILE]' prefixes, or error message if failed
    
        Note:
            - Path must be within allowed directory roots
            - Fails if path is not a directory
            - Entries are sorted alphabetically
            - Format: '[DIR] dirname' or '[FILE] filename'
        """
        try:
            rp = _resolve(path)
            if not rp.is_dir():
                return f"Error listing directory: '{rp}' is not a directory"
            out = []
            for child in sorted(rp.iterdir()):
                tag = "[DIR]" if child.is_dir() else "[FILE]"
                out.append(f"{tag} {child.name}")
            return "\n".join(out)
        except Exception as e:
            return _human_error(e, "listing directory")
Behavior4/5

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

With no annotations provided, the description carries full burden and does well: it discloses constraints (path must be within allowed roots, fails if not a directory), behavioral traits (entries sorted alphabetically, specific output format), and error handling (returns error message if failed). It covers key aspects like safety and output behavior without contradictions.

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

Conciseness5/5

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

The description is well-structured with clear sections (Args, Returns, Note), front-loaded purpose, and every sentence adds value: no redundancy, with efficient bullet points for notes. It's appropriately sized for the tool's complexity.

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

Completeness5/5

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

Given the tool's moderate complexity, no annotations, and an output schema present (which covers return values), the description is complete: it explains purpose, usage, parameters, constraints, behavior, and output format. It provides all necessary context for an agent to invoke it correctly without gaps.

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

Parameters4/5

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

The input schema has 0% description coverage, so the description must compensate. It adds meaning beyond the schema by explaining the 'path' parameter as 'Directory path to list (absolute or relative to allowed directories)', clarifying scope and constraints. This adequately covers the single parameter's semantics.

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

Purpose5/5

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

The description clearly states the verb ('List') and resource ('contents of a directory'), specifying it provides 'type annotations' with '[DIR]' or '[FILE]' prefixes. It distinguishes from siblings like 'directory_tree' (which likely shows hierarchical structure) and 'list_allowed_directories' (which lists allowed roots rather than directory contents).

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

Usage Guidelines4/5

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

The description provides clear context for when to use it: to list directory contents with type annotations. It implicitly distinguishes from alternatives by noting the sorted alphabetical format and error conditions, but does not explicitly name when to choose this over siblings like 'directory_tree' or 'search_files'.

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/Preston-Harrison/fs-mcp-py'

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