Skip to main content
Glama

get_backlinks

Find all notes that link to a specific note in your Obsidian vault to understand connections and discover incoming references for better content organization.

Instructions

Get all notes that link to a specific note (incoming links)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNo
pathYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Registration of the get_backlinks MCP tool using the @mcp.tool decorator.
    @mcp.tool(
        name="get_backlinks",
        description="Get all notes that link to a specific note (incoming links)",
    )
  • MCP tool handler function for 'get_backlinks'. Performs input validation, calls the vault method, formats output, and handles errors.
    async def get_backlinks(path: str, limit: int | None = None) -> str:
        """
        Get all notes that link to this note.
    
        Args:
            path: Relative path to the note (e.g., "Projects/MCP.md")
            limit: Optional maximum number of notes to scan (recommended for large vaults)
    
        Returns:
            Formatted list of notes that link to this note
        """
        if not path or not path.strip():
            return "Error: Path cannot be empty"
        if len(path) > 1000:
            return "Error: Path too long"
    
        context = _get_context()
    
        try:
            backlinks = await context.vault.get_backlinks(path, limit=limit)
    
            if not backlinks:
                return f"No backlinks found for '{path}'"
    
            output = f"Found {len(backlinks)} note(s) linking to '{path}':\n\n"
            for i, link_path in enumerate(backlinks, 1):
                output += f"{i}. `{link_path}`\n"
    
            return output
    
        except FileNotFoundError:
            return f"Error: Note not found: {path}"
        except VaultSecurityError as e:
            return f"Error: Security violation: {e}"
        except Exception as e:
            logger.exception(f"Error getting backlinks for {path}")
            return f"Error getting backlinks: {e}"
  • Core implementation of the backlinks functionality in the ObsidianVault class. Scans notes, extracts wikilinks, and finds incoming links to the target note.
    async def get_backlinks(self, relative_path: str, limit: int | None = None) -> list[str]:
        """
        Get all notes that link to this note.
    
        Warning: This method scans all notes in the vault (O(n) behavior) which can be slow
        for large vaults. Consider using the 'limit' parameter to cap the number of notes
        scanned, or wait for future versions with persistent link indexing for better performance.
    
        Args:
            relative_path: Path to the target note
            limit: Optional maximum number of notes to scan. If None, scans all notes but
                   logs a warning for large vaults (>1000 notes).
    
        Returns:
            List of note paths that link to this note
    
        Future: A persistent link index will be added to eliminate the O(n) scan overhead.
        """
        target_name = Path(relative_path).stem
        backlinks = []
    
        # Get list of notes to scan
        all_notes = list(self.list_notes(limit=10000))
        notes_to_scan = all_notes if limit is None else all_notes[:limit]
    
        # Warn if scanning large vault without limit
        if limit is None and len(all_notes) > 1000:
            logger.warning(
                f"get_backlinks scanning {len(all_notes)} notes without limit. "
                f"Consider using limit parameter for better performance on large vaults."
            )
    
        # Search through notes
        scanned = 0
        for note_meta in notes_to_scan:
            try:
                note = await self.read_note(note_meta.path)
                links = self._extract_links(note.content)
    
                # Check if any link resolves to target
                for link in links:
                    # Match by filename or full path
                    if link == target_name or link == relative_path.replace(".md", ""):
                        backlinks.append(note_meta.path)
                        break
    
                scanned += 1
                if limit and scanned >= limit:
                    break
            except Exception as e:
                logger.debug(f"Error checking backlinks in {note_meta.path}: {e}")
                continue
    
        return backlinks
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 only states the basic function without mentioning permissions, rate limits, pagination, or response format. For a read operation with no annotation coverage, this is insufficient to inform the agent about key behavioral traits.

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 with zero waste, front-loading the core purpose. Every word earns its place, making it highly concise and well-structured for quick understanding.

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

Completeness3/5

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

Given the tool's moderate complexity (2 parameters, no annotations, but with an output schema), the description is minimally adequate. It states the purpose clearly but lacks details on parameters, behavioral context, or usage nuances. The presence of an output schema reduces the need to explain return values, but overall completeness is limited.

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 0%, so the description must compensate for undocumented parameters. It does not mention any parameters, leaving both 'path' and 'limit' unexplained. The baseline is 3 because the schema provides full structure, but the description adds no semantic meaning beyond what the schema already defines.

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 ('Get all notes that link to') and resource ('a specific note'), explicitly distinguishing it from sibling tools like 'get_outgoing_links' by specifying 'incoming links' in parentheses. This provides precise differentiation from related tools in the server.

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 context by specifying 'incoming links,' which suggests when to use this tool versus alternatives like 'get_outgoing_links.' However, it lacks explicit guidance on when not to use it or comparisons with other tools like 'get_related_otes' or 'get_link_graph,' leaving some ambiguity.

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/getglad/obsidian_mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server