Skip to main content
Glama

list_directory

Retrieve a detailed listing of files and directories in a specified path with [FILE] and [DIR] prefixes for easy identification. Works within allowed directories for clear organization.

Instructions

Get a detailed listing of all files and directories in a specified path. Results distinguish between files and directories with [FILE] and [DIR] prefixes. Only works within allowed directories.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYes

Implementation Reference

  • Handler for the list_directory tool: parses input arguments using the schema, calls the listDirectory helper function with the path, and returns the directory entries as a formatted text response.
    case "list_directory": { const parsed = ListDirectoryArgsSchema.parse(args); const entries = await listDirectory(parsed.path); return { content: [{ type: "text", text: entries.join('\n') }], }; }
  • Exact implementation of the listDirectory function: validates the directory path for security, reads the directory contents asynchronously using fs.readdir with file types, and maps entries to strings prefixed with [DIR] or [FILE].
    export async function listDirectory(dirPath: string): Promise<string[]> { const validPath = await validatePath(dirPath); const entries = await fs.readdir(validPath, { withFileTypes: true }); return entries.map((entry) => `${entry.isDirectory() ? "[DIR]" : "[FILE]"} ${entry.name}`); }
  • src/server.ts:156-162 (registration)
    Tool registration in the ListToolsRequestHandler: defines the tool name, detailed description, and references the input schema.
    { name: "list_directory", description: "Get a detailed listing of all files and directories in a specified path. " + "Results distinguish between files and directories with [FILE] and [DIR] prefixes. " + "Only works within allowed directories.", inputSchema: zodToJsonSchema(ListDirectoryArgsSchema),
  • Zod input schema for the list_directory tool, requiring a single 'path' string parameter.
    export const ListDirectoryArgsSchema = z.object({ path: z.string(), });

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/MrGNSS/ClaudeDesktopCommander'

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