Skip to main content
Glama

create_relation

Establish typed connections between memory nodes to build semantic relationships within codebases, supporting various relation types with weighted edges that update automatically.

Instructions

Create a typed edge between two memory nodes. Supports relation types: relates_to, depends_on, implements, references, similar_to, contains. Edges have weights (0-1) that decay over time via e^(-λt). Duplicate edges update weight instead of creating new ones.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
source_idYesID of the source memory node.
target_idYesID of the target memory node.
relationYesRelationship type between nodes.
weightNoEdge weight 0-1. Higher = stronger relationship. Default: 1.0.
metadataNoOptional key-value metadata for the edge.

Implementation Reference

  • The core function `createRelation` that creates or updates a relationship edge between two memory nodes in the graph storage.
    export async function createRelation(rootDir: string, sourceId: string, targetId: string, relation: RelationType, weight?: number, metadata?: Record<string, string>): Promise<MemoryEdge | null> {
      const graph = await loadGraph(rootDir);
      if (!graph.nodes[sourceId] || !graph.nodes[targetId]) return null;
    
      const duplicate = Object.values(graph.edges).find(e =>
        e.source === sourceId && e.target === targetId && e.relation === relation
      );
      if (duplicate) {
        duplicate.weight = weight ?? duplicate.weight;
        if (metadata) Object.assign(duplicate.metadata, metadata);
        scheduleSave(rootDir);
        return duplicate;
      }
    
      const edge: MemoryEdge = {
        id: generateId("me"),
        source: sourceId,
        target: targetId,
        relation,
        weight: weight ?? 1.0,
        createdAt: Date.now(),
        metadata: metadata ?? {},
      };
      graph.edges[edge.id] = edge;
      scheduleSave(rootDir);
      return edge;
    }
  • The tool wrapper `toolCreateRelation` which exposes `createRelation` as an MCP tool, handling request mapping and providing user-friendly feedback.
    export async function toolCreateRelation(options: CreateRelationOptions): Promise<string> {
      const edge = await createRelation(options.rootDir, options.sourceId, options.targetId, options.relation, options.weight, options.metadata);
      if (!edge) return `❌ Failed: one or both node IDs not found (source: ${options.sourceId}, target: ${options.targetId})`;
    
      const stats = await getGraphStats(options.rootDir);
      return [
        `✅ Relation created: ${options.sourceId} --[${edge.relation}]--> ${options.targetId}`,
        `  Edge ID: ${edge.id}`,
        `  Weight: ${edge.weight}`,
        `\nGraph: ${stats.nodes} nodes, ${stats.edges} edges`,
      ].join("\n");
    }
Behavior5/5

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

Superior disclosure despite no annotations. Uniquely documents temporal decay physics (e^(-λt)) and idempotent upsert behavior on duplicates—critical behavioral traits for a write operation that agents need to understand for correct invocation and expectation-setting.

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?

Four precisely ordered sentences spanning purpose, valid types, physics, and uniqueness constraints. Zero waste—every clause earns its place. Front-loaded with the core action, followed by necessary constraints and behaviors.

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?

Comprehensive for a graph mutation tool without output schema. Covers unique domain logic (decay, duplicates) that schema cannot express. Minor gap: does not explicitly state prerequisite that source/target nodes must exist (implied but not guaranteed).

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?

With 100% schema coverage, baseline is 3. Description adds value by contextualizing the weight parameter (decay mechanics, 0-1 range emphasis) and implying directional semantics via 'typed edge'. Lists enum values explicitly, slightly redundant with schema but reinforces valid options.

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?

Excellent specificity with clear verb 'Create' and resource 'typed edge between two memory nodes'. Distinctly differentiates from sibling node-creation tools (upsert_memory_node) and retrieval tools by explicitly mentioning edges/relationships.

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?

Provides implicit guidance through enumeration of relation types and duplicate-handling behavior, but lacks explicit 'when to use this vs alternatives' guidance. Does not clarify when to prefer this over add_interlinked_context or prerequisite that nodes must exist first.

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/ForLoopCodes/contextplus'

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