list_directories
Lists all directories within a specified folder under the configured root path.
Instructions
List directories 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:181-189 (handler)The handler function for the list_directories MCP tool. Resolves the path via _resolve_file_ops_path (which enforces the FILE_OPS_ROOT sandbox), validates it's a directory, then returns a sorted JSON list of subdirectory names.
@mcp.tool() def list_directories(path: str = ".") -> str: """List directories 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}") directories = sorted(p.name for p in target.iterdir() if p.is_dir()) return json.dumps(directories, indent=2) - server.py:181-181 (registration)The tool is registered via the @mcp.tool() decorator on FastMCP instance, which automatically registers list_directories as an MCP tool.
@mcp.tool() - server.py:66-76 (helper)Helper function used by list_directories to resolve and sandbox paths within the configured MCP_FILE_OPS_ROOT directory.
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