list_files
Retrieve all files within a specified directory to verify compliance with organizational policies before execution.
Instructions
List all files in directory
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | No | Directory path |
Implementation Reference
- server.py:201-211 (handler)Handler for the 'list_files' tool. Resolves the directory path, recursively finds all files using rglob('*'), collects relative paths of files only, sorts them, and returns as a newline-separated text content.elif name == "list_files": dir_path = resolve_path(arguments.get("path", "")) if not dir_path.exists(): return [TextContent(type="text", text="Error: Directory not found")] files = [] for item in dir_path.rglob("*"): if item.is_file(): files.append(str(item.relative_to(PROTECTED_DIR))) return [TextContent(type="text", text="\n".join(sorted(files)) if files else "No files found")]
- server.py:123-132 (registration)Registration of the 'list_files' tool in the list_tools() function, including its description and input schema.Tool( name="list_files", description="List all files in directory", inputSchema={ "type": "object", "properties": { "path": {"type": "string", "description": "Directory path", "default": ""} } } )
- server.py:126-131 (schema)Input schema for the 'list_files' tool: an object with optional 'path' string property defaulting to empty string.inputSchema={ "type": "object", "properties": { "path": {"type": "string", "description": "Directory path", "default": ""} } }