list_directory
Browse files and folders in your workspace to navigate Markdown projects. Use this tool to view directory contents and locate documents for editing.
Instructions
Lists files and folders in the workspace.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | No | . |
Implementation Reference
- Core handler function that implements the directory listing logic: validates path safety, scans directory with os.scandir, builds item dictionaries, handles exceptions.async def list_directory(self, path: str = ".") -> Optional[List[Dict[str, Any]]]: """List files and folders""" try: # Validate path safety error = self._validate_path(path) if error: logger.error(error) return None abs_path = self._get_abs_path(path) if not os.path.exists(abs_path): return None base_path = get_base_path() items = [] for entry in os.scandir(abs_path): items.append( { "name": entry.name, "is_dir": entry.is_dir(), "size": entry.stat().st_size if entry.is_file() else 0, "path": os.path.relpath(entry.path, base_path), } ) return items except Exception as e: logger.error(f"Error listing directory {path}: {e}") return None
- Input schema expects optional 'path' parameter (string, default '.'); output schema returns 'items' array of file/dir objects with name, is_dir, size, path.inputSchema={ "type": "object", "properties": { "path": { "type": "string", "default": ".", "examples": [".", "./docs", "/path/to/directory"], } }, "additionalProperties": False, }, outputSchema={ "type": "object", "properties": { "items": { "type": "array", "description": "List of directory entries", "items": { "type": "object", "properties": { "name": {"type": "string"}, "is_dir": {"type": "boolean"}, "size": {"type": "integer"}, "path": {"type": "string"}, }, }, } }, },
- src/markdown_editor/server.py:382-415 (registration)Tool registration in @app.list_tools(): defines name, title, description, input/output schemas for MCP discovery.Tool( name="list_directory", title="List Directory", description="Lists files and folders in the workspace.", inputSchema={ "type": "object", "properties": { "path": { "type": "string", "default": ".", "examples": [".", "./docs", "/path/to/directory"], } }, "additionalProperties": False, }, outputSchema={ "type": "object", "properties": { "items": { "type": "array", "description": "List of directory entries", "items": { "type": "object", "properties": { "name": {"type": "string"}, "is_dir": {"type": "boolean"}, "size": {"type": "integer"}, "path": {"type": "string"}, }, }, } }, }, ),
- Singleton wrapper delegating to FileOperationsTool instance; imported and directly called from server.py.async def list_directory(path: str = "."): return await _instance.list_directory(path)
- src/markdown_editor/server.py:515-523 (handler)Dispatch handler in @app.call_tool(): parses arguments, invokes list_directory wrapper, formats CallToolResult with JSON text and structured content.if name == "list_directory": path = arguments.get("path", ".") items = await list_directory(path) result = {"items": items} return CallToolResult( content=[TextContent(type="text", text=json.dumps(result, ensure_ascii=False, indent=2))], structuredContent=result, isError=items is None, )