Skip to main content
Glama

zk_create_link

Establishes a link between two notes in a Zettelkasten system, defining connection types like reference, extends, or contradicts. Supports bidirectional linking and optional descriptions for clarity.

Instructions

Create a link between two notes. Args: source_id: ID of the source note target_id: ID of the target note link_type: Type of link (reference, extends, refines, contradicts, questions, supports, related) description: Optional description of the link bidirectional: Whether to create a link in both directions

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
bidirectionalNo
descriptionNo
link_typeNoreference
source_idYes
target_idYes

Implementation Reference

  • The handler function that executes the zk_create_link tool logic. It validates inputs (converting link_type to enum), calls ZettelService.create_link, and handles errors including duplicate links.
    def zk_create_link(
        source_id: str,
        target_id: str,
        link_type: str = "reference",
        description: str | None = None,
        bidirectional: bool = False,
    ) -> str:
        """Create a semantic link between two notes to build knowledge connections.
    
        Args:
            source_id: The unique ID of the source note
            target_id: The unique ID of the target note
            link_type: Type of semantic relationship - one of: reference, extends, refines, contradicts, questions, supports, related (default: reference)
            description: Optional text describing the nature of this specific link
            bidirectional: If true, creates links in both directions (source→target and target→source)
        """
        try:
            # Convert link_type string to enum
            try:
                source_id_str = str(source_id)
                target_id_str = str(target_id)
                link_type_enum = LinkType(link_type.lower())
            except ValueError:
                return f"Invalid link type: {link_type}. Valid types are: {', '.join(t.value for t in LinkType)}"
    
            # Create the link
            source_note, target_note = self.zettel_service.create_link(
                source_id=source_id,
                target_id=target_id,
                link_type=link_type_enum,
                description=description,
                bidirectional=bidirectional,
            )
            if bidirectional:
                return f"Bidirectional link created between {source_id} and {target_id}"
            else:
                return f"Link created from {source_id} to {target_id}"
        except (Exception, sqlalchemy_exc.IntegrityError) as e:
            if "UNIQUE constraint failed" in str(e):
                return f"A link of this type already exists between these notes. Try a different link type."
            return self.format_error_response(e)
  • The registration of the zk_create_link tool using the FastMCP @tool decorator, specifying name, description, and hints. Includes function assignment to instance and logging.
    @self.mcp.tool(
        name="zk_create_link",
        description="Create a semantic link between two notes to build knowledge connections.",
        annotations={
            "readOnlyHint": False,
            "destructiveHint": False,
            "idempotentHint": False,
        },
    )
    def zk_create_link(
        source_id: str,
        target_id: str,
        link_type: str = "reference",
        description: str | None = None,
        bidirectional: bool = False,
    ) -> str:
        """Create a semantic link between two notes to build knowledge connections.
    
        Args:
            source_id: The unique ID of the source note
            target_id: The unique ID of the target note
            link_type: Type of semantic relationship - one of: reference, extends, refines, contradicts, questions, supports, related (default: reference)
            description: Optional text describing the nature of this specific link
            bidirectional: If true, creates links in both directions (source→target and target→source)
        """
        try:
            # Convert link_type string to enum
            try:
                source_id_str = str(source_id)
                target_id_str = str(target_id)
                link_type_enum = LinkType(link_type.lower())
            except ValueError:
                return f"Invalid link type: {link_type}. Valid types are: {', '.join(t.value for t in LinkType)}"
    
            # Create the link
            source_note, target_note = self.zettel_service.create_link(
                source_id=source_id,
                target_id=target_id,
                link_type=link_type_enum,
                description=description,
                bidirectional=bidirectional,
            )
            if bidirectional:
                return f"Bidirectional link created between {source_id} and {target_id}"
            else:
                return f"Link created from {source_id} to {target_id}"
        except (Exception, sqlalchemy_exc.IntegrityError) as e:
            if "UNIQUE constraint failed" in str(e):
                return f"A link of this type already exists between these notes. Try a different link type."
            return self.format_error_response(e)
    
    self.zk_create_link = zk_create_link
    
    logger.debug("Tool zk_create_link registered")
  • Input schema inferred from function parameters: source_id (str), target_id (str), link_type (str, default 'reference'), description (optional str), bidirectional (bool, default False). Output is str response.
    def zk_create_link(
        source_id: str,
        target_id: str,
        link_type: str = "reference",
        description: str | None = None,
        bidirectional: bool = False,
    ) -> str:
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the action 'create a link' but doesn't describe what happens on success/failure, whether links are mutable, if there are rate limits, or permission requirements. The description covers basic functionality but misses critical behavioral details for a mutation tool with no annotation support.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured and appropriately sized, with a clear purpose statement followed by a bullet-point-like parameter list. Every sentence earns its place by providing essential information. It could be slightly more front-loaded with key behavioral details, but overall it's efficient and readable.

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 complexity (mutation tool with 5 parameters), no annotations, and no output schema, the description is moderately complete. It covers parameters well but lacks behavioral context (e.g., error handling, return values) and usage guidelines. For a tool that creates relationships between notes, more context on implications and alternatives would improve completeness.

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?

Schema description coverage is 0%, so the description must compensate, which it does effectively by listing all 5 parameters with clear explanations. It adds meaning beyond the schema by specifying link_type options (e.g., 'reference', 'extends'), clarifying description as optional, and explaining bidirectional behavior. This significantly enhances parameter understanding despite the schema's lack of descriptions.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'create' and the resource 'link between two notes', making the purpose immediately understandable. It distinguishes this from sibling tools like zk_remove_link (deletion) and zk_get_linked_notes (retrieval), though it doesn't explicitly contrast with all siblings. The purpose is specific but could be slightly more distinctive.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., existing note IDs), compare with similar tools like zk_update_note for modifying links, or indicate scenarios where creating links is appropriate versus other operations. Usage is implied by the action but lacks explicit context.

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

Related 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/Liam-Deacon/zettelkasten-mcp'

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