list_directory
Retrieve and display the contents of a specified directory path to view files and folders within Windows systems.
Instructions
列出目录内容
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | 目录路径 |
Implementation Reference
- src/tools/filesystem.js:156-168 (handler)The handler function that implements the list_directory tool logic. It reads the directory using fs.readdir with file types, maps files to objects with name, type (directory/file), and full path, and returns success with items or error.async listDirectory(dirPath) { try { const files = await fs.readdir(dirPath, { withFileTypes: true }); const items = files.map(file => ({ name: file.name, type: file.isDirectory() ? 'directory' : 'file', path: path.join(dirPath, file.name), })); return { success: true, items, path: dirPath }; } catch (error) { return { success: false, error: error.message }; } }
- src/tools/filesystem.js:37-47 (schema)The schema definition for the list_directory tool, including name, description, and inputSchema requiring a 'path' string.{ name: 'list_directory', description: '列出目录内容', inputSchema: { type: 'object', properties: { path: { type: 'string', description: '目录路径' }, }, required: ['path'], }, },
- src/tools/filesystem.js:121-122 (registration)Registration/dispatch in the executeTool method switch statement, which calls the listDirectory handler for the 'list_directory' tool.case 'list_directory': return await this.listDirectory(args.path);
- src/tools/filesystem.js:110-111 (registration)Tool name listed in the canHandle method's tools array for checking if the class can handle 'list_directory'.const tools = ['read_file', 'write_file', 'list_directory', 'create_directory', 'delete_file', 'copy_file', 'move_file', 'search_files'];