get_memory
Retrieve stored memory by ID and record its access for AI systems to maintain continuity and reference past data.
Instructions
Retrieve a specific memory by ID and mark it as accessed
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| memory_id | Yes | UUID of the memory to retrieve |
Implementation Reference
- mcp.js:561-563 (handler)MCP tool handler for get_memory - calls memoryManager.accessMemory() with the provided memory_id and returns the retrieved memory as JSON
case "get_memory": const retrievedMemory = await memoryManager.accessMemory(args.memory_id); return { content: [{ type: "text", text: JSON.stringify(retrievedMemory, null, 2) }] }; - src/memory-manager.js:199-214 (handler)Core implementation of accessMemory method - increments accessCount and lastAccessed timestamp, then retrieves and returns the full memory with type-specific data
async accessMemory(memoryId) { try { await this.db .update(schema.memories) .set({ accessCount: sql`${schema.memories.accessCount} + 1`, lastAccessed: new Date() }) .where(eq(schema.memories.id, memoryId)); return await this.getMemoryById(memoryId); } catch (error) { console.error('Error accessing memory:', error); throw error; } } - src/memory-manager.js:129-196 (helper)Helper method getMemoryById - retrieves base memory record and fetches type-specific data from the appropriate table (episodicMemories, semanticMemories, proceduralMemories, or strategicMemories)
async getMemoryById(memoryId) { try { const memory = await this.db .select() .from(schema.memories) .where(eq(schema.memories.id, memoryId)) .limit(1); if (!memory.length) return null; const baseMemory = memory[0]; let typeSpecificData = null; // Get type-specific data switch (baseMemory.type) { case 'episodic': const episodic = await this.db .select() .from(schema.episodicMemories) .where(eq(schema.episodicMemories.memoryId, memoryId)) .limit(1); typeSpecificData = episodic[0] || null; break; case 'semantic': const semantic = await this.db .select() .from(schema.semanticMemories) .where(eq(schema.semanticMemories.memoryId, memoryId)) .limit(1); typeSpecificData = semantic[0] || null; break; case 'procedural': const procedural = await this.db .select() .from(schema.proceduralMemories) .where(eq(schema.proceduralMemories.memoryId, memoryId)) .limit(1); typeSpecificData = procedural[0] || null; break; case 'strategic': const strategic = await this.db .select() .from(schema.strategicMemories) .where(eq(schema.strategicMemories.memoryId, memoryId)) .limit(1); typeSpecificData = strategic[0] || null; break; } return { ...baseMemory, type_specific_data: typeSpecificData }; } catch (error) { // Handle invalid UUID format gracefully if (error.cause && error.cause.message && error.cause.message.includes('invalid input syntax for type uuid')) { return null; } if (error.message && error.message.includes('invalid input syntax for type uuid')) { return null; } console.error('Error getting memory by ID:', error); throw error; } } - mcp.js:106-119 (registration)MCP tool registration for get_memory - defines the tool name, description, and input schema (requires memory_id parameter)
{ name: "get_memory", description: "Retrieve a specific memory by ID and mark it as accessed", inputSchema: { type: "object", properties: { memory_id: { type: "string", description: "UUID of the memory to retrieve" } }, required: ["memory_id"] } }, - src/tools/memory-tools.js:80-92 (schema)Tool schema definition for get_memory in memory-tools.js export - defines input validation schema for the tool
{ name: "get_memory", description: "Retrieve a specific memory by ID and mark it as accessed", inputSchema: { type: "object", properties: { memory_id: { type: "string", description: "UUID of the memory to retrieve" } }, required: ["memory_id"] }