Skip to main content
Glama
PWalaGov

Enhanced Directory Context MCP Server

by PWalaGov

batch_file_operations

Execute multiple file operations like create, update, delete, or rename in a single transaction with rollback capability for error handling.

Instructions

Perform multiple file operations in a single transaction

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
operationsYesArray of file operations to perform
rollback_on_errorNoRollback all operations if any fails

Implementation Reference

  • Core handler function for 'batch_file_operations' tool. Executes multiple file operations sequentially, tracks performed actions for potential rollback, returns JSON summary of results.
    async handleBatchFileOperations(args) {
      const { operations, rollback_on_error = true } = args;
      const results = [];
      const performedOperations = [];
      
      try {
        for (const op of operations) {
          const { operation, params } = op;
          
          try {
            let result;
            switch (operation) {
              case 'create':
                result = await this.handleCreateFile(params);
                performedOperations.push({ type: 'create', path: params.path });
                break;
              
              case 'update':
                result = await this.handleUpdateFile({ ...params, backup: false });
                performedOperations.push({ type: 'update', path: params.path, backupPath: `${params.path}.batch-backup` });
                break;
              
              case 'append':
                result = await this.handleAppendToFile(params);
                performedOperations.push({ type: 'append', path: params.path });
                break;
              
              case 'delete':
                result = await this.handleDeleteFile({ ...params, backup: false });
                performedOperations.push({ type: 'delete', path: params.path });
                break;
              
              case 'rename':
                result = await this.handleRenameFile(params);
                performedOperations.push({ type: 'rename', oldPath: params.old_path, newPath: params.new_path });
                break;
              
              default:
                throw new Error(`Unknown operation: ${operation}`);
            }
            
            results.push({
              operation,
              status: 'success',
              message: result.content[0].text,
            });
          } catch (error) {
            results.push({
              operation,
              status: 'error',
              message: error.message,
            });
            
            if (rollback_on_error) {
              // Rollback performed operations
              await this.rollbackOperations(performedOperations);
              throw new Error(`Batch operation failed at step ${results.length}. All changes rolled back. Error: ${error.message}`);
            }
          }
        }
        
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify({
                summary: `Batch operations completed: ${results.filter(r => r.status === 'success').length}/${operations.length} successful`,
                results,
              }, null, 2),
            },
          ],
        };
      } catch (error) {
        throw new McpError(ErrorCode.InternalError, `Batch operations failed: ${error.message}`);
      }
    }
  • Input schema defining the structure for batch_file_operations arguments: array of operations (each with type and params) and optional rollback flag.
    inputSchema: {
      type: 'object',
      properties: {
        operations: {
          type: 'array',
          description: 'Array of file operations to perform',
          items: {
            type: 'object',
            properties: {
              operation: {
                type: 'string',
                enum: ['create', 'update', 'append', 'delete', 'rename'],
                description: 'Type of operation',
              },
              params: {
                type: 'object',
                description: 'Parameters for the operation',
              },
            },
            required: ['operation', 'params'],
          },
        },
        rollback_on_error: {
          type: 'boolean',
          description: 'Rollback all operations if any fails',
          default: true,
        },
      },
      required: ['operations'],
    },
  • server.js:337-370 (registration)
    Tool registration in ListToolsRequestSchema handler, defining name, description, and inputSchema for batch_file_operations.
    {
      name: 'batch_file_operations',
      description: 'Perform multiple file operations in a single transaction',
      inputSchema: {
        type: 'object',
        properties: {
          operations: {
            type: 'array',
            description: 'Array of file operations to perform',
            items: {
              type: 'object',
              properties: {
                operation: {
                  type: 'string',
                  enum: ['create', 'update', 'append', 'delete', 'rename'],
                  description: 'Type of operation',
                },
                params: {
                  type: 'object',
                  description: 'Parameters for the operation',
                },
              },
              required: ['operation', 'params'],
            },
          },
          rollback_on_error: {
            type: 'boolean',
            description: 'Rollback all operations if any fails',
            default: true,
          },
        },
        required: ['operations'],
      },
    },
  • server.js:491-492 (registration)
    Dispatch case in CallToolRequestSchema handler that routes calls to batch_file_operations to the handleBatchFileOperations method.
    case 'batch_file_operations':
      return await this.handleBatchFileOperations(args);
  • Supporting helper method called by the handler to rollback operations in reverse order if an error occurs and rollback is enabled.
    async rollbackOperations(operations) {
      // Rollback in reverse order
      for (let i = operations.length - 1; i >= 0; i--) {
        const op = operations[i];
        try {
          switch (op.type) {
            case 'create':
              await fs.unlink(path.resolve(this.workingDirectory, op.path));
              break;
            
            case 'update':
              if (op.backupPath) {
                const fullPath = path.resolve(this.workingDirectory, op.path);
                const backupPath = path.resolve(this.workingDirectory, op.backupPath);
                await fs.copyFile(backupPath, fullPath);
                await fs.unlink(backupPath);
              }
              break;
            
            case 'rename':
              await fs.rename(
                path.resolve(this.workingDirectory, op.newPath),
                path.resolve(this.workingDirectory, op.oldPath)
              );
              break;
            
            // append and delete are harder to rollback without backups
          }
        } catch (error) {
          console.error(`Failed to rollback operation:`, op, error);
        }
      }
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It mentions transactional behavior ('single transaction') and implies atomicity with rollback, but doesn't disclose critical details like whether operations are executed in order, what happens on partial failures, authentication requirements, rate limits, or error handling. For a batch mutation tool with zero annotation coverage, this is a significant gap in behavioral 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, efficient sentence: 'Perform multiple file operations in a single transaction.' It is front-loaded with the core purpose, has zero wasted words, and appropriately sized for the tool's complexity, earning its place clearly.

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?

Given the tool's complexity (batch mutations with transactional behavior), lack of annotations, and no output schema, the description is incomplete. It doesn't explain return values, error cases, or detailed behavioral traits needed for safe invocation. The description should do more to compensate for the missing structured data, especially for a mutation tool.

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 (operations and rollback_on_error) with good detail. The description adds no additional parameter semantics beyond implying batching and transactionality, which is partially covered by the schema's rollback description. Baseline 3 is appropriate as the schema does the heavy lifting.

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: 'Perform multiple file operations in a single transaction.' It specifies the verb ('perform') and resource ('file operations'), and the transactional aspect distinguishes it from single-operation siblings like create_file or delete_file. However, it doesn't explicitly differentiate from all siblings (e.g., batch vs. individual operations could be more clearly contrasted).

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

Usage Guidelines3/5

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

The description implies usage context through 'multiple file operations in a single transaction,' suggesting it should be used when batching operations for atomicity. However, it doesn't explicitly state when to use this tool versus alternatives (e.g., using individual tools like create_file for single operations) or mention any prerequisites or exclusions, leaving some ambiguity for the agent.

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/PWalaGov/File-Control-MCP'

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