Skip to main content
Glama

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
NameRequiredDescriptionDefault
pathNo.

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"}, }, }, } }, },
  • 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)
  • 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, )

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/KazKozDev/markdown-editor-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server