list_files
List the contents of a directory within the configured file operations root.
Instructions
List files directly inside a folder within MCP_FILE_OPS_ROOT.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | No | . |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- server.py:170-178 (handler)The list_files tool handler: decorated with @mcp.tool(), resolves the path, validates it's a directory, lists all files (not directories) inside it, and returns them as a sorted JSON array.
@mcp.tool() def list_files(path: str = ".") -> str: """List files directly inside a folder within MCP_FILE_OPS_ROOT.""" target = _resolve_file_ops_path(path) if not target.is_dir(): raise ValueError(f"Not a directory: {target}") files = sorted(p.name for p in target.iterdir() if p.is_file()) return json.dumps(files, indent=2) - server.py:66-76 (helper)The _resolve_file_ops_path helper that list_files uses: resolves the path against MCP_FILE_OPS_ROOT, ensures it doesn't escape the root, and returns the Path object.
def _resolve_file_ops_path(path: str | None = None) -> Path: if not FILE_OPS_ROOT: raise ValueError("MCP_FILE_OPS_ROOT is not configured in .env.") root = Path(FILE_OPS_ROOT).expanduser().resolve() root.mkdir(parents=True, exist_ok=True) target = root if path is None else (root / path).resolve() if target != root and root not in target.parents: raise ValueError("Path escapes the configured MCP_FILE_OPS_ROOT.") return target - server.py:170-170 (registration)The @mcp.tool() decorator registering list_files as an MCP tool on the FastMCP instance.
@mcp.tool() - server.py:171-171 (schema)Input schema: single 'path' parameter with type str and default value '.'
def list_files(path: str = ".") -> str: