Skip to main content
Glama

get_memory_relationships

Retrieve connections between stored memories to analyze how data points relate within the AGI MCP Server's persistent memory system.

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

  • Main handler implementation that executes the get_memory_relationships tool logic. Queries the memory_relationships table with optional filters for direction (incoming/outgoing/both) and relationship_type. Returns results sorted by strength and creation date.
    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 [];
      }
    }
  • mcp.js:610-616 (registration)
    Tool handler invocation in the MCP server's request router that calls the memoryManager.getMemoryRelationships method with arguments from the MCP request.
    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:248-270 (registration)
    Tool registration in the MCP server defining the input schema for get_memory_relationships including memory_id (required), direction (enum: incoming/outgoing/both, default: both), and relationship_type (optional).
    {
      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"]
      }
  • Database schema definition for memory_relationships table that stores relationships between memories, including id, fromMemoryId, toMemoryId, relationshipType, strength, properties, and createdAt fields with indexes and foreign key constraints.
    export const memoryRelationships = pgTable("memory_relationships", {
    	id: uuid().defaultRandom().primaryKey().notNull(),
    	fromMemoryId: uuid("from_memory_id").notNull(),
    	toMemoryId: uuid("to_memory_id").notNull(),
    	relationshipType: text("relationship_type").notNull(),
    	strength: doublePrecision().default(0.5),
    	properties: jsonb(),
    	createdAt: timestamp("created_at", { withTimezone: true, mode: 'string' }).default(sql`CURRENT_TIMESTAMP`),
    }, (table) => [
    	index("memory_relationships_from_memory_id_idx").using("btree", table.fromMemoryId.asc().nullsLast().op("uuid_ops")),
    	index("memory_relationships_to_memory_id_idx").using("btree", table.toMemoryId.asc().nullsLast().op("uuid_ops")),
    	index("memory_relationships_type_strength_idx").using("btree", table.relationshipType.asc().nullsLast().op("text_ops"), table.strength.desc().nullsFirst().op("float8_ops")),
    	foreignKey({
    			columns: [table.fromMemoryId],
    			foreignColumns: [memories.id],
    			name: "memory_relationships_from_memory_id_fkey"
    		}).onDelete("cascade"),
    	foreignKey({
    			columns: [table.toMemoryId],
    			foreignColumns: [memories.id],
    			name: "memory_relationships_to_memory_id_fkey"
    		}).onDelete("cascade"),
    ]);
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states what the tool does but doesn't describe how it behaves—such as whether it returns all relationships or paginated results, error handling for invalid memory IDs, or performance characteristics. This leaves significant gaps for a tool with potential complexity.

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?

The description is a single, clear sentence that efficiently conveys the core purpose without unnecessary words. It's front-loaded with the essential action and target, making it easy to parse and understand quickly.

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

Completeness3/5

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

Given the tool's moderate complexity (3 parameters, no output schema, no annotations), the description is minimally adequate but incomplete. It covers the basic purpose but lacks details on usage context, behavioral traits, and output format, which are important for effective tool invocation in this memory system with many sibling tools.

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 description coverage is 100%, so the schema fully documents all parameters (memory_id, direction, relationship_type) with descriptions and defaults. The description adds no additional semantic context beyond implying a retrieval action, which doesn't enhance understanding of the parameters. This meets the baseline for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Get') and target ('relationships for a specific memory'), making the purpose immediately understandable. However, it doesn't differentiate this tool from sibling tools like 'find_related_memories' or 'get_memory_history', which might also retrieve relationship-related data, so it doesn't achieve full sibling differentiation.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. With siblings like 'find_related_memories' and 'get_memory_history' that might overlap in functionality, there's no indication of context, prerequisites, or exclusions for choosing this specific tool.

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

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