Skip to main content
Glama

list_files

Display files in a specified directory, optionally filtered by a pattern like *.txt, to organize and manage file contents effectively.

Instructions

List files in a directory

Input Schema

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

Input Schema (JSON Schema)

{ "properties": { "directory": { "description": "Path to the directory to list files from", "type": "string" }, "pattern": { "description": "Pattern to filter files by (e.g., *.txt)", "type": "string" } }, "required": [ "directory" ], "type": "object" }

Implementation Reference

  • The main handler function that lists files in a directory, optionally filtering by a 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)
    Registration of the 'list_files' tool on the MCPServer, including its 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 } });
  • The JSON schema defining inputs for the list_files tool: directory (required), pattern (optional).
    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']
  • Handler in OperationRouter's executeWithFileSystem that delegates list_files operation to FileSystemManager.listFiles.
    case 'list_files': return this.fileSystemManager.listFiles(operation.params.directory, operation.params.pattern);
  • 'list_files' classified as a simple operation in the complexity analysis.
    'list_files',

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

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