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
| Name | Required | Description | Default |
|---|---|---|---|
| path | No | Directory path relative to notes directory (defaults to root notes directory if not provided) |
Implementation Reference
- src/tools/filesystem.ts:289-323 (handler)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 }; }
- src/tools/filesystem.ts:101-116 (schema)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: "" } } }, },
- src/tools/filesystem.ts:35-37 (schema)TypeScript interface defining the input arguments for the list_directory handler.interface ListDirectoryArgs { path?: string; }
- src/tools/index.ts:357-358 (registration)Registration in the main tool dispatcher switch statement, routing list_directory calls to the handleListDirectory function.case "list_directory": return await handleListDirectory(notesPath, args);
- src/tools/index.ts:204-204 (registration)Inclusion of filesystem tools (including list_directory schema) in the main getToolDefinitions() function via spread operator....filesystemTools