list_folder
List all notes and subfolders within a specified folder in your Obsidian vault. Use this tool to organize and navigate your vault structure by viewing contents at any directory level.
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 core logic for the 'list_folder' tool. It reads the directory at the given path, lists .md notes and subfolders, and recursively lists subfolders if specified, returning a JSON object with notes and folders arrays.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:208-227 (registration)The tool definition object in the 'tools' array used for registration. Includes the name, description, and input schema, returned by ListToolsRequest.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 in the main CallToolRequest handler that dispatches calls to the 'list_folder' tool to its handler function.case "list_folder": result = await handleListFolder( args as { path?: string; recursive?: boolean } ); break;
- src/index.ts:211-226 (schema)The input schema defining the parameters for the 'list_folder' tool: optional path (string) and recursive (boolean).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: [], },