Skip to main content
Glama

file_list

List files and directories at a specified path, with options for recursive traversal and extension filtering to explore project structures or audit directory contents.

Instructions

List files and directories at a given path.

Features:

  • List contents of any directory

  • Recursive listing with configurable depth

  • Filter results by file extension

  • Returns file sizes and types

Use cases:

  • Exploring project structures

  • Finding specific file types

  • Auditing directory contents

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dirPathYesPath to the directory to list (defaults to current directory).
recursiveNoWhether to list subdirectories recursively.
extensionNoOptional file extension filter (e.g., '.ts', '.json').

Implementation Reference

  • The registerFileListTool function registers and implements the `file_list` MCP tool. It reads a directory, supports recursive listing with depth control, filters by extension, skips hidden files and node_modules, and returns structured JSON with file/directory metadata.
    export function registerFileListTool(server: McpServer): void {
      server.tool(
        "file_list",
        `List files and directories at a given path.
    
    Features:
      - List contents of any directory
      - Recursive listing with configurable depth
      - Filter results by file extension
      - Returns file sizes and types
    
    Use cases:
      - Exploring project structures
      - Finding specific file types
      - Auditing directory contents`,
        {
          dirPath: z
            .string()
            .describe("Path to the directory to list (defaults to current directory)."),
          recursive: z
            .boolean()
            .default(false)
            .describe("Whether to list subdirectories recursively."),
          extension: z
            .string()
            .optional()
            .describe("Optional file extension filter (e.g., '.ts', '.json')."),
        },
        async ({ dirPath, recursive, extension }) => {
          try {
            const resolvedPath = path.resolve(dirPath || ".");
            const entries: Array<{
              name: string;
              path: string;
              type: "file" | "directory";
              size?: number;
            }> = [];
    
            async function walk(currentPath: string, depth: number): Promise<void> {
              const MAX_DEPTH = 10;
              if (depth > MAX_DEPTH) return;
    
              const items = await fs.readdir(currentPath, {
                withFileTypes: true,
              });
    
              for (const item of items) {
                // Skip hidden files and node_modules
                if (item.name.startsWith(".") || item.name === "node_modules") {
                  continue;
                }
    
                const fullPath = path.join(currentPath, item.name);
                const entry: (typeof entries)[number] = {
                  name: item.name,
                  path: fullPath,
                  type: item.isDirectory() ? "directory" : "file",
                };
    
                if (item.isFile()) {
                  if (extension && !item.name.endsWith(extension)) continue;
                  const stat = await fs.stat(fullPath);
                  entry.size = stat.size;
                }
    
                entries.push(entry);
    
                if (item.isDirectory() && recursive) {
                  await walk(fullPath, depth + 1);
                }
              }
            }
    
            await walk(resolvedPath, 0);
    
            return {
              content: [
                {
                  type: "text" as const,
                  text: JSON.stringify(
                    {
                      path: resolvedPath,
                      totalEntries: entries.length,
                      files: entries.filter((e) => e.type === "file").length,
                      directories: entries.filter((e) => e.type === "directory").length,
                      entries,
                    },
                    null,
                    2
                  ),
                },
              ],
            };
          } catch (err: any) {
            return {
              content: [
                {
                  type: "text" as const,
                  text: `File List Error: ${err.message}`,
                },
              ],
              isError: true,
            };
          }
        }
      );
    }
  • Zod schema defining the input parameters: dirPath (string, required), recursive (boolean, default false), extension (optional string filter).
    {
      dirPath: z
        .string()
        .describe("Path to the directory to list (defaults to current directory)."),
      recursive: z
        .boolean()
        .default(false)
        .describe("Whether to list subdirectories recursively."),
      extension: z
        .string()
        .optional()
        .describe("Optional file extension filter (e.g., '.ts', '.json')."),
    },
  • src/index.ts:49-49 (registration)
    The tool is registered on the MCP server in the McpToolkitServer.registerTools() method via registerFileListTool(this.server).
    registerFileListTool(this.server);
  • Shared helper types (ToolResult) and utility functions (textResult, errorResult, jsonResult) used across all tool handlers.
    /**
     * Shared utility types and helpers for MCP Toolkit Server tools.
     */
    
    /** Standard success response shape returned by tool handlers. */
    export interface ToolResult {
      content: Array<{ type: "text"; text: string }>;
      isError?: boolean;
    }
    
    /** Helper to build a success text response. */
    export function textResult(text: string): ToolResult {
      return { content: [{ type: "text" as const, text }] };
    }
    
    /** Helper to build an error text response. */
    export function errorResult(message: string): ToolResult {
      return {
        content: [{ type: "text" as const, text: message }],
        isError: true,
      };
    }
    
    /** Helper to JSON-stringify and wrap in a text result. */
    export function jsonResult(data: unknown, pretty = true): ToolResult {
      return {
        content: [
          {
            type: "text" as const,
            text: JSON.stringify(data, null, pretty ? 2 : 0),
          },
        ],
      };
    }
Behavior3/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. It mentions returning file sizes and types, but does not disclose behavior for edge cases (e.g., permission errors, large directories, missing paths) or whether results are sorted.

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 and well-structured with distinct sections for features and use cases. Every sentence adds value, and the bullet points make it scannable. No unnecessary details.

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?

Given the lack of an output schema, the description covers what the tool does and returns (sizes and types), but does not specify the exact return format (e.g., array of objects). It is complete enough for a simple listing tool but could be more detailed.

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, so the schema already documents parameters clearly. The description repeats parameter names in features but adds little new semantic meaning beyond the schema descriptions.

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 verb (List) and resource (files and directories at a given path). It distinguishes itself from siblings like file_read and file_write by focusing on directory listing, and includes specific features like recursive depth and extension filtering.

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 explicit use cases (exploring, finding, auditing) which imply when to use the tool. However, it does not mention when not to use it or suggest alternatives, which would strengthen guidance.

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/vyshnavi-nandyala/mcp-toolkit-server'

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