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

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).

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "destination": { "description": "The new path for the file or directory (relative to the workspace directory).", "type": "string" }, "source": { "description": "The current path of the file or directory to move (relative to the workspace directory).", "type": "string" } }, "required": [ "source", "destination" ], "type": "object" }

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";

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