list_directory
Browse and view the contents of directories in your notes system to locate files and folders. Specify a relative path to explore specific note collections.
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 implements the list_directory tool logic: reads the directory using fs.readdir, formats entries with [DIR]/[FILE] prefixes, ensures path security, and returns formatted content.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)Tool definition including name, description, and input schema (optional 'path' parameter) for the list_directory tool, exported via getFilesystemToolDefinitions().{ 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 handleToolCall switch statement, dispatching list_directory calls to the handler.case "list_directory": return await handleListDirectory(notesPath, args);
- src/tools/index.ts:204-204 (registration)Includes filesystem tools (containing list_directory definition) in the main getToolDefinitions() array for tool registration....filesystemTools