Skip to main content
Glama

get_link_graph

Generate a visual link graph showing connections between notes in your Obsidian vault to analyze relationships and discover content connections.

Instructions

Get the link graph for the vault

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
max_notesNo

Implementation Reference

  • Core implementation of get_link_graph: iterates over notes, extracts wikilinks, resolves them to paths, builds nodes and directed edges for graph visualization.
    async def get_link_graph(self, max_notes: int = 1000) -> dict[str, Any]: """ Build a link graph for the vault. Returns: Dict with 'nodes' and 'edges' for visualization """ nodes = [] edges = [] seen_paths = set() for note_meta in self.list_notes(limit=max_notes): # Add node if note_meta.path not in seen_paths: nodes.append( { "id": note_meta.path, "name": note_meta.name, "size": note_meta.size, "tags": note_meta.tags if note_meta.tags else [], } ) seen_paths.add(note_meta.path) # Add edges (links) try: note = await self.read_note(note_meta.path) links = self._extract_links(note.content) for link in links: resolved = self._resolve_link(link, note_meta.path) if resolved and resolved in seen_paths: edges.append( { "source": note_meta.path, "target": resolved, } ) except Exception as e: logger.debug(f"Error building graph for {note_meta.path}: {e}") continue return { "nodes": nodes, "edges": edges, "total_nodes": len(nodes), "total_edges": len(edges), }
  • MCP tool registration for get_link_graph: wrapper that calls vault.get_link_graph, formats summary and full JSON output.
    @mcp.tool(name="get_link_graph", description="Get the link graph for the vault") async def get_link_graph(max_notes: int = 500) -> str: """ Build a link graph of the vault. Args: max_notes: Maximum number of notes to include (default: 500) Returns: JSON representation of the graph with nodes and edges """ if max_notes <= 0 or max_notes > 10000: return "Error: max_notes must be between 1 and 10000" context = _get_context() try: graph = await context.vault.get_link_graph(max_notes) output = "# Link Graph\n\n" output += f"**Total Nodes:** {graph['total_nodes']}\n" output += f"**Total Edges:** {graph['total_edges']}\n\n" output += "## Sample Nodes (first 10):\n" for node in graph["nodes"][:10]: output += f"- {node['name']} ({node['id']})\n" output += "\n## Sample Edges (first 10):\n" for edge in graph["edges"][:10]: output += f"- {edge['source']} → {edge['target']}\n" output += "\n\n**Full Graph Data (JSON):**\n```json\n" output += json.dumps(graph, indent=2) output += "\n```" return output except Exception as e: logger.exception("Error building link graph") return f"Error building link graph: {e}"

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/getglad/obsidian_mcp'

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