Skip to main content
Glama
bazylhorsey
by bazylhorsey

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
NameRequiredDescriptionDefault
vaultYesVault 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'],
      },
    },
  • Input schema for list_folders tool: requires 'vault' string parameter.
    inputSchema: {
      type: 'object',
      properties: {
        vault: { type: 'string', description: 'Vault name' },
      },
      required: ['vault'],
    },
  • 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) }],
      };
    }
  • 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() };
      }
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/bazylhorsey/obsidian-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server