Skip to main content
Glama

get_memory_stats

Retrieve statistical data about short-term memories to monitor usage patterns and analyze memory performance within conversations.

Instructions

Get statistical information about short-term memories.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
conversation_idNoOptional conversation ID for context

Implementation Reference

  • The MCP tool handler for get_memory_stats. Calls ShortTermMemoryManager.getStats() and formats date fields for output.
    handler: async (args) => { try { const stats = memoryManager.getStats(); return { ...stats, oldestMemory: stats.oldestMemory ? new Date(stats.oldestMemory).toISOString() : null, newestMemory: stats.newestMemory ? new Date(stats.newestMemory).toISOString() : null, lastCleanup: new Date(stats.lastCleanup).toISOString() }; } catch (error) { return { error: error.message }; }
  • Zod input schema for the tool, accepting an optional conversation_id.
    inputSchema: z.object({ conversation_id: z.string().optional().describe('Optional conversation ID for context') }),
  • src/index.js:152-154 (registration)
    Registers all short-term tools, including get_memory_stats, to the global toolRegistry using default managers for list_tools.
    // 注册所有短期记忆工具 const shortTermTools = createShortTermTools(defaultShortTermManager, defaultStorageManager); shortTermTools.forEach(tool => registerTool(tool, 'short-term'));
  • Core statistics computation in ShortTermMemoryManager.getStats(), aggregating memory counts, scores, timestamps, and conversation stats.
    getStats() { const now = Date.now(); const conversationCounts = {}; let totalScore = 0; let maxScore = -Infinity; let minScore = Infinity; for (const mem of this.memories) { conversationCounts[mem.conversation_id] = (conversationCounts[mem.conversation_id] || 0) + 1; totalScore += mem.score; maxScore = Math.max(maxScore, mem.score); minScore = Math.min(minScore, mem.score); } return { total: this.memories.length, conversationCounts, avgScore: this.memories.length > 0 ? totalScore / this.memories.length : 0, maxScore: this.memories.length > 0 ? maxScore : 0, minScore: this.memories.length > 0 ? minScore : 0, oldestMemory: this.memories.length > 0 ? Math.min(...this.memories.map(m => m.time_stamp.getTime())) : null, newestMemory: this.memories.length > 0 ? Math.max(...this.memories.map(m => m.time_stamp.getTime())) : null, lastCleanup: this.lastCleanupTime }; }
  • src/index.js:284-289 (registration)
    Dynamic recreation and execution of short-term tools (including get_memory_stats) with conversation-specific managers during tool call handling.
    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