Skip to main content
Glama
p-united
by p-united

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);
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions the constraint '許可されたディレクトリのみ' (only permitted directories), which is useful context about access restrictions. However, it lacks details on output format (e.g., list of filenames, metadata), error handling for invalid paths, or whether it's a read-only operation (implied but not stated). For a tool with no annotation coverage, this leaves significant gaps.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence in Japanese that conveys the core purpose and a key constraint. It's front-loaded with the main action ('一覧表示します') and includes no redundant information. Every part of the sentence adds value, making it appropriately concise for a simple tool.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's low complexity (one parameter, no output schema, no annotations), the description is minimally adequate. It covers the basic purpose and access restriction but lacks details on output format, error cases, or how it differs from siblings. Without annotations or output schema, more behavioral context would improve completeness, but it's not severely lacking for a simple listing tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, with 'dirpath' documented as '一覧表示するディレクトリのパス' (path of the directory to list). The description doesn't add any parameter-specific details beyond what the schema provides, such as path format examples or constraints related to '許可されたディレクトリ' (permitted directories). With high schema coverage, the baseline score of 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: '一覧表示します' (list/display) for '指定されたディレクトリの内容' (contents of a specified directory). It specifies the verb (list) and resource (directory contents), though it doesn't explicitly differentiate from sibling tools like 'get_allowed_paths' or 'read_file'. The mention of '許可されたディレクトリのみ' (only permitted directories) adds useful context but doesn't fully distinguish it from siblings.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage context through '許可されたディレクトリのみ' (only permitted directories), suggesting this tool is for browsing accessible directories rather than arbitrary paths. However, it doesn't explicitly state when to use this versus alternatives like 'get_allowed_paths' (which might list permitted directories themselves) or 'read_file' (for file contents). No explicit exclusions or prerequisites are provided.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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