list_directory
Retrieve contents of a specified directory by providing its path. Lists files and directories with [FILE] or [DIR] prefixes for clear identification.
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 main handler logic for the 'list_directory' tool. It extracts the directory path from arguments, validates access, reads directory entries, asynchronously stats each entry to determine if it's a file or directory, formats each with [DIR] or [FILE] prefix, joins them with newlines, and returns as text content.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 ListTools response, including its name, description, and input schema definition.{ 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)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'], },