Skip to main content
Glama

backup_memories

Backup conversation memories to files with metadata and timestamps. Export short-term and long-term memories from Memory MCP Server for preservation and analysis.

Instructions

將指定對話的所有記憶備份到文件。支持導出短期和長期記憶,包含完整的元數據和時間戳。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
conversation_idYes對話 ID
output_pathNo輸出文件路徑(默認為 data/backups/)
include_short_termNo是否包含短期記憶
include_long_termNo是否包含長期記憶
compressNo是否壓縮(保留用於將來實現)

Implementation Reference

  • The async handler that implements the backup_memories tool logic: loads specified memories, creates timestamped JSON backup file in data/backups/, returns file path, memory counts, and size.
    async handler(args) {
      const { conversation_id, output_path, include_short_term, include_long_term } = args;
    
      try {
        const storage = getStorageManager(conversation_id);
        const backup = {
          version: '1.0',
          timestamp: new Date().toISOString(),
          conversation_id,
          short_term: null,
          long_term: null
        };
    
        let totalMemories = 0;
    
        // 加載短期記憶
        if (include_short_term) {
          const shortTerm = await storage.loadShortTermMemories();
          backup.short_term = shortTerm;
          totalMemories += shortTerm.length;
        }
    
        // 加載長期記憶
        if (include_long_term) {
          const longTerm = await storage.loadLongTermMemories();
          backup.long_term = longTerm;
          totalMemories += longTerm.length;
        }
    
        // 確定輸出路徑
        const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
        const defaultPath = path.join(__dirname, '../../data/backups');
        const backupDir = output_path || defaultPath;
    
        await fs.mkdir(backupDir, { recursive: true });
    
        const fileName = `backup_${conversation_id}_${timestamp}.json`;
        const filePath = path.join(backupDir, fileName);
    
        // 寫入備份文件
        const content = JSON.stringify(backup, null, 2);
        await fs.writeFile(filePath, content, 'utf-8');
    
        const sizeKB = (Buffer.byteLength(content, 'utf-8') / 1024).toFixed(2);
    
        return {
          success: true,
          backup_path: filePath,
          total_memories: totalMemories,
          short_term_count: backup.short_term?.length || 0,
          long_term_count: backup.long_term?.length || 0,
          size_kb: sizeKB,
          timestamp: backup.timestamp
        };
      } catch (error) {
        return {
          success: false,
          error: error.message
        };
      }
    }
  • Zod input schema for backup_memories tool parameters.
    inputSchema: z.object({
      conversation_id: z.string().describe('對話 ID'),
      output_path: z.string().optional().describe('輸出文件路徑(默認為 data/backups/)'),
      include_short_term: z.boolean().default(true).describe('是否包含短期記憶'),
      include_long_term: z.boolean().default(true).describe('是否包含長期記憶'),
      compress: z.boolean().default(false).describe('是否壓縮(保留用於將來實現)')
    }),
  • Tool definition pushed to the tools array returned by createBackupTools, including name, description, schema, and handler.
    tools.push({
      name: 'backup_memories',
      description: '將指定對話的所有記憶備份到文件。支持導出短期和長期記憶,包含完整的元數據和時間戳。',
      inputSchema: z.object({
        conversation_id: z.string().describe('對話 ID'),
        output_path: z.string().optional().describe('輸出文件路徑(默認為 data/backups/)'),
        include_short_term: z.boolean().default(true).describe('是否包含短期記憶'),
        include_long_term: z.boolean().default(true).describe('是否包含長期記憶'),
        compress: z.boolean().default(false).describe('是否壓縮(保留用於將來實現)')
      }),
      async handler(args) {
        const { conversation_id, output_path, include_short_term, include_long_term } = args;
    
        try {
          const storage = getStorageManager(conversation_id);
          const backup = {
            version: '1.0',
            timestamp: new Date().toISOString(),
            conversation_id,
            short_term: null,
            long_term: null
          };
    
          let totalMemories = 0;
    
          // 加載短期記憶
          if (include_short_term) {
            const shortTerm = await storage.loadShortTermMemories();
            backup.short_term = shortTerm;
            totalMemories += shortTerm.length;
          }
    
          // 加載長期記憶
          if (include_long_term) {
            const longTerm = await storage.loadLongTermMemories();
            backup.long_term = longTerm;
            totalMemories += longTerm.length;
          }
    
          // 確定輸出路徑
          const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
          const defaultPath = path.join(__dirname, '../../data/backups');
          const backupDir = output_path || defaultPath;
    
          await fs.mkdir(backupDir, { recursive: true });
    
          const fileName = `backup_${conversation_id}_${timestamp}.json`;
          const filePath = path.join(backupDir, fileName);
    
          // 寫入備份文件
          const content = JSON.stringify(backup, null, 2);
          await fs.writeFile(filePath, content, 'utf-8');
    
          const sizeKB = (Buffer.byteLength(content, 'utf-8') / 1024).toFixed(2);
    
          return {
            success: true,
            backup_path: filePath,
            total_memories: totalMemories,
            short_term_count: backup.short_term?.length || 0,
            long_term_count: backup.long_term?.length || 0,
            size_kb: sizeKB,
            timestamp: backup.timestamp
          };
        } catch (error) {
          return {
            success: false,
            error: error.message
          };
        }
      }
    });
  • src/index.js:161-162 (registration)
    Registers all backup tools (including backup_memories) from createBackupTools into the server's toolRegistry with 'backup' scope.
    const backupTools = createBackupTools(getShortTermManager, getLongTermManager, getStorageManager);
    backupTools.forEach(tool => registerTool(tool, 'backup'));
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It mentions the tool '支持導出短期和長期記憶,包含完整的元數據和時間戳' (supports exporting short-term and long-term memories, including complete metadata and timestamps), which adds some behavioral context about what gets exported. However, it doesn't disclose critical traits like whether this is a read-only operation, what permissions are needed, whether it overwrites existing files, or what the output format is (e.g., JSON, CSV). For a backup tool with zero annotation coverage, this leaves significant gaps.

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 a single, efficient sentence that front-loads the core purpose ('將指定對話的所有記憶備份到文件') and follows with supporting details about memory types and metadata. Every part earns its place with no redundant or vague language, making it highly concise and well-structured.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of a backup operation with 5 parameters, no annotations, and no output schema, the description is incomplete. It lacks information on behavioral aspects (e.g., file overwriting, permissions), output details (e.g., file format, success indicators), and usage constraints. While the schema covers parameters well, the description doesn't compensate for missing annotations or output schema, leaving the agent with insufficient context for safe and effective use.

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?

Schema description coverage is 100%, so the schema already documents all 5 parameters thoroughly. The description adds minimal value beyond the schema by mentioning '短期和長期記憶' (short-term and long-term memories), which aligns with the include_short_term and include_long_term parameters, but doesn't provide additional syntax, format, or usage details. This meets the baseline of 3 when the schema does the heavy lifting.

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 ('備份到文件' - backup to file) and resource ('指定對話的所有記憶' - all memories of a specified conversation). It distinguishes itself from sibling tools by focusing on backup/export functionality rather than memory manipulation, analysis, or retrieval operations found in tools like add_long_term_memory, analyze_memory_patterns, or list_backups.

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

Usage Guidelines3/5

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

The description implies usage context through '將指定對話的所有記憶備份到文件' (backup all memories of a specified conversation to a file), suggesting this tool is for creating backups rather than other memory operations. However, it doesn't explicitly state when to use this versus alternatives like list_backups (which likely lists existing backups) or restore_memories (which likely restores from backups), nor does it mention any prerequisites or exclusions.

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