Skip to main content
Glama
rawr-ai

Filesystem MCP Server

by rawr-ai

list_directory

Retrieve detailed file and directory listings from a specified path, using [FILE] and [DIR] prefixes for clear differentiation. Essential for analyzing directory structures and locating specific files within permitted directories.

Instructions

Get a detailed listing of all files and directories in a specified path. Results clearly distinguish between files and directories with [FILE] and [DIR] prefixes. This tool is essential for understanding directory structure and finding specific files within a directory. Only works within allowed directories.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYes

Implementation Reference

  • The main handler function for list_directory tool. Parses arguments, validates path, reads directory contents using fs.readdir, formats as [DIR]/[FILE] list, and returns as text content.
    export async function handleListDirectory(
      args: unknown,
      allowedDirectories: string[],
      symlinksMap: Map<string, string>,
      noFollowSymlinks: boolean
    ) {
      const parsed = parseArgs(ListDirectoryArgsSchema, args, 'list_directory');
      const validPath = await validatePath(parsed.path, allowedDirectories, symlinksMap, noFollowSymlinks);
      const entries = await fs.readdir(validPath, { withFileTypes: true });
      const formatted = entries
        .map((entry) => `${entry.isDirectory() ? "[DIR]" : "[FILE]"} ${entry.name}`)
        .join("\n");
      return {
        content: [{ type: "text", text: formatted }],
      };
    }
  • Input schema definition for list_directory: requires a 'path' string parameter.
    export const ListDirectoryArgsSchema = Type.Object({
      path: Type.String(),
    });
    export type ListDirectoryArgs = Static<typeof ListDirectoryArgsSchema>;
  • index.ts:208-209 (registration)
    Registers the list_directory tool handler by binding the handleListDirectory function with context parameters in the toolHandlers object.
    list_directory: (a: unknown) =>
      handleListDirectory(a, allowedDirectories, symlinksMap, noFollowSymlinks),
  • index.ts:307-307 (registration)
    Declares the list_directory tool metadata (name and description) in the allTools array, used for conditional registration based on permissions.
    { name: "list_directory", description: "List directory contents" },
  • Maps the ListDirectoryArgsSchema to the 'list_directory' key in the central toolSchemas export, making it available for registration.
    list_directory: ListDirectoryArgsSchema,

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.0

TDQS

A4/5.0
Behavior3/5

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

With no annotations provided, the description carries the full burden. It adds useful behavioral details: results are prefixed with [FILE] and [DIR], and the tool is restricted to allowed directories. However, it omits other potentially relevant behaviors like recursion, hidden files, or error handling for invalid paths, so transparency is moderate.

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 concise (4 sentences) and each sentence earns its place: purpose, output format, usage context, and a critical constraint. There is no fluff or redundant information, and it is well-structured with front-loaded purpose.

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

Completeness4/5

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

For a simple tool with one parameter and no output schema, the description covers the main aspects: what it does, what results look like, and a usage constraint. It is mostly complete, though it could mention whether the listing is recursive or only immediate children, but given the tool's simplicity, it is sufficiently complete.

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 schema description coverage is 0% with only a single 'path' parameter. The description compensates somewhat by implying the path should be a directory ('...in a specified path') and adding the constraint about allowed directories. However, it does not clarify whether the path must be absolute, relative, or what happens for nonexistent paths, so the compensation is partial.

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

Purpose5/5

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

The description clearly states the tool's function: 'Get a detailed listing of all files and directories in a specified path.' This is a specific verb+resource that uniquely identifies the tool as a directory listing operation, distinguishing it from siblings like read_file (content) or search_files.

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

Usage Guidelines4/5

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

The description provides context on when to use the tool: 'essential for understanding directory structure and finding specific files within a directory.' It also notes the constraint 'Only works within allowed directories,' giving clear usage boundaries. It does not explicitly name alternatives, but the purpose is clear enough for an agent to choose it appropriately.

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