Skip to main content
Glama

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
NameRequiredDescriptionDefault
filepathYes
contentYes

Implementation Reference

  • 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)}

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/Andrew82106/LLM_Docx_Agent_MCP'

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