copy_docx
Copy Microsoft Word documents to new locations for backup, sharing, or version control. Specify source and destination file paths to duplicate DOCX files.
Instructions
Copy a Word document to a new location.
Args: source_filepath: Path to the source document destination_filepath: Path for the copied document
Returns: Dictionary with status
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| source_filepath | Yes | ||
| destination_filepath | Yes |
Implementation Reference
- src/docx_mcp/server.py:297-335 (handler)The 'copy_docx' tool handler implementation, which copies a Word document to a new location using the docx library.
def copy_docx(source_filepath: str, destination_filepath: str) -> dict[str, Any]: """ Copy a Word document to a new location. Args: source_filepath: Path to the source document destination_filepath: Path for the copied document Returns: Dictionary with status """ logger.info( "Copying document", extra={"tool": "copy_docx", "source": source_filepath, "destination": destination_filepath}, ) try: source_path = validate_docx_file(source_filepath) dest_path = normalize_path(destination_filepath) dest_path.parent.mkdir(parents=True, exist_ok=True) # Read and save as new document (preserves all formatting) doc = Document(str(source_path)) doc.save(str(dest_path)) logger.info("Document copied successfully", extra={"destination": destination_filepath}) return { "status": "success", "source": str(source_path), "destination": str(dest_path), "message": "Document copied successfully", } except DocxMcpError as e: logger.warning(e.message, extra={"tool": "copy_docx", "error_code": e.error_code}) return {"status": "error", "error": e.message, "error_code": e.error_code} except Exception as e: logger.error(f"Unexpected error copying document: {str(e)}") return {"status": "error", "error": str(e)} - src/docx_mcp/server.py:296-296 (registration)Registration of the 'copy_docx' tool using the @app.tool() decorator.
@app.tool()