list_directory_files
Lists files in a workspace directory to help developers navigate project structures and manage code assets within the AI Development Pipeline MCP environment.
Instructions
List files in a workspace directory (restricted to workspace directory)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| dir | Yes |
Implementation Reference
- local-mcp-server.ts:123-143 (registration)Registration of the 'list_directory_files' tool using server.tool(), including schema and inline handler function.server.tool( 'list_directory_files', 'List files in a workspace directory (restricted to workspace directory)', { dir: z.string() }, async ({ dir }) => { try { const safePath = validatePath(dir); const files = fs.readdirSync(safePath); // Filter out sensitive files const filteredFiles = files.filter(file => !file.startsWith('.env') && !file.includes('secret') && !file.includes('key') && !file.includes('password') ); return { content: [{ type: 'text', text: JSON.stringify(filteredFiles, null, 2) }] }; } catch (err: any) { return { content: [{ type: 'text', text: `Directory read error: ${err.message}` }] }; } } );
- local-mcp-server.ts:127-142 (handler)Handler function that validates the directory path, reads files using fs.readdirSync, filters sensitive files, and returns JSON list.async ({ dir }) => { try { const safePath = validatePath(dir); const files = fs.readdirSync(safePath); // Filter out sensitive files const filteredFiles = files.filter(file => !file.startsWith('.env') && !file.includes('secret') && !file.includes('key') && !file.includes('password') ); return { content: [{ type: 'text', text: JSON.stringify(filteredFiles, null, 2) }] }; } catch (err: any) { return { content: [{ type: 'text', text: `Directory read error: ${err.message}` }] }; } }
- local-mcp-server.ts:126-126 (schema)Input schema defining 'dir' parameter as string using Zod.{ dir: z.string() },
- local-mcp-server.ts:15-21 (helper)Helper function validatePath used to secure directory path against traversal attacks.function validatePath(filePath: string): string { const resolvedPath = path.resolve(WORKSPACE_ROOT, filePath); if (!resolvedPath.startsWith(WORKSPACE_ROOT)) { throw new Error('Path traversal detected - access denied'); } return resolvedPath; }