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"]
      }
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 the behavioral trait of marking the memory as accessed, which is useful beyond basic retrieval. However, it doesn't cover other aspects like permissions, rate limits, or response format, leaving gaps in behavioral context.

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 and includes the key behavioral detail. There is zero waste, making it appropriately sized and well-structured for its purpose.

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 (1 parameter, no output schema, no annotations), the description is minimally adequate. It covers the main action and a side effect but lacks details on output, error handling, or integration with siblings, leaving room for improvement in 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?

Schema description coverage is 100%, so the schema already documents the 'memory_id' parameter as a UUID. The description adds no additional meaning beyond what the schema provides, such as format details or usage examples, resulting in a baseline score.

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 'specific memory by ID', making the purpose understandable. However, it doesn't differentiate from sibling tools like 'get_memory_history' or 'get_memory_relationships' that also retrieve memory-related data, so it doesn't fully distinguish its specific scope.

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 such as 'search_memories_advanced' or 'get_memory_history'. It lacks explicit when/when-not instructions or named alternatives, leaving usage context implied at best.

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