Skip to main content
Glama
maxkuminov

Obsidian MCP (pgvector + Ollama, self-hosted)

get_links

Retrieves all outgoing links from a note path, including both resolved and dangling links. Helps identify dependencies and broken references in your Obsidian vault.

Instructions

Outgoing links from path — both resolved and dangling.

Useful for "what does this note depend on?" or finding broken references that need follow-up notes.

Args: path: Vault-relative path to the source note.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Core implementation of the get_links tool. Queries the note_links table (NoteLink model) for all outgoing links from a given note path, categorizing them into resolved (target_note_id is not null) and dangling (target_note_id is null). Uses current_user_id context var for multi-tenant isolation.
    @_tracked("get_links", ["path"])
    async def get_links_impl(path: str) -> str:
        """Outgoing links from `path` — both resolved and dangling."""
        from sqlalchemy import select
        from sqlalchemy.orm import aliased
        from src.models.db import NoteLink, NoteMetadata
    
        uid = current_user_id.get()
        async with async_session() as session:
            src_stmt = select(NoteMetadata).where(NoteMetadata.file_path == path)
            if uid is not None:
                src_stmt = src_stmt.where(NoteMetadata.user_id == uid)
            source = (await session.execute(src_stmt)).scalar_one_or_none()
            if source is None:
                return f"Note not found: {path}"
    
            TargetMeta = aliased(NoteMetadata)
            stmt = (
                select(
                    NoteLink.kind,
                    NoteLink.link_text,
                    NoteLink.position,
                    NoteLink.target_path,
                    NoteLink.target_note_id,
                    TargetMeta.file_path,
                    TargetMeta.title,
                )
                .outerjoin(TargetMeta, NoteLink.target_note_id == TargetMeta.id)
                .where(NoteLink.source_note_id == source.id)
                .order_by(NoteLink.position)
            )
            rows = (await session.execute(stmt)).all()
    
        if not rows:
            return f"`{path}` has no outgoing links"
        resolved = [r for r in rows if r.target_note_id is not None]
        dangling = [r for r in rows if r.target_note_id is None]
        lines = [f"`{path}` — {len(resolved)} resolved, {len(dangling)} dangling:\n"]
        if resolved:
            lines.append("**Resolved:**")
            for r in resolved:
                lines.append(
                    f"- {r.kind} → **{r.title}** (`{r.file_path}`) — `{r.link_text}`"
                )
        if dangling:
            lines.append("\n**Dangling:**")
            for r in dangling:
                lines.append(f"- {r.kind} → `{r.target_path}` — `{r.link_text}`")
        return "\n".join(lines)
  • MCP tool registration wrapping get_links_impl. The @mcp.tool() decorator registers this as an MCP tool named 'get_links'. Delegates immediately to get_links_impl.
    @mcp.tool()
    async def get_links(path: str) -> str:
        """Outgoing links from `path` — both resolved and dangling.
    
        Useful for "what does this note depend on?" or finding broken references
        that need follow-up notes.
    
        Args:
            path: Vault-relative path to the source note.
        """
        return await get_links_impl(path)
  • Import of get_links_impl from tools.py into server.py for registration.
    get_links_impl,
  • NoteLink SQLAlchemy model defining the note_links table schema. Fields include source_note_id, target_note_id, target_path, link_text, kind, and position. Used by get_links_impl to query outgoing links.
    class NoteLink(Base):
        __tablename__ = "note_links"
    
        id: Mapped[int] = mapped_column(Integer, primary_key=True)
        source_note_id: Mapped[int] = mapped_column(
            Integer,
            ForeignKey("notes_metadata.id", ondelete="CASCADE"),
            nullable=False,
        )
        target_note_id: Mapped[int | None] = mapped_column(
            Integer,
            ForeignKey("notes_metadata.id", ondelete="SET NULL"),
            nullable=True,
        )
        target_path: Mapped[str] = mapped_column(String(1024), nullable=False)
        link_text: Mapped[str | None] = mapped_column(Text, nullable=True)
        kind: Mapped[str] = mapped_column(String(16), nullable=False, default="link")
        position: Mapped[int | None] = mapped_column(Integer, nullable=True)
    
        __table_args__ = (
            Index("ix_note_links_source", "source_note_id"),
            Index("ix_note_links_target", "target_note_id"),
            Index("ix_note_links_target_path", "target_path"),
        )
Behavior4/5

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

With no annotations, the description reveals key behavior: returns both resolved and dangling links. Does not mention performance or side effects, but the read-only nature is implied.

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?

Extremely concise: two short sentences plus a clear args line. Every sentence serves a purpose, and the main action is front-loaded.

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

Completeness4/5

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

Given output schema exists (no need to detail returns), the description covers input, output behavior (resolved/dangling), and use cases. Minor omission: no mention of link type or formatting details.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Adds meaning beyond schema: explains 'path' is 'Vault-relative path to the source note'. Schema had 0% description coverage, so this clarification is valuable.

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?

Clearly states 'Outgoing links from `path`' with specific verb and resource. Distinguishes from sibling tools like get_backlinks (incoming links) by focusing on outgoing edges.

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

Usage Guidelines4/5

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

Provides concrete use cases: 'what does this note depend on?' and 'finding broken references'. Does not explicitly mention when not to use or list alternatives, but the context is clear.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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/maxkuminov/obsidian-mcp'

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