Skip to main content
Glama

restore_memories

Recover conversation memories from backup files to restore previous context and information, with options to selectively restore short-term or long-term memory data.

Instructions

從備份文件還原記憶。警告:這將覆蓋當前對話的所有記憶。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
conversation_idYes目標對話 ID
backup_pathYes備份文件路徑
restore_short_termNo是否還原短期記憶
restore_long_termNo是否還原長期記憶
mergeNo是否合併而非覆蓋(保留現有記憶)

Implementation Reference

  • The main handler function for the 'restore_memories' tool. Reads a backup file, validates it, and restores short-term and/or long-term memories to the specified conversation, with options for merge or overwrite.
    async handler(args) { const { conversation_id, backup_path, restore_short_term, restore_long_term, merge } = args; try { // 讀取備份文件 const content = await fs.readFile(backup_path, 'utf-8'); const backup = JSON.parse(content); // 驗證備份格式 if (!backup.version || !backup.timestamp) { return { success: false, error: 'Invalid backup file format' }; } const storage = getStorageManager(conversation_id); let restored = 0; // 還原短期記憶 if (restore_short_term && backup.short_term) { if (merge) { const existing = await storage.loadShortTermMemories(); const merged = [...existing, ...backup.short_term]; await storage.saveShortTermMemories(merged); restored += backup.short_term.length; } else { await storage.saveShortTermMemories(backup.short_term); restored += backup.short_term.length; } // 重新加載管理器 const manager = await getShortTermManager(conversation_id); const memories = await storage.loadShortTermMemories(); manager.loadMemories(memories); } // 還原長期記憶 if (restore_long_term && backup.long_term) { if (merge) { const existing = await storage.loadLongTermMemories(); const merged = [...existing, ...backup.long_term]; await storage.saveLongTermMemories(merged); restored += backup.long_term.length; } else { await storage.saveLongTermMemories(backup.long_term); restored += backup.long_term.length; } // 重新加載管理器 const manager = await getLongTermManager(conversation_id); const memories = await storage.loadLongTermMemories(); manager.loadMemories(memories); } return { success: true, conversation_id, restored_memories: restored, backup_timestamp: backup.timestamp, mode: merge ? 'merge' : 'overwrite' }; } catch (error) { return { success: false, error: error.message }; } }
  • Zod schema defining the input parameters for the restore_memories tool.
    inputSchema: z.object({ conversation_id: z.string().describe('目標對話 ID'), backup_path: z.string().describe('備份文件路徑'), restore_short_term: z.boolean().default(true).describe('是否還原短期記憶'), restore_long_term: z.boolean().default(true).describe('是否還原長期記憶'), merge: z.boolean().default(false).describe('是否合併而非覆蓋(保留現有記憶)')
  • src/index.js:161-162 (registration)
    Initial registration of backup tools (including restore_memories) to the toolRegistry with 'backup' scope.
    const backupTools = createBackupTools(getShortTermManager, getLongTermManager, getStorageManager); backupTools.forEach(tool => registerTool(tool, 'backup'));
  • src/index.js:297-299 (registration)
    Dynamic recreation and execution of backup tools during tool call handling for 'backup' scope tools.
    const tools = createBackupTools(getShortTermManager, getLongTermManager, getStorageManager); const tool = tools.find(t => t.name === toolName); result = await withTimeout(tool.handler(validatedArgs), TIMEOUT_CONFIG.BACKUP, `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