Skip to main content
Glama
ConnorBoetig-dev

Unrestricted Development MCP Server

fs_list_directory

List directory contents with detailed file information including type, size, and permissions for development environment navigation and file management.

Instructions

List contents of a directory with detailed information about each entry (name, type, size, permissions, etc.)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesAbsolute or relative path to the directory
recursiveNoList subdirectories recursively
showHiddenNoShow hidden files (starting with .)

Implementation Reference

  • The core handler function that executes the fs_list_directory tool: reads directory entries, computes stats, supports recursive listing and hidden file filtering, returns JSON-formatted directory listing.
    export async function listDirectory(args: z.infer<typeof listDirectorySchema>): Promise<ToolResponse> {
      try {
        const entries = await fs.readdir(args.path, { withFileTypes: true });
    
        let files: any[] = [];
    
        for (const entry of entries) {
          // Skip hidden files if not requested
          if (!args.showHidden && entry.name.startsWith('.')) {
            continue;
          }
    
          const fullPath = path.join(args.path, entry.name);
          const stats = await fs.stat(fullPath);
    
          const fileInfo = {
            name: entry.name,
            path: fullPath,
            type: entry.isDirectory() ? 'directory' : entry.isSymbolicLink() ? 'symlink' : 'file',
            size: stats.size,
            modified: stats.mtime,
            permissions: stats.mode
          };
    
          files.push(fileInfo);
    
          // Recurse into subdirectories if requested
          if (args.recursive && entry.isDirectory()) {
            const subResult = await listDirectory({
              path: fullPath,
              recursive: true,
              showHidden: args.showHidden
            });
    
            // Parse the sub-result and add to files
            const subData = JSON.parse(subResult.content[0].text);
            if (subData.success) {
              files = files.concat(subData.entries);
            }
          }
        }
    
        return {
          content: [
            {
              type: "text" as const,
              text: JSON.stringify({
                success: true,
                path: args.path,
                count: files.length,
                entries: files
              }, null, 2)
            }
          ]
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text" as const,
              text: JSON.stringify({
                success: false,
                error: error instanceof Error ? error.message : String(error)
              }, null, 2)
            }
          ],
          isError: true
        };
      }
    }
  • Zod input validation schema for the fs_list_directory tool parameters.
    export const listDirectorySchema = z.object({
      path: z.string().describe('Absolute or relative path to the directory'),
      recursive: z.boolean().default(false).describe('List subdirectories recursively'),
      showHidden: z.boolean().default(false).describe('Show hidden files (starting with .)')
    });
  • MCP tool definition object for 'fs_list_directory' (part of filesystemTools array), including name, description, and inputSchema; used in listTools response for tool discovery.
    {
      name: 'fs_list_directory',
      description: 'List contents of a directory with detailed information about each entry (name, type, size, permissions, etc.)',
      inputSchema: {
        type: 'object',
        properties: {
          path: {
            type: 'string',
            description: 'Absolute or relative path to the directory'
          },
          recursive: {
            type: 'boolean',
            default: false,
            description: 'List subdirectories recursively'
          },
          showHidden: {
            type: 'boolean',
            default: false,
            description: 'Show hidden files (starting with .)'
          }
        },
        required: ['path']
      }
    },
  • Dispatch handler in main server: validates input using listDirectorySchema and calls the listDirectory implementation for fs_list_directory tool calls.
    if (name === 'fs_list_directory') {
      const validated = listDirectorySchema.parse(args);
      return await listDirectory(validated);
    }
  • src/index.ts:284-296 (registration)
    Server request handler for listing tools; includes filesystemTools (containing fs_list_directory definition) in the response, effectively registering the tool.
    this.server.setRequestHandler(ListToolsRequestSchema, async () => {
      return {
        tools: [
          ...filesystemTools,
          ...shellTools,
          ...dockerTools,
          ...mongodbTools,
          ...redisTools,
          ...gitTools,
          ...processTools,
          ...networkTools
        ]
      };
Behavior2/5

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

With no annotations provided, the description carries full burden but only states what information is returned, not behavioral aspects. It doesn't mention error conditions (e.g., non-existent paths), performance implications of recursive listing, permission requirements, or output format details.

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 front-loads the core purpose and adds useful detail about the returned information. Every word earns its place with no redundancy or unnecessary elaboration.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a read-only directory listing tool with no output schema, the description adequately covers the basic purpose but lacks important context about error handling, output structure, and performance considerations. It's minimally viable but has clear gaps in behavioral transparency.

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?

Schema description coverage is 100%, so the schema fully documents all three parameters. The description doesn't add any parameter-specific information beyond what's already in the schema, meeting the baseline for high coverage.

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

Purpose5/5

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

The description clearly states the specific action ('List contents') and resource ('directory'), with additional detail about the information returned ('detailed information about each entry'). It distinguishes from sibling tools like fs_get_file_info (single file) and fs_read_file (file content).

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?

No guidance is provided on when to use this tool versus alternatives. While the purpose is clear, there's no mention of when to choose this over similar tools like fs_get_file_info (for single files) or when recursive listing is preferable to non-recursive.

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/ConnorBoetig-dev/mcp2'

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