Skip to main content
Glama
gabrielmaialva33

MCP Filesystem Server

list_directory

Retrieve a structured listing of files and directories within a specified path, marked with [FILE] and [DIR] prefixes. Use this tool to analyze directory structures and locate specific items efficiently within permitted directories.

Instructions

Get a detailed listing of all files and directories in a specified path. Results clearly distinguish between files and directories with [FILE] and [DIR] prefixes. This tool is essential for understanding directory structure and finding specific files within a directory. Only works within allowed directories.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesPath of the directory to list

Implementation Reference

  • Handler for the list_directory tool: parses arguments, validates path access, reads directory contents using fs.readdir with file types, sorts entries (directories first alphabetically, then files), formats output with [DIR] or [FILE] prefixes, logs the operation, and returns formatted text content.
    case 'list_directory': {
      const parsed = ListDirectoryArgsSchema.safeParse(a)
      if (!parsed.success) {
        throw new FileSystemError(`Invalid arguments for ${name}`, 'INVALID_ARGS', undefined, {
          errors: parsed.error.format(),
        })
      }
    
      const validPath = await validatePath(parsed.data.path, config)
      const entries = await fs.readdir(validPath, { withFileTypes: true })
    
      // Sort directories first, then files, both alphabetically
      entries.sort((c, d) => {
        if (c.isDirectory() && !d.isDirectory()) return -1
        if (!c.isDirectory() && d.isDirectory()) return 1
        return c.name.localeCompare(d.name)
      })
    
      const formatted = entries
        .map((entry) => `${entry.isDirectory() ? '[DIR]' : '[FILE]'} ${entry.name}`)
        .join('\n')
    
      await logger.debug(`Listed directory: ${validPath}`, { entryCount: entries.length })
    
      endMetric()
      return {
        content: [{ type: 'text', text: formatted }],
      }
    }
  • Zod schema for list_directory tool input, requiring a 'path' string parameter.
    const ListDirectoryArgsSchema = z.object({
      path: z.string().describe('Path of the directory to list'),
    })
  • src/index.ts:279-287 (registration)
    Tool registration in the ListTools response: defines name, detailed description, and references the input schema.
    {
      name: 'list_directory',
      description:
        'Get a detailed listing of all files and directories in a specified path. ' +
        'Results clearly distinguish between files and directories with [FILE] and [DIR] ' +
        'prefixes. This tool is essential for understanding directory structure and ' +
        'finding specific files within a directory. Only works within allowed directories.',
      inputSchema: zodToJsonSchema(ListDirectoryArgsSchema) as ToolInput,
    },
Behavior3/5

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

With no annotations provided, the description carries the full burden. It discloses key behavioral traits like output formatting ('[FILE] and [DIR] prefixes') and access restrictions ('Only works within allowed directories'), but lacks details on error handling, pagination, or performance limits, leaving gaps for a tool with no annotation coverage.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized with three sentences that are front-loaded (purpose first, then details, then restriction). However, the third sentence ('This tool is essential...') is somewhat redundant with the first, slightly reducing efficiency.

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?

Given the tool's moderate complexity (single parameter, no output schema, no annotations), the description covers purpose, output format, and restrictions adequately but lacks details on return values (e.g., structure of the listing) and error cases, making it minimally viable but with clear gaps.

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 already documents the 'path' parameter fully. The description adds no additional meaning beyond what the schema provides, such as format examples or constraints, resulting in a baseline score of 3.

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 tool's purpose with specific verbs ('Get a detailed listing') and resources ('files and directories in a specified path'), and distinguishes it from siblings like 'directory_tree' (which might show hierarchical structure) and 'list_allowed_directories' (which lists allowed paths rather than contents).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context with 'Only works within allowed directories' and implies usage for 'understanding directory structure and finding specific files,' but doesn't explicitly state when to use alternatives like 'search_files' for filtering or 'directory_tree' for hierarchical views, missing explicit exclusions or comparisons.

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

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

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