Skip to main content
Glama

get_knowledge_graph

Retrieve the complete knowledge graph for an Obsidian vault to analyze connections and relationships between notes, enabling comprehensive understanding of your knowledge base structure.

Instructions

Get the complete knowledge graph for a vault

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
vaultYesVault name

Implementation Reference

  • Tool handler switch case: fetches all notes from vault connector, updates KnowledgeGraphService with notes, builds the graph using buildGraph(), and returns JSON serialized graph.
    case 'get_knowledge_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 graph = this.knowledgeGraph.buildGraph(); return { content: [{ type: 'text', text: JSON.stringify(graph, null, 2) }], }; } throw new Error('Failed to build knowledge graph'); }
  • Input schema definition for the tool, requiring 'vault' parameter.
    { name: 'get_knowledge_graph', description: 'Get the complete knowledge graph for a vault', inputSchema: { type: 'object', properties: { vault: { type: 'string', description: 'Vault name' }, }, required: ['vault'], }, },
  • src/index.ts:166-176 (registration)
    Tool registration in the ListToolsRequestSchema handler, including name, description, and schema.
    { name: 'get_knowledge_graph', description: 'Get the complete knowledge graph for a vault', inputSchema: { type: 'object', properties: { vault: { type: 'string', description: 'Vault name' }, }, required: ['vault'], }, },
  • Core implementation: builds KnowledgeGraph with note nodes, link edges, tag nodes/edges, and folder nodes/edges from stored notes.
    buildGraph(): KnowledgeGraph { const nodes: GraphNode[] = []; const edges: GraphEdge[] = []; const tagNodes = new Map<string, GraphNode>(); const folderNodes = new Map<string, GraphNode>(); // Create note nodes for (const note of this.notes.values()) { nodes.push({ id: note.path, title: note.title, type: 'note', metadata: { tags: note.tags, wordCount: note.content.length, linkCount: note.links?.length || 0 } }); // Create edges for note links if (note.links) { for (const link of note.links) { edges.push({ source: note.path, target: this.resolveNotePath(link.target), type: link.type, weight: 1 }); } } // Create tag nodes and edges if (note.tags) { for (const tag of note.tags) { if (!tagNodes.has(tag)) { const tagNode: GraphNode = { id: `tag:${tag}`, title: tag, type: 'tag' }; tagNodes.set(tag, tagNode); nodes.push(tagNode); } edges.push({ source: note.path, target: `tag:${tag}`, type: 'tagged-with', weight: 1 }); } } // Create folder nodes and edges const folder = this.getFolder(note.path); if (folder && folder !== '.') { if (!folderNodes.has(folder)) { const folderNode: GraphNode = { id: `folder:${folder}`, title: folder, type: 'folder' }; folderNodes.set(folder, folderNode); nodes.push(folderNode); } edges.push({ source: note.path, target: `folder:${folder}`, type: 'in-folder', weight: 1 }); } } return { nodes, edges }; }
  • Updates internal notes map with new list of notes, called before building graph.
    updateNotes(notes: Note[]): void { this.notes.clear(); for (const note of notes) { this.notes.set(note.path, note); } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/bazylhorsey/obsidian-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server