Skip to main content
Glama

get_deep_directory_tree

Generate a detailed directory tree from a specified path, customizing depth and excluding specific patterns for efficient file structure visualization and analysis.

Instructions

Get deep directory tree

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
optionsNoTree generation options
pathYesPath to get the directory tree (preferably absolute path)

Implementation Reference

  • src/index.ts:70-105 (registration)
    Registration of the 'get_deep_directory_tree' tool with the MCP server using mcp.tool(), specifying name, description, input schema, and handler function.
    mcp.tool(
      "get_deep_directory_tree",
      "Get deep directory tree",
      {
        path: z
          .string()
          .describe("Path to get the directory tree (preferably absolute path)"),
        options: z
          .object({
            depth: z.number().default(3).describe("Depth of the directory tree"),
            excludePatterns: z
              .array(z.string())
              .default(["node_modules", ".git", ".turbo", "dist", ".next"])
              .describe(
                "Patterns to exclude from the tree (e.g., ['node_modules', '*.log'])"
              ),
          })
          .default({
            depth: 3,
            excludePatterns: ["node_modules", ".git", ".turbo", "dist", ".next"],
          })
          .describe("Tree generation options"),
      },
      async ({ path, options }) => {
        const directoryStructure = getDirectoryTree(path, options);
    
        return {
          content: [
            {
              type: "text",
              text: directoryStructure,
            },
          ],
        };
      }
    );
  • Zod schema definition for the tool inputs: 'path' (string) and 'options' (object with depth and excludePatterns).
    {
      path: z
        .string()
        .describe("Path to get the directory tree (preferably absolute path)"),
      options: z
        .object({
          depth: z.number().default(3).describe("Depth of the directory tree"),
          excludePatterns: z
            .array(z.string())
            .default(["node_modules", ".git", ".turbo", "dist", ".next"])
            .describe(
              "Patterns to exclude from the tree (e.g., ['node_modules', '*.log'])"
            ),
        })
        .default({
          depth: 3,
          excludePatterns: ["node_modules", ".git", ".turbo", "dist", ".next"],
        })
        .describe("Tree generation options"),
    },
  • Async handler function that invokes getDirectoryTree with provided path and options, then returns the directory structure as text content in MCP format.
      async ({ path, options }) => {
        const directoryStructure = getDirectoryTree(path, options);
    
        return {
          content: [
            {
              type: "text",
              text: directoryStructure,
            },
          ],
        };
      }
    );
  • Core helper function getDirectoryTree that recursively traverses the directory up to specified depth, excludes patterns, and builds a tree string representation.
    function getDirectoryTree(
      rootPath: string,
      options: TreeOptions = {
        depth: 3,
        excludePatterns: ["node_modules", ".git", ".turbo", "dist", ".next"],
      }
    ) {
      const tree: string[] = [];
    
      function shouldExclude(file: string): boolean {
        return options.excludePatterns.some((pattern) => {
          if (pattern.includes("*")) {
            const regexPattern = pattern.replace(/\*/g, ".*");
            return new RegExp(regexPattern).test(file);
          }
          return file === pattern;
        });
      }
    
      function traverse(dir: string, currentDepth: number = 0) {
        if (currentDepth >= options.depth) return;
    
        const files = fs.readdirSync(dir);
        const filteredFiles = files.filter((file) => !shouldExclude(file));
    
        filteredFiles.forEach((file, index) => {
          const filePath = path.join(dir, file);
          const stats = fs.statSync(filePath);
          const isLast = index === filteredFiles.length - 1;
          const prefix = isLast ? "└── " : "├── ";
    
          if (stats.isDirectory()) {
            tree.push(`${"  ".repeat(currentDepth)}${prefix}${file}`);
            traverse(filePath, currentDepth + 1);
          } else {
            tree.push(`${"  ".repeat(currentDepth)}${prefix}${file}`);
          }
        });
      }
    
      traverse(rootPath);
      return tree.join("\n");
    }
Behavior2/5

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

With no annotations, the description carries the full burden of behavioral disclosure. It only states the action without detailing output format, performance implications, error handling, or system impacts. This is inadequate for a tool that likely returns structured data and may have depth/exclusion constraints.

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 with a single phrase, front-loaded and without unnecessary words. It efficiently conveys the core intent, though this brevity contributes to gaps in other dimensions.

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 no annotations, no output schema, and a tool with behavioral complexity (e.g., tree generation with exclusions), the description is incomplete. It fails to explain return values, error cases, or practical use, leaving significant gaps for agent understanding.

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 description coverage is 100%, so the schema fully documents parameters like 'path' and 'options' with defaults. The description adds no parameter semantics beyond what the schema provides, meeting the baseline for high coverage but not enhancing understanding.

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

Purpose3/5

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

The description 'Get deep directory tree' states the basic action (get) and resource (directory tree), but lacks specificity about what 'deep' means or how it differs from a shallow tree. Without sibling tools, differentiation isn't needed, but the purpose remains vague about the nature of the operation beyond the literal interpretation.

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?

No guidance is provided on when to use this tool versus alternatives or any prerequisites. The description does not mention context like file system exploration or debugging scenarios, leaving the agent with no usage cues beyond the tool name.

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

Related 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/andredezzy/deep-directory-tree-mcp'

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