Skip to main content
Glama

move_file_or_directory

Move or rename files and directories within the workspace filesystem. Transfer items between directories or rename them in a single operation, with OS-dependent behavior for existing destination paths.

Instructions

Move or rename files and directories within the workspace filesystem. Can move items between directories and rename them in a single operation. If the destination path already exists, the operation will likely fail (OS-dependent).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
destinationYesThe new path for the file or directory (relative to the workspace directory).
sourceYesThe current path of the file or directory to move (relative to the workspace directory).

Implementation Reference

  • The main handler logic for the 'move_file_or_directory' tool. Parses arguments using the schema, validates source != destination, sanitizes paths with validateWorkspacePath, ensures destination directory exists, performs fs.rename, and sets success message.
    case "move_file_or_directory": {
      const parsed = MoveFileArgsSchema.parse(args);
       if (parsed.source === parsed.destination) {
         throw new McpError(ErrorCode.InvalidParams, `Source and destination paths cannot be the same for ${toolName}.`);
       }
      const validSourcePath = validateWorkspacePath(parsed.source);
      const validDestPath = validateWorkspacePath(parsed.destination);
      await fs.mkdir(path.dirname(validDestPath), { recursive: true });
      await fs.rename(validSourcePath, validDestPath);
      resultText = `Successfully moved ${parsed.source} to ${parsed.destination}`;
      break;
  • Zod schema defining the input parameters for the tool: source and destination paths as strings.
    export const MoveFileArgsSchema = z.object({
      source: z.string().describe("The current path of the file or directory to move (relative to the workspace directory)."),
      destination: z.string().describe("The new path for the file or directory (relative to the workspace directory)."),
    });
  • ToolDefinition export for 'move_file_or_directory', including name, description, inputSchema reference, and a minimal buildPrompt for validation (bypassed for filesystem tools).
    export const moveFileTool: ToolDefinition = {
        name: "move_file_or_directory", // Renamed slightly
        description:
          "Move or rename files and directories within the workspace filesystem. " +
          "Can move items between directories and rename them in a single operation. " +
          "If the destination path already exists, the operation will likely fail (OS-dependent).",
        inputSchema: MoveFileJsonSchema as any, // Cast as any if needed
    
        // Minimal buildPrompt as execution logic is separate
        buildPrompt: (args: any, modelId: string) => {
            const parsed = MoveFileArgsSchema.safeParse(args);
            if (!parsed.success) {
                throw new McpError(ErrorCode.InvalidParams, `Invalid arguments for move_file_or_directory: ${parsed.error}`);
            }
            // Add check: source and destination cannot be the same
            if (parsed.data.source === parsed.data.destination) {
                 throw new McpError(ErrorCode.InvalidParams, `Invalid arguments for move_file_or_directory: source and destination paths cannot be the same.`);
            }
            return {
                systemInstructionText: "",
                userQueryText: "",
                useWebSearch: false,
                enableFunctionCalling: false
            };
        },
        // No 'execute' function here
    };
  • Includes moveFileTool in the allTools array, which is used by the MCP server for tool listing and dispatching.
    directoryTreeTool,
    moveFileTool,
  • Imports the moveFileTool definition for inclusion in allTools.
    import { moveFileTool } from "./move_file.js";
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 usefully adds context about the operation potentially failing if the destination exists (OS-dependent), which is valuable beyond basic function. However, it lacks details on permissions needed, whether the operation is reversible, or what happens on failure beyond 'likely fail'.

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 efficiently structured in three sentences: first states the core function, second elaborates on capabilities, third provides important behavioral caveat. Every sentence adds value with zero wasted words, making it easy to parse.

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

Completeness4/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 does well by covering the core function, dual capability, and a key failure scenario. However, it could be more complete by mentioning permissions, return values, or error handling specifics, given the tool's potential for destructive changes.

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 both parameters (source and destination). The description adds no additional parameter semantics beyond what the schema provides, such as path format examples or constraints. Baseline 3 is appropriate when the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Move or rename files and directories') and the resource ('within the workspace filesystem'), distinguishing it from sibling tools like create_directory, edit_file_content, and list_directory_contents. It explicitly mentions the dual functionality of moving between directories and renaming in one operation.

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

Usage Guidelines4/5

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

The description provides clear context for when to use this tool (moving/renaming files/directories) and implicitly distinguishes it from tools like create_directory (for creation) or edit_file_content (for content modification). However, it does not explicitly state when NOT to use it or name specific alternatives for edge cases.

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

Related 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/shariqriazz/vertex-ai-mcp-server'

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