Skip to main content
Glama

get_deep_directory_tree

Visualize complex directory structures by generating a deep tree view. Specify path, depth, and exclude patterns to efficiently navigate and manage filesystem hierarchies.

Instructions

Get deep directory tree

Input Schema

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

Implementation Reference

  • The asynchronous handler function provided to mcp.tool for executing the get_deep_directory_tree tool logic. It invokes getDirectoryTree and returns the result formatted as MCP content.
    async ({ path, options }) => { const directoryStructure = getDirectoryTree(path, options); return { content: [ { type: "text", text: directoryStructure, }, ], }; }
  • Zod schema defining the input parameters for the get_deep_directory_tree tool: 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 with the MCP server using mcp.tool(), including name, description, input schema, and handler.
    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 traverses the directory, builds the tree structure as a string array, handles exclusion patterns and depth limits, and returns the formatted tree.
    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"); }

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-filesystem-tree-mcp'

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