Skip to main content
Glama

create_relation

Link two memories with a typed relationship to establish connections and organize information within the Mnemex memory system.

Instructions

Create an explicit relation between two memories.

Links two memories with a typed relationship (e.g., "references",
"follows_from", "similar_to").

Args:
    from_memory_id: Source memory ID.
    to_memory_id: Target memory ID.
    relation_type: Type of relation.
    strength: Strength of the relation (0.0-1.0).
    metadata: Additional metadata about the relation.

Returns:
    Created relation ID and confirmation.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
from_memory_idYes
metadataNo
relation_typeYes
strengthNo
to_memory_idYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The main handler function for the 'create_relation' tool, decorated with @mcp.tool(). It validates inputs, checks for existing relations, creates a new Relation model instance, persists it using db.create_relation, and returns a success response with details.
    @mcp.tool()
    def create_relation(
        from_memory_id: str,
        to_memory_id: str,
        relation_type: str,
        strength: float = 1.0,
        metadata: dict[str, Any] | None = None,
    ) -> dict[str, Any]:
        """
        Create an explicit relation between two memories.
    
        Links two memories with a typed relationship.
    
        Args:
            from_memory_id: Source memory ID (valid UUID).
            to_memory_id: Target memory ID (valid UUID).
            relation_type: Type of relation (must be one of: related, causes, supports,
                           contradicts, has_decision, consolidated_from).
            strength: Strength of the relation (0.0-1.0).
            metadata: Additional metadata about the relation.
    
        Returns:
            Created relation ID and confirmation.
    
        Raises:
            ValueError: If any input fails validation.
        """
        # Input validation
        from_memory_id = validate_uuid(from_memory_id, "from_memory_id")
        to_memory_id = validate_uuid(to_memory_id, "to_memory_id")
        relation_type = validate_relation_type(relation_type, "relation_type")
        strength = validate_score(strength, "strength")
    
        if not db.get_memory(from_memory_id):
            return {"success": False, "message": f"Source memory not found: {from_memory_id}"}
        if not db.get_memory(to_memory_id):
            return {"success": False, "message": f"Target memory not found: {to_memory_id}"}
    
        if existing := db.get_relations(
            from_memory_id=from_memory_id,
            to_memory_id=to_memory_id,
            relation_type=relation_type,
        ):
            return {
                "success": False,
                "message": f"Relation already exists: {existing[0].id}",
                "existing_relation_id": existing[0].id,
            }
    
        relation = Relation(
            id=str(uuid.uuid4()),
            from_memory_id=from_memory_id,
            to_memory_id=to_memory_id,
            relation_type=relation_type,
            strength=strength,
            created_at=int(time.time()),
            metadata=metadata or {},
        )
        db.create_relation(relation)
    
        return {
            "success": True,
            "relation_id": relation.id,
            "from": from_memory_id,
            "to": to_memory_id,
            "type": relation_type,
            "strength": strength,
            "message": f"Relation created: {from_memory_id} --[{relation_type}]--> {to_memory_id}",
        }
Behavior2/5

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

No annotations are provided, so the description carries full burden. It states the tool creates a relation and returns an ID and confirmation, which covers basic behavior. However, it lacks details on permissions needed, whether the operation is idempotent, error conditions (e.g., invalid memory IDs), or side effects (e.g., updating memory graphs). For a mutation tool with zero annotation coverage, this is insufficient.

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 efficiently structured: a concise purpose statement, a brief elaboration with examples, and a well-organized Args/Returns section. Every sentence adds value without redundancy, and information is front-loaded with the core purpose stated first.

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 complexity (mutation with 5 parameters) and the presence of an output schema (which covers return values), the description is partially complete. It explains parameters well but lacks behavioral context (e.g., error handling, idempotency) and usage guidelines. With no annotations, it should do more to guide safe and effective use.

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. It provides clear semantic explanations for all 5 parameters (e.g., 'Source memory ID', 'Type of relation', 'Strength of the relation (0.0-1.0)'), adding meaningful context beyond the schema's titles. However, it does not elaborate on relation_type examples beyond the parenthetical list or metadata structure.

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 ('Create an explicit relation') and resource ('between two memories'), with a parenthetical list of example relation types. It distinguishes this from sibling tools like 'cluster_memories' or 'read_graph' by focusing on explicit pairwise linking rather than grouping, analyzing, or retrieving existing relations.

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 when linking two specific memories with a typed relationship, but does not explicitly state when to use this tool versus alternatives like 'cluster_memories' (for grouping) or 'read_graph' (for viewing existing relations). No guidance on prerequisites, exclusions, or common scenarios is provided.

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/prefrontal-systems/mnemex'

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