list_directory
Lists contents of a specified directory within secure, permitted paths to view files and folders.
Instructions
指定されたディレクトリの内容を一覧表示します(許可されたディレクトリのみ)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| dirpath | Yes | 一覧表示するディレクトリのパス |
Implementation Reference
- src/index.ts:374-400 (handler)The main handler function for the 'list_directory' tool. It validates the input directory path using PathValidator, lists the directory contents with fs.readdir (including file types), formats the output with directory/file icons, and returns a formatted CallToolResult.private async listDirectory(dirpath: string): Promise<CallToolResult> { try { const pathValidation = this.pathValidator.validatePath(dirpath); if (!pathValidation.isValid) { throw new Error(pathValidation.error); } console.error(`Listing directory: ${pathValidation.normalizedPath}`); const items = await fs.readdir(pathValidation.normalizedPath, { withFileTypes: true }); const fileList = items.map(item => { const type = item.isDirectory() ? "📁" : "📄"; return `${type} ${item.name}`; }); return { content: [ { type: "text", text: `ディレクトリ "${pathValidation.normalizedPath}" の内容:\n\n${fileList.join("\n")}`, }, ], isError: false, }; } catch (error) { throw new Error(`ディレクトリの一覧取得に失敗: ${error}`); } }
- src/index.ts:150-159 (schema)The input schema definition for the 'list_directory' tool, specifying an object with a required 'dirpath' string property.inputSchema: { type: "object", properties: { dirpath: { type: "string", description: "一覧表示するディレクトリのパス", }, }, required: ["dirpath"], },
- src/index.ts:147-160 (registration)Registration of the 'list_directory' tool in the TOOLS array, which is returned by the ListToolsRequestSchema handler. Includes name, description, and input schema.{ name: "list_directory", description: "指定されたディレクトリの内容を一覧表示します(許可されたディレクトリのみ)", inputSchema: { type: "object", properties: { dirpath: { type: "string", description: "一覧表示するディレクトリのパス", }, }, required: ["dirpath"], }, },
- src/index.ts:284-285 (registration)Dispatch case in the CallToolRequestSchema handler that routes 'list_directory' calls to the listDirectory method.case "list_directory": return await this.listDirectory(args.dirpath as string);