Skip to main content
Glama

tree

Display directory tree structures to visualize file organization and hierarchy within virtual filesystem workspaces.

Instructions

Display directory tree structure.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathNo.
max_depthNo

Implementation Reference

  • Core handler implementation that recursively traverses the VFS directory structure to build a TreeNode hierarchy up to the specified max_depth, handling files, directories, and truncation.
    async def tree(self, path: str = ".", max_depth: int = 3) -> TreeResponse:
        """
        Display directory tree structure.
    
        Args:
            path: Root path for tree
            max_depth: Maximum depth to traverse
    
        Returns:
            TreeResponse with nested tree structure
        """
        vfs = self.workspace_manager.get_current_vfs()
        resolved_path = self.workspace_manager.resolve_path(path)
    
        async def build_tree(current_path: str, depth: int) -> TreeNode:
            if depth > max_depth:
                return TreeNode(name="...", type=NodeType.DIRECTORY, truncated=True)
    
            node_info = await vfs.get_node_info(current_path)
            if not node_info:
                return TreeNode(name="???", type=NodeType.FILE, size=0)
    
            node_type = NodeType.DIRECTORY if node_info.is_dir else NodeType.FILE
    
            if not node_info.is_dir:
                return TreeNode(
                    name=Path(current_path).name, type=node_type, size=node_info.size
                )
    
            # Recursively build tree for directory
            children: list[TreeNode] = []
            filenames = await vfs.ls(current_path)
            for name in filenames:
                if current_path == "/":
                    child_path = f"/{name}"
                else:
                    child_path = f"{current_path}/{name}"
                child_tree = await build_tree(child_path, depth + 1)
                children.append(child_tree)
    
            return TreeNode(
                name=Path(current_path).name if current_path != "/" else "/",
                type=node_type,
                children=children if children else None,
            )
    
        root = await build_tree(resolved_path, 0)
        return TreeResponse(root=root)
  • MCP server registration of the 'tree' tool using @server.tool decorator, which delegates execution to the VFSTools.tree handler.
    @server.tool
    async def tree(path: str = ".", max_depth: int = 3):
        """Display directory tree structure."""
        return await vfs_tools.tree(path, max_depth)
  • Pydantic models defining the schema for TreeNode (recursive structure for tree nodes) and TreeResponse (output model returned by the tree tool). NodeType enum is also used but defined earlier.
    class TreeNode(BaseModel):
        """Node in a directory tree"""
    
        name: str
        type: NodeType
        size: int | None = None
        children: list["TreeNode"] | None = None
        truncated: bool = False
    
    
    class TreeResponse(BaseModel):
        """Response from tree operation"""
    
        root: TreeNode
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states what the tool does but doesn't mention whether it's read-only, if it requires specific permissions, how it handles errors, or what the output format looks like. This is inadequate for a tool with parameters and no output schema.

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 extremely concise and front-loaded with a single, clear sentence that directly states the tool's purpose. There is no wasted verbiage, making it efficient for quick understanding.

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?

Given the tool has 2 parameters, no annotations, and no output schema, the description is incomplete. It doesn't cover parameter meanings, behavioral traits, or output details, which are essential for effective tool use. The simplicity of the tool somewhat mitigates this, but key information is missing.

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

Parameters2/5

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

The description adds no information about parameters beyond what the input schema provides. With 0% schema description coverage and 2 parameters (path and max_depth), the description fails to explain what these parameters mean, their expected formats, or how they affect the tree display, leaving significant gaps.

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 clearly states the tool's purpose with a specific verb ('display') and resource ('directory tree structure'), making it immediately understandable. It doesn't explicitly differentiate from siblings like 'ls' or 'find', but the focus on tree structure is reasonably distinct.

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 'ls' for listing or 'find' for searching. It lacks any context about use cases, prerequisites, or comparisons with sibling tools, leaving the agent to infer usage scenarios.

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