Skip to main content
Glama
idapixl

MCP Starter Kit

list_directory

Display files and directories within a workspace. Specify a path to view contents, enable recursive listing to see nested items, and control depth and entry limits for organized browsing.

Instructions

List files and directories. Paths are relative to the configured root (/app/workspace). Set recursive=true to list all nested files.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathNoDirectory path relative to the configured root.
recursiveNoWhether to list files recursively
max_depthNoMaximum directory depth for recursive listing (default: 3, max: 10)
max_entriesNoMaximum total entries to return (default: 10000)

Implementation Reference

  • The core handler function for 'list_directory' which reads a directory and formats the output into a list of file entries.
    export async function listDirectory(
      input: ListDirectoryInput
    ): Promise<ToolResult<ListDirectoryResult>> {
      const userPath = input.path ?? ".";
      const result = safePath(userPath);
      if ("error" in result) {
        return { ok: false, error: result.error, code: "PATH_TRAVERSAL" };
      }
    
      const { resolved } = result;
    
      // M2: Apply depth/entry caps with defaults from schema
      const maxDepth = input.max_depth ?? 3;
      const maxEntries = input.max_entries ?? 10000;
    
      logger.debug("Listing directory", {
        path: resolved,
        recursive: input.recursive,
        maxDepth,
        maxEntries,
      });
    
      const counter = { count: 0, truncated: false };
    
      let entries: FileEntry[];
      try {
        entries = await collectEntries(
          resolved,
          userPath,
          input.recursive ?? false,
          0,
          maxDepth,
          maxEntries,
          counter
        );
      } catch (err) {
        const code = (err as NodeJS.ErrnoException).code;
        if (code === "ENOENT") {
          return {
            ok: false,
            error: `Directory not found: ${userPath}`,
            code: "NOT_FOUND",
          };
        }
        if (code === "ENOTDIR") {
          return {
            ok: false,
            error: `Path is not a directory: ${userPath}`,
            code: "NOT_A_DIRECTORY",
          };
        }
        return {
          ok: false,
          error: `Failed to list directory: ${(err as Error).message}`,
          code: "LIST_ERROR",
        };
      }
    
      return {
        ok: true,
        data: {
          path: userPath,
          entries,
          total: entries.length,
          ...(counter.truncated ? { truncated: true } : {}),
        } as ListDirectoryResult,
      };
    }
  • The Zod schema definition for 'list_directory' input parameters and result structures.
    export const ListDirectorySchema = z.object({
      path: z
        .string()
        .optional()
        .default(".")
        .describe("Directory path relative to the configured root"),
      recursive: z
        .boolean()
        .optional()
        .default(false)
        .describe("Whether to list files recursively"),
      max_depth: z
        .number()
        .int()
        .min(1)
        .max(10)
        .optional()
        .default(3)
        .describe("Maximum directory depth for recursive listing (default: 3, max: 10)"),
      max_entries: z
        .number()
        .int()
        .min(1)
        .optional()
        .default(10000)
        .describe("Maximum total entries to return (default: 10000)"),
    });
  • src/index.ts:94-100 (registration)
    Registration of the 'list_directory' tool with the MCP server using the handler and schema.
    server.tool(
      "list_directory",
      `List files and directories. Paths are relative to the configured root (${config.fileReaderRoot}). ` +
        "Set recursive=true to list all nested files.",
      ListDirectorySchema.shape,
      async (args) => {
        const result = await listDirectory(args);
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 root path configuration and recursive behavior, but it doesn't cover important aspects like whether this is a read-only operation, potential rate limits, error conditions (e.g., invalid paths), or what the output format looks like (since there's no output schema). For a tool with no annotations, this leaves significant gaps in understanding its behavior.

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 very concise and front-loaded: it states the core purpose in the first sentence, followed by key contextual details. Both sentences earn their place by providing essential information without redundancy. It's appropriately sized for the tool's complexity.

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

Completeness2/5

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

Given the tool has no annotations and no output schema, the description is incomplete. It covers basic purpose and some parameter hints but lacks crucial behavioral details (e.g., safety, errors, output format) and doesn't fully compensate for the missing structured data. For a 4-parameter tool with no annotations or output schema, this description should do more to guide the agent.

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?

Schema description coverage is 100%, so the schema already documents all parameters thoroughly. The description adds minimal value beyond the schema: it mentions the root path context and hints at the 'recursive' parameter's effect. However, it doesn't provide additional semantic context for parameters like 'max_depth' or 'max_entries' that aren't covered in the description. Baseline 3 is appropriate when the schema does most of the work.

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 files and directories.' It specifies the verb ('List') and resource ('files and directories'), making it easy to understand what the tool does. However, it doesn't explicitly differentiate from sibling tools like 'fetch_url' or 'read_file', though the distinction is somewhat implied by the domain.

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 provides some usage context: 'Paths are relative to the configured root (/app/workspace). Set recursive=true to list all nested files.' This gives basic guidance on when to use certain parameters, but it doesn't explicitly state when to use this tool versus alternatives like 'fetch_url' or 'read_file', nor does it mention any exclusions or prerequisites.

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/idapixl/mcp-starter-kit'

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