create_docx
Create new blank Word documents with optional titles using the docx-mcp server. Specify filepath to generate documents for writing, editing, or content management.
Instructions
Create a new blank Word document.
Args: filepath: Path where to create the document title: Optional title for the document
Returns: Dictionary with status and document info
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filepath | Yes | ||
| title | No |
Implementation Reference
- src/docx_mcp/server.py:64-101 (handler)The 'create_docx' tool handler function that creates a new blank Word document.
@app.tool() def create_docx(filepath: str, title: Optional[str] = None) -> dict[str, Any]: """ Create a new blank Word document. Args: filepath: Path where to create the document title: Optional title for the document Returns: Dictionary with status and document info """ logger.info("Creating new document", extra={"tool": "create_docx", "filepath": filepath}) try: path = normalize_path(filepath) path.parent.mkdir(parents=True, exist_ok=True) doc = Document() if title: doc.core_properties.title = title doc.save(str(path)) logger.info("Document created successfully", extra={"filepath": filepath}) return { "status": "success", "filepath": str(path), "message": f"Document created: {path.name}", } except DocxMcpError as e: logger.warning(e.message, extra={"tool": "create_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 creating document: {str(e)}") return {"status": "error", "error": str(e)}