Skip to main content
Glama

copy

Copy files while preserving metadata and performing safety checks to prevent data loss.

Instructions

Copy files with metadata preservation and safety checks

Input Schema

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

Implementation Reference

  • The main handler function that executes the copy tool logic, including input validation with Zod, security checks for paths and gitignore, existence checks, directory creation, and file copy with metadata preservation using node:fs/promises copyFile, utimes, and chmod.
    async execute(args: any): Promise<any> {
      try {
        // Validate and parse input using Zod schema
        const validatedArgs = CopyToolInputSchema.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]}). Copy 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 copy operation
        await this.performCopy(fromResolved, toResolved);
    
        const message = destinationExists
          ? `✅ Successfully copied (overwrote existing): ${fromPath} → ${toPath}`
          : `✅ Successfully copied: ${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("Copy operation", error);
      }
    }
  • MCP tool definition including name, description, and JSON input schema for the copy tool.
    getDefinition(): Tool {
      return {
        name: "copy",
        description: "Copy files with metadata preservation and safety checks",
        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"],
        },
      };
    }
  • Tool dispatch registration in the handleToolCall switch statement, routing 'copy' calls to CopyTool.execute.
    case "copy":
      return await this.copyTool.execute(args);
  • Instantiation of CopyTool instance in FileMCPServer constructor.
    this.copyTool = new CopyTool();
  • Zod schema used internally for input validation in CopyTool.execute.
    // Copy tool input schema
    export const CopyToolInputSchema = z.object({
      from: FilePathSchema,
      to: FilePathSchema,
      overwrite: BooleanFlagSchema,
    });
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 of behavioral disclosure. It adds some context beyond basic copying by mentioning metadata preservation and safety checks, but it lacks details on error handling, performance, permissions, or what specific safety checks are involved. This is a minimal but not comprehensive disclosure for a mutation tool.

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 that front-loads the core action ('Copy files') and adds two key qualifiers ('with metadata preservation and safety checks'). There's no wasted language, making it highly concise and well-structured for quick comprehension.

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 tool's moderate complexity (a mutation operation with 3 parameters) and no annotations or output schema, the description is minimally adequate. It covers the basic purpose and hints at behavior but lacks details on outcomes, errors, or integration with siblings, leaving gaps for the agent to navigate.

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?

The input schema has 100% description coverage, clearly documenting all three parameters. The description doesn't add any parameter-specific details beyond what the schema provides, such as path formats or examples. Since the schema does the heavy lifting, the baseline score of 3 is appropriate.

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 ('Copy') and resource ('files'), and it adds meaningful context about metadata preservation and safety checks. However, it doesn't explicitly differentiate from sibling tools like 'move' or 'write', which would require more specific comparison.

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 like 'move' (which might relocate instead of copy) or 'write' (which might create new content). There's no mention of prerequisites, typical use cases, or exclusions, leaving the agent to infer usage from context alone.

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