Skip to main content
Glama

get_short_term_memory

Retrieve session-specific data from temporary memory storage to maintain context and continuity in AI interactions.

Instructions

Retrieve data from short-term memory

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keyNoMemory key (optional, returns all if not provided)
sessionIdYesSession identifier

Implementation Reference

  • MCP tool handler execution logic: validates sessionId and optional key, retrieves short-term memory from store, returns as formatted JSON text response.
    case "get_short_term_memory": {
      const { sessionId, key } = request.params.arguments as any;
      
      // Validate inputs
      ValidationUtils.validateSessionId(sessionId);
      if (key !== undefined) {
        ValidationUtils.validateMemoryKey(key);
      }
      
      const memory = memoryStore.getShortTermMemory(sessionId, key);
      return {
        content: [{
          type: "text",
          text: JSON.stringify(memory, null, 2)
        }]
      };
    }
  • Input schema definition for the get_short_term_memory tool, specifying sessionId as required and key as optional.
    inputSchema: {
      type: "object",
      properties: {
        sessionId: {
          type: "string",
          description: "Session identifier"
        },
        key: {
          type: "string",
          description: "Memory key (optional, returns all if not provided)"
        }
      },
      required: ["sessionId"]
  • Tool registration in the list of available tools, including name, description, and input schema.
    {
      name: "get_short_term_memory",
      description: "Retrieve data from short-term memory",
      inputSchema: {
        type: "object",
        properties: {
          sessionId: {
            type: "string",
            description: "Session identifier"
          },
          key: {
            type: "string",
            description: "Memory key (optional, returns all if not provided)"
          }
        },
        required: ["sessionId"]
      }
    },
  • Core implementation of short-term memory retrieval: fetches from in-memory map, checks expiration and cleans up if expired, returns specific key or entire session data.
    getShortTermMemory(sessionId: string, key?: string): any {
      const memory = this.shortTermMemory.get(sessionId);
      if (!memory || memory.expiresAt <= Date.now()) {
        this.shortTermMemory.delete(sessionId);
        return null;
      }
      return key ? memory.data[key] : memory.data;
    }

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/cbuntingde/memory-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server