Skip to main content
Glama

add_short_term_memory

Store recent conversation messages as short-term memory entries that are indexed by keywords and scored for relevance over time to maintain context awareness.

Instructions

Add a new short-term memory entry from recent conversation messages. The memory will be indexed by keywords and scored based on relevance over time.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
messagesYes
conversation_idYes
roleWeightsNo

Implementation Reference

  • MCP tool handler that processes input arguments, adds short-term memory entries using ShortTermMemoryManager.addMemory, persists memories via storage, and returns operation status.
    handler: async (args) => { try { const success = await memoryManager.addMemory( args.messages, args.conversation_id, { roleWeights: args.roleWeights } ); if (success) { await storageManager.saveShortTermMemories(memoryManager.getMemories()); return { success: true, message: 'Memory added successfully', totalMemories: memoryManager.getMemories().length }; } else { return { success: false, message: 'Failed to add memory (possibly empty content)' }; } } catch (error) { return { success: false, error: error.message }; } }
  • Zod schema for tool input validation, specifying structure for messages array, required conversation_id, and optional role weights.
    inputSchema: z.object({ messages: z.array(z.object({ role: z.enum(['user', 'assistant', 'system']).describe('Message role'), content: z.string().describe('Message content'), timestamp: z.number().optional().describe('Unix timestamp in milliseconds') })).describe('Array of recent messages to create memory from'), conversation_id: z.string().describe('Unique identifier for the conversation'), roleWeights: z.object({ user: z.number().optional(), assistant: z.number().optional(), system: z.number().optional() }).optional().describe('Optional weights for different roles when extracting keywords (default: user=2.7, assistant=2.0, system=1.0)') }),
  • src/index.js:152-154 (registration)
    Static registration of short-term tools (including add_short_term_memory) into the toolRegistry for discovery via list_tools.
    // 注册所有短期记忆工具 const shortTermTools = createShortTermTools(defaultShortTermManager, defaultStorageManager); shortTermTools.forEach(tool => registerTool(tool, 'short-term'));
  • src/index.js:284-289 (registration)
    Dynamic recreation of conversation-specific short-term tools and invocation of the matching tool handler during call_tool requests.
    if (toolScope === 'short-term' || toolName.includes('short_term')) { manager = await getShortTermManager(conversationId); storage = getStorageManager(conversationId); const tools = createShortTermTools(manager, storage, queryCache); const tool = tools.find(t => t.name === toolName); result = await withTimeout(tool.handler(validatedArgs), timeout, `Tool ${toolName} timeout`);

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

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