list_directory
Retrieve 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 function that executes the 'list_directory' tool. It reads the directory contents using fs.readdir, gets stats for each entry, and returns a JSON-formatted list of items with name, type, size, and modification time.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:98-111 (schema)The tool definition including name, description, and input schema for 'list_directory', which specifies the required 'path' parameter.{ 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"], }, },
- src/index.ts:261-263 (registration)The handler for ListToolsRequestSchema that returns the TOOLS array, which includes the 'list_directory' tool registration.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: TOOLS }; });