list_folders
Retrieve all folder names within an Obsidian vault to organize and navigate your knowledge base structure effectively.
Instructions
List all folders in a vault
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| vault | Yes | Vault name |
Implementation Reference
- src/index.ts:155-165 (registration)Registers the 'list_folders' MCP tool with description and input schema requiring a 'vault' name.{ name: 'list_folders', description: 'List all folders in a vault', inputSchema: { type: 'object', properties: { vault: { type: 'string', description: 'Vault name' }, }, required: ['vault'], }, },
- src/index.ts:158-164 (schema)Input schema for list_folders tool: requires 'vault' string parameter.inputSchema: { type: 'object', properties: { vault: { type: 'string', description: 'Vault name' }, }, required: ['vault'], },
- src/index.ts:565-574 (handler)MCP tool dispatch handler: retrieves vault connector and calls its listFolders() method, returns JSON result.case 'list_folders': { const connector = this.connectors.get(args?.vault as string); if (!connector) { throw new Error(`Vault "${args?.vault}" not found`); } const result = await connector.listFolders(); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }], }; }
- src/connectors/LocalConnector.ts:259-280 (handler)Local vault implementation: extracts unique folder paths from all notes' paths (excluding root), sorts them.async listFolders(): Promise<VaultOperationResult<string[]>> { try { const folders = new Set<string>(); const notes = await this.getAllNotes(); if (notes.success && notes.data) { for (const note of notes.data) { const folder = path.dirname(note.path); if (folder !== '.') { folders.add(folder); } } } return { success: true, data: Array.from(folders).sort() }; } catch (error) { return { success: false, error: `Failed to list folders: ${error instanceof Error ? error.message : String(error)}` }; } }
- Remote vault implementation: prefers API /folders endpoint, falls back to extracting folders from notes' paths.async listFolders(): Promise<VaultOperationResult<string[]>> { try { const response = await this.client.get('/folders'); return { success: true, data: response.data }; } catch (error) { // Fallback to extracting from notes const notes = await this.getAllNotes(); if (!notes.success || !notes.data) { return { success: false, error: 'Failed to list folders' }; } const folders = new Set<string>(); for (const note of notes.data) { const folder = note.path.substring(0, note.path.lastIndexOf('/')); if (folder) { folders.add(folder); } } return { success: true, data: Array.from(folders).sort() }; } }