list_notes
Retrieve notes from your Obsidian vault or specific folder to organize and access your knowledge base efficiently.
Instructions
List all notes in the vault or a specific folder
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| folder | No | Folder to list notes from (omit for entire vault) | |
| limit | No | Maximum number of notes to return |
Implementation Reference
- src/tools/read.ts:125-161 (handler)The MCP tool "list_notes" is registered here, which calls the `listNotes` library function and formats the response.
server.registerTool( "list_notes", { description: "List all notes in the vault or a specific folder", inputSchema: { folder: z .string() .optional() .describe("Folder to list notes from (omit for entire vault)"), limit: z .number() .optional() .default(50) .describe("Maximum number of notes to return"), }, }, async ({ folder, limit }) => { try { const notes = await listNotes(vaultPath, folder); const limited = notes.slice(0, limit); const totalCount = notes.length; const lines: string[] = [ `Found ${totalCount} note(s)${folder ? ` in "${folder}"` : ""}${totalCount > limit ? ` (showing first ${limit})` : ""}:`, "", ...limited, ]; return { content: [{ type: "text" as const, text: lines.join("\n") }], }; } catch (err) { console.error("list_notes error:", err); return errorResult(`Error listing notes: ${err instanceof Error ? err.message : String(err)}`); } }, ); - src/lib/vault.ts:26-58 (handler)The actual implementation of the note listing logic, which reads the vault directory, filters for Markdown files, and sorts them.
export async function listNotes( vaultPath: string, folder?: string, ): Promise<string[]> { const baseDir = folder ? resolveVaultPath(vaultPath, folder) : path.resolve(vaultPath); let entries: string[]; try { entries = await fs.readdir(baseDir, { recursive: true }) as unknown as string[]; } catch (err) { if ((err as NodeJS.ErrnoException).code === "ENOENT") { return []; } throw err; } const notes: string[] = []; for (const entry of entries) { const normalized = entry.replace(/\\/g, "/"); if (!normalized.endsWith(".md")) continue; const relativeFromVault = folder ? `${folder}/${normalized}`.replace(/\\/g, "/") : normalized; if (isExcluded(relativeFromVault)) continue; notes.push(relativeFromVault); } return notes.sort(); }