get_backlinks
Retrieve all notes in your Obsidian vault that contain links to a specified note, revealing interconnections and references.
Instructions
Find all notes that link to the specified note.
Args: path: Path to the target note
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes |
Implementation Reference
- server.py:234-254 (handler)MCP tool handler for 'get_backlinks' - decorated with @mcp.tool(). Takes a note path, retrieves all backlinks via the vault client, and returns a formatted list of note_path, note_title, and link_text for each backlink.
@mcp.tool() def get_backlinks(path: str) -> list: """Find all notes that link to the specified note. Args: path: Path to the target note """ try: client = get_vault_client() backlinks = client.get_backlinks(path) return [ { "note_path": link['note']['path'], "note_title": link['note']['title'], "link_text": link['link_text'] } for link in backlinks ] except Exception as e: return [{"error": str(e)}] - server.py:234-235 (registration)Registration of 'get_backlinks' as an MCP tool via the @mcp.tool() decorator.
@mcp.tool() def get_backlinks(path: str) -> list: - obsidian_client.py:213-237 (helper)Helper client method 'get_backlinks' on ObsidianVaultClient. Parses all notes in the vault using a wikilink regex pattern, finds notes that link to the target note (by filename stem or full path), and returns a list of dicts with note info and link text.
def get_backlinks(self, path: str) -> List[Dict[str, Any]]: """Find all notes that link to the specified note.""" target_name = Path(path).stem all_notes = self.list_notes() backlinks = [] link_pattern = re.compile(r'\\[\\[([^\\]|]+)\\|?([^\\]]*)?\\]\\]') for note in all_notes: if note['path'] == path: continue content = note['content'] matches = link_pattern.findall(content) for match in matches: link_target = match[0].split('#')[0] # Remove header references if link_target == target_name or link_target == path: backlinks.append({ 'note': note, 'link_text': match[1] if match[1] else match[0] }) break return backlinks