Skip to main content
Glama

Directory Tree

directory_tree
Read-onlyIdempotent

Returns a recursive JSON tree of files and directories within allowed paths, with optional depth limits and exclusion patterns for inspecting project structure.

Instructions

Get a recursive tree view of files and directories as a JSON structure. Each entry includes 'name', 'type' (file/directory), and 'children' for directories. Files have no children array, while directories always have a children array (which may be empty), except at the last level when 'depth' limits the tree: those directories are not read and have no children array. The output is formatted with 2-space indentation for readability. Only works within allowed directories.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "path": "<path>"
    },
    "name": "directory_tree"
  }
}

Input Schema

NameRequiredDescriptionDefault
pathYesThe directory at the root of the tree. Absolute, or relative to an allowed directory; it must resolve inside the allowed directories.
depthNoHow many levels to descend: 1 lists only the entries directly in path. Directories at the last level have no children array. Omit for the whole tree.
excludePatternsNoPatterns for entries to leave out, with their contents, matched against each entry's path relative to path. A pattern with no '*' matches that name at any depth ('node_modules' leaves out every node_modules directory); a pattern with '*' is a glob matched as written, and one ending in '/**' also leaves out the directory it names.

Output Schema

NameRequiredDescriptionDefault
contentYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.3.0

TDQS

B3.3/5.0
Behavior4/5

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

Annotations already declare read-only, idempotent, closed-world behavior, so the description only needs to add operational detail. It does so usefully: it discloses that directories at the depth boundary are not read at all (an I/O behavior, not just a shape detail) and that the path must resolve inside allowed directories. It does not disclose any cost/size risk of a full recursive walk.

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

Conciseness3/5

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

The opening sentence is well front-loaded, but the middle of the description spends three sentences on the JSON shape and 2-space indentation that a dedicated output schema already defines, which is repetition rather than value. The 'only works within allowed directories' constraint would be better placed first, next to the other scoping rules.

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

Completeness3/5

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

An output schema exists, so the prose about children arrays and indentation is redundant, and the description omits guidance on the one parameter it does not touch, excludePatterns. For a tool whose main risk is an expensive full-tree walk on a large directory, no guidance is given about using depth or exclusions to bound the call.

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?

Schema coverage is 100%, so path, depth, and excludePatterns are already fully documented in the schema, establishing the baseline of 3. The description's depth remarks restate the schema's own wording ('Directories at the last level have no children array') and excludePatterns is never mentioned, so no meaning is added beyond the structured fields.

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?

States a specific verb and resource ('Get a recursive tree view of files and directories as a JSON structure'), which is clearly distinct from flat listing tools in what it returns. However, it never names or contrasts with siblings such as list_directory or search_files, so the agent must infer the distinction from the word 'recursive' alone.

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 only usage constraint given is 'Only works within allowed directories', which is a prerequisite, not when-to-use guidance. There is no statement about when to prefer this over list_directory or list_directory_with_sizes, nor when to use depth limiting versus a full walk.

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