get_unique_values
Retrieve all distinct values for a metadata field in your Obsidian vault to analyze content patterns and organize information effectively.
Instructions
Get all unique values for a metadata field
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| field | Yes | Metadata field name | |
| vault | Yes | Vault name |
Implementation Reference
- src/services/DataviewService.ts:143-160 (handler)Core implementation of get_unique_values tool: iterates over all notes, extracts metadata, collects unique values for the specified field using a Set, handles arrays, and returns sorted array.getUniqueValues(field: string): any[] { const values = new Set<any>(); for (const note of this.notes) { const metadata = this.extractMetadata(note); const value = this.getNestedValue(metadata, field); if (value !== undefined && value !== null) { if (Array.isArray(value)) { value.forEach(v => values.add(v)); } else { values.add(value); } } } return Array.from(values); }
- src/index.ts:342-349 (schema)Input schema definition for the get_unique_values tool, requiring 'vault' and 'field' parameters.inputSchema: { type: 'object', properties: { vault: { type: 'string', description: 'Vault name' }, field: { type: 'string', description: 'Metadata field name' }, }, required: ['vault', 'field'], },
- src/index.ts:339-350 (registration)Tool registration in the list of tools returned by ListToolsRequestHandler.{ name: 'get_unique_values', description: 'Get all unique values for a metadata field', inputSchema: { type: 'object', properties: { vault: { type: 'string', description: 'Vault name' }, field: { type: 'string', description: 'Metadata field name' }, }, required: ['vault', 'field'], }, },
- src/index.ts:797-815 (handler)Top-level dispatch handler for get_unique_values: loads notes from vault connector, updates DataviewService, calls getUniqueValues, and formats response.case 'get_unique_values': { const connector = this.connectors.get(args?.vault as string); if (!connector) { throw new Error(`Vault "${args?.vault}" not found`); } const notesResult = await connector.getAllNotes(); if (!notesResult.success || !notesResult.data) { throw new Error('Failed to get notes'); } this.dataviewService.updateNotes(notesResult.data); const values = this.dataviewService.getUniqueValues(args?.field as string); return { content: [{ type: 'text', text: JSON.stringify(values, null, 2) }], }; }