copy_file
Duplicate files by specifying source and destination paths to organize or back up data within the ACF environment.
Instructions
Copy file
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| source | Yes | ||
| destination | Yes |
Implementation Reference
- src/filesystem_tools.js:476-540 (handler)Actual implementation of the copy_file tool. Copies a file or directory recursively, with path validation, existence checks, and error handling.
function copyFile(sourcePath, destinationPath, allowedDirs) { try { if (!sourcePath) { return { success: false, message: 'No source path provided' }; } if (!destinationPath) { return { success: false, message: 'No destination path provided' }; } if (!isPathAllowed(sourcePath, allowedDirs) || !isPathAllowed(destinationPath, allowedDirs)) { return { success: false, message: 'Access to source or destination path is not allowed' }; } const resolvedSourcePath = path.resolve(sourcePath); const resolvedDestPath = path.resolve(destinationPath); // Check if source exists if (!fs.existsSync(resolvedSourcePath)) { return { success: false, message: `Source not found: ${sourcePath}` }; } // Check if source is a directory or file const stats = fs.statSync(resolvedSourcePath); if (stats.isDirectory()) { // Create destination directory if it doesn't exist if (!fs.existsSync(resolvedDestPath)) { fs.mkdirSync(resolvedDestPath, { recursive: true }); } // Copy directory contents recursively const items = fs.readdirSync(resolvedSourcePath); for (const item of items) { const srcItemPath = path.join(resolvedSourcePath, item); const destItemPath = path.join(resolvedDestPath, item); if (fs.statSync(srcItemPath).isDirectory()) { // Recursive call for subdirectories copyFile(srcItemPath, destItemPath, allowedDirs); } else { // Copy file fs.copyFileSync(srcItemPath, destItemPath); } } } else { // Ensure destination directory exists const destDir = path.dirname(resolvedDestPath); if (!fs.existsSync(destDir)) { fs.mkdirSync(destDir, { recursive: true }); } // Copy file fs.copyFileSync(resolvedSourcePath, resolvedDestPath); } return { success: true, message: `Successfully copied ${sourcePath} to ${destinationPath}`, source: sourcePath, destination: destinationPath, type: stats.isDirectory() ? 'directory' : 'file' }; } catch (error) { logger.error(`Error copying file: ${error.message}`); return { success: false, message: `Error copying file: ${error.message}` }; } - src/mcp/server.js:84-84 (schema)Input schema for copy_file tool registration: defines 'source' and 'destination' as required string properties.
{ name:'copy_file', description:'Copy file'+(readonlyMode?' (RO)':''), inputSchema:{ type:'object', properties:{ source:{type:'string'}, destination:{type:'string'} }, required:['source','destination'] } }, - src/mcp/server.js:84-84 (registration)Registration of copy_file tool in the tools/list handler, including description and input schema.
{ name:'copy_file', description:'Copy file'+(readonlyMode?' (RO)':''), inputSchema:{ type:'object', properties:{ source:{type:'string'}, destination:{type:'string'} }, required:['source','destination'] } }, - src/mcp/server.js:216-219 (handler)Dispatch handler for copy_file - checks read-only mode then calls filesystemTools.copyFile.
case 'copy_file': if (!checkReadOnly('copy_file')) { data = { success:false, message:'Operation not allowed: read-only mode' }; break; } data = filesystemTools.copyFile(args.source, args.destination, allowedDirectories); break; - src/mcp/server.js:37-41 (helper)Read-only check helper that lists 'copy_file' as a write operation, preventing execution in read-only mode.
function checkReadOnly(toolName) { if (!readonlyMode) return true; const writes = ['write_file','copy_file','move_file','delete_file','create_directory']; return !writes.includes(toolName); }