list_directory
Browse and view contents of directories by listing files and folders with clear type indicators for easy navigation.
Instructions
List directory contents with [FILE] or [DIR] prefixes
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Path to the directory to list |
Implementation Reference
- src/index.ts:317-339 (handler)The handler for the 'list_directory' tool. It validates the path, reads the directory contents, stats each entry to determine if it's a file or directory, formats with [DIR] or [FILE] prefixes, and returns the list as text.case 'list_directory': { const { path: dirPath } = request.params.arguments as { path: string }; validatePath(dirPath); const entries = await fs.readdir(dirPath); const formattedEntries = await Promise.all( entries.map(async (entry) => { const entryPath = path.join(dirPath, entry); const stats = await fs.stat(entryPath); const prefix = stats.isDirectory() ? '[DIR]' : '[FILE]'; return `${prefix} ${entry}`; }) ); return { content: [ { type: 'text', text: formattedEntries.join('\n'), }, ], }; }
- src/index.ts:158-171 (registration)Registration of the 'list_directory' tool in the list of tools provided by ListToolsRequestSchema, including its name, description, and input schema.{ name: 'list_directory', description: 'List directory contents with [FILE] or [DIR] prefixes', inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'Path to the directory to list', }, }, required: ['path'], }, },
- src/index.ts:161-170 (schema)The input schema definition for the 'list_directory' tool, specifying the required 'path' parameter.inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'Path to the directory to list', }, }, required: ['path'], },