Skip to main content
Glama

ls

List files and directories in a specified path to view virtual filesystem contents. Use this tool to navigate and inspect workspace structure within the MCP server.

Instructions

List directory contents.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathNo.

Implementation Reference

  • The 'ls' handler function in VFSTools class that performs directory listing using the workspace VFS, retrieves node info for each entry, 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)
  • Pydantic model defining the output schema for the 'ls' tool response: path and list of FileEntry objects.
    class ListDirectoryResponse(BaseModel): """Response from ls operation""" path: str entries: list[FileEntry]
  • MCP tool registration for 'ls' using @server.tool decorator on a wrapper function that delegates to VFSTools.ls.
    @server.tool async def ls(path: str = "."): """List directory contents.""" return await vfs_tools.ls(path)
  • Pydantic model for individual file/directory entries used in ListDirectoryResponse.entries for '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.type for distinguishing file vs directory in 'ls' output.
    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