Skip to main content
Glama

get_backlinks

Find all notes that link to a specific note in your Obsidian vault to analyze connections and track references.

Instructions

Find all notes that link to a specific note

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesThe target note path (relative to vault root)

Implementation Reference

  • The implementation of the get_backlinks tool handler. It builds a link graph of the vault, resolves the target note path, retrieves backlinks from the graph, and formats the output showing the source notes and context lines.
    // ── get_backlinks ──────────────────────────────────────────────
    server.registerTool(
      "get_backlinks",
      {
        description: "Find all notes that link to a specific note",
        inputSchema: {
          path: z.string().min(1).describe("The target note path (relative to vault root)"),
        },
      },
      async ({ path: targetPath }) => {
        try {
          const graph = await buildLinkGraph(vaultPath);
    
          // Normalize target for comparison
          const targetNormalized = targetPath.replace(/\.md$/i, "").toLowerCase();
          const targetBasename = targetNormalized.split("/").pop() ?? targetNormalized;
    
          // Find the actual note path that matches the target
          let resolvedTarget: string | null = null;
          for (const notePath of graph.allNotes) {
            const noteNormalized = notePath.replace(/\.md$/i, "").toLowerCase();
            if (noteNormalized === targetNormalized) {
              resolvedTarget = notePath;
              break;
            }
          }
    
          // Also try basename matching if exact match failed
          if (!resolvedTarget) {
            for (const notePath of graph.allNotes) {
              const noteBasename = notePath
                .replace(/\.md$/i, "")
                .split("/")
                .pop()
                ?.toLowerCase();
              if (noteBasename === targetBasename) {
                resolvedTarget = notePath;
                break;
              }
            }
          }
    
          if (!resolvedTarget) {
            return errorResult(`No note found matching path: ${targetPath}`);
          }
    
          const backlinkSources = graph.backlinks.get(resolvedTarget);
          if (!backlinkSources || backlinkSources.size === 0) {
            return {
              content: [
                {
                  type: "text" as const,
                  text: `No backlinks found for: ${resolvedTarget}`,
                },
              ],
            };
          }
    
          const results: { source: string; line: number; context: string }[] = [];
    
          for (const sourcePath of backlinkSources) {
            const lines = graph.noteLines.get(sourcePath) ?? [];
            // Find the line(s) that contain the link to the target
            const links = graph.rawLinks.get(sourcePath) ?? [];
            const relevantLinks = links.filter((l) => {
              const base = l.target.split("#")[0].trim();
              const resolved = resolveWikilink(base, sourcePath, graph.allNotes);
              return resolved === resolvedTarget;
            });
    
            if (relevantLinks.length > 0) {
              for (const link of relevantLinks) {
                const lineInfo = findLineWithLink(lines, link.target);
                results.push({
                  source: sourcePath,
                  line: lineInfo.line,
                  context: lineInfo.content,
                });
              }
            } else {
              results.push({ source: sourcePath, line: 0, context: "" });
            }
          }
    
          // Deduplicate by source+line
          const seen = new Set<string>();
          const deduped = results.filter((r) => {
            const key = `${r.source}:${r.line}`;
            if (seen.has(key)) return false;
            seen.add(key);
            return true;
          });
    
          const output = [
            `Backlinks to: ${resolvedTarget}`,
            `Found: ${deduped.length} backlink(s)\n`,
            ...deduped.map((r) => {
              const lineStr = r.line > 0 ? `:${r.line}` : "";
              const contextStr = r.context ? `  → ${r.context}` : "";
              return `- ${r.source}${lineStr}${contextStr}`;
            }),
          ].join("\n");
    
          return { content: [{ type: "text" as const, text: output }] };
        } catch (err) {
          console.error("get_backlinks error:", err);
          return errorResult(`Error finding backlinks: ${err instanceof Error ? err.message : String(err)}`);
        }
      },
    );
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states what the tool does but lacks critical details: it doesn't specify the return format (e.g., list of note paths, metadata), whether it's read-only or has side effects, or any performance considerations like rate limits. For a tool with zero annotation coverage, this is inadequate.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that directly states the tool's purpose without any fluff or redundancy. It is appropriately sized and front-loaded, making it easy to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the lack of annotations and output schema, the description is incomplete. It doesn't explain what the tool returns (e.g., a list of note names, full paths, or metadata), which is critical for an agent to use it effectively. For a tool with no structured output information, the description should compensate but fails to do so.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, with the 'path' parameter clearly documented as 'The target note path (relative to vault root)'. The description adds no additional parameter semantics beyond this, so it meets the baseline of 3 where the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Find') and resource ('all notes that link to a specific note'), making the purpose immediately understandable. However, it doesn't explicitly differentiate from sibling tools like 'get_outlinks' (which likely finds links from a note) or 'find_broken_links' (which likely finds broken links), so it misses the top score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention sibling tools like 'get_outlinks' (for outgoing links) or 'find_broken_links' (for broken links), nor does it specify prerequisites or contexts for usage. This leaves the agent with minimal direction.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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