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"
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. 'List directory contents' implies a read-only operation, but doesn't specify what happens with permissions, hidden files, symbolic links, or error conditions. It lacks details on output format, sorting, or any behavioral traits beyond the basic action.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is perfectly concise at just three words. It's front-loaded with the essential action and resource, with zero wasted words. Every element earns its place in communicating the core function efficiently.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a file system tool with no annotations and no output schema, the description is insufficiently complete. It doesn't explain what 'list' means in practice (format, details included), how errors are handled, or differences from similar tools. Given the complexity of file operations and rich sibling toolset, more context would be helpful.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description mentions 'directory contents' which implies a path parameter, but doesn't explicitly describe the 'path' parameter or its default value ('.'). With 0% schema description coverage and only 1 parameter, the description adds minimal semantic context beyond what's obvious from the tool name, meeting the baseline for simple tools.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'List directory contents' clearly states the verb ('List') and resource ('directory contents'), making the purpose immediately understandable. It doesn't explicitly distinguish from sibling tools like 'tree' or 'find' which also list directory contents in different ways, but it's specific enough to understand the basic function.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'tree' (which shows hierarchical structure), 'find' (which searches), or 'pwd' (which shows current directory). There's no mention of context, prerequisites, or exclusions, leaving the agent to infer usage from the tool name alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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

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