list_files
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
| Name | Required | Description | Default |
|---|---|---|---|
| directory | Yes | Path to the directory to list files from | |
| pattern | No | Pattern 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 } });
- src/router/operation-router.ts:416-417 (handler)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}`); } }