get_backlinks
Discover all notes linking to a specific note in your Obsidian vault to understand connections and references.
Instructions
Find all notes that link to a specific note
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Path to the note to find backlinks for |
Implementation Reference
- src/index.ts:694-716 (handler)The main handler function that scans all notes in the vault for wikilinks and markdown links pointing to the specified path and returns a JSON list of backlinking notes.async function handleGetBacklinks(args: { path: string }): Promise<string> { const noteName = path.basename(args.path, ".md"); const allNotes = await getAllNotes(); const backlinks: string[] = []; for (const notePath of allNotes) { if (notePath === args.path) continue; const fullPath = path.join(VAULT_PATH, notePath); const content = await fs.readFile(fullPath, "utf-8"); // Check for wikilinks to this note const wikiLinkPattern = new RegExp(`\\[\\[${noteName}(\\|[^\\]]+)?\\]\\]`); // Check for markdown links const mdLinkPattern = new RegExp(`\\]\\(${args.path}\\)`); if (wikiLinkPattern.test(content) || mdLinkPattern.test(content)) { backlinks.push(notePath); } } return JSON.stringify(backlinks, null, 2); }
- src/index.ts:258-270 (schema)The tool schema definition including name, description, and input schema for validation and listing.name: "get_backlinks", description: "Find all notes that link to a specific note", inputSchema: { type: "object", properties: { path: { type: "string", description: "Path to the note to find backlinks for", }, }, required: ["path"], }, },
- src/index.ts:917-919 (registration)The dispatch case in the CallTool request handler that routes calls to the get_backlinks handler function.case "get_backlinks": result = await handleGetBacklinks(args as { path: string }); break;