Skip to main content
Glama

find_broken_links

Identify wikilinks pointing to missing notes in your Obsidian vault to maintain content integrity.

Instructions

Find all wikilinks that point to non-existent notes

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
folderNoLimit scan to a specific folder
maxResultsNoMaximum results to return

Implementation Reference

  • The handler implementation for the `find_broken_links` tool. It scans notes for wikilinks and verifies their targets, identifying those that do not resolve to an existing note.
    // ── find_broken_links ──────────────────────────────────────────
    server.registerTool(
      "find_broken_links",
      {
        description: "Find all wikilinks that point to non-existent notes",
        inputSchema: {
          folder: z
            .string()
            .optional()
            .describe("Limit scan to a specific folder"),
          maxResults: z
            .number()
            .optional()
            .default(200)
            .describe("Maximum results to return"),
        },
      },
      async ({ folder, maxResults }) => {
        try {
          // Get all notes in vault for resolution, but only scan the folder
          const allNotes = await listNotes(vaultPath);
          const scanNotes = folder ? await listNotes(vaultPath, folder) : allNotes;
    
          const brokenBySource = new Map<string, BrokenLink[]>();
    
          for (const notePath of scanNotes) {
            let content: string;
            try {
              content = await readNote(vaultPath, notePath);
            } catch {
              console.error(`Failed to read note for broken link scan: ${notePath}`);
              continue;
            }
    
            const lines = content.split("\n");
            const links = extractWikilinks(content);
    
            for (const link of links) {
              const targetBase = link.target.split("#")[0].trim();
              if (!targetBase) continue;
    
              const resolved = resolveWikilink(targetBase, notePath, allNotes);
              if (!resolved) {
                const lineInfo = findLineWithLink(lines, link.target);
                const broken: BrokenLink = {
                  sourcePath: notePath,
                  targetLink: link.target,
                  line: lineInfo.line,
                };
    
                if (!brokenBySource.has(notePath)) {
                  brokenBySource.set(notePath, []);
                }
                brokenBySource.get(notePath)!.push(broken);
              }
            }
          }
    
          if (brokenBySource.size === 0) {
            const scopeStr = folder ? ` in folder: ${folder}` : "";
            return {
              content: [
                {
                  type: "text" as const,
                  text: `No broken links found${scopeStr}`,
                },
              ],
            };
          }
    
          let totalBroken = 0;
          for (const brokenLinks of brokenBySource.values()) {
            totalBroken += brokenLinks.length;
          }
    
          const lines: string[] = [];
          const scopeStr = folder ? ` (folder: ${folder})` : "";
          lines.push(`Broken links report${scopeStr}\n`);
    
          let shown = 0;
          for (const [sourcePath, brokenLinks] of brokenBySource) {
            if (shown >= maxResults) break;
            lines.push(`${sourcePath}:`);
            for (const bl of brokenLinks) {
              if (shown >= maxResults) break;
              const lineStr = bl.line > 0 ? ` (line ${bl.line})` : "";
              lines.push(`  - [[${bl.targetLink}]]${lineStr}`);
              shown++;
            }
            lines.push("");
          }
    
          if (shown < totalBroken) {
            lines.push(`... and ${totalBroken - shown} more broken link(s) not shown`);
          }
          lines.push(`Total: ${totalBroken} broken link(s) across ${brokenBySource.size} file(s)`);
    
          return { content: [{ type: "text" as const, text: lines.join("\n") }] };
        } catch (err) {
          console.error("find_broken_links error:", err);
          return errorResult(`Error finding broken links: ${err instanceof Error ? err.message : String(err)}`);
        }
      },
    );
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It mentions scanning for 'non-existent notes', which hints at read-only behavior, but fails to disclose critical details like whether it requires specific permissions, how it handles large datasets, performance implications, or error handling. This leaves significant behavioral gaps for a tool that likely processes multiple files.

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, direct sentence with zero wasted words. It front-loads the core purpose ('Find all wikilinks...') and efficiently conveys the scope ('that point to non-existent notes'), 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 tool's complexity (scanning wikilinks across notes) and lack of annotations or output schema, the description is insufficient. It does not explain what the output looks like (e.g., list of broken links with metadata), performance considerations, or error scenarios, leaving the agent with incomplete operational context.

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?

Schema description coverage is 100%, so the schema fully documents both parameters ('folder' and 'maxResults'). The description adds no additional parameter semantics beyond what the schema provides, such as explaining folder path formats or result limitations. This meets the baseline for high schema coverage.

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

Purpose5/5

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

The description clearly states the specific action ('find') and resource ('wikilinks that point to non-existent notes'), distinguishing it from siblings like 'find_orphans' (which likely finds notes without links) or 'get_outlinks' (which retrieves existing links). It precisely defines the tool's function without ambiguity.

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

Usage Guidelines3/5

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

The description implies usage for identifying broken wikilinks, but does not explicitly state when to use it versus alternatives like 'find_orphans' or 'get_outlinks'. It provides basic context (scanning wikilinks) but lacks guidance on prerequisites, exclusions, or comparisons to sibling tools.

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