Skip to main content
Glama

Graph Weaken

graph_weaken
Idempotent

Reduce the weight of a graph edge when the user corrects a recalled fact, such as saying 'no' or 'that's wrong'. Persists immediately with weight clamped at 0.0.

Instructions

Decrease an edge's weight when the user corrects a recalled fact. Call this when the user says 'no', 'that's wrong', or corrects something from the graph. Persists immediately; weight clamps at 0.0. Returns an error if the edge doesn't exist — use graph_delete to remove an entity outright. To replace a fact rather than weaken it, prefer graph_relate with the new fact and SUPERSEDES.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
from_nameYesSource entity name or ID
to_nameYesTarget entity name or ID
relationYesRelationship type
amountNoWeaken amount (default: 0.3)
reasonNoWhy weakening

Implementation Reference

  • The `weaken` method on Neo4jClient — the core logic. It executes a Cypher query that finds the edge (tenant-scoped), subtracts `amount` from its weight (clamping at 0.0), updates `last_confirmed`, and returns previous/new weight. Throws if edge not found.
    async weaken(
      tenantId: string,
      fromId: string,
      toId: string,
      type: RelationshipType,
      amount?: number,
    ): Promise<{ previous_weight: number; new_weight: number }> {
      const config = getConfig();
      const weakenAmount = amount ?? config.weights.weaken_on_correct;
      const rows = await this.run(
        `
        MATCH (a:Entity {tenant_id: $tenantId, id: $fromId})-[r:\`${type}\`]->(b:Entity {tenant_id: $tenantId, id: $toId})
        WITH r, r.weight AS old_weight
        SET r.weight = CASE WHEN r.weight - $amount < 0.0 THEN 0.0 ELSE r.weight - $amount END,
            r.last_confirmed = datetime()
        RETURN old_weight, r.weight AS new_weight
        `,
        { tenantId, fromId, toId, amount: weakenAmount },
      );
      const row = rows[0];
      if (!row) throw new Error(`Edge not found: ${fromId} -[${type}]-> ${toId} in tenant ${tenantId}`);
      return {
        previous_weight: Number(row["old_weight"]),
        new_weight: Number(row["new_weight"]),
      };
    }
  • The `graph_weaken` tool handler — the MCP tool's async callback. Resolves entity names to IDs (via findEntityIdByName or slugify), delegates to `client.weaken()`, and returns the result with a `pruned` flag.
    // ─── Tool: graph_weaken ───
    
    server.registerTool("graph_weaken", {
      title: "Graph Weaken",
      description:
        "Decrease an edge's weight when the user corrects a recalled fact. Call this when the user says 'no', 'that's wrong', or corrects something from the graph. Persists immediately; weight clamps at 0.0. Returns an error if the edge doesn't exist — use graph_delete to remove an entity outright. To replace a fact rather than weaken it, prefer graph_relate with the new fact and SUPERSEDES.",
      inputSchema: {
        from_name: z.string().describe("Source entity name or ID"),
        to_name: z.string().describe("Target entity name or ID"),
        relation: z.string().describe("Relationship type"),
        amount: z.number().optional().default(0.3).describe("Weaken amount (default: 0.3)"),
        reason: z.string().optional().describe("Why weakening"),
      },
      annotations: { idempotentHint: true },
    }, async (args) => {
      try {
        const tenantId = currentTenant();
        const fromId = (await client.findEntityIdByName(tenantId, args.from_name)) ?? slugify(args.from_name);
        const toId = (await client.findEntityIdByName(tenantId, args.to_name)) ?? slugify(args.to_name);
        const result = await client.weaken(tenantId, fromId, toId, args.relation as RelationshipType, args.amount);
        return toolResult({
          previous_weight: result.previous_weight,
          new_weight: result.new_weight,
          edge: { from: fromId, to: toId, type: args.relation },
          pruned: result.new_weight <= 0.05,
        });
      } catch (err) {
        return toolError(`graph_weaken failed: ${err instanceof Error ? err.message : String(err)}`);
      }
    });
  • Input schema for graph_weaken using Zod: `from_name`, `to_name`, `relation` (required strings), `amount` (optional number, default 0.3), `reason` (optional string).
    inputSchema: {
      from_name: z.string().describe("Source entity name or ID"),
      to_name: z.string().describe("Target entity name or ID"),
      relation: z.string().describe("Relationship type"),
      amount: z.number().optional().default(0.3).describe("Weaken amount (default: 0.3)"),
      reason: z.string().optional().describe("Why weakening"),
    },
  • Registration of the graph_weaken tool via `server.registerTool('graph_weaken', ...)` on the MCP server instance.
    server.registerTool("graph_weaken", {
      title: "Graph Weaken",
      description:
        "Decrease an edge's weight when the user corrects a recalled fact. Call this when the user says 'no', 'that's wrong', or corrects something from the graph. Persists immediately; weight clamps at 0.0. Returns an error if the edge doesn't exist — use graph_delete to remove an entity outright. To replace a fact rather than weaken it, prefer graph_relate with the new fact and SUPERSEDES.",
      inputSchema: {
        from_name: z.string().describe("Source entity name or ID"),
        to_name: z.string().describe("Target entity name or ID"),
        relation: z.string().describe("Relationship type"),
        amount: z.number().optional().default(0.3).describe("Weaken amount (default: 0.3)"),
        reason: z.string().optional().describe("Why weakening"),
      },
      annotations: { idempotentHint: true },
    }, async (args) => {
      try {
        const tenantId = currentTenant();
        const fromId = (await client.findEntityIdByName(tenantId, args.from_name)) ?? slugify(args.from_name);
        const toId = (await client.findEntityIdByName(tenantId, args.to_name)) ?? slugify(args.to_name);
        const result = await client.weaken(tenantId, fromId, toId, args.relation as RelationshipType, args.amount);
        return toolResult({
          previous_weight: result.previous_weight,
          new_weight: result.new_weight,
          edge: { from: fromId, to: toId, type: args.relation },
          pruned: result.new_weight <= 0.05,
        });
      } catch (err) {
        return toolError(`graph_weaken failed: ${err instanceof Error ? err.message : String(err)}`);
      }
    });
  • Default config value `weaken_on_correct: 0.3` — the default weaken amount used when the tool's `amount` parameter is not provided.
    weights: {
      explicit_statement: 0.7,
      inferred: 0.3,
      from_memory_file: 0.5,
      boost_on_confirm: 0.15,
      boost_on_mention: 0.05,
      weaken_on_correct: 0.3,
      project_context_boost: 0.1,
    },
Behavior5/5

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

Describes persistence, clamping at 0.0, and error if edge doesn't exist. Adds value beyond annotations (idempotentHint) with concrete behavioral details.

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 sentences, each essential and front-loaded. No wasted words.

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

Completeness5/5

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

Covers purpose, usage, behavior, and alternatives. Missing output schema but tool's effect is straightforward; description suffices for correct use.

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 covers all parameters with descriptions; description does not add significant new meaning beyond schema. Baseline 3 due to high schema coverage.

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 the action (decrease edge weight) and context (user correction of recalled fact). Distinguishes from siblings like graph_delete and graph_relate with SUPERSEDES.

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

Usage Guidelines5/5

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

Explicitly says when to call (user says 'no', 'that's wrong') and when not to (use graph_delete for removal, graph_relate for replacement). Provides clear alternatives.

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/stevepridemore/graph-memory'

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