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");
    }

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