move_file
Move or rename files and directories between locations using absolute paths for reliable file organization and management 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 processes the move_file tool call: validates input with MoveFileArgsSchema, calls the moveFile helper, and returns success/error response./** * Handle move_file command */ 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/server.ts:1260-1262 (registration)Dispatch registration in the main CallToolRequest handler: routes 'move_file' tool calls to handleMoveFile.case "move_file": result = await handlers.handleMoveFile(args); break;
- src/tools/schemas.ts:110-113 (schema)Zod schema defining input parameters for the move_file tool: source and destination paths.export const MoveFileArgsSchema = z.object({ source: z.string(), destination: z.string(), });
- src/tools/filesystem.ts:1001-1005 (helper)Core implementation: validates paths and performs fs.rename to move/rename the file.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:459-476 (registration)Tool metadata registration in ListToolsRequest handler: defines name, description, input schema (MoveFileArgsSchema), and annotations for the move_file tool.{ 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, }, },