Skip to main content
Glama

list_files

Read-only

List files in a specified directory, optionally filtering by pattern like *.txt, to view available files for editing operations.

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

  • src/index.ts:191-212 (registration)
    Registration of the 'list_files' MCP tool, including schema definition for input parameters (directory and optional pattern) and annotations indicating it's read-only.
    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
      }
    });
  • Handler dispatch for 'list_files' tool in the operation router's filesystem executor, calling FileSystemManager.listFiles with directory and pattern from params.
    case 'list_files':
      return this.fileSystemManager.listFiles(operation.params.directory, operation.params.pattern);
  • Core implementation of listFiles method in FileSystemManager: reads directory entries, filters files, applies optional pattern filter using regex, returns full file paths.
    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}`);
      }
    }
Behavior3/5

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

Annotations already declare readOnlyHint=true and openWorldHint=false, indicating this is a safe read operation with limited scope. The description adds the basic action of listing files but doesn't provide additional behavioral context such as pagination, sorting, error handling, or performance characteristics. With annotations covering safety and scope, this earns a baseline score for adding minimal value.

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, clear sentence with zero wasted words. It's front-loaded with the core action and resource, making it immediately understandable without any 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 operation), 100% schema coverage, and annotations providing safety/scope information, the description is adequate but minimal. It doesn't explain return values (no output schema exists) or edge cases, leaving some gaps in completeness for a tool that might need to handle various directory structures.

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 both parameters ('directory' and 'pattern') fully documented in the schema. The description mentions 'directory' but doesn't add any semantic details beyond what the schema provides, such as path format examples or pattern usage scenarios. This meets the baseline for when 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 'List' and resource 'files in a directory', making the purpose immediately understandable. However, it doesn't differentiate this tool from potential sibling tools like 'find_in_file' or 'complex_find_replace' that might also involve file operations, so it doesn't reach the highest score.

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. With sibling tools like 'find_in_file' and 'read_file' available, there's no indication of when listing files is preferred over searching within them or reading their contents. This leaves the agent without contextual usage information.

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

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