get_memory_relationships
Retrieve related memories for a specific memory ID in the AGI MCP Server, filtering by relationship direction or type to analyze connections within the AI's persistent memory system.
Instructions
Get relationships for a specific memory
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| direction | No | Direction of relationships to retrieve | both |
| memory_id | Yes | UUID of the memory | |
| relationship_type | No | Filter by relationship type (optional) |
Implementation Reference
- src/memory-manager.js:628-675 (handler)Core handler function in MemoryManager class that executes the database query to fetch memory relationships based on memory ID, direction (incoming/outgoing/both), 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 []; } }
- mcp.js:610-616 (registration)MCP server switch-case registration that handles incoming tool calls by invoking MemoryManager.getMemoryRelationships and formatting the response.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-270 (schema)Input schema definition for the tool in the MCP server's listTools response.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"] }
- src/tools/memory-tools.js:223-245 (schema)Tool schema definition in the exported memoryTools array (potentially for modular tool definitions).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"] } },