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`);
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It successfully warns about the destructive overwrite behavior ('這將覆蓋當前對話的所有記憶'), which is crucial for a mutation tool. However, it doesn't mention authentication requirements, rate limits, error conditions, or what happens when the backup file is invalid or missing.

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 perfectly concise with just two sentences. The first sentence states the core purpose, and the second provides a critical warning. Every word earns its place, and the warning is appropriately front-loaded for a destructive operation.

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?

For a mutation tool with no annotations and no output schema, the description does the minimum by stating the purpose and warning about destructive behavior. However, it doesn't explain what the tool returns (success/failure indicators), doesn't mention error conditions, and doesn't provide guidance on backup file format or location requirements. Given the complexity of a restore operation, more context would be helpful.

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?

The schema description coverage is 100%, providing complete documentation for all 5 parameters. The description doesn't add any parameter-specific information beyond what's already in the schema, so it meets the baseline of 3. It doesn't explain parameter interactions or provide usage examples.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('從備份文件還原記憶' - restore memories from backup files) and the resource (memories). It distinguishes itself from siblings like 'backup_memories' (which creates backups) and 'list_backups' (which lists available backups) by focusing on restoration from existing backups.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context about when to use this tool ('從備份文件還原記憶') and includes a warning about its destructive nature ('這將覆蓋當前對話的所有記憶' - this will overwrite all current conversation memories). However, it doesn't explicitly mention when NOT to use it or name specific alternatives like 'merge' operations (though the merge parameter is documented in the schema).

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

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