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
| Name | Required | Description | Default |
|---|---|---|---|
| destination | Yes | The new path for the file or directory (relative to the workspace directory). | |
| source | Yes | The 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
- src/index.ts:482-492 (handler)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;
- src/tools/move_file.ts:7-10 (schema)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)."), });
- src/tools/move_file.ts:15-41 (registration)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 };
- src/tools/index.ts:54-55 (registration)Includes moveFileTool in the allTools array, which is used by the MCP server for tool listing and dispatching.directoryTreeTool, moveFileTool,
- src/tools/index.ts:15-15 (registration)Imports the moveFileTool definition for inclusion in allTools.import { moveFileTool } from "./move_file.js";