backup_and_edit
Create backups of files before editing them to prevent data loss. Specify files and edit operations to safely modify content.
Instructions
Create backups of files before editing them
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| files | Yes | List of files to backup and edit | |
| operation | Yes | The edit operation to perform |
Implementation Reference
- src/router/operation-router.ts:551-579 (handler)Main execution logic for the 'backup_and_edit' tool. Backs up files using FileSystemManager, delegates editing to EditInstanceManager via executeWithEdit, includes backup info in response, and restores files from backups if editing 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, defining its name, description, input schema, and operational 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 } });
- src/index.ts:368-388 (schema)Input schema definition for the 'backup_and_edit' tool, specifying required 'files' array and 'operation' object.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 } });