### Install and Run Office-Word-MCP-Server Source: https://context7.com/gongrzhe/office-word-mcp-server/llms.txt Instructions for installing the server package and running it with different transport modes (stdio, streamable-http, sse). Includes enabling debug logging. ```bash pip install office-word-mcp-server ``` ```bash git clone https://github.com/GongRzhe/Office-Word-MCP-Server.git cd Office-Word-MCP-Server pip install -r requirements.txt ``` ```bash python word_mcp_server.py ``` ```bash MCP_TRANSPORT=streamable-http MCP_PORT=8000 python word_mcp_server.py ``` ```bash MCP_TRANSPORT=sse MCP_HOST=127.0.0.1 MCP_PORT=9000 python word_mcp_server.py ``` ```bash MCP_DEBUG=1 python word_mcp_server.py ``` -------------------------------- ### Run Office Word Document Server Setup Script Source: https://github.com/gongrzhe/office-word-mcp-server/blob/main/README.md Execute the setup script to automatically handle prerequisites, virtual environment setup, dependency installation, and MCP configuration. ```bash python setup_mcp.py ``` -------------------------------- ### Basic Installation of Office Word Document Server Source: https://github.com/gongrzhe/office-word-mcp-server/blob/main/README.md Clone the repository and install the necessary Python dependencies using pip. Ensure Python 3.8 or higher is installed. ```bash # Clone the repository git clone https://github.com/GongRzhe/Office-Word-MCP-Server.git cd Office-Word-MCP-Server # Install dependencies pip install -r requirements.txt ``` -------------------------------- ### Install Office Word Document Server via Smithery Source: https://github.com/gongrzhe/office-word-mcp-server/blob/main/README.md Use this command to automatically install the Office Word Document Server for Claude Desktop using the Smithery package manager. ```bash npx -y @smithery/cli install @GongRzhe/Office-Word-MCP-Server --client claude ``` -------------------------------- ### Configure Claude for Desktop without Local Installation (using uvx) Source: https://github.com/gongrzhe/office-word-mcp-server/blob/main/README.md Configure Claude for Desktop to use the server without local installation by specifying the 'uvx' command and package name. This method uses the uvx package manager. ```json { "mcpServers": { "word-document-server": { "command": "uvx", "args": ["--from", "office-word-mcp-server", "word_mcp_server"] } } } ``` -------------------------------- ### Configure Claude for Desktop with Local Installation Source: https://github.com/gongrzhe/office-word-mcp-server/blob/main/README.md Add this JSON configuration to your Claude for Desktop settings to connect to a locally installed Office Word Document Server. Ensure the path to the Python script is correct. ```json { "mcpServers": { "word-document-server": { "command": "python", "args": ["/path/to/word_mcp_server.py"] } } } ``` -------------------------------- ### Handle Missing PDF Converter Source: https://context7.com/gongrzhe/office-word-mcp-server/llms.txt Illustrates the error message returned when the document cannot be converted to PDF using any available methods. It suggests installing LibreOffice for conversion. ```text # → "Failed to convert document to PDF using all available methods. # To convert documents to PDF, please install LibreOffice (recommended for Linux/macOS) ..." ``` -------------------------------- ### Get Paragraph Text by Index Source: https://context7.com/gongrzhe/office-word-mcp-server/llms.txt Retrieves the full text and style information for a specific paragraph using its index. Useful for precise targeting and inspection. ```python result = await get_paragraph_text_from_document( filename="report.docx", paragraph_index=7 ) # Returns JSON: # { # "paragraph_index": 7, # "text": "Key Findings from the analysis indicate...", # "style": "Normal" # } ``` -------------------------------- ### replace_block_between_manual_anchors Source: https://context7.com/gongrzhe/office-word-mcp-server/llms.txt Replaces paragraphs between specified start and end anchors, or until the next heading if no end anchor is provided. ```APIDOC ## `replace_block_between_manual_anchors` — Replace Content Between Two Anchors Replaces all paragraphs between a `start_anchor_text` and an optional `end_anchor_text`. If no end anchor is provided, replacement continues until the next logical heading. ### Parameters - **filename** (string) - Required - The name of the document file. - **start_anchor_text** (string) - Required - The text of the starting anchor. - **end_anchor_text** (string) - Optional - The text of the ending anchor. If omitted, replacement continues to the next heading. - **new_paragraphs** (list of strings) - Required - A list of new paragraphs to insert. - **new_paragraph_style** (string) - Optional - The style to apply to the new paragraphs. ### Example ```python await replace_block_between_manual_anchors( filename="report.docx", start_anchor_text="", end_anchor_text="", new_paragraphs=[ "Primary risk: supply chain disruption in Southeast Asia.", "Mitigation: dual-sourcing policy implemented in Q2." ], new_paragraph_style="Normal" ) ``` ``` -------------------------------- ### Get Document Heading Structure Source: https://context7.com/gongrzhe/office-word-mcp-server/llms.txt Asynchronously retrieves a JSON list of all headings in the document, including their level and text. Useful for navigation, TOC generation, or understanding document structure. ```python result = await get_document_outline(filename="report.docx") # Returns JSON: # [ # {"level": 1, "text": "Executive Summary"}, # {"level": 2, "text": "Key Findings"}, # {"level": 2, "text": "Recommendations"}, # {"level": 1, "text": "Financial Overview"} # ] ``` -------------------------------- ### Extract All Plain Text from Document Source: https://context7.com/gongrzhe/office-word-mcp-server/llms.txt Asynchronously extracts all text from a document into a single string, with paragraphs separated by newlines. Useful for content analysis or feeding to LLMs. Includes an example of searching within the extracted text. ```python text = await get_document_text(filename="contract.docx") # → "Contract Agreement\n\nThis agreement is made between...\n\nSection 1: ..." ``` ```python # Search within extracted text if "liability" in text.lower(): print("Liability clause found") ``` -------------------------------- ### Format Text Range in Paragraph Source: https://context7.com/gongrzhe/office-word-mcp-server/llms.txt Applies rich formatting (bold, color, font size, underline) to a specific character range within a paragraph. Requires filename, paragraph index, start and end positions, and desired formatting options. ```python # Make the word "critical" at positions 14-22 bold and red await format_text( filename="report.docx", paragraph_index=3, start_pos=14, end_pos=22, bold=True, color="red", # Named color or hex string like "FF0000" font_size=12, underline=False ) # → "Text 'critical' formatted successfully in paragraph 3." # Available named colors: red, blue, green, yellow, black, gray, white, purple, orange ``` -------------------------------- ### Replace Content Between Anchors Source: https://context7.com/gongrzhe/office-word-mcp-server/llms.txt Replaces paragraphs between specified start and end anchor texts. If no end anchor is provided, it replaces content until the next logical heading. Allows specifying a new paragraph style. ```python await replace_block_between_manual_anchors( filename="report.docx", start_anchor_text="", end_anchor_text="", new_paragraphs=[ "Primary risk: supply chain disruption in Southeast Asia.", "Mitigation: dual-sourcing policy implemented in Q2." ], new_paragraph_style="Normal" ) ``` -------------------------------- ### Claude Desktop Configuration for MCP Server Source: https://context7.com/gongrzhe/office-word-mcp-server/llms.txt Configuration snippet for Claude Desktop to connect to the word-document-server using the 'uvx' command. ```json // Claude Desktop config (~/.config/claude/claude_desktop_config.json on macOS) { "mcpServers": { "word-document-server": { "command": "uvx", "args": ["--from", "office-word-mcp-server", "word_mcp_server"] } } } ``` -------------------------------- ### List .docx Files in a Directory Source: https://context7.com/gongrzhe/office-word-mcp-server/llms.txt Scans a specified directory and returns all .docx files along with their sizes in KB. Defaults to the current working directory if no directory is provided. ```python result = await list_available_documents(directory="/home/user/documents") # → "Found 3 Word documents in /home/user/documents: # - annual_report.docx (48.20 KB) ``` -------------------------------- ### Create a New Word Document with Metadata Source: https://context7.com/gongrzhe/office-word-mcp-server/llms.txt Asynchronously creates a new .docx file with optional title and author. The .docx extension is appended automatically if omitted. Ensures default styles are present. ```python # Via MCP tool call (async, returns string result) result = await create_document( filename="reports/annual_report", # → saved as reports/annual_report.docx title="Annual Report 2024", author="Finance Team" ) # → "Document reports/annual_report.docx created successfully" ``` ```python # Error case — file locked result = await create_document(filename="/read-only/doc.docx") # → "Cannot create document: File is not writeable" ``` -------------------------------- ### Merge Table Cells Source: https://github.com/gongrzhe/office-word-mcp-server/blob/main/README.md Merges a rectangular block of cells within a table into a single cell. Specify the start and end row/column indices for the merge operation. ```python merge_table_cells(filename, table_index, start_row, start_col, end_row, end_col) ``` ```python merge_table_cells_horizontal(filename, table_index, row_index, start_col, end_col) ``` ```python merge_table_cells_vertical(filename, table_index, col_index, start_row, end_row) ``` -------------------------------- ### Python API: Document Creation and Properties Source: https://github.com/gongrzhe/office-word-mcp-server/blob/main/README.md Functions for creating, retrieving information about, and managing documents. Includes listing available documents and converting to PDF. ```python create_document(filename, title=None, author=None) get_document_info(filename) get_document_text(filename) get_document_outline(filename) list_available_documents(directory=".") copy_document(source_filename, destination_filename=None) convert_to_pdf(filename, output_filename=None) ``` -------------------------------- ### Merge Rectangular Block of Table Cells Source: https://context7.com/gongrzhe/office-word-mcp-server/llms.txt Merges cells within a specified rectangular area defined by start and end row/column indices. Use `merge_table_cells_horizontal` or `merge_table_cells_vertical` for single-direction merging. ```python # Merge top-left 2×3 block (rows 0-1, cols 0-2) await merge_table_cells( filename="report.docx", table_index=0, start_row=0, start_col=0, end_row=1, end_col=2 ) ``` ```python # Merge row 0, columns 1 through 3 (spanning header cells) await merge_table_cells_horizontal( filename="report.docx", table_index=0, row_index=0, start_col=1, end_col=3 ) ``` -------------------------------- ### Format Table with Borders, Headers, and Shading Source: https://context7.com/gongrzhe/office-word-mcp-server/llms.txt Applies a holistic style to an existing table, including borders, header row formatting, and optional per-cell background colors. Requires filename, table index, and border style. Shading is provided as a 2D color list. ```python await format_table( filename="report.docx", table_index=0, # First table in document (0-based) has_header_row=True, border_style="single", # 'none', 'single', 'double', 'thick' shading=[ ["4472C4", "4472C4", "4472C4"], # Row 0 — blue header ["FFFFFF", "F2F2F2", "FFFFFF"], # Row 1 ["FFFFFF", "F2F2F2", "FFFFFF"], # Row 2 ] ) # → "Table at index 0 formatted successfully." ``` -------------------------------- ### List Available Documents Source: https://context7.com/gongrzhe/office-word-mcp-server/llms.txt Lists documents in a specified directory. Throws an error if the directory does not exist. ```python result = await list_available_documents(directory="/nonexistent") # → "Directory /nonexistent does not exist" ``` -------------------------------- ### Document Creation and Properties Source: https://github.com/gongrzhe/office-word-mcp-server/blob/main/README.md Functions for creating, retrieving information about, and managing documents. ```APIDOC ## create_document ### Description Creates a new document with an optional title and author. ### Method Signature `create_document(filename, title=None, author=None)` ### Parameters - **filename** (str) - Required - The name of the file to create. - **title** (str) - Optional - The title of the document. - **author** (str) - Optional - The author of the document. ``` ```APIDOC ## get_document_info ### Description Retrieves information about a specified document. ### Method Signature `get_document_info(filename)` ### Parameters - **filename** (str) - Required - The name of the document to get information for. ``` ```APIDOC ## get_document_text ### Description Retrieves the text content of a specified document. ### Method Signature `get_document_text(filename)` ### Parameters - **filename** (str) - Required - The name of the document to retrieve text from. ``` ```APIDOC ## get_document_outline ### Description Retrieves the outline or structure of a specified document. ### Method Signature `get_document_outline(filename)` ### Parameters - **filename** (str) - Required - The name of the document to get the outline for. ``` ```APIDOC ## list_available_documents ### Description Lists all available documents in a specified directory. ### Method Signature `list_available_documents(directory='.')` ### Parameters - **directory** (str) - Optional - The directory to list documents from. Defaults to the current directory. ``` ```APIDOC ## copy_document ### Description Copies a document from a source to a destination. ### Method Signature `copy_document(source_filename, destination_filename=None)` ### Parameters - **source_filename** (str) - Required - The name of the document to copy. - **destination_filename** (str) - Optional - The name for the new copied document. If not provided, a default name will be used. ``` ```APIDOC ## convert_to_pdf ### Description Converts a document to PDF format. ### Method Signature `convert_to_pdf(filename, output_filename=None)` ### Parameters - **filename** (str) - Required - The name of the document to convert. - **output_filename** (str) - Optional - The name for the output PDF file. If not provided, a default name will be used. ``` -------------------------------- ### Convert DOCX to PDF with Auto-Naming Source: https://context7.com/gongrzhe/office-word-mcp-server/llms.txt Converts a DOCX file to PDF using the default output path. The result indicates successful conversion and the generated PDF path. ```python result = await convert_to_pdf(filename="report.docx") ``` -------------------------------- ### list_available_documents Source: https://context7.com/gongrzhe/office-word-mcp-server/llms.txt Scans a specified directory and returns a list of all .docx files found, including their sizes in KB. Defaults to the current working directory if none is provided. ```APIDOC ## list_available_documents ### Description Scans a directory and returns all `.docx` files with their sizes in KB. Defaults to the current working directory. ### Method `list_available_documents` (async function) ### Parameters - **directory** (string) - Optional - The directory to scan for `.docx` files. Defaults to the current working directory. ### Request Example ```python result = await list_available_documents(directory="/home/user/documents") ``` ### Response Example ``` "Found 3 Word documents in /home/user/documents: - annual_report.docx (48.20 KB) ``` ``` -------------------------------- ### create_document Source: https://context7.com/gongrzhe/office-word-mcp-server/llms.txt Creates a new, blank .docx file. It can optionally include title and author metadata. The server automatically appends the '.docx' extension if it's missing and ensures default styles are present. ```APIDOC ## create_document ### Description Creates a blank `.docx` file with optional title and author metadata. The `.docx` extension is appended automatically if omitted. Ensures default heading and table styles are present in the new document. ### Method `create_document` (async function) ### Parameters - **filename** (string) - Required - The name of the file to create. '.docx' will be appended if missing. - **title** (string) - Optional - The title metadata for the document. - **author** (string) - Optional - The author metadata for the document. ### Request Example ```python result = await create_document( filename="reports/annual_report", title="Annual Report 2024", author="Finance Team" ) ``` ### Response Example ``` "Document reports/annual_report.docx created successfully" ``` ### Error Handling Example ```python result = await create_document(filename="/read-only/doc.docx") # → "Cannot create document: File is not writeable" ``` ``` -------------------------------- ### Copy Document Source: https://context7.com/gongrzhe/office-word-mcp-server/llms.txt Creates a copy of an existing document. If no destination is provided, a timestamped copy name is generated automatically. ```python result = await copy_document( source_filename="template.docx", destination_filename="project_report.docx" ) # → "Document copied successfully: template.docx → project_report.docx" ``` ```python # Auto-generated name result = await copy_document(source_filename="template.docx") # → "Document copied successfully: template.docx → template_copy_20240115_143022.docx" ``` -------------------------------- ### convert_to_pdf Source: https://context7.com/gongrzhe/office-word-mcp-server/llms.txt Converts a .docx file to PDF format using available converters like LibreOffice or Microsoft Word. ```APIDOC ## `convert_to_pdf` — Export to PDF Converts a `.docx` file to PDF. Uses LibreOffice on Linux/macOS (via subprocess), or `docx2pdf`/Microsoft Word on Windows. Falls back gracefully between available converters. ### Parameters - **filename** (string) - Required - The name of the .docx file to convert. - **output_filename** (string) - Optional - The desired name for the output PDF file. If omitted, a name based on the input filename will be used. ### Example ```python await convert_to_pdf(filename="document.docx", output_filename="document.pdf") ``` ``` -------------------------------- ### Enable Debug Logging Source: https://github.com/gongrzhe/office-word-mcp-server/blob/main/README.md Activates detailed logging for the MCP server by setting the MCP_DEBUG environment variable. This is useful for diagnosing issues. ```bash export MCP_DEBUG=1 # Linux/macOS set MCP_DEBUG=1 # Windows ``` -------------------------------- ### Highlight Table Header Row Source: https://context7.com/gongrzhe/office-word-mcp-server/llms.txt Applies a background color to the first row of a table and sets the text color, creating a professional header bar. Works on existing table content. Requires filename, table index, header color, and text color. ```python await highlight_table_header( filename="report.docx", table_index=0, header_color="2E74B5", # Deep blue (no '#') text_color="FFFFFF" # White text ) # → "Header highlighting applied successfully to table 0." ``` -------------------------------- ### Convert DOCX to PDF with Explicit Output Path Source: https://context7.com/gongrzhe/office-word-mcp-server/llms.txt Converts a DOCX file to PDF, specifying a custom output filename and path. This is useful for controlling where the generated PDF is saved. ```python result = await convert_to_pdf( filename="report.docx", output_filename="/var/www/exports/report_final.pdf" ) ``` -------------------------------- ### Add Table Source: https://context7.com/gongrzhe/office-word-mcp-server/llms.txt Adds a table of the specified dimensions, optionally pre-filled with a 2D list of strings. Uses `Table Grid` style if available. ```python await add_table( filename="report.docx", rows=4, cols=3, data=[ ["Quarter", "Revenue ($M)", "Growth (%)"], ["Q1 2024", "12.4", "+8.2"], ["Q2 2024", "14.1", "+13.7"], ["Q3 2024", "15.9", "+12.8"], ] ) # → "Table (4x3) added to report.docx" ``` -------------------------------- ### Manage Table Column Width Source: https://github.com/gongrzhe/office-word-mcp-server/blob/main/README.md Sets the width for a specific column or all columns in a table. Width can be specified in points or as a percentage. Auto-fitting columns may override manual settings. ```python set_table_column_width(filename, table_index, col_index, width, width_type="points") ``` ```python set_table_column_widths(filename, table_index, widths, width_type="points") ``` ```python set_table_width(filename, table_index, width, width_type="points") ``` ```python auto_fit_table_columns(filename, table_index) ``` -------------------------------- ### Format Text in Word Document Source: https://github.com/gongrzhe/office-word-mcp-server/blob/main/README.md Applies various text formatting options like bold, italic, underline, color, font size, and font name to a specified range within a document. Ensure correct filename, paragraph index, and start/end positions are provided. ```python format_text(filename, paragraph_index, start_pos, end_pos, bold=None, italic=None, underline=None, color=None, font_size=None, font_name=None) ``` -------------------------------- ### Create Custom Paragraph Style Source: https://context7.com/gongrzhe/office-word-mcp-server/llms.txt Defines a reusable paragraph style in the document, which can be applied later using `add_paragraph(style=...)`. Supports basing the new style on an existing one and specifying various formatting properties. ```python await create_custom_style( filename="report.docx", style_name="CalloutBox", bold=False, italic=True, font_size=11, font_name="Calibri", color="1F497D", # Dark blue hex base_style="Normal" ) # → "Style 'CalloutBox' created successfully." # Now use it await add_paragraph( filename="report.docx", text="Note: This section requires manager approval.", style="CalloutBox" ) ``` -------------------------------- ### Format Table in Word Document Source: https://github.com/gongrzhe/office-word-mcp-server/blob/main/README.md Applies general formatting to a table, including header row presence, border style, and shading. Specify the table index accurately. ```python format_table(filename, table_index, has_header_row=None, border_style=None, shading=None) ``` -------------------------------- ### Convert Document to PDF Source: https://context7.com/gongrzhe/office-word-mcp-server/llms.txt Converts a .docx file to PDF format. It utilizes LibreOffice on Linux/macOS and docx2pdf/Microsoft Word on Windows, with fallback mechanisms for available converters. ```python await convert_to_pdf(filename="document.docx") ``` -------------------------------- ### Protect and Unprotect Documents Source: https://context7.com/gongrzhe/office-word-mcp-server/llms.txt Encrypts a .docx file using AES-compatible Office encryption with a password, replacing the original file. `unprotect_document` decrypts the file using the correct password. ```python # Encrypt the document await protect_document( filename="confidential_report.docx", password="S3cr3tP@ss!" ) # → "Document confidential_report.docx encrypted successfully with password." # Decrypt await unprotect_document( filename="confidential_report.docx", password="S3cr3tP@ss!" ) # → "Document confidential_report.docx decrypted successfully." # Wrong password # → "Failed to decrypt document: Incorrect password." ``` -------------------------------- ### add_table Source: https://context7.com/gongrzhe/office-word-mcp-server/llms.txt Adds a table of the specified dimensions, optionally pre-filled with a 2D list of strings. Uses `Table Grid` style if available. ```APIDOC ## `add_table` — Insert a Table with Data Adds a table of the specified dimensions, optionally pre-filled with a 2D list of strings. Uses `Table Grid` style if available. ```python await add_table( filename="report.docx", rows=4, cols=3, data=[ ["Quarter", "Revenue ($M)", "Growth (%)"], ["Q1 2024", "12.4", "+8.2"], ["Q2 2024", "14.1", "+13.7"], ["Q3 2024", "15.9", "+12.8"], ] ) # → "Table (4x3) added to report.docx" ``` ``` -------------------------------- ### Add Picture Source: https://context7.com/gongrzhe/office-word-mcp-server/llms.txt Inserts an image into the document. Width is specified in inches; if omitted the image is inserted at its natural size. Requires an absolute image path for reliability. ```python await add_picture( filename="report.docx", image_path="/home/user/charts/revenue_chart.png", width=5.5 # 5.5 inches wide, proportional height ) # → "Picture /home/user/charts/revenue_chart.png added to report.docx" ``` ```python # Error case — file not found # → "Image file not found: /home/user/charts/revenue_chart.png" ``` -------------------------------- ### add_picture Source: https://context7.com/gongrzhe/office-word-mcp-server/llms.txt Inserts an image into the document. Width is specified in inches; if omitted the image is inserted at its natural size. Requires an absolute image path for reliability. ```APIDOC ## `add_picture` — Embed an Image Inserts an image into the document. Width is specified in inches; if omitted the image is inserted at its natural size. Requires an absolute image path for reliability. ```python await add_picture( filename="report.docx", image_path="/home/user/charts/revenue_chart.png", width=5.5 # 5.5 inches wide, proportional height ) # → "Picture /home/user/charts/revenue_chart.png added to report.docx" # Error case — file not found # → "Image file not found: /home/user/charts/revenue_chart.png" ``` ``` -------------------------------- ### copy_document Source: https://context7.com/gongrzhe/office-word-mcp-server/llms.txt Creates a copy of an existing document. If no destination is provided, a timestamped copy name is generated automatically. Useful before making destructive edits. ```APIDOC ## `copy_document` — Duplicate a Document Creates a copy of an existing document. If no destination is provided, a timestamped copy name is generated automatically. Useful before making destructive edits. ```python result = await copy_document( source_filename="template.docx", destination_filename="project_report.docx" ) # → "Document copied successfully: template.docx → project_report.docx" # Auto-generated name result = await copy_document(source_filename="template.docx") # → "Document copied successfully: template.docx → template_copy_20240115_143022.docx" ``` ``` -------------------------------- ### Highlight Table Header Row Source: https://github.com/gongrzhe/office-word-mcp-server/blob/main/README.md Applies a specific background color and text color to the header row of a table. Ensure the table index is correct. ```python highlight_table_header(filename, table_index, header_color="4472C4", text_color="FFFFFF") ``` -------------------------------- ### Create Custom Style in Word Document Source: https://github.com/gongrzhe/office-word-mcp-server/blob/main/README.md Defines a new custom style for a Word document, allowing for consistent formatting. Options include bold, italic, font size, font name, color, and the ability to base it on an existing style. ```python create_custom_style(filename, style_name, bold=None, italic=None, font_size=None, font_name=None, color=None, base_style=None) ``` -------------------------------- ### Find Text in Document with Options Source: https://context7.com/gongrzhe/office-word-mcp-server/llms.txt Searches for specific text within a Word document, returning locations with options for case-sensitive and whole-word matching. Results include paragraph index, text content, and match position. ```python result = await find_text_in_document( filename="contract.docx", text_to_find="force majeure", match_case=False, whole_word=True ) ``` -------------------------------- ### Retrieve Document Metadata Source: https://context7.com/gongrzhe/office-word-mcp-server/llms.txt Asynchronously retrieves core document properties including title, author, paragraph count, word count, table count, and file size in KB. The result is returned as a JSON string. ```python result = await get_document_info(filename="annual_report.docx") # Returns JSON: # { # "title": "Annual Report 2024", # "author": "Finance Team", # "paragraphs": 42, # "words": 1830, # "tables": 3, # "file_size_kb": 48.2 # } ``` ```python import json info = json.loads(result) print(f"Word count: {info['words']}, Tables: {info['tables']}") ``` -------------------------------- ### Python API: Content Addition Source: https://github.com/gongrzhe/office-word-mcp-server/blob/main/README.md Functions for adding various types of content to a document, including headings, paragraphs, tables, and pictures. Supports basic formatting options. ```python add_heading(filename, text, level=1, font_name=None, font_size=None, bold=None, italic=None, border_bottom=False) add_paragraph(filename, text, style=None, font_name=None, font_size=None, bold=None, italic=None, color=None) add_table(filename, rows, cols, data=None) add_picture(filename, image_path, width=None) add_page_break(filename) ``` -------------------------------- ### Control Table Column Widths Source: https://context7.com/gongrzhe/office-word-mcp-server/llms.txt Sets the width for individual columns or all columns simultaneously. Supports various units including points, inches, cm, percent, and auto. `auto_fit_table_columns` resizes columns based on content. ```python # Set single column width await set_table_column_width( filename="report.docx", table_index=0, col_index=0, width=100.0, width_type="points" # 'points', 'inches', 'cm', 'percent', 'auto' ) ``` ```python # Set all column widths at once await set_table_column_widths( filename="report.docx", table_index=0, widths=[80.0, 200.0, 120.0, 120.0], width_type="points" ) ``` ```python # Auto-fit all columns to their content await auto_fit_table_columns(filename="report.docx", table_index=0) ``` -------------------------------- ### Content Addition Source: https://github.com/gongrzhe/office-word-mcp-server/blob/main/README.md Functions for adding various types of content to documents. ```APIDOC ## add_heading ### Description Adds a heading to the document. ### Method Signature `add_heading(filename, text, level=1, font_name=None, font_size=None, bold=None, italic=None, border_bottom=False)` ### Parameters - **filename** (str) - Required - The name of the document to add the heading to. - **text** (str) - Required - The text content of the heading. - **level** (int) - Optional - The heading level (e.g., 1 for H1, 2 for H2). Defaults to 1. - **font_name** (str) - Optional - The font name for the heading. - **font_size** (int) - Optional - The font size for the heading. - **bold** (bool) - Optional - Whether the heading text should be bold. - **italic** (bool) - Optional - Whether the heading text should be italic. - **border_bottom** (bool) - Optional - Whether to add a bottom border to the heading. Defaults to False. ``` ```APIDOC ## add_paragraph ### Description Adds a paragraph to the document. ### Method Signature `add_paragraph(filename, text, style=None, font_name=None, font_size=None, bold=None, italic=None, color=None)` ### Parameters - **filename** (str) - Required - The name of the document to add the paragraph to. - **text** (str) - Required - The text content of the paragraph. - **style** (str) - Optional - The style to apply to the paragraph. - **font_name** (str) - Optional - The font name for the paragraph. - **font_size** (int) - Optional - The font size for the paragraph. - **bold** (bool) - Optional - Whether the paragraph text should be bold. - **italic** (bool) - Optional - Whether the paragraph text should be italic. - **color** (str) - Optional - The color of the paragraph text. ``` ```APIDOC ## add_table ### Description Adds a table to the document. ### Method Signature `add_table(filename, rows, cols, data=None)` ### Parameters - **filename** (str) - Required - The name of the document to add the table to. - **rows** (int) - Required - The number of rows in the table. - **cols** (int) - Required - The number of columns in the table. - **data** (list of lists) - Optional - The data to populate the table with. ``` ```APIDOC ## add_picture ### Description Adds a picture to the document. ### Method Signature `add_picture(filename, image_path, width=None)` ### Parameters - **filename** (str) - Required - The name of the document to add the picture to. - **image_path** (str) - Required - The path to the image file. - **width** (int) - Optional - The width of the picture in the document. ``` ```APIDOC ## add_page_break ### Description Inserts a page break into the document. ### Method Signature `add_page_break(filename)` ### Parameters - **filename** (str) - Required - The name of the document to add the page break to. ``` -------------------------------- ### get_document_outline Source: https://context7.com/gongrzhe/office-word-mcp-server/llms.txt Retrieves the heading structure of a Word document, returning a JSON list of headings with their respective levels and text. ```APIDOC ## get_document_outline ### Description Returns a JSON list of all headings in the document with their level and text, useful for navigation, generating TOCs, or understanding document structure. ### Method `get_document_outline` (async function) ### Parameters - **filename** (string) - Required - The path to the Word document. ### Request Example ```python result = await get_document_outline(filename="report.docx") ``` ### Response Example ```json [ {"level": 1, "text": "Executive Summary"}, {"level": 2, "text": "Key Findings"}, {"level": 2, "text": "Recommendations"}, {"level": 1, "text": "Financial Overview"} ] ``` ``` -------------------------------- ### get_paragraph_text_from_document Source: https://context7.com/gongrzhe/office-word-mcp-server/llms.txt Retrieves the full text and style information of a specific paragraph by its index. ```APIDOC ## `get_paragraph_text_from_document` — Get a Single Paragraph by Index Returns the full text and style information of a specific paragraph. Useful when you know the position and need to inspect or target it precisely. ### Parameters - **filename** (string) - Required - The name of the document file. - **paragraph_index** (integer) - Required - The index of the paragraph to retrieve. ### Response Example ```json { "paragraph_index": 7, "text": "Key Findings from the analysis indicate...", "style": "Normal" } ``` ``` -------------------------------- ### Add Paragraph Source: https://context7.com/gongrzhe/office-word-mcp-server/llms.txt Appends a paragraph to the document. Supports Word style names, font family, font size, bold, italic, and hex RGB text color — all applied inline without requiring a pre-existing style. ```python # Styled paragraph with direct formatting await add_paragraph( filename="report.docx", text="This result is critically important for the project timeline.", font_name="Times New Roman", font_size=12, bold=True, italic=False, color="C00000" # Dark red, no '#' prefix ) # → "Paragraph added to report.docx" ``` ```python # Using a named Word style await add_paragraph( filename="report.docx", text="Note: All figures are approximate.", style="Quote" ) ``` -------------------------------- ### search_and_replace Source: https://context7.com/gongrzhe/office-word-mcp-server/llms.txt Replaces all occurrences of a string throughout the entire document (paragraphs and tables). Returns the number of replacements made. ```APIDOC ## `search_and_replace` — Find and Replace Text Replaces all occurrences of a string throughout the entire document (paragraphs and tables). Returns the number of replacements made. ```python result = await search_and_replace( filename="contract.docx", find_text="ACME Corporation", replace_text="Globex Industries" ) # → "Replaced 7 occurrence(s) of 'ACME Corporation' with 'Globex Industries'." # No match result = await search_and_replace( filename="contract.docx", find_text="foobar", replace_text="baz" ) # → "No occurrences of 'foobar' found." ``` ``` -------------------------------- ### Insert Header Near Text or Paragraph Index Source: https://context7.com/gongrzhe/office-word-mcp-server/llms.txt Inserts a new section heading before or after a specified text or paragraph index. Requires specifying the filename, header title, position, and optionally the header style. ```python await insert_header_near_text( filename="report.docx", target_text="Introduction", header_title="Background and Context", position="after", # 'before' or 'after' header_style="Heading 2" ) ``` ```python await insert_header_near_text( filename="report.docx", target_paragraph_index=10, header_title="Appendix A", position="after", header_style="Heading 1" ) ``` -------------------------------- ### add_heading Source: https://context7.com/gongrzhe/office-word-mcp-server/llms.txt Appends a heading paragraph to the document. Supports levels 1–9, custom font name/size, bold/italic overrides, and an optional bottom border for section separators. ```APIDOC ## `add_heading` — Add a Heading with Optional Formatting Appends a heading paragraph to the document. Supports levels 1–9, custom font name/size, bold/italic overrides, and an optional bottom border for section separators. ```python # Simple level-1 heading await add_heading(filename="report.docx", text="Introduction", level=1) # Styled heading with bottom border await add_heading( filename="report.docx", text="Technical Architecture", level=2, font_name="Helvetica", font_size=14, bold=True, border_bottom=True ) # → "Heading 'Technical Architecture' (level 2) added to report.docx" ``` ``` -------------------------------- ### Set All Table Cell Alignments Source: https://github.com/gongrzhe/office-word-mcp-server/blob/main/README.md Applies uniform horizontal and vertical alignment to all cells within a specified table. Default alignment is left and top. ```python set_table_alignment_all(filename, table_index, horizontal="left", vertical="top") ``` -------------------------------- ### protect_document / unprotect_document Source: https://context7.com/gongrzhe/office-word-mcp-server/llms.txt Encrypts and decrypts Word documents using AES-compatible Office encryption with a password. ```APIDOC ## `protect_document` / `unprotect_document` — Encrypt and Decrypt Documents Encrypts a `.docx` file using `msoffcrypto` (AES-compatible Office encryption). The file is replaced in-place with the encrypted version. `unprotect_document` decrypts it back. ### Parameters for `protect_document` - **filename** (string) - Required - The name of the document file to encrypt. - **password** (string) - Required - The password for encryption. ### Parameters for `unprotect_document` - **filename** (string) - Required - The name of the document file to decrypt. - **password** (string) - Required - The password for decryption. ### Response Example (Success) ``` "Document [filename] encrypted successfully with password." ``` ### Response Example (Decryption Failure) ``` "Failed to decrypt document: Incorrect password." ``` ``` -------------------------------- ### get_document_info Source: https://context7.com/gongrzhe/office-word-mcp-server/llms.txt Retrieves metadata for a specified Word document, including title, author, paragraph count, word count, table count, and file size. ```APIDOC ## get_document_info ### Description Returns a JSON object with core document properties: title, author, paragraph count, word count, table count, and file size in KB. ### Method `get_document_info` (async function) ### Parameters - **filename** (string) - Required - The path to the Word document. ### Request Example ```python result = await get_document_info(filename="annual_report.docx") ``` ### Response Example ```json { "title": "Annual Report 2024", "author": "Finance Team", "paragraphs": 42, "words": 1830, "tables": 3, "file_size_kb": 48.2 } ``` ### Usage Example ```python import json info = json.loads(result) print(f"Word count: {info['words']}, Tables: {info['tables']}") ``` ``` -------------------------------- ### Add Heading Source: https://context7.com/gongrzhe/office-word-mcp-server/llms.txt Appends a heading paragraph to the document. Supports levels 1–9, custom font name/size, bold/italic overrides, and an optional bottom border for section separators. ```python # Simple level-1 heading await add_heading(filename="report.docx", text="Introduction", level=1) ``` ```python # Styled heading with bottom border await add_heading( filename="report.docx", text="Technical Architecture", level=2, font_name="Helvetica", font_size=14, bold=True, border_bottom=True ) # → "Heading 'Technical Architecture' (level 2) added to report.docx" ``` -------------------------------- ### Insert Paragraph Near Text or Paragraph Index Source: https://context7.com/gongrzhe/office-word-mcp-server/llms.txt Inserts a new paragraph before or after a target location identified by text or index. The style of the new paragraph can be specified or match the target. Requires filename, line text, position, and optionally line style. ```python await insert_line_or_paragraph_near_text( filename="report.docx", target_text="Executive Summary", line_text="This document is confidential and intended for internal use only.", position="after", line_style="Quote" ) ``` ```python await insert_line_or_paragraph_near_text( filename="report.docx", target_paragraph_index=0, line_text="DRAFT — Not for distribution", position="before" ) ``` -------------------------------- ### Apply Alternating Row Colors to a Table Source: https://context7.com/gongrzhe/office-word-mcp-server/llms.txt Use this function to apply zebra-striping to table rows for better readability. Defaults to white and light gray. ```python await apply_table_alternating_rows( filename="report.docx", table_index=0, color1="FFFFFF", # Odd rows — white color2="EBF3FB" # Even rows — light blue ) ``` -------------------------------- ### add_paragraph Source: https://context7.com/gongrzhe/office-word-mcp-server/llms.txt Appends a paragraph to the document. Supports Word style names, font family, font size, bold, italic, and hex RGB text color — all applied inline without requiring a pre-existing style. ```APIDOC ## `add_paragraph` — Add a Paragraph with Inline Formatting Appends a paragraph to the document. Supports Word style names, font family, font size, bold, italic, and hex RGB text color — all applied inline without requiring a pre-existing style. ```python # Styled paragraph with direct formatting await add_paragraph( filename="report.docx", text="This result is critically important for the project timeline.", font_name="Times New Roman", font_size=12, bold=True, italic=False, color="C00000" # Dark red, no '#' prefix ) # → "Paragraph added to report.docx" # Using a named Word style await add_paragraph( filename="report.docx", text="Note: All figures are approximate.", style="Quote" ) ``` ``` -------------------------------- ### Advanced Content Manipulation Source: https://github.com/gongrzhe/office-word-mcp-server/blob/main/README.md Functions for inserting content relative to existing elements or with specific formatting. ```APIDOC ## insert_header_near_text ### Description Inserts a header near specified text or at a specific paragraph index. ### Method Signature `insert_header_near_text(filename, target_text=None, header_title=None, position='after', header_style='Heading 1', target_paragraph_index=None)` ### Parameters - **filename** (str) - Required - The name of the document. - **target_text** (str) - Optional - The text to find to determine insertion point. - **header_title** (str) - Optional - The title of the header to insert. - **position** (str) - Optional - The position relative to the target ('after' or 'before'). Defaults to 'after'. - **header_style** (str) - Optional - The style for the header. Defaults to 'Heading 1'. - **target_paragraph_index** (int) - Optional - The index of the paragraph to insert near. ``` ```APIDOC ## insert_line_or_paragraph_near_text ### Description Inserts a line or paragraph near specified text or at a specific paragraph index. ### Method Signature `insert_line_or_paragraph_near_text(filename, target_text=None, line_text=None, position='after', line_style=None, target_paragraph_index=None)` ### Parameters - **filename** (str) - Required - The name of the document. - **target_text** (str) - Optional - The text to find to determine insertion point. - **line_text** (str) - Optional - The text of the line or paragraph to insert. - **position** (str) - Optional - The position relative to the target ('after' or 'before'). Defaults to 'after'. - **line_style** (str) - Optional - The style for the inserted line or paragraph. - **target_paragraph_index** (int) - Optional - The index of the paragraph to insert near. ``` ```APIDOC ## insert_numbered_list_near_text ### Description Inserts a numbered or bulleted list near specified text or at a specific paragraph index. ### Method Signature `insert_numbered_list_near_text(filename, target_text=None, list_items=None, position='after', target_paragraph_index=None, bullet_type='bullet')` ### Parameters - **filename** (str) - Required - The name of the document. - **target_text** (str) - Optional - The text to find to determine insertion point. - **list_items** (list) - Required - A list of items for the list. - **position** (str) - Optional - The position relative to the target ('after' or 'before'). Defaults to 'after'. - **target_paragraph_index** (int) - Optional - The index of the paragraph to insert near. - **bullet_type** (str) - Optional - The type of list ('bullet' or 'number'). Defaults to 'bullet'. ``` -------------------------------- ### apply_table_alternating_rows Source: https://context7.com/gongrzhe/office-word-mcp-server/llms.txt Applies alternating row background colors to a table for improved readability. Defaults to white and light gray. ```APIDOC ## `apply_table_alternating_rows` — Zebra-Stripe a Table ### Description Sets alternating row background colors throughout a table for improved readability. Defaults to white and light gray. ### Parameters #### Path Parameters - `filename` (string) - Required - The name of the Word document. - `table_index` (integer) - Required - The 0-based index of the table to modify. - `color1` (string) - Optional - The background color for odd rows (e.g., "FFFFFF" for white). - `color2` (string) - Optional - The background color for even rows (e.g., "EBF3FB" for light blue). ### Request Example ```python await apply_table_alternating_rows( filename="report.docx", table_index=0, color1="FFFFFF", # Odd rows — white color2="EBF3FB" # Even rows — light blue ) ``` ### Response #### Success Response (200) - A success message indicating the operation was completed. ``` -------------------------------- ### Apply Alternating Row Shading to Table Source: https://github.com/gongrzhe/office-word-mcp-server/blob/main/README.md Applies distinct background colors to alternating rows in a table for improved readability. Default colors are light gray and white. ```python apply_table_alternating_rows(filename, table_index, color1="FFFFFF", color2="F2F2F2") ```