Skip to main content
Glama

prune_stale_links

Remove stale memory graph edges and orphan nodes to maintain an optimized, lean graph structure by eliminating low-weight connections and unused elements.

Instructions

Remove stale memory graph edges whose weight has decayed below threshold via e^(-λt) formula. Also removes orphan nodes with no edges, low access count, and >7 days since last access. Keeps the graph lean.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
thresholdNoMinimum decayed weight to keep an edge. Default: 0.15. Lower = keep more edges.

Implementation Reference

  • The core implementation of the pruneStaleLinks logic that removes edges based on decay and cleans up orphan nodes.
    export async function pruneStaleLinks(rootDir: string, threshold?: number): Promise<{ removed: number; remaining: number }> {
      const graph = await loadGraph(rootDir);
      const cutoff = threshold ?? STALE_THRESHOLD;
      const toRemove: string[] = [];
    
      for (const [edgeId, edge] of Object.entries(graph.edges)) {
        if (decayWeight(edge) < cutoff) toRemove.push(edgeId);
      }
    
      for (const id of toRemove) delete graph.edges[id];
    
      const orphanNodeIds = Object.keys(graph.nodes).filter(nodeId =>
        getEdgesForNode(graph, nodeId).length === 0
          && graph.nodes[nodeId].accessCount <= 1
          && (Date.now() - graph.nodes[nodeId].lastAccessed) > 7 * 86_400_000
      );
      for (const id of orphanNodeIds) delete graph.nodes[id];
    
      scheduleSave(rootDir);
      return { removed: toRemove.length + orphanNodeIds.length, remaining: Object.keys(graph.edges).length };
    }
  • The MCP tool wrapper for the pruneStaleLinks function.
    export async function toolPruneStaleLinks(options: PruneStaleLinksOptions): Promise<string> {
      const result = await pruneStaleLinks(options.rootDir, options.threshold);
      return [
        `🧹 Pruning complete`,
        `  Removed: ${result.removed} stale links/orphan nodes`,
        `  Remaining edges: ${result.remaining}`,
      ].join("\n");
    }
Behavior4/5

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

With no annotations, description carries significant burden. It discloses the decay algorithm (e^(-λt)), side effects (orphan node removal with multi-criteria: no edges, low access count, >7 days), and destructive nature. Missing reversibility or atomicity details, but strong coverage of complex behavioral mechanics.

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?

Three dense sentences: main operation with algorithm, side-effect logic (orphan criteria), and rationale. Front-loaded with the primary action. Every clause earns its place; no repetition of structured data.

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?

Appropriate for complexity: explains multi-stage operation (edge decay pruning + orphan cleanup) without output schema. Covers the graph maintenance semantics well, though could mention return format or whether operation is logged/reversible.

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 has 100% coverage (baseline 3). Description adds value by contextualizing 'threshold' within the exponential decay formula and explaining its effect ('decayed below threshold'), helping agents understand how to tune the value (0.15 default mentioned in schema).

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?

Clear specific verb+resource: 'Remove stale memory graph edges'. Distinguishes from siblings like 'create_relation' or 'upsert_memory_node' (creation vs cleanup), and from search/retrieval tools by specifying the decay mechanism and orphan removal behavior.

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?

Implies maintenance usage via 'stale', 'decayed', and 'Keeps the graph lean'. However, lacks explicit when-to-use guidance (e.g., 'run when memory exceeds X') or when-not-to-use warnings (e.g., 'do not use if you need to preserve weak associations').

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