Skip to main content
Glama

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
NameRequiredDescriptionDefault
pathYesThe note path (relative to vault root)

Implementation Reference

  • 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)}`);
        }
      },
    );
  • 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)}`);
        }
      },
    );

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/rps321321/obsidian-mcp-pro'

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