Skip to main content
Glama
bazylhorsey
by bazylhorsey

get_vault_stats

Retrieve statistics about an Obsidian vault to analyze content metrics and vault structure for knowledge management insights.

Instructions

Get statistics about a vault

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
vaultYesVault name

Implementation Reference

  • src/index.ts:133-143 (registration)
    Tool registration in listTools handler, including name, description, and input schema for get_vault_stats
    {
      name: 'get_vault_stats',
      description: 'Get statistics about a vault',
      inputSchema: {
        type: 'object',
        properties: {
          vault: { type: 'string', description: 'Vault name' },
        },
        required: ['vault'],
      },
    },
  • Dispatch handler in callToolRequestSchema that retrieves the connector for the vault and calls connector.getStats()
    case 'get_vault_stats': {
      const connector = this.connectors.get(args?.vault as string);
      if (!connector) {
        throw new Error(`Vault "${args?.vault}" not found`);
      }
      const result = await connector.getStats();
      return {
        content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
      };
    }
  • Core implementation of getStats() in LocalConnector: computes vault statistics by iterating over all notes, counting words, links, tags, and tracking last modified date
    async getStats(): Promise<VaultOperationResult<VaultStats>> {
      try {
        const allNotes = await this.getAllNotes();
        if (!allNotes.success || !allNotes.data) {
          return { success: false, error: 'Failed to get notes for stats' };
        }
    
        const notes = allNotes.data;
        const tags = new Map<string, number>();
        let totalWords = 0;
        let totalLinks = 0;
        let lastModified: Date | undefined;
    
        for (const note of notes) {
          totalWords += countWords(note.content);
    
          if (note.links) {
            totalLinks += note.links.length;
          }
    
          if (note.tags) {
            for (const tag of note.tags) {
              tags.set(tag, (tags.get(tag) || 0) + 1);
            }
          }
    
          if (note.modifiedAt && (!lastModified || note.modifiedAt > lastModified)) {
            lastModified = note.modifiedAt;
          }
        }
    
        const stats: VaultStats = {
          noteCount: notes.length,
          totalWords,
          totalLinks,
          tags,
          lastModified
        };
    
        return { success: true, data: stats };
      } catch (error) {
        return {
          success: false,
          error: `Failed to get stats: ${error instanceof Error ? error.message : String(error)}`
        };
      }
    }
  • Implementation of getStats() in RemoteConnector: prefers server-side /stats endpoint, falls back to client-side calculation similar to LocalConnector (no lastModified)
    async getStats(): Promise<VaultOperationResult<VaultStats>> {
      try {
        // Try server-side stats first
        try {
          const response = await this.client.get('/stats');
          if (response.data) {
            return { success: true, data: response.data };
          }
        } catch {
          // Fall back to client-side calculation
        }
    
        // Client-side stats calculation
        const allNotes = await this.getAllNotes();
        if (!allNotes.success || !allNotes.data) {
          return { success: false, error: 'Failed to get notes for stats' };
        }
    
        const notes = allNotes.data;
        const tags = new Map<string, number>();
        let totalWords = 0;
        let totalLinks = 0;
    
        for (const note of notes) {
          totalWords += countWords(note.content);
    
          if (note.links) {
            totalLinks += note.links.length;
          }
    
          if (note.tags) {
            for (const tag of note.tags) {
              tags.set(tag, (tags.get(tag) || 0) + 1);
            }
          }
        }
    
        const stats: VaultStats = {
          noteCount: notes.length,
          totalWords,
          totalLinks,
          tags
        };
    
        return { success: true, data: stats };
      } catch (error) {
        return {
          success: false,
          error: `Failed to get stats: ${error instanceof Error ? error.message : String(error)}`
        };
      }
    }

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