Skip to main content
Glama

get_deep_directory_tree

Generate a visual directory tree structure from a specified path with configurable depth and exclusion patterns to analyze file system organization.

Instructions

Get deep directory tree

Input Schema

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

Implementation Reference

  • The tool handler function that invokes getDirectoryTree with the provided path and options, then returns the directory structure as text content.
    async ({ path, options }) => { const directoryStructure = getDirectoryTree(path, options); return { content: [ { type: "text", text: directoryStructure, }, ], }; }
  • Zod schema defining the input parameters: 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"), },
  • src/index.ts:70-105 (registration)
    Registration of the 'get_deep_directory_tree' tool using mcp.tool(), including 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, }, ], }; } );
  • Core helper function that recursively traverses the directory tree up to the specified depth, excludes patterns, and builds a formatted tree string using Unicode characters.
    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"); }
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/andredezzy/deep-filesystem-tree-mcp'

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