Skip to main content
Glama

fast_get_directory_tree

Retrieve and visualize directory tree structures with configurable depth, hidden file visibility, and file inclusion. Ideal for organizing and navigating complex file systems efficiently.

Instructions

디렉토리 트리 구조를 가져옵니다

Input Schema

NameRequiredDescriptionDefault
include_filesNo파일 포함
max_depthNo최대 깊이
pathYes루트 디렉토리 경로
show_hiddenNo숨김 파일 표시

Input Schema (JSON Schema)

{ "properties": { "include_files": { "default": true, "description": "파일 포함", "type": "boolean" }, "max_depth": { "default": 3, "description": "최대 깊이", "type": "number" }, "path": { "description": "루트 디렉토리 경로", "type": "string" }, "show_hidden": { "default": false, "description": "숨김 파일 표시", "type": "boolean" } }, "required": [ "path" ], "type": "object" }

Implementation Reference

  • Main handler function that implements the fast_get_directory_tree tool logic. It validates the path, recursively builds a directory tree up to the specified max_depth, filters out hidden/excluded files, and returns a structured tree object.
    async function handleGetDirectoryTree(args: any) { const { path: rootPath, max_depth = 3, show_hidden = false, include_files = true } = args; const safePath_resolved = safePath(rootPath); async function buildTree(currentPath: string, currentDepth: number): Promise<any> { if (currentDepth > max_depth) return null; try { const stats = await fs.stat(currentPath); const name = path.basename(currentPath); if (!show_hidden && name.startsWith('.')) return null; if (shouldExcludePath(currentPath)) return null; const node: any = { name: name, path: currentPath, type: stats.isDirectory() ? 'directory' : 'file', size: stats.size, size_readable: formatSize(stats.size), modified: stats.mtime.toISOString() }; if (stats.isDirectory()) { node.children = []; try { const entries = await fs.readdir(currentPath, { withFileTypes: true }); for (const entry of entries) { const childPath = path.join(currentPath, entry.name); if (entry.isDirectory()) { const childNode = await buildTree(childPath, currentDepth + 1); if (childNode) node.children.push(childNode); } else if (include_files) { const childNode = await buildTree(childPath, currentDepth + 1); if (childNode) node.children.push(childNode); } } } catch { // 권한 없는 디렉토리 node.error = 'Access denied'; } } return node; } catch { return null; } } const tree = await buildTree(safePath_resolved, 0); return { tree: tree, root_path: safePath_resolved, max_depth: max_depth, show_hidden: show_hidden, include_files: include_files, timestamp: new Date().toISOString() }; }
  • Tool definition including name, description, and input schema for parameter validation (path, max_depth, show_hidden, include_files). This is part of the MCP_TOOLS array used for tool listing.
    { name: 'fast_get_directory_tree', description: '디렉토리 트리 구조를 가져옵니다', inputSchema: { type: 'object', properties: { path: { type: 'string', description: '루트 디렉토리 경로' }, max_depth: { type: 'number', description: '최대 깊이', default: 3 }, show_hidden: { type: 'boolean', description: '숨김 파일 표시', default: false }, include_files: { type: 'boolean', description: '파일 포함', default: true } }, required: ['path'] } },
  • api/server.ts:341-343 (registration)
    Dispatch/registration in the tools/call switch statement, mapping the tool name to its handler function.
    case 'fast_get_directory_tree': result = await handleGetDirectoryTree(args); break;
  • Recursive helper function inside the handler that builds the directory tree node by node, respecting depth limits, exclusions, and visibility settings.
    async function buildTree(currentPath: string, currentDepth: number): Promise<any> { if (currentDepth > max_depth) return null; try { const stats = await fs.stat(currentPath); const name = path.basename(currentPath); if (!show_hidden && name.startsWith('.')) return null; if (shouldExcludePath(currentPath)) return null; const node: any = { name: name, path: currentPath, type: stats.isDirectory() ? 'directory' : 'file', size: stats.size, size_readable: formatSize(stats.size), modified: stats.mtime.toISOString() }; if (stats.isDirectory()) { node.children = []; try { const entries = await fs.readdir(currentPath, { withFileTypes: true }); for (const entry of entries) { const childPath = path.join(currentPath, entry.name); if (entry.isDirectory()) { const childNode = await buildTree(childPath, currentDepth + 1); if (childNode) node.children.push(childNode); } else if (include_files) { const childNode = await buildTree(childPath, currentDepth + 1); if (childNode) node.children.push(childNode); } } } catch { // 권한 없는 디렉토리 node.error = 'Access denied'; } } return node; } catch { return null; } }

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/efforthye/fast-filesystem-mcp'

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