Skip to main content
Glama

backup_and_edit

Destructive

Create file backups before editing to prevent data loss. Safely modify files while preserving original versions for recovery.

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 handler for 'backup_and_edit' hybrid operation: creates file backups, executes nested edit operation, returns result with backup info or restores backups and rethrows on failure.
    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)
    Tool registration defining name, description, input schema, and annotations for 'backup_and_edit'.
    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 validation for 'backup_and_edit' tool: requires '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']
  • Helper function to create timestamped backup of a file, used by 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 function to restore a file from backup, used by backup_and_edit handler on failure.
    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}`);
      }
Behavior3/5

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

Annotations already indicate destructiveHint=true, readOnlyHint=false, etc., so the agent knows this is a non-idempotent, destructive write operation. The description adds value by specifying that backups are created before editing, which clarifies the safety mechanism beyond the annotations. However, it doesn't detail behavioral traits like error handling, backup location, or rollback options, which would be useful context.

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, clear sentence that efficiently conveys the core functionality without unnecessary words. It's front-loaded with the main action, making it easy for an agent to quickly understand the tool's purpose.

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

Completeness3/5

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

Given the complexity (destructive operation with backups) and lack of output schema, the description is minimally adequate. Annotations cover safety aspects, but the description could better explain the backup process or return values. It meets basic needs but leaves gaps in understanding the full workflow, such as how backups are managed or what happens on failure.

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 both parameters ('files' and 'operation'). The description implies that 'files' are backed up and edited, and 'operation' is performed, but doesn't add meaning beyond what the schema provides, such as examples of operations or file format constraints. Baseline 3 is appropriate when the schema handles most documentation.

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 tool's purpose with a specific verb ('Create backups') and resource ('files'), and distinguishes it from siblings like 'write_file' or 'interactive_edit_session' by emphasizing the backup aspect. However, it doesn't explicitly differentiate from 'smart_refactor' or 'complex_find_replace', which might also involve editing with safety measures.

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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites, such as needing write permissions, or compare it to siblings like 'write_file' (which might not create backups) or 'interactive_edit_session' (which might offer more control). This leaves the agent with minimal context for selection.

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

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