Skip to main content
Glama

list_directory

Display organized contents of a directory in your notes, including files and subdirectories, by specifying a relative path. Use this tool to navigate and manage your knowledge base efficiently.

Instructions

List the contents of a directory in your notes. Shows all files and directories with clear labels. Specify path relative to your notes directory (e.g., 'Log' or 'Rollups').

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathNoDirectory path relative to notes directory (defaults to root notes directory if not provided)

Implementation Reference

  • The handler function that executes the list_directory tool logic. It reads the directory contents using fs.readdir, formats them with [DIR]/[FILE] prefixes, ensures path security, and returns formatted text or error.
    export async function handleListDirectory(notesPath: string, args: ListDirectoryArgs): Promise<ToolCallResult> { try { // Use provided path or default to NOTES_PATH root const dirPath = args.path ? path.join(notesPath, args.path) : notesPath; // Ensure the path is within allowed directory if (!dirPath.startsWith(notesPath)) { throw new Error("Access denied - path outside notes directory"); } try { const entries = await fs.readdir(dirPath, { withFileTypes: true }); const formatted = entries .map((entry) => `${entry.isDirectory() ? "[DIR]" : "[FILE]"} ${entry.name}`) .join("\n"); const relativePath = path.relative(notesPath, dirPath) || '.'; return { content: [{ type: "text", text: `Contents of ${relativePath}:\n\n${formatted || "No files or directories found."}` }] }; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); throw new Error(`Error reading directory: ${errorMessage}`); } } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); return { content: [{ type: "text", text: `Error listing directory: ${errorMessage}` }], isError: true }; }
  • The tool definition including name, description, and inputSchema for the list_directory tool, used for validation and registration.
    { name: "list_directory", description: "List the contents of a directory in your notes. " + "Shows all files and directories with clear labels. " + "Specify path relative to your notes directory (e.g., 'Log' or 'Rollups').", inputSchema: { type: "object", properties: { path: { type: "string", description: "Directory path relative to notes directory (defaults to root notes directory if not provided)", default: "" } } }, },
  • TypeScript interface defining the input arguments for the list_directory handler.
    interface ListDirectoryArgs { path?: string; }
  • Registration in the main tool dispatcher switch statement, routing list_directory calls to the handleListDirectory function.
    case "list_directory": return await handleListDirectory(notesPath, args);
  • Inclusion of filesystem tools (including list_directory schema) in the main getToolDefinitions() function via spread operator.
    ...filesystemTools

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/mikeysrecipes/mcp-notes'

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