Skip to main content
Glama
rawr-ai

Filesystem MCP Server

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,

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/rawr-ai/mcp-filesystem'

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