Skip to main content
Glama

backup_and_edit

Create backups of files before making edits to ensure data safety and prevent loss during modification processes.

Instructions

Create backups of files before editing them

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filesYesList of files to backup and edit
operationYesThe edit operation to perform

Implementation Reference

  • Main execution handler for the 'backup_and_edit' tool. Creates backups of affected files using FileSystemManager, delegates the actual edit to the Edit executor, returns results with backup info, and restores backups if the edit fails.
    case 'backup_and_edit': // Create backups with file system const backups = await Promise.all( operation.affectedFiles.map(file => this.fileSystemManager.createBackup(file) ) ); try { // Use Edit for the edits const result = await this.executeWithEdit({ ...operation, type: operation.params.operation.type }); return { ...result, backups }; } catch (error) { // If edits fail, restore backups await Promise.all( operation.affectedFiles.map((file, index) => this.fileSystemManager.restoreBackup(backups[index], file) ) ); throw error; }
  • src/index.ts:365-388 (registration)
    Registers the 'backup_and_edit' tool with the MCP server in the registerHybridTools function, including name, description, input schema, and annotations.
    mcpServer.registerTool({ name: 'backup_and_edit', description: 'Create backups of files before editing them', inputSchema: { type: 'object', properties: { files: { type: 'array', description: 'List of files to backup and edit' }, operation: { type: 'object', description: 'The edit operation to perform' } }, required: ['files', 'operation'] }, annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: false } });
  • Input schema definition for the 'backup_and_edit' tool, specifying files array and operation object as required parameters.
    inputSchema: { type: 'object', properties: { files: { type: 'array', description: 'List of files to backup and edit' }, operation: { type: 'object', description: 'The edit operation to perform' } }, required: ['files', 'operation']
  • Helper method in FileSystemManager to create a timestamped backup file and track it in an internal map, used by the backup_and_edit handler.
    public async createBackup(filePath: string): Promise<string> { try { const content = await this.readFile(filePath); const backupPath = `${filePath}.backup.${Date.now()}`; await this.writeFile(backupPath, content); this.backups.set(filePath, backupPath); return backupPath; } catch (error: any) { throw new Error(`Failed to create backup of ${filePath}: ${error.message}`); }
  • Helper method to restore a backup file to the original path, used for rollback in case of edit failure in backup_and_edit.
    public async restoreBackup(backupPath: string, originalPath: string): Promise<void> { try { const content = await this.readFile(backupPath); await this.writeFile(originalPath, content); } catch (error: any) { throw new Error(`Failed to restore backup ${backupPath} to ${originalPath}: ${error.message}`); }

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/mixelpixx/microsoft-edit-mcp'

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