Skip to main content
Glama

copy_document

Duplicates a Word document by specifying a source and destination filename for precise file management within the Office Word MCP Server.

Instructions

Create a copy of a Word document.

Input Schema

NameRequiredDescriptionDefault
destination_filenameNo
source_filenameYes

Input Schema (JSON Schema)

{ "properties": { "destination_filename": { "default": null, "title": "Destination Filename", "type": "string" }, "source_filename": { "title": "Source Filename", "type": "string" } }, "required": [ "source_filename" ], "type": "object" }

Implementation Reference

  • The primary handler function for the copy_document tool. It ensures proper .docx extensions and delegates the actual copying to the create_document_copy utility function.
    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}"
  • Registration of the copy_document tool using the FastMCP @mcp.tool() decorator. The function signature and docstring define the tool's schema.
    @mcp.tool() def copy_document(source_filename: str, destination_filename: str = None): """Create a copy of a Word document.""" return document_tools.copy_document(source_filename, destination_filename)
  • Utility function that performs the actual file copying operation using shutil.copy2, handling destination path generation if needed.
    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

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/GongRzhe/Office-Word-MCP-Server'

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