Skip to main content
Glama

listFiles

List files and directories within a specified path using the Claude Code MCP server, enabling efficient file management and organization.

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: invokes the file listing helper and returns formatted JSON response or error.
    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 }; } }
  • Input schema for the listFiles tool: requires 'path' parameter validated by Zod.
    { path: z.string().describe("The absolute path to the directory to list") },
  • Full registration of the listFiles MCP tool on the server, including name, description, schema, and handler.
    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 }; } } );
  • Core helper function that implements file listing logic using Node.js fs module, returning file details including name, path, type, size, and modification time.
    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; } }

Other Tools

Related 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