Skip to main content
Glama

move_file

Move or rename files and directories by specifying source and destination paths, with optional overwrite capability for existing items.

Instructions

Move or rename a file or directory

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sourceYesSource path
destinationYesDestination path
overwriteNoOverwrite if exists

Implementation Reference

  • The handler function that executes the logic for the `move_file` tool.
    async function moveFileImpl(input: MoveFileInput): Promise<ToolResult> {
      try {
        const srcPath = path.resolve(input.source);
        const destPath = path.resolve(input.destination);
    
        // Check if source exists
        await fs.stat(srcPath);
    
        // Check if destination exists
        let destExists = false;
        try {
          await fs.access(destPath);
          destExists = true;
        } catch {
          // Destination doesn't exist
        }
    
        if (destExists && !input.overwrite) {
          return {
            isError: true,
            content: [
              {
                type: 'text',
                text: JSON.stringify({
                  code: 'ALREADY_EXISTS',
                  message: `Destination already exists and overwrite is false: ${input.destination}`,
                }),
              },
            ],
          };
        }
    
        // Ensure parent directory exists
        await fs.mkdir(path.dirname(destPath), { recursive: true });
    
        // Move/rename
        await fs.rename(srcPath, destPath);
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify({
                success: true,
                source: srcPath,
                destination: destPath,
              }),
            },
          ],
        };
      } catch (error) {
        const err = error as NodeJS.ErrnoException;
    
        if (err.code === 'ENOENT') {
          return {
            isError: true,
            content: [
              {
                type: 'text',
                text: JSON.stringify({
                  code: 'FILE_NOT_FOUND',
                  message: `Source not found: ${input.source}`,
                }),
              },
            ],
          };
        }
    
        if (err.code === 'EACCES') {
          return {
            isError: true,
            content: [
              {
                type: 'text',
                text: JSON.stringify({
                  code: 'PERMISSION_DENIED',
                  message: `Permission denied`,
                }),
              },
            ],
          };
        }
    
        return {
          isError: true,
          content: [
            {
              type: 'text',
              text: JSON.stringify({
                code: 'UNKNOWN_ERROR',
                message: `Error moving: ${err.message}`,
              }),
            },
          ],
        };
      }
    }
  • Input schema and type definitions for the `move_file` tool.
    export const MoveFileInputSchema = z.object({
      source: z.string().describe('Source path'),
      destination: z.string().describe('Destination path'),
      overwrite: z.boolean().default(false).describe('Overwrite if exists'),
    });
    
    export type MoveFileInput = z.infer<typeof MoveFileInputSchema>;
  • Registration of the `move_file` tool with the MCP server.
    // move_file tool
    server.tool(
      'move_file',
      'Move or rename a file or directory',
      {
        source: z.string().describe('Source path'),
        destination: z.string().describe('Destination path'),
        overwrite: z.boolean().optional().describe('Overwrite if exists'),
      },
      async (args) => {
        const input = MoveFileInputSchema.parse(args);
        return await moveFileImpl(input);
      }
    );
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 'move or rename' but doesn't disclose critical behavioral traits like whether it requires write permissions, if it's destructive (overwrites by default or not), error handling for missing sources, or what happens on success/failure. The 'overwrite' parameter hints at potential data loss, but this isn't explicitly warned in the description.

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 with zero wasted words. It's front-loaded with the core action and resource, making it easy to scan and understand quickly.

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?

For a mutation tool with no annotations and no output schema, the description is incomplete. It lacks information on permissions, error conditions, return values (e.g., success confirmation or error details), and how it differs from similar tools like 'copy_file'. Given the complexity of file operations, more context is needed for safe and effective use.

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 (source, destination, overwrite) clearly. The description adds no additional meaning beyond what's in the schema, such as path format examples or rename-specific usage. Baseline 3 is appropriate when the schema handles parameter documentation adequately.

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 action ('move or rename') and the resource ('a file or directory'), making the purpose immediately understandable. It doesn't explicitly differentiate from sibling tools like 'copy_file' or 'rename_file' (if present), but the verb 'move' inherently implies relocation rather than duplication or simple name change.

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 'copy_file' or 'rename_file' (if applicable), nor does it mention prerequisites such as file existence or permissions. It simply states what the tool does without contextual usage instructions.

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/mcp-tool-shop-org/mcp-file-forge'

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