Skip to main content
Glama

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
NameRequiredDescriptionDefault
dirpathYes一覧表示するディレクトリのパス

Implementation Reference

  • 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> {
  • 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);

Other Tools

Related Tools

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