move_file
Move or rename files and directories by specifying source and destination paths. Use absolute paths for reliable file system operations.
Instructions
Move or rename files and directories.
Can move files between directories and rename them in a single operation.
Both source and destination must be within allowed directories.
IMPORTANT: Always use absolute paths for reliability. Paths are automatically normalized regardless of slash direction. Relative paths may fail as they depend on the current working directory. Tilde paths (~/...) might not work in all contexts. Unless the user explicitly asks for relative paths, use absolute paths.
This command can be referenced as "DC: ..." or "use Desktop Commander to ..." in your instructions.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| source | Yes | ||
| destination | Yes |
Implementation Reference
- Handler function that parses arguments using MoveFileArgsSchema, calls the moveFile helper with source and destination paths, and returns a success or error message.export async function handleMoveFile(args: unknown): Promise<ServerResult> { try { const parsed = MoveFileArgsSchema.parse(args); await moveFile(parsed.source, parsed.destination); return { content: [{ type: "text", text: `Successfully moved ${parsed.source} to ${parsed.destination}` }], }; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); return createErrorResponse(errorMessage); } }
- src/tools/schemas.ts:115-118 (schema)Zod schema defining input parameters: source and destination as strings.export const MoveFileArgsSchema = z.object({ source: z.string(), destination: z.string(), });
- src/server.ts:476-492 (registration)MCP tool registration in list_tools handler: defines name 'move_file', description, input schema from MoveFileArgsSchema, and annotations.name: "move_file", description: ` Move or rename files and directories. Can move files between directories and rename them in a single operation. Both source and destination must be within allowed directories. ${PATH_GUIDANCE} ${CMD_PREFIX_DESCRIPTION}`, inputSchema: zodToJsonSchema(MoveFileArgsSchema), annotations: { title: "Move/Rename File", readOnlyHint: false, destructiveHint: true, openWorldHint: false, }, },
- src/tools/filesystem.ts:620-624 (helper)Core filesystem move implementation: validates both paths and performs fs.rename.export async function moveFile(sourcePath: string, destinationPath: string): Promise<void> { const validSourcePath = await validatePath(sourcePath); const validDestPath = await validatePath(destinationPath); await fs.rename(validSourcePath, validDestPath); }
- src/server.ts:1298-1300 (registration)Dispatcher in call_tool handler that routes 'move_file' calls to handleMoveFile.case "move_file": result = await handlers.handleMoveFile(args); break;