list_folder
List notes and subfolders within an Obsidian vault folder to organize and navigate your knowledge base content.
Instructions
List all notes and subfolders in a folder
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | No | Folder path relative to vault root. Use empty string for vault root | |
| recursive | No | Whether to list recursively. Default: false |
Implementation Reference
- src/index.ts:606-644 (handler)The handler function that implements the list_folder tool logic. It reads the directory at the given path, lists .md files as notes and subdirectories as folders, and supports recursive listing by calling itself.async function handleListFolder(args: { path?: string; recursive?: boolean; }): Promise<string> { const folderPath = path.join(VAULT_PATH, args.path || ""); const recursive = args.recursive ?? false; if (!(await fileExists(folderPath))) { throw new Error(`Folder not found at ${args.path}`); } const entries = await fs.readdir(folderPath, { withFileTypes: true }); const result: { notes: string[]; folders: string[] } = { notes: [], folders: [], }; for (const entry of entries) { if (entry.name.startsWith(".")) continue; if (entry.isDirectory()) { result.folders.push(entry.name); if (recursive) { const subResult = await handleListFolder({ path: path.join(args.path || "", entry.name), recursive: true, }); const parsed = JSON.parse(subResult); result.notes.push( ...parsed.notes.map((n: string) => path.join(entry.name, n)) ); } } else if (entry.isFile() && entry.name.endsWith(".md")) { result.notes.push(entry.name); } } return JSON.stringify(result, null, 2); }
- src/index.ts:207-227 (schema)The tool definition including name, description, and input schema for validation.{ name: "list_folder", description: "List all notes and subfolders in a folder", inputSchema: { type: "object", properties: { path: { type: "string", description: "Folder path relative to vault root. Use empty string for vault root", default: "", }, recursive: { type: "boolean", description: "Whether to list recursively. Default: false", default: false, }, }, required: [], }, },
- src/index.ts:906-910 (registration)The switch case that registers and dispatches the list_folder tool call to its handler.case "list_folder": result = await handleListFolder( args as { path?: string; recursive?: boolean } ); break;
- src/index.ts:853-855 (registration)Handler for listing available tools, which includes the list_folder tool definition.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools, }));
- src/index.ts:356-362 (helper)Helper function used by handleListFolder to check if the folder exists.async function fileExists(filePath: string): Promise<boolean> { try { await fs.access(filePath); return true; } catch { return false; }