list_directory
Retrieve and display a list of contents from a specified directory, ensuring access is limited to authorized and secure paths only.
Instructions
指定されたディレクトリの内容を一覧表示します(許可されたディレクトリのみ)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| dirpath | Yes | 一覧表示するディレクトリのパス |
Implementation Reference
- src/index.ts:374-402 (handler)The main handler function that validates the directory path and lists its contents using fs.readdir, formatting directories with 📁 and files with 📄.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}`); } } private async getSystemInfo(): Promise<CallToolResult> {
- src/index.ts:150-159 (schema)The input schema for the list_directory tool, requiring a 'dirpath' string parameter.inputSchema: { type: "object", properties: { dirpath: { type: "string", description: "一覧表示するディレクトリのパス", }, }, required: ["dirpath"], },
- src/index.ts:147-160 (registration)The Tool object definition in the TOOLS array that registers the list_directory tool with its name, description, and schema for the ListTools handler.{ name: "list_directory", description: "指定されたディレクトリの内容を一覧表示します(許可されたディレクトリのみ)", inputSchema: { type: "object", properties: { dirpath: { type: "string", description: "一覧表示するディレクトリのパス", }, }, required: ["dirpath"], }, },
- src/index.ts:284-285 (registration)The switch case in the CallToolRequestSchema handler that routes calls to the listDirectory method.case "list_directory": return await this.listDirectory(args.dirpath as string);