analyze_graph
Analyze the structure of your knowledge graph to understand connections and relationships within your Obsidian vault.
Instructions
Analyze the knowledge graph structure
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| vault | Yes | Vault name |
Implementation Reference
- src/index.ts:190-200 (registration)Registration of the 'analyze_graph' tool in the ListToolsRequestHandler, defining its name, description, and input schema requiring a 'vault' parameter.{ name: 'analyze_graph', description: 'Analyze the knowledge graph structure', inputSchema: { type: 'object', properties: { vault: { type: 'string', description: 'Vault name' }, }, required: ['vault'], }, },
- src/index.ts:608-622 (handler)Dispatch handler for 'analyze_graph' tool: retrieves notes from the specified vault, updates the KnowledgeGraphService, calls analyzeGraph(), and returns the JSON-serialized analysis.case 'analyze_graph': { 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 analysis = this.knowledgeGraph.analyzeGraph(); return { content: [{ type: 'text', text: JSON.stringify(analysis, null, 2) }], }; } throw new Error('Failed to analyze graph'); }
- src/services/KnowledgeGraph.ts:188-218 (handler)Core implementation of graph analysis in KnowledgeGraphService: calculates connection counts, identifies orphans, finds most connected nodes, builds the graph, and returns GraphAnalysis./** * Analyze the knowledge graph */ analyzeGraph(): GraphAnalysis { const connectionCounts = new Map<string, number>(); const orphans: string[] = []; for (const note of this.notes.values()) { const linkCount = (note.links?.length || 0) + (note.backlinks?.length || 0); connectionCounts.set(note.path, linkCount); if (linkCount === 0) { orphans.push(note.path); } } // Sort by connection count const mostConnected = Array.from(connectionCounts.entries()) .sort((a, b) => b[1] - a[1]) .slice(0, 10) .map(([id, connections]) => ({ id, connections })); const graph = this.buildGraph(); return { totalNodes: graph.nodes.filter(n => n.type === 'note').length, totalEdges: graph.edges.length, mostConnectedNodes: mostConnected, orphanNotes: orphans }; }
- src/services/KnowledgeGraph.ts:7-13 (schema)TypeScript interface defining the output structure of the analyzeGraph method.export interface GraphAnalysis { totalNodes: number; totalEdges: number; mostConnectedNodes: Array<{ id: string; connections: number }>; orphanNotes: string[]; clusters?: Array<string[]>; }