Skip to main content
Glama

restore_backup

Restore a file from its most recent backup (.bak) on the MCP SmallEdit server. Optionally keep the backup file after restoration for added security or reference.

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 the 'restore_backup' tool. It checks for a .bak backup file (or alternatives), creates a safety backup of the current file, restores the content from the backup to the original file, optionally removes 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 listTools 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).
    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'] }
  • Help documentation and usage examples for the 'restore_backup' tool.
    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 `,

Other Tools

Related 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