Skip to main content
Glama

fast_get_directory_tree

Generate a visual directory tree structure from a specified path, with configurable depth, hidden file visibility, and file inclusion options.

Instructions

Gets the directory tree structure

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesRoot directory path
max_depthNoMaximum depth
show_hiddenNoShow hidden files
include_filesNoInclude files in the tree

Implementation Reference

  • The main handler function for 'fast_get_directory_tree' that recursively builds a directory tree structure up to the specified max_depth, filtering hidden files and excluded paths, and optionally including files.
    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()
      };
    }
  • Input schema defining the parameters for the fast_get_directory_tree tool: path (required), max_depth, show_hidden, include_files.
    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:193-206 (registration)
    Registration of the fast_get_directory_tree tool in the MCP_TOOLS array, including name, description, and input schema.
    {
      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 switch statement for tools/call method, calling the handleGetDirectoryTree handler.
    case 'fast_get_directory_tree':
      result = await handleGetDirectoryTree(args);
      break;

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