Skip to main content
Glama

restore_backup

Restore files from their most recent backup copies to recover previous versions or fix errors, with options to preserve backup files after restoration.

Instructions

Restore a file from its most recent backup (.bak)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fileYesFile to restore from backup
keepBackupNoKeep the backup file after restoring

Implementation Reference

  • The handler function for 'restore_backup' tool. It restores the specified file from its .bak backup (or alternatives), creates a .before-restore safety backup of the current file, writes the backup content back to the original file, optionally deletes the backup, and returns a success message.
    case 'restore_backup': {
      const { file, keepBackup = true } = args;
      
      const backupFile = `${file}.bak`;
      
      // Check if backup exists
      if (!existsSync(backupFile)) {
        // Look for other common backup patterns
        const alternatives = [
          `${file}~`,
          `${file}.backup`,
          `${file}.orig`
        ].filter(existsSync);
        
        if (alternatives.length > 0) {
          throw new Error(`No .bak file found, but found: ${alternatives.join(', ')}`);
        }
        throw new Error(`No backup file found for ${file}`);
      }
      
      // Read backup content
      const backupContent = await readFile(backupFile, 'utf-8');
      
      // Check if current file exists and create a safety backup
      if (existsSync(file)) {
        await writeFile(`${file}.before-restore`, await readFile(file, 'utf-8'));
      }
      
      // Restore the backup
      await writeFile(file, backupContent);
      
      // Remove backup if requested
      if (!keepBackup) {
        await execAsync(`rm -f '${backupFile}'`);
      }
      
      return {
        content: [{
          type: 'text',
          text: `Successfully restored ${file} from backup${!keepBackup ? ' (backup removed)' : ''}\nSafety backup created: ${file}.before-restore`
        }]
      };
    }
  • src/index.ts:227-245 (registration)
    Registration of the 'restore_backup' tool in the ListToolsRequestSchema handler, including name, description, and input schema.
    {
      name: 'restore_backup',
      description: 'Restore a file from its most recent backup (.bak)',
      inputSchema: {
        type: 'object',
        properties: {
          file: {
            type: 'string',
            description: 'File to restore from backup'
          },
          keepBackup: {
            type: 'boolean',
            default: true,
            description: 'Keep the backup file after restoring'
          }
        },
        required: ['file']
      }
    },
  • Input schema definition for the restore_backup tool, specifying parameters 'file' (required) and 'keepBackup' (optional boolean).
    type: 'object',
    properties: {
      file: {
        type: 'string',
        description: 'File to restore from backup'
      },
      keepBackup: {
        type: 'boolean',
        default: true,
        description: 'Keep the backup file after restoring'
      }
    },
    required: ['file']
  • Help text and usage examples for the restore_backup tool in the helpContent object.
      restore_backup: `restore_backup - Restore from backup
    =================================
    Restore a file from its .bak backup file.
    
    Examples:
      // Basic restore
      restore_backup({ file: "config.json" })
      // Looks for config.json.bak and restores it
      
      // Restore and remove backup
      restore_backup({ file: "data.txt", keepBackup: false })
      
      // After a bad edit
      sed_edit({ file: "app.js", pattern: "s/function/fungtion/g" }) // Oops!
      restore_backup({ file: "app.js" }) // Fixed!
    
    Safety features:
    - Creates .before-restore backup of current file
    - Checks for alternative backup formats (.backup, .orig, ~)
    - Clear error if no backup found
    `,
Behavior2/5

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

With no annotations, the description carries full burden but lacks behavioral details. It doesn't disclose if this is destructive (overwrites the original file), requires specific permissions, has side effects, or what happens on failure (e.g., if no backup exists).

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 with zero waste. It's front-loaded with the core action and resource, making it easy to parse quickly.

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?

For a mutation tool with no annotations and no output schema, the description is incomplete. It misses critical details like behavioral risks (e.g., data loss), error handling, and output expectations, leaving gaps for safe agent invocation.

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 parameters are documented in the schema. The description adds no additional meaning beyond implying '.bak' extension context, but doesn't clarify parameter interactions (e.g., how 'keepBackup' affects the restore process).

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

Purpose4/5

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

The description clearly states the action ('Restore') and resource ('a file from its most recent backup'), making the purpose understandable. However, it doesn't differentiate from sibling tools like 'list_backups' beyond the basic verb, missing explicit contrast.

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

Usage Guidelines2/5

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

No guidance is provided on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., requiring a backup to exist), exclusions, or comparisons to siblings like 'list_backups' for checking available backups first.

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/MikeyBeez/mcp-smalledit'

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