Skip to main content
Glama
Preston-Harrison

Filesystem MCP Server

list_directory

Retrieve and display directory contents with type annotations ([DIR] or [FILE]). Specify the path to list files and folders within allowed directories, sorted alphabetically.

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

Implementation Reference

  • main.py:404-431 (handler)
    The handler function for the 'list_directory' tool. It resolves the path, checks if it's a directory, lists contents sorted alphabetically with [DIR] or [FILE] prefixes, and handles errors gracefully.
    @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")
  • main.py:404-404 (registration)
    The @mcp.tool decorator registers the list_directory function as an MCP tool.
    @mcp.tool

Other Tools

Related 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