move_file
Move or rename files and directories across allowed paths. Fails if the destination already exists. Supports operations within or between directories.
Instructions
Move or rename files and directories. Can move files between directories and rename them in a single operation. If the destination exists, the operation will fail. Works across different directories and can be used for simple renaming within the same directory. Both source and destination must be within allowed directories.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| destination | Yes | Destination path where to move the file or directory | |
| source | Yes | Source path of the file or directory to move |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"destination": {
"description": "Destination path where to move the file or directory",
"type": "string"
},
"source": {
"description": "Source path of the file or directory to move",
"type": "string"
}
},
"required": [
"source",
"destination"
],
"type": "object"
}
Implementation Reference
- src/index.ts:577-604 (handler)Main execution logic for move_file tool: parses arguments, validates source and destination paths, ensures destination directory exists, renames/moves the file using fs.rename, logs the action, and returns success message.case 'move_file': { const parsed = MoveFileArgsSchema.safeParse(a) if (!parsed.success) { throw new FileSystemError(`Invalid arguments for ${name}`, 'INVALID_ARGS', undefined, { errors: parsed.error.format(), }) } const validSourcePath = await validatePath(parsed.data.source, config) const validDestPath = await validatePath(parsed.data.destination, config) // Ensure the destination parent directory exists const destDir = path.dirname(validDestPath) await fs.mkdir(destDir, { recursive: true }) await fs.rename(validSourcePath, validDestPath) await logger.debug(`Moved file from ${validSourcePath} to ${validDestPath}`) endMetric() return { content: [ { type: 'text', text: `Successfully moved ${parsed.data.source} to ${parsed.data.destination}`, }, ], } }
- src/index.ts:128-131 (schema)Zod schema defining input arguments for move_file: source and destination paths.const MoveFileArgsSchema = z.object({ source: z.string().describe('Source path of the file or directory to move'), destination: z.string().describe('Destination path where to move the file or directory'), })
- src/index.ts:297-305 (registration)Tool registration in the list_tools response, including name, description, and input schema reference.{ name: 'move_file', description: 'Move or rename files and directories. Can move files between directories ' + 'and rename them in a single operation. If the destination exists, the ' + 'operation will fail. Works across different directories and can be used ' + 'for simple renaming within the same directory. Both source and destination must be within allowed directories.', inputSchema: zodToJsonSchema(MoveFileArgsSchema) as ToolInput, },