Skip to main content
Glama

add_interlinked_context

Add multiple memory nodes with automatic similarity linking. Computes embeddings and creates connections between related concepts, files, or notes for semantic intelligence.

Instructions

Bulk-add multiple memory nodes with automatic similarity linking. Computes embeddings for all items, then creates similarity edges between any pair (new-to-new and new-to-existing) with cosine similarity ≥ 0.72. Ideal for importing related concepts, files, or notes at once.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
itemsYesArray of nodes to add. Each needs type, label, and content.
auto_linkNoWhether to auto-create similarity edges. Default: true.

Implementation Reference

  • The core implementation of the logic to add nodes and interlink them based on similarity.
    export async function addInterlinkedContext(rootDir: string, items: Array<{ type: NodeType; label: string; content: string; metadata?: Record<string, string> }>, autoLink: boolean = true): Promise<{ nodes: MemoryNode[]; edges: MemoryEdge[] }> {
      const createdNodes: MemoryNode[] = [];
      for (const item of items) {
        createdNodes.push(await upsertNode(rootDir, item.type, item.label, item.content, item.metadata));
      }
    
      const createdEdges: MemoryEdge[] = [];
    
      if (autoLink && createdNodes.length > 1) {
        for (let i = 0; i < createdNodes.length; i++) {
          for (let j = i + 1; j < createdNodes.length; j++) {
            const similarity = cosine(createdNodes[i].embedding, createdNodes[j].embedding);
            if (similarity >= SIMILARITY_THRESHOLD) {
              const edge = await createRelation(rootDir, createdNodes[i].id, createdNodes[j].id, "similar_to", similarity);
              if (edge) createdEdges.push(edge);
            }
          }
        }
      }
    
      const graph = await loadGraph(rootDir);
      const existingNodes = Object.values(graph.nodes)
        .filter(n => !createdNodes.find(cn => cn.id === n.id))
        .slice(0, 200);
      if (autoLink) {
        for (const newNode of createdNodes) {
          for (const existing of existingNodes) {
            const similarity = cosine(newNode.embedding, existing.embedding);
            if (similarity >= SIMILARITY_THRESHOLD) {
              const edge = await createRelation(rootDir, newNode.id, existing.id, "similar_to", similarity);
              if (edge) createdEdges.push(edge);
            }
          }
        }
      }
    
      return { nodes: createdNodes, edges: createdEdges };
    }
  • The MCP tool handler that wraps the core logic and formats the output string.
    export async function toolAddInterlinkedContext(options: AddInterlinkedContextOptions): Promise<string> {
      const result = await addInterlinkedContext(options.rootDir, options.items, options.autoLink);
      const sections = [
        `✅ Added ${result.nodes.length} interlinked nodes`,
        result.edges.length > 0 ? `  Auto-linked: ${result.edges.length} similarity edges (threshold ≥ 0.72)` : "  No auto-links above threshold",
        "\nNodes:",
      ];
    
      for (const node of result.nodes) {
        sections.push(`  [${node.type}] ${node.label} → ${node.id}`);
      }
    
      if (result.edges.length > 0) {
        sections.push("\nEdges:");
        for (const edge of result.edges) {
          sections.push(`  ${edge.source} --[${edge.relation} w:${Math.round(edge.weight * 100) / 100}]--> ${edge.target}`);
        }
      }
    
      const stats = await getGraphStats(options.rootDir);
      sections.push(`\nGraph total: ${stats.nodes} nodes, ${stats.edges} edges`);
      return sections.join("\n");
    }
Behavior4/5

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

Discloses significant implementation detail absent from annotations: specifically cites the cosine similarity threshold (≥0.72), reveals embedding computation occurs, and clarifies edge creation scope (new-to-new AND new-to-existing). Missing only operational details like atomicity guarantees or failure modes.

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?

Two dense sentences with zero redundancy. Front-loaded with the core action (bulk-add), followed by technical mechanism (embeddings/similarity), then usage context. Every clause provides distinct value.

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?

Comprehensively explains the mutation behavior (node creation + edge linking) and algorithmic specifics (0.72 threshold). Lacks only return value documentation, which is relevant given no output schema exists, but the behavioral description is complete enough for invocation decisions.

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 100%, providing complete documentation for both 'items' and 'auto_link' parameters. The description references these concepts ('all items', 'automatic similarity linking') but does not augment the schema with additional semantic guidance (e.g., content format recommendations), warranting baseline 3.

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: 'Bulk-add multiple memory nodes with automatic similarity linking' clearly defines the verb (bulk-add), resource (memory nodes), and distinguishing mechanism (automatic similarity linking). Differentiates from sibling 'upsert_memory_node' (single node) and 'create_relation' (manual edges) through the bulk/automatic scope.

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 clear contextual signal with 'Ideal for importing related concepts, files, or notes at once,' indicating bulk ingestion use cases. However, lacks explicit contrast with single-node alternative (upsert_memory_node) or when to disable auto_link.

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