list_directory
View files and folders in a local directory to explore system contents safely. Specify a path or use current location by default.
Instructions
List the contents of a local directory. Default is current directory.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | No | . |
Implementation Reference
- server.py:66-77 (handler)The handler function for the 'list_directory' tool. It lists the contents of the specified directory using os.listdir, formats them as a bullet list, and handles errors. Registered via @mcp.tool() decorator.@mcp.tool() def list_directory(path: str = ".") -> str: """List the contents of a local directory. Default is current directory.""" try: items = os.listdir(path) if not items: return f"The directory '{path}' is empty." return "\n".join([f"- {item}" for item in items]) except Exception as e: return f"Error reading directory: {str(e)}"