Skip to main content
Glama
PWalaGov

Enhanced Directory Context MCP Server

by PWalaGov

get_directory_structure

Retrieve complete directory structures with file metadata to analyze project organization and locate files efficiently.

Instructions

Get the complete directory structure with file metadata

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
max_depthNoMaximum depth to traverse (default: 10)
include_hiddenNoInclude hidden files and directories
file_typesNoFilter by file extensions (e.g., [".js", ".py", ".md"])

Implementation Reference

  • Main handler function for 'get_directory_structure' tool. Parses input arguments, invokes the recursive directory traversal helper, and returns the directory structure as formatted JSON.
    async handleGetDirectoryStructure(args) {
      const { max_depth = 10, include_hidden = false, file_types } = args;
      
      const structure = await this.getDirectoryStructure(
        this.workingDirectory,
        max_depth,
        include_hidden,
        file_types
      );
      
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(structure, null, 2),
          },
        ],
      };
    }
  • Core recursive implementation that builds the directory tree structure using fs.readdir and fs.stat, filtering by depth, hidden files, and file types, including file metadata.
    async getDirectoryStructure(dirPath, maxDepth = 10, includeHidden = false, fileTypes = null, currentDepth = 0) {
      if (currentDepth >= maxDepth) {
        return null;
      }
    
      try {
        const entries = await fs.readdir(dirPath, { withFileTypes: true });
        const structure = {
          name: path.basename(dirPath),
          path: path.relative(this.workingDirectory, dirPath) || '.',
          type: 'directory',
          children: [],
        };
    
        for (const entry of entries) {
          if (!includeHidden && entry.name.startsWith('.')) {
            continue;
          }
    
          const fullPath = path.join(dirPath, entry.name);
          const relativePath = path.relative(this.workingDirectory, fullPath);
    
          if (entry.isDirectory()) {
            const subStructure = await this.getDirectoryStructure(
              fullPath,
              maxDepth,
              includeHidden,
              fileTypes,
              currentDepth + 1
            );
            if (subStructure) {
              structure.children.push(subStructure);
            }
          } else {
            const ext = path.extname(entry.name);
            if (!fileTypes || fileTypes.includes(ext)) {
              const stats = await fs.stat(fullPath);
              structure.children.push({
                name: entry.name,
                path: relativePath,
                type: 'file',
                size: stats.size,
                modified: stats.mtime.toISOString(),
                extension: ext,
              });
            }
          }
        }
    
        return structure;
      } catch (error) {
        return {
          name: path.basename(dirPath),
          path: path.relative(this.workingDirectory, dirPath),
          type: 'directory',
          error: error.message,
        };
      }
    }
  • Input schema validation for tool parameters: max_depth, include_hidden, file_types.
    inputSchema: {
      type: 'object',
      properties: {
        max_depth: {
          type: 'number',
          description: 'Maximum depth to traverse (default: 10)',
          default: 10,
        },
        include_hidden: {
          type: 'boolean',
          description: 'Include hidden files and directories',
          default: false,
        },
        file_types: {
          type: 'array',
          description: 'Filter by file extensions (e.g., [".js", ".py", ".md"])',
          items: { type: 'string' },
        },
      },
    },
  • server.js:457-458 (registration)
    Dispatch registration in the switch statement handling tool calls, routing to the specific handler.
    case 'get_directory_structure':
      return await this.handleGetDirectoryStructure(args);
  • server.js:65-88 (registration)
    Tool registration in the tools list returned by ListTools handler, including name, description, and input schema.
    {
      name: 'get_directory_structure',
      description: 'Get the complete directory structure with file metadata',
      inputSchema: {
        type: 'object',
        properties: {
          max_depth: {
            type: 'number',
            description: 'Maximum depth to traverse (default: 10)',
            default: 10,
          },
          include_hidden: {
            type: 'boolean',
            description: 'Include hidden files and directories',
            default: false,
          },
          file_types: {
            type: 'array',
            description: 'Filter by file extensions (e.g., [".js", ".py", ".md"])',
            items: { type: 'string' },
          },
        },
      },
    },
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. While 'Get' implies a read-only operation, the description doesn't address important behavioral aspects like performance characteristics (could be slow for large directories), whether it traverses symlinks, what metadata is included, or how results are structured. The description is too minimal for a tool that returns potentially complex directory structures.

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 a single, efficient sentence that gets straight to the point with zero wasted words. It's appropriately sized for a tool with well-documented parameters and no output schema, making it easy to parse and understand at a glance.

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?

For a tool that returns directory structures with metadata and has no output schema, the description is insufficient. It doesn't explain what 'file metadata' includes (size, permissions, timestamps, etc.), how the structure is organized, whether it's recursive by default, or what format the output takes. Given the complexity of directory traversal and the lack of output schema, more context is needed.

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?

The input schema has 100% description coverage, with all three parameters well-documented in the schema itself. The description adds no additional parameter information beyond what's already in the schema descriptions, so it meets the baseline of 3 where the schema does the heavy lifting.

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

Purpose4/5

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

The description clearly states the verb ('Get') and resource ('complete directory structure with file metadata'), making the purpose immediately understandable. It doesn't explicitly distinguish from sibling tools like 'search_files' or 'get_file_contents', but the scope ('complete directory structure') provides some implicit differentiation.

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?

The description provides no guidance on when to use this tool versus alternatives like 'search_files' (for targeted searches) or 'get_file_contents' (for reading specific files). There's no mention of prerequisites, typical use cases, or when this tool would be preferred over other file system operations available in the sibling list.

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

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/PWalaGov/File-Control-MCP'

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