Skip to main content
Glama

listFiles

List files and directories in a specified path to view folder contents and manage file structures within Claude Code MCP server.

Instructions

Lists files and directories in a given path

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesThe absolute path to the directory to list

Implementation Reference

  • MCP tool handler for listFiles that invokes the utility function and formats the response as JSON.
    async ({ path }) => {
      try {
        const files = await listFiles(path);
        return {
          content: [{ type: "text", text: JSON.stringify(files, null, 2) }]
        };
      } catch (error) {
        return {
          content: [{ 
            type: "text", 
            text: error instanceof Error ? error.message : String(error)
          }],
          isError: true
        };
      }
    }
  • Zod input schema defining the 'path' parameter for the listFiles tool.
    {
      path: z.string().describe("The absolute path to the directory to list")
    },
  • Registration of the listFiles MCP tool using server.tool().
    server.tool(
      "listFiles",
      "Lists files and directories in a given path",
      {
        path: z.string().describe("The absolute path to the directory to list")
      },
      async ({ path }) => {
        try {
          const files = await listFiles(path);
          return {
            content: [{ type: "text", text: JSON.stringify(files, null, 2) }]
          };
        } catch (error) {
          return {
            content: [{ 
              type: "text", 
              text: error instanceof Error ? error.message : String(error)
            }],
            isError: true
          };
        }
      }
    );
  • Helper utility function that lists files in a directory with details using Node.js fs module.
    export async function listFiles(dirPath: string): Promise<any[]> {
      try {
        const files = await fs.readdir(dirPath);
        const fileDetails = await Promise.all(
          files.map(async (file) => {
            const filePath = path.join(dirPath, file);
            const stats = await fs.stat(filePath);
            return {
              name: file,
              path: filePath,
              isDirectory: stats.isDirectory(),
              size: stats.size,
              modified: stats.mtime.toISOString()
            };
          })
        );
        
        return fileDetails;
      } catch (error) {
        throw error;
      }
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the basic action but doesn't describe key behaviors like whether it returns recursive listings, handles symbolic links, includes hidden files, or what happens if the path is invalid. This leaves significant gaps for an agent to understand how the tool behaves beyond the simple listing.

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, clear sentence that directly states the tool's function without any unnecessary words. It's front-loaded with the core action and resource, making it highly efficient and easy to parse.

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 lack of annotations and output schema, the description is incomplete for a tool that performs file system operations. It doesn't address important contextual aspects like error handling, output format, or behavioral details (e.g., recursion, hidden files), which are crucial for an agent to use this tool effectively in real scenarios.

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 the 'path' parameter clearly documented as 'The absolute path to the directory to list'. The description adds no additional semantic information beyond what the schema provides, so it meets the baseline for adequate but unenhanced parameter documentation.

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 action ('Lists') and the target ('files and directories in a given path'), making the purpose immediately understandable. However, it doesn't distinguish this tool from potential siblings like 'searchGlob' or 'grep' that might also involve file operations, so it doesn't achieve full differentiation.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives like 'searchGlob' or 'grep'. It lacks any context about prerequisites, such as whether the path must exist or be accessible, or when other tools might be more appropriate for similar tasks.

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/auchenberg/claude-code-mcp'

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