add_page_break
Insert a page break into a Microsoft Word document to organize content efficiently. Use this tool to split text and improve document structure with precision.
Instructions
Add a page break to the document.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filename | Yes |
Implementation Reference
- Core handler function that loads the Word document using python-docx, adds a page break at the end, saves the document in-place after checks, and returns success or error message.async def add_page_break(filename: str) -> str: """Add a page break to the document. Args: filename: Path to the Word document """ filename = ensure_docx_extension(filename) if not os.path.exists(filename): return f"Document {filename} does not exist" # Check if file is writeable is_writeable, error_message = check_file_writeable(filename) if not is_writeable: return f"Cannot modify document: {error_message}. Consider creating a copy first." try: doc = Document(filename) doc.add_page_break() doc.save(filename) return f"Page break added to {filename}." except Exception as e: return f"Failed to add page break: {str(e)}"
- word_document_server/main.py:192-195 (registration)MCP tool registration using @mcp.tool() decorator. This thin wrapper delegates execution to the content_tools.add_page_break implementation.@mcp.tool() def add_page_break(filename: str): """Add a page break to the document.""" return content_tools.add_page_break(filename)
- Exports add_page_break from content_tools module to make it available for import in main.py and other modules.from word_document_server.tools.content_tools import ( add_heading, add_paragraph, add_table, add_picture, add_page_break, add_table_of_contents, delete_paragraph, search_and_replace )