Skip to main content
Glama

list_directory

Lists contents of a specified directory within secure, permitted paths to view files and folders.

Instructions

指定されたディレクトリの内容を一覧表示します(許可されたディレクトリのみ)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dirpathYes一覧表示するディレクトリのパス

Implementation Reference

  • 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}`); } }
  • 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);

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/p-united/mcpSample'

If you have feedback or need assistance with the MCP directory API, please join our Discord server