Skip to main content
Glama

list_files

Read-only

List files in a directory with optional pattern filtering to find specific files quickly.

Instructions

List files in a directory

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
directoryYesPath to the directory to list files from
patternNoPattern to filter files by (e.g., *.txt)

Implementation Reference

  • Core handler function that lists files in a directory, filtering by optional pattern using fs.readdir.
    public async listFiles(dirPath: string, pattern?: string): Promise<string[]> {
      try {
        const entries = await readdir(dirPath, { withFileTypes: true });
        let files = entries
          .filter(entry => entry.isFile())
          .map(entry => path.join(dirPath, entry.name));
        
        if (pattern) {
          const regex = new RegExp(pattern);
          files = files.filter(file => regex.test(file));
        }
        
        return files;
      } catch (error: any) {
        throw new Error(`Failed to list files in ${dirPath}: ${error.message}`);
      }
    }
  • src/index.ts:191-212 (registration)
    Registers the 'list_files' tool with the MCP server, providing description, input schema, and annotations.
    mcpServer.registerTool({
      name: 'list_files',
      description: 'List files in a directory',
      inputSchema: {
        type: 'object',
        properties: {
          directory: {
            type: 'string',
            description: 'Path to the directory to list files from'
          },
          pattern: {
            type: 'string',
            description: 'Pattern to filter files by (e.g., *.txt)'
          }
        },
        required: ['directory']
      },
      annotations: {
        readOnlyHint: true,
        openWorldHint: false
      }
    });
  • Input schema definition for the list_files tool, specifying directory (required) and optional pattern.
    inputSchema: {
      type: 'object',
      properties: {
        directory: {
          type: 'string',
          description: 'Path to the directory to list files from'
        },
        pattern: {
          type: 'string',
          description: 'Pattern to filter files by (e.g., *.txt)'
        }
      },
      required: ['directory']
  • Router dispatch for 'list_files' tool calls, delegating to FileSystemManager.listFiles.
    case 'list_files':
      return this.fileSystemManager.listFiles(operation.params.directory, operation.params.pattern);
Behavior3/5

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

Annotations already declare readOnlyHint=true and openWorldHint=false, indicating a safe, non-destructive operation with limited scope. The description adds minimal behavioral context beyond this, such as implying directory-based listing, but doesn't detail aspects like pagination, error handling, or return format. No contradiction with annotations exists.

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 with zero waste. It's front-loaded with the core action and resource, making it easy to parse quickly. Every word earns its place without 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?

Given the tool's low complexity (simple listing), high schema coverage, and annotations covering safety and scope, the description is minimally adequate. However, with no output schema, it doesn't explain return values like file list format or error cases, leaving gaps for an agent to infer behavior.

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%, with clear descriptions for both parameters ('directory' and 'pattern'). The description adds no additional meaning beyond what the schema provides, such as explaining pattern syntax or directory path conventions. Baseline 3 is appropriate as the schema handles parameter documentation adequately.

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 'List files in a directory' clearly states the verb ('List') and resource ('files'), specifying the scope ('in a directory'). It distinguishes from siblings like 'read_file' or 'find_in_file' by focusing on listing rather than reading or searching content, though it doesn't explicitly mention sibling 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. It doesn't mention when to prefer 'list_files' over 'find_in_file' for filtering or 'complex_find_replace' for more advanced operations, nor does it specify prerequisites like directory existence or permissions.

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/mixelpixx/edit-mcp'

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