copy_document
Duplicate a Word document by specifying source and optional destination filenames. Enables quick replication of content for editing, sharing, or backup purposes within a Word document management system.
Instructions
Create a copy of a Word document.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| destination_filename | No | ||
| source_filename | Yes |
Implementation Reference
- word_document_server/main.py:528-531 (registration)MCP tool registration for 'copy_document'. This is the entrypoint where the tool is registered with the FastMCP server using @mcp.tool() decorator. It delegates to the implementation in document_tools.async def copy_document(source_filename: str, destination_filename: Optional[str] = None): """Create a copy of a Word document.""" return await document_tools.copy_document(source_filename, destination_filename)
- The main handler function that executes the copy_document tool logic. Ensures .docx extensions and calls the file_utils helper to perform the copy.async def copy_document(source_filename: str, destination_filename: Optional[str] = None) -> str: """Create a copy of a Word document. Args: source_filename: Path to the source document destination_filename: Optional path for the copy. If not provided, a default name will be generated. """ source_filename = ensure_docx_extension(source_filename) if destination_filename: destination_filename = ensure_docx_extension(destination_filename) success, message, new_path = create_document_copy(source_filename, destination_filename) if success: return message else: return f"Failed to copy document: {message}"
- Supporting utility function that performs the actual file copying using shutil.copy2, generates destination name if needed, and handles errors.def create_document_copy(source_path: str, dest_path: Optional[str] = None) -> Tuple[bool, str, Optional[str]]: """ Create a copy of a document. Args: source_path: Path to the source document dest_path: Optional path for the new document. If not provided, will use source_path + '_copy.docx' Returns: Tuple of (success, message, new_filepath) """ if not os.path.exists(source_path): return False, f"Source document {source_path} does not exist", None if not dest_path: # Generate a new filename if not provided base, ext = os.path.splitext(source_path) dest_path = f"{base}_copy{ext}" try: # Simple file copy shutil.copy2(source_path, dest_path) return True, f"Document copied to {dest_path}", dest_path except Exception as e: return False, f"Failed to copy document: {str(e)}", None
- word_document_server/tools/__init__.py:9-12 (registration)Import registration in tools package __init__.py, exposing copy_document for use in main.py.from word_document_server.tools.document_tools import ( create_document, get_document_info, get_document_text, get_document_outline, list_available_documents, copy_document, merge_documents