get_note_metadata
Retrieve metadata for specific notes in your Obsidian vault to access file properties, tags, and frontmatter information for better organization and analysis.
Instructions
Get metadata for a specific note
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Note path | |
| vault | Yes | Vault name |
Implementation Reference
- src/index.ts:327-338 (registration)Registration of the get_note_metadata tool including its input schema in the ListTools handler.{ name: 'get_note_metadata', description: 'Get metadata for a specific note', inputSchema: { type: 'object', properties: { vault: { type: 'string', description: 'Vault name' }, path: { type: 'string', description: 'Note path' }, }, required: ['vault', 'path'], }, },
- src/index.ts:774-795 (handler)Handler implementation that loads all notes from the vault, updates the DataviewService, retrieves metadata for the specified note path, and returns it as JSON.case 'get_note_metadata': { 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 metadata = this.dataviewService.getMetadata(args?.path as string); if (!metadata) { throw new Error(`Note not found: ${args?.path}`); } return { content: [{ type: 'text', text: JSON.stringify(metadata, null, 2) }], }; }
- Core helper function in DataviewService that finds the note by path and delegates to extractMetadata.getMetadata(notePath: string): NoteMetadata | null { const note = this.notes.find(n => n.path === notePath); if (!note) return null; return this.extractMetadata(note); }
- Extracts comprehensive metadata including file info, frontmatter, and inline fields from a note.extractMetadata(note: Note): NoteMetadata { const metadata: NoteMetadata = { path: note.path, title: note.title, created: note.createdAt, modified: note.modifiedAt, tags: note.tags, aliases: note.frontmatter?.aliases, }; // Add all frontmatter fields if (note.frontmatter) { Object.assign(metadata, note.frontmatter); } // Extract inline fields const inlineFields = this.extractInlineFields(note.content); for (const field of inlineFields) { if (!metadata[field.key]) { metadata[field.key] = this.parseFieldValue(field.value); } } return metadata; }
- src/types/dataview.ts:57-72 (schema)Type definition for NoteMetadata, the return type of get_note_metadata.export interface NoteMetadata { // File properties path: string; title: string; // Dates created?: Date; modified?: Date; // Content properties tags?: string[]; aliases?: string[]; // Custom frontmatter [key: string]: any; }