Skip to main content
Glama

move_file

Move or rename files and directories within allowed paths using absolute paths for reliable operation. Simplify file management with a single action for both tasks.

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

NameRequiredDescriptionDefault
destinationYes
sourceYes

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "destination": { "type": "string" }, "source": { "type": "string" } }, "required": [ "source", "destination" ], "type": "object" }

Implementation Reference

  • The main handler function for the 'move_file' tool. It validates input arguments using MoveFileArgsSchema, calls the moveFile helper function, and returns a success message or error response.
    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); } }
  • Zod schema defining the input parameters for the move_file tool: source path and destination path.
    export const MoveFileArgsSchema = z.object({ source: z.string(), destination: z.string(), });
  • Core helper function that performs the actual file move operation using fs.rename after path validation.
    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); }

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/wonderwhy-er/DesktopCommanderMCP'

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