obsidian_links
Retrieve outgoing links, backlinks, tags, and frontmatter for any note in your Obsidian vault. Ideal for analyzing note connections and metadata.
Instructions
Return outgoing links, backlinks, tags, and frontmatter for one note.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| vault | No | Optional configured vault name. Defaults to the server default vault. | |
| path | Yes | Vault-relative path. Absolute paths and traversal are rejected. |
Implementation Reference
- src/tools.ts:725-741 (handler)The 'obsidian_links' tool handler: loads all notes, builds the graph, and returns outgoing links, backlinks, tags, and frontmatter for one note.
tool( "obsidian_links", "Return outgoing links, backlinks, tags, and frontmatter for one note.", { vault: vaultArg, path: pathArg }, async (args) => { const notes = await loadNotes(vaults, args.vault); const graph = buildGraph(notes); const note = notes.find((item) => item.path === vaults.notePath(args.path) || item.path.endsWith(`/${vaults.notePath(args.path)}`)); return { path: args.path, outgoing: outgoing(graph, args.path), backlinks: backlinks(graph, args.path), note: note ? { title: note.title, tags: note.tags, frontmatter: note.frontmatter } : null, }; }, { readOnlyHint: true }, ); - src/graph.ts:73-77 (helper)The `outgoing()` function filters the graph for edges where the source matches the given path. Used by obsidian_links handler.
export function outgoing(graph: VaultGraph, sourcePath: string): GraphEdge[] { const source = resolveGraphPath(graph, sourcePath); if (!source) return []; return graph.edges.filter((edge) => !edge.unresolved && edge.source === source.path); } - src/graph.ts:67-71 (helper)The `backlinks()` function filters the graph for edges where the target matches the given path. Used by obsidian_links handler.
export function backlinks(graph: VaultGraph, targetPath: string): GraphEdge[] { const target = resolveGraphPath(graph, targetPath); if (!target) return []; return graph.edges.filter((edge) => !edge.unresolved && edge.target === target.path); } - src/graph.ts:28-65 (helper)The `buildGraph()` function constructs the full vault graph from all notes, creating nodes and edges from wiki/Markdown links. Used by obsidian_links handler.
export function buildGraph(notes: NoteRecord[]): VaultGraph { const resolver = createResolver(notes); const edges: GraphEdge[] = []; for (const note of notes) { for (const link of extractWikiLinks(note.content)) { const target = resolver(link.target); edges.push({ source: note.path, target: target ?? link.target, rawTarget: link.target, kind: "wiki", unresolved: !target, line: link.line, }); } for (const link of extractMarkdownLinks(note.content)) { const target = resolver(link.target); edges.push({ source: note.path, target: target ?? link.target, rawTarget: link.target, kind: "markdown", unresolved: !target, line: link.line, }); } } const outCounts = countBy(edges.filter((e) => !e.unresolved), (edge) => edge.source); const inCounts = countBy(edges.filter((e) => !e.unresolved), (edge) => edge.target); const nodes = notes.map((note) => ({ path: note.path, title: note.title, tags: note.tags, outDegree: outCounts.get(note.path) ?? 0, inDegree: inCounts.get(note.path) ?? 0, })); return { nodes, edges, byPath: new Map(nodes.map((node) => [node.path, node])) }; } - src/tools.ts:147-153 (registration)The tool is registered inside `registerObsidianTools()` via the helper function `tool()` which calls `server.tool()` with schema, annotations, and handler.
tags: extractAllTags(read.text), stat: { size: read.stat.size, mtime: read.stat.mtime.toISOString(), ctime: read.stat.ctime.toISOString() }, links: args.includeLinks ? { wiki: extractWikiLinks(read.text), markdown: extractMarkdownLinks(read.text) } : undefined, }; }, { readOnlyHint: true }, );