get_related_notes
Find notes connected to a specific note in your Obsidian vault by analyzing link relationships and connections between your knowledge base entries.
Instructions
Get notes related to a specific note
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| maxDepth | No | Maximum link depth (default: 2) | |
| path | Yes | Path to the note | |
| vault | Yes | Vault name |
Implementation Reference
- src/index.ts:177-189 (registration)Tool registration including name, description, and input schema definition for 'get_related_notes'.{ name: 'get_related_notes', description: 'Get notes related to a specific note', inputSchema: { type: 'object', properties: { vault: { type: 'string', description: 'Vault name' }, path: { type: 'string', description: 'Path to the note' }, maxDepth: { type: 'number', description: 'Maximum link depth (default: 2)' }, }, required: ['vault', 'path'], }, },
- src/index.ts:180-187 (schema)Input schema defining parameters: vault (required), path (required), maxDepth (optional).inputSchema: { type: 'object', properties: { vault: { type: 'string', description: 'Vault name' }, path: { type: 'string', description: 'Path to the note' }, maxDepth: { type: 'number', description: 'Maximum link depth (default: 2)' }, }, required: ['vault', 'path'],
- src/index.ts:592-606 (handler)Handler in the main switch statement that fetches all notes, updates the knowledge graph, calls getRelatedNotes on it with path and maxDepth, and returns the related notes as JSON.case 'get_related_notes': { 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) { this.knowledgeGraph.updateNotes(notesResult.data); const related = this.knowledgeGraph.getRelatedNotes(args?.path as string, (args?.maxDepth as number) || 2); return { content: [{ type: 'text', text: JSON.stringify(related, null, 2) }], }; } throw new Error('Failed to get related notes'); }
- Core implementation in KnowledgeGraph service: traverses links and backlinks up to maxDepth using DFS, collects related note paths, and returns Note objects.getRelatedNotes(notePath: string, maxDepth: number = 2): Note[] { const related = new Set<string>(); const visited = new Set<string>(); const traverse = (path: string, depth: number) => { if (depth > maxDepth || visited.has(path)) { return; } visited.add(path); const note = this.notes.get(path); if (!note) return; if (depth > 0) { related.add(path); } // Follow outgoing links if (note.links) { for (const link of note.links) { const target = this.resolveNotePath(link.target); traverse(target, depth + 1); } } // Follow backlinks if (note.backlinks) { for (const backlink of note.backlinks) { traverse(backlink.source, depth + 1); } } }; traverse(notePath, 0); return Array.from(related) .map(path => this.notes.get(path)) .filter((note): note is Note => note !== undefined); }