get_backlinks
Find all notes linking to a specific note in your Obsidian vault to track references and connections.
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 implements the get_backlinks tool. It iterates over all notes in the vault, checks for wikilinks ([[note]]) and markdown links to the target path using regex, and returns a JSON array of paths to notes that link to it.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:257-270 (schema)The tool definition object containing the name, description, and input schema for validation and tool 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 central tool call handler that routes 'get_backlinks' calls to the appropriate handler function.case "get_backlinks": result = await handleGetBacklinks(args as { path: string }); break;