Skip to main content
Glama
QuixiAI

AGI MCP Server

by QuixiAI

get_memory_relationships

Retrieve connected memories by specifying a memory ID, direction, and optional relationship type to analyze memory associations in AI systems.

Instructions

Get relationships for a specific memory

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
memory_idYesUUID of the memory
directionNoDirection of relationships to retrieveboth
relationship_typeNoFilter by relationship type (optional)

Implementation Reference

  • Core handler function that executes the database query to retrieve memory relationships based on the given memory ID, direction, and optional relationship type filter.
    async getMemoryRelationships(memoryId, direction = 'both', relationshipType = null) {
      try {
        let query = this.db
          .select({
            id: schema.memoryRelationships.id,
            fromMemoryId: schema.memoryRelationships.fromMemoryId,
            toMemoryId: schema.memoryRelationships.toMemoryId,
            relationshipType: schema.memoryRelationships.relationshipType,
            strength: schema.memoryRelationships.strength,
            properties: schema.memoryRelationships.properties,
            createdAt: schema.memoryRelationships.createdAt,
            direction: sql`CASE 
              WHEN ${schema.memoryRelationships.fromMemoryId} = ${memoryId} THEN 'outgoing'
              ELSE 'incoming'
            END`.as('direction'),
            relatedMemoryId: sql`CASE 
              WHEN ${schema.memoryRelationships.fromMemoryId} = ${memoryId} THEN ${schema.memoryRelationships.toMemoryId}
              ELSE ${schema.memoryRelationships.fromMemoryId}
            END`.as('related_memory_id')
          })
          .from(schema.memoryRelationships);
    
        if (direction === 'outgoing') {
          query = query.where(eq(schema.memoryRelationships.fromMemoryId, memoryId));
        } else if (direction === 'incoming') {
          query = query.where(eq(schema.memoryRelationships.toMemoryId, memoryId));
        } else {
          query = query.where(
            or(
              eq(schema.memoryRelationships.fromMemoryId, memoryId),
              eq(schema.memoryRelationships.toMemoryId, memoryId)
            )
          );
        }
    
        if (relationshipType) {
          query = query.where(eq(schema.memoryRelationships.relationshipType, relationshipType));
        }
    
        const results = await query
          .orderBy(desc(schema.memoryRelationships.strength), desc(schema.memoryRelationships.createdAt));
        
        return results;
      } catch (error) {
        console.warn('Memory relationships query failed:', error.message);
        return [];
      }
    }
  • Input schema definition for the get_memory_relationships tool, including parameters for memory_id, direction, and relationship_type.
      name: "get_memory_relationships",
      description: "Get relationships for a specific memory",
      inputSchema: {
        type: "object",
        properties: {
          memory_id: {
            type: "string",
            description: "UUID of the memory"
          },
          direction: {
            type: "string",
            enum: ["incoming", "outgoing", "both"],
            description: "Direction of relationships to retrieve",
            default: "both"
          },
          relationship_type: {
            type: "string",
            description: "Filter by relationship type (optional)"
          }
        },
        required: ["memory_id"]
      }
    },
  • mcp.js:610-616 (handler)
    MCP server tool dispatch handler for get_memory_relationships that extracts arguments and calls the memoryManager implementation.
    case "get_memory_relationships":
      const relationships = await memoryManager.getMemoryRelationships(
        args.memory_id,
        args.direction || 'both',
        args.relationship_type || null
      );
      return { content: [{ type: "text", text: JSON.stringify(relationships, null, 2) }] };
  • mcp.js:249-271 (registration)
    Tool registration in the ListTools response, defining the tool name, description, and schema.
      name: "get_memory_relationships",
      description: "Get relationships for a specific memory",
      inputSchema: {
        type: "object",
        properties: {
          memory_id: {
            type: "string",
            description: "UUID of the memory"
          },
          direction: {
            type: "string",
            enum: ["incoming", "outgoing", "both"],
            description: "Direction of relationships to retrieve",
            default: "both"
          },
          relationship_type: {
            type: "string",
            description: "Filter by relationship type (optional)"
          }
        },
        required: ["memory_id"]
      }
    },
  • Duplicate schema definition in memory tools export (possibly for reference or alternative use).
    name: "get_memory_relationships",
    description: "Get relationships for a specific memory",
    inputSchema: {
      type: "object",
      properties: {
        memory_id: {
          type: "string",
          description: "UUID of the memory"
        },
        direction: {
          type: "string",
          enum: ["incoming", "outgoing", "both"],
          description: "Direction of relationships to retrieve",
          default: "both"
        },
        relationship_type: {
          type: "string",
          description: "Filter by relationship type (optional)"
        }
      },
      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