list_files
Retrieve and filter files in a specified directory using a pattern. Ideal for organizing and managing file listings efficiently on the Edit MCP server.
Instructions
List files in a directory
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| directory | Yes | Path to the directory to list files from | |
| pattern | No | Pattern 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
- Core implementation of the list_files tool. Lists files in the given directory using fs.readdir, filters files only, optionally matches against a pattern regex, returns array of full 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}`); } }
- src/index.ts:191-212 (registration)Registers the list_files tool with the MCP server, providing name, description, input schema (directory required, optional pattern), and annotations indicating 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 } });
- src/router/operation-router.ts:416-417 (handler)In the filesystem executor, handles 'list_files' operation by calling FileSystemManager.listFiles with params directory and pattern.case 'list_files': return this.fileSystemManager.listFiles(operation.params.directory, operation.params.pattern);
- src/router/operation-router.ts:87-96 (helper)Classifies 'list_files' as a simple operation for routing decisions in analyzeComplexity method.const simpleOperations = [ 'read_file_content', 'write_file_content', 'append_to_file', 'get_file_info', 'list_files', 'create_directory', 'delete_file', 'simple_find_replace' ];