list_directory
Get a detailed listing of files and directories in a specified path, including names, types, sizes, and modification times to understand directory structure and locate files.
Instructions
Get a detailed listing of all files and directories in a specified path. Results include names, types (file/directory), sizes, and modification times. Useful for understanding directory structure and finding files.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | The path of the directory to list |
Implementation Reference
- src/index.ts:355-380 (handler)The handler for the list_directory tool. It reads the directory using fs.readdir with file types, then for each entry gets stats and constructs a list of items with name, type, size, and modification time, returning them as JSON text.case "list_directory": { const dirPath = args.path as string; const entries = await fs.readdir(dirPath, { withFileTypes: true }); const items = await Promise.all( entries.map(async (entry) => { const fullPath = path.join(dirPath, entry.name); const stats = await fs.stat(fullPath); return { name: entry.name, type: entry.isDirectory() ? "directory" : "file", size: stats.size, modified: stats.mtime.toISOString(), }; }) ); return { content: [ { type: "text", text: JSON.stringify(items, null, 2), }, ], }; }
- src/index.ts:101-110 (schema)The input schema definition for the list_directory tool, specifying an object with a required 'path' string property.inputSchema: { type: "object", properties: { path: { type: "string", description: "The path of the directory to list", }, }, required: ["path"], },
- src/index.ts:98-111 (registration)The registration of the list_directory tool in the TOOLS array, which is returned in response to ListTools requests.{ name: "list_directory", description: "Get a detailed listing of all files and directories in a specified path. Results include names, types (file/directory), sizes, and modification times. Useful for understanding directory structure and finding files.", inputSchema: { type: "object", properties: { path: { type: "string", description: "The path of the directory to list", }, }, required: ["path"], }, },