Skip to main content
Glama

move

Relocate files between locations with safety validations and directory restrictions to prevent unintended overwrites.

Instructions

Move files with safety checks and current directory restrictions

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fromYesSource file path (required)
toYesDestination file path (required)
overwriteNoAllow overwriting existing files (default: false)

Implementation Reference

  • Core handler function executing the move tool logic: validates input with Zod, performs security and boundary checks, ensures directories, handles overwrite logic, and executes file rename (with fallback copy+delete for cross-device).
    async execute(args: any): Promise<any> {
      try {
        // Validate and parse input using Zod schema
        const validatedArgs = MoveToolInputSchema.parse(args);
        const { from: fromPath, to: toPath, overwrite } = validatedArgs;
        // Resolve absolute paths
        const fromResolved = resolve(fromPath);
        const toResolved = resolve(toPath);
    
        // Security checks
        this.validateCurrentDirectoryBounds(fromResolved, toResolved);
    
        if (PathSecurity.isDangerousFile(fromPath) || PathSecurity.isDangerousFile(toPath)) {
          throw new Error(
            `Security protection: Cannot operate on dangerous files (${fromPath} → ${toPath})`
          );
        }
    
        if (
          (await PathSecurity.isIgnoredByGit(fromResolved)) ||
          (await PathSecurity.isIgnoredByGit(toResolved))
        ) {
          throw new Error(
            `gitignore protection: Cannot operate on ignored files (${fromPath} → ${toPath})`
          );
        }
    
        // Check if source exists
        try {
          await access(fromResolved);
        } catch {
          throw new Error(`Source file not found: ${fromPath}`);
        }
    
        // Check if destination exists
        const destinationExists = await this.checkDestinationExists(toResolved);
    
        // Smart dryRun control
        if (destinationExists && !overwrite) {
          const destStats = await stat(toResolved);
          const destSize = Math.round((destStats.size / 1024) * 100) / 100;
    
          throw new Error(
            `Destination already exists: ${toPath} (${destSize}KB, modified ${destStats.mtime.toISOString().split("T")[0]}). Move operation would overwrite this file. Use overwrite=true to force overwrite or choose a different destination path.`
          );
        }
    
        // Ensure destination directory exists
        await this.ensureDestinationDirectory(toResolved);
    
        // Perform move operation
        await this.performMove(fromResolved, toResolved);
    
        const message = destinationExists
          ? `✅ Successfully moved (overwrote existing): ${fromPath} → ${toPath}`
          : `✅ Successfully moved: ${fromPath} → ${toPath}`;
        return ResultFormatter.createResponse(message);
      } catch (error: any) {
        // Handle Zod validation errors
        if (error instanceof Error && error.name === "ZodError") {
          throw ToolError.createValidationError("input", args, `Invalid input: ${error.message}`);
        }
        throw ToolError.wrapError("Move operation", error);
      }
    }
  • Zod schema defining input parameters for the move tool: from (source path), to (destination path), overwrite (boolean flag). Used in execute for validation.
    // Move tool input schema
    export const MoveToolInputSchema = z.object({
      from: FilePathSchema,
      to: FilePathSchema,
      overwrite: BooleanFlagSchema,
    });
  • Tool definition for MCP protocol, including the JSON inputSchema matching the Zod schema.
    getDefinition(): Tool {
      return {
        name: "move",
        description: "Move files with safety checks and current directory restrictions",
        inputSchema: {
          type: "object",
          properties: {
            from: {
              type: "string",
              description: "Source file path (required)",
            },
            to: {
              type: "string",
              description: "Destination file path (required)",
            },
            overwrite: {
              type: "boolean",
              description: "Allow overwriting existing files (default: false)",
              default: false,
            },
          },
          required: ["from", "to"],
        },
      };
    }
  • Registration of the move tool's definition in the listTools response via getTools().
    protected getTools(): Tool[] {
      return [
        this.readTool.getDefinition(),
        this.findTool.getDefinition(),
        this.grepTool.getDefinition(),
        this.writeTool.getDefinition(),
        this.editTool.getDefinition(),
        this.moveTool.getDefinition(),
        this.copyTool.getDefinition(),
      ];
    }
  • Tool dispatch in handleToolCall: routes 'move' calls to MoveTool.execute.
    case "move":
      return await this.moveTool.execute(args);
Behavior3/5

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

With no annotations provided, the description carries the full burden. It adds some behavioral context ('safety checks', 'current directory restrictions'), which hints at constraints and validation, but doesn't detail what these checks entail, error conditions, or mutation effects. More specifics on permissions or side effects would improve transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core action ('Move files') and adds qualifying details. It avoids redundancy and wastes no words, though it could be slightly more structured for clarity.

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 no annotations and no output schema, the description is moderately complete for a mutation tool with full schema coverage. It covers the basic action and hints at constraints, but lacks details on return values, error handling, or deeper behavioral traits, leaving gaps for an AI agent.

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 all parameters thoroughly. The description doesn't add any meaning beyond what the schema provides, such as explaining path formats or overwrite implications. Baseline 3 is appropriate when 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 verb ('Move') and resource ('files'), making the purpose evident. However, it doesn't distinguish this tool from its sibling 'copy', which also handles file operations, leaving room for ambiguity in sibling differentiation.

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 mentions 'safety checks and current directory restrictions', which implies some usage context, but it doesn't explicitly state when to use 'move' versus alternatives like 'copy' or 'write'. No guidance on prerequisites or exclusions is provided.

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/d-issy/mcp'

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