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

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")

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