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
| Name | Required | Description | Default |
|---|---|---|---|
| vault | Yes | Vault 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'], }, },
- src/index.ts:543-552 (handler)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) }], }; }
- src/connectors/LocalConnector.ts:211-257 (handler)Core implementation of getStats() in LocalConnector: computes vault statistics by iterating over all notes, counting words, links, tags, and tracking last modified dateasync 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)}` }; } }