Skip to main content
Glama

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
NameRequiredDescriptionDefault
memory_idYesUUID 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) }] };
  • 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;
      }
    }
  • 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"]
      }
    },
  • 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"]
      }

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