append_docx
Add text to existing Word documents. Use this tool to append content to DOCX files by specifying the file path and text to add.
Instructions
Append text content to an existing document.
Args: filepath: Path to the document content: Text content to append
Returns: Dictionary with status
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filepath | Yes | ||
| content | Yes |
Implementation Reference
- src/docx_mcp/server.py:173-208 (handler)The implementation of the append_docx tool. It uses safe_open_document to open the existing document, appends paragraphs, and then saves it using safe_save_document.
@app.tool() def append_docx(filepath: str, content: str) -> dict[str, Any]: """ Append text content to an existing document. Args: filepath: Path to the document content: Text content to append Returns: Dictionary with status """ logger.info("Appending to document", extra={"tool": "append_docx", "filepath": filepath}) try: doc = safe_open_document(filepath) for paragraph_text in content.split("\n"): if paragraph_text.strip(): doc.add_paragraph(paragraph_text) safe_save_document(doc, filepath) logger.info("Content appended successfully", extra={"filepath": filepath}) return { "status": "success", "filepath": filepath, "message": "Content appended successfully", } except DocxMcpError as e: logger.warning(e.message, extra={"tool": "append_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 appending to document: {str(e)}") return {"status": "error", "error": str(e)}