Skip to main content
Glama
QuixiAI

AGI MCP Server

by QuixiAI

find_related_memories

Discover connected memories by traversing relationship graphs from a starting memory, with configurable depth and strength thresholds.

Instructions

Find memories related through graph traversal

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
memory_idYesUUID of the starting memory
max_depthNoMaximum depth to traverse
min_strengthNoMinimum relationship strength

Implementation Reference

  • Core handler function implementing graph traversal to find related memories using recursive SQL CTE, filtering by maximum depth and minimum relationship strength.
    async findRelatedMemories(memoryId, maxDepth = 2, minStrength = 0.3) {
      try {
        // Use recursive CTE to find related memories up to maxDepth
        const results = await this.db.execute(sql`
          WITH RECURSIVE memory_graph AS (
            -- Base case: direct relationships
            SELECT 
              mr.to_memory_id as memory_id,
              mr.relationship_type,
              mr.strength,
              1 as depth,
              ARRAY[mr.from_memory_id] as path
            FROM memory_relationships mr
            WHERE mr.from_memory_id = ${memoryId} AND mr.strength >= ${minStrength}
            
            UNION ALL
            
            -- Recursive case: follow relationships
            SELECT 
              mr.to_memory_id as memory_id,
              mr.relationship_type,
              mr.strength * mg.strength as strength,
              mg.depth + 1,
              mg.path || mr.from_memory_id
            FROM memory_relationships mr
            JOIN memory_graph mg ON mr.from_memory_id = mg.memory_id
            WHERE mg.depth < ${maxDepth}
              AND mr.strength >= ${minStrength}
              AND NOT (mr.to_memory_id = ANY(mg.path))
          )
          SELECT 
            mg.*,
            m.content,
            m.type,
            m.importance
          FROM memory_graph mg
          JOIN memories m ON mg.memory_id = m.id
          WHERE m.status = 'active'
          ORDER BY mg.strength DESC, mg.depth ASC
        `);
        
        return results.rows || [];
      } catch (error) {
        console.warn('Related memories query failed:', error.message);
        return [];
      }
    }
  • mcp.js:272-295 (registration)
    Registration of the 'find_related_memories' tool in the MCP server's ListTools response, including full input schema definition.
    {
      name: "find_related_memories",
      description: "Find memories related through graph traversal",
      inputSchema: {
        type: "object",
        properties: {
          memory_id: {
            type: "string",
            description: "UUID of the starting memory"
          },
          max_depth: {
            type: "integer",
            description: "Maximum depth to traverse",
            default: 2
          },
          min_strength: {
            type: "number",
            description: "Minimum relationship strength",
            default: 0.3
          }
        },
        required: ["memory_id"]
      }
    },
  • mcp.js:618-624 (handler)
    Dispatch handler in MCP CallToolRequestSchema that parses arguments and calls the core findRelatedMemories implementation on MemoryManager.
    case "find_related_memories":
      const relatedMemories = await memoryManager.findRelatedMemories(
        args.memory_id,
        args.max_depth || 2,
        args.min_strength || 0.3
      );
      return { content: [{ type: "text", text: JSON.stringify(relatedMemories, null, 2) }] };
  • Standalone schema definition for the find_related_memories tool (potentially imported or duplicated).
    name: "find_related_memories",
    description: "Find memories related through graph traversal",
    inputSchema: {
      type: "object",
      properties: {
        memory_id: {
          type: "string",
          description: "UUID of the starting memory"
        },
        max_depth: {
          type: "integer",
          description: "Maximum depth to traverse",
          default: 2
        },
        min_strength: {
          type: "number",
          description: "Minimum relationship strength",
          default: 0.3
        }
      },
      required: ["memory_id"]
    }

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/QuixiAI/agi-mcp-server'

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