get_outlinks
Extract all outgoing links from a specific Obsidian note to analyze connections and references within your vault.
Instructions
Get all links from a specific note
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | The note path (relative to vault root) |
Implementation Reference
- src/tools/links.ts:214-285 (handler)The handler implementation for the 'get_outlinks' tool, which reads a note, extracts wikilinks, resolves them, and returns a formatted list of valid and broken links.
// ── get_outlinks ─────────────────────────────────────────────── server.registerTool( "get_outlinks", { description: "Get all links from a specific note", inputSchema: { path: z.string().min(1).describe("The note path (relative to vault root)"), }, }, async ({ path: notePath }) => { try { const allNotes = await listNotes(vaultPath); const content = await readNote(vaultPath, notePath); const links = extractWikilinks(content); const results: { target: string; resolvedPath: string | null; isValid: boolean; isEmbed: boolean }[] = []; for (const link of links) { const targetBase = link.target.split("#")[0].trim(); if (!targetBase) continue; const resolved = resolveWikilink(targetBase, notePath, allNotes); results.push({ target: link.target, resolvedPath: resolved, isValid: resolved !== null, isEmbed: link.isEmbed, }); } if (results.length === 0) { return { content: [ { type: "text" as const, text: `No outgoing links found in: ${notePath}`, }, ], }; } const valid = results.filter((r) => r.isValid); const broken = results.filter((r) => !r.isValid); const lines: string[] = [ `Outgoing links from: ${notePath}`, `Total: ${results.length} (${valid.length} valid, ${broken.length} broken)\n`, ]; if (valid.length > 0) { lines.push("Valid links:"); for (const r of valid) { const embedPrefix = r.isEmbed ? "📎 " : ""; lines.push(` ${embedPrefix}[[${r.target}]] → ${r.resolvedPath}`); } } if (broken.length > 0) { lines.push("\nBroken links:"); for (const r of broken) { const embedPrefix = r.isEmbed ? "📎 " : ""; lines.push(` ${embedPrefix}[[${r.target}]] → (not found)`); } } return { content: [{ type: "text" as const, text: lines.join("\n") }] }; } catch (err) { console.error("get_outlinks error:", err); return errorResult(`Error getting outlinks: ${err instanceof Error ? err.message : String(err)}`); } }, ); - src/tools/links.ts:214-285 (handler)The implementation of the get_outlinks tool. It reads a note, extracts wikilinks, resolves them, and returns a formatted list of valid and broken links.
// ── get_outlinks ─────────────────────────────────────────────── server.registerTool( "get_outlinks", { description: "Get all links from a specific note", inputSchema: { path: z.string().min(1).describe("The note path (relative to vault root)"), }, }, async ({ path: notePath }) => { try { const allNotes = await listNotes(vaultPath); const content = await readNote(vaultPath, notePath); const links = extractWikilinks(content); const results: { target: string; resolvedPath: string | null; isValid: boolean; isEmbed: boolean }[] = []; for (const link of links) { const targetBase = link.target.split("#")[0].trim(); if (!targetBase) continue; const resolved = resolveWikilink(targetBase, notePath, allNotes); results.push({ target: link.target, resolvedPath: resolved, isValid: resolved !== null, isEmbed: link.isEmbed, }); } if (results.length === 0) { return { content: [ { type: "text" as const, text: `No outgoing links found in: ${notePath}`, }, ], }; } const valid = results.filter((r) => r.isValid); const broken = results.filter((r) => !r.isValid); const lines: string[] = [ `Outgoing links from: ${notePath}`, `Total: ${results.length} (${valid.length} valid, ${broken.length} broken)\n`, ]; if (valid.length > 0) { lines.push("Valid links:"); for (const r of valid) { const embedPrefix = r.isEmbed ? "📎 " : ""; lines.push(` ${embedPrefix}[[${r.target}]] → ${r.resolvedPath}`); } } if (broken.length > 0) { lines.push("\nBroken links:"); for (const r of broken) { const embedPrefix = r.isEmbed ? "📎 " : ""; lines.push(` ${embedPrefix}[[${r.target}]] → (not found)`); } } return { content: [{ type: "text" as const, text: lines.join("\n") }] }; } catch (err) { console.error("get_outlinks error:", err); return errorResult(`Error getting outlinks: ${err instanceof Error ? err.message : String(err)}`); } }, );