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"]
      }

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.0

TDQS

B3.3/5.0
Behavior3/5

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

With no annotations provided, the description carries the full burden. It discloses a behavioral trait ('mark it as accessed') that indicates a side effect beyond simple retrieval, which is useful. However, it lacks details on permissions, rate limits, or error handling, leaving gaps in behavioral understanding.

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, efficient sentence that front-loads the core action ('Retrieve a specific memory by ID') and includes a key behavioral note ('mark it as accessed'). There is no wasted wording, making it highly concise and well-structured.

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 has one parameter with full schema coverage and no output schema, the description is minimally adequate. It covers the basic action and a side effect, but for a tool that modifies state (marking as accessed), more context on implications or return values would improve completeness.

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?

The input schema has 100% description coverage, with the parameter 'memory_id' documented as a UUID. The description adds no additional meaning beyond this, such as format examples or constraints, so it meets the baseline score without compensating further.

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 verb ('Retrieve') and resource ('a specific memory by ID'), making the purpose understandable. However, it doesn't explicitly differentiate this tool from sibling tools like 'get_memory_history' or 'get_memory_relationships', which might also retrieve memory-related data, so it doesn't reach the highest score.

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 like 'search_memories_advanced' or 'find_related_memories'. It mentions marking the memory as accessed, but this doesn't clarify usage context or exclusions, leaving the agent with minimal direction.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.