Skip to main content
Glama

list_directory

Get a detailed listing of files and directories in a specified path, including names, types, sizes, and modification times to understand directory structure and locate files.

Instructions

Get a detailed listing of all files and directories in a specified path. Results include names, types (file/directory), sizes, and modification times. Useful for understanding directory structure and finding files.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesThe path of the directory to list

Implementation Reference

  • The handler for the list_directory tool. It reads the directory using fs.readdir with file types, then for each entry gets stats and constructs a list of items with name, type, size, and modification time, returning them as JSON text.
    case "list_directory": { const dirPath = args.path as string; const entries = await fs.readdir(dirPath, { withFileTypes: true }); const items = await Promise.all( entries.map(async (entry) => { const fullPath = path.join(dirPath, entry.name); const stats = await fs.stat(fullPath); return { name: entry.name, type: entry.isDirectory() ? "directory" : "file", size: stats.size, modified: stats.mtime.toISOString(), }; }) ); return { content: [ { type: "text", text: JSON.stringify(items, null, 2), }, ], }; }
  • The input schema definition for the list_directory tool, specifying an object with a required 'path' string property.
    inputSchema: { type: "object", properties: { path: { type: "string", description: "The path of the directory to list", }, }, required: ["path"], },
  • src/index.ts:98-111 (registration)
    The registration of the list_directory tool in the TOOLS array, which is returned in response to ListTools requests.
    { name: "list_directory", description: "Get a detailed listing of all files and directories in a specified path. Results include names, types (file/directory), sizes, and modification times. Useful for understanding directory structure and finding files.", inputSchema: { type: "object", properties: { path: { type: "string", description: "The path of the directory to list", }, }, required: ["path"], }, },

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/koopatroopa787/first_mcp'

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