Skip to main content
Glama

ls

List files and directories in a specified path to view virtual filesystem contents. Use this command to navigate and inspect workspace structure.

Instructions

List directory contents.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathNo.

Implementation Reference

  • The core handler function for the 'ls' tool. Resolves the path, lists filenames using the VFS, fetches detailed node info for each entry, constructs FileEntry objects, and returns a ListDirectoryResponse.
    async def ls(self, path: str = ".") -> ListDirectoryResponse:
        """
        List directory contents.
    
        Args:
            path: Directory path (default: current directory)
    
        Returns:
            ListDirectoryResponse with entries
        """
        vfs = self.workspace_manager.get_current_vfs()
        resolved_path = self.workspace_manager.resolve_path(path)
    
        # ls() returns list of filenames
        filenames = await vfs.ls(resolved_path)
    
        file_entries = []
        for name in filenames:
            # Construct full path
            if resolved_path == "/":
                full_path = f"/{name}"
            else:
                full_path = f"{resolved_path}/{name}"
    
            # Get node info for each entry
            node_info = await vfs.get_node_info(full_path)
            if node_info:
                # Parse modified_at timestamp if it's a string
                modified: datetime | None = None
                if node_info.modified_at:
                    if isinstance(node_info.modified_at, str):
                        modified = datetime.fromisoformat(node_info.modified_at)
                    else:
                        modified = node_info.modified_at
    
                file_entries.append(
                    FileEntry(
                        name=name,
                        path=full_path,
                        type=NodeType.DIRECTORY if node_info.is_dir else NodeType.FILE,
                        size=node_info.size,
                        modified=modified,
                    )
                )
    
        return ListDirectoryResponse(path=resolved_path, entries=file_entries)
  • Registers the 'ls' tool in the MCP server using the @server.tool decorator. Delegates execution to the VFSTools.ls handler method.
    @server.tool
    async def ls(path: str = "."):
        """List directory contents."""
        return await vfs_tools.ls(path)
  • Pydantic model defining the output schema for the 'ls' tool response, consisting of the path and a list of FileEntry objects.
    class ListDirectoryResponse(BaseModel):
        """Response from ls operation"""
    
        path: str
        entries: list[FileEntry]
  • Pydantic model for individual file/directory entries returned by the 'ls' tool.
    class FileEntry(BaseModel):
        """A file or directory entry"""
    
        name: str
        path: str
        type: NodeType
        size: int
        modified: datetime | None = None
  • Enum used in FileEntry to indicate whether an entry is a file or directory.
    class NodeType(str, Enum):
        """Filesystem node types"""
    
        FILE = "file"
        DIRECTORY = "directory"

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/chrishayuk/chuk-mcp-vfs'

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