### Create Word Document Source: https://context7.com/m87shaonv/word_mcp/llms.txt Creates a blank Word document with a '.docx' extension. The extension is automatically added if it is missing from the provided filename. ```APIDOC ## create_word_document ### Description Creates a blank Word document with a '.docx' extension. The extension is automatically added if it is missing from the provided filename. ### Method POST ### Endpoint /create_word_document ### Parameters #### Request Body - **filename** (string) - Required - The name of the Word document to create. Extension can be omitted. ### Request Example ```json { "filename": "report.docx" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the success of the operation. - **message** (string) - A confirmation message including the name of the created file. #### Response Example ```json { "status": "success", "message": "成功创建文件: report.docx" } ``` ``` -------------------------------- ### Create Blank Word Document with Python Source: https://context7.com/m87shaonv/word_mcp/llms.txt Creates a new, blank Word document (.docx). The '.docx' extension is automatically added if it's missing from the provided 'filename'. Documents are saved in the configured WORD_MCP_PATH or a default desktop location. ```python # Create new Word document result = client.call_tool("create_word_document", { "filename": "report.docx" }) # Returns: {"status": "success", "message": "成功创建文件: report.docx"} # Extension is optional - automatically added if missing result = client.call_tool("create_word_document", { "filename": "meeting_notes" }) # Creates: meeting_notes.docx in configured WORD_MCP_PATH or ~/桌面 ``` -------------------------------- ### Create Empty TXT File with Python Source: https://context7.com/m87shaonv/word_mcp/llms.txt Creates an empty TXT file in the configured output directory. The 'filename' parameter can be provided with or without the '.txt' extension, as it will be automatically appended if missing. This tool is useful for initializing new text-based documents. ```python from mcp import Client client = Client("word_mcp") result = client.call_tool("create_empty_txt", { "filename": "notes.txt" }) # Returns: {"status": "success", "message": "成功在 /path/to/output 创建了空白文件: notes.txt"} # Filename without extension gets .txt appended automatically result = client.call_tool("create_empty_txt", { "filename": "draft" }) # Creates: draft.txt ``` -------------------------------- ### Create Empty TXT File Source: https://context7.com/m87shaonv/word_mcp/llms.txt Creates an empty TXT file at the specified location with UTF-8 encoding. The '.txt' extension is automatically appended if omitted. ```APIDOC ## create_empty_txt ### Description Creates an empty TXT file at the specified location with UTF-8 encoding. The '.txt' extension is automatically appended if omitted. ### Method POST ### Endpoint /create_empty_txt ### Parameters #### Request Body - **filename** (string) - Required - The name of the file to create. Extension can be omitted. ### Request Example ```json { "filename": "notes.txt" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the success of the operation. - **message** (string) - A confirmation message including the path where the file was created. #### Response Example ```json { "status": "success", "message": "成功在 /path/to/output 创建了空白文件: notes.txt" } ``` ``` -------------------------------- ### Query Document Metadata with Python Source: https://context7.com/m87shaonv/word_mcp/llms.txt Retrieves comprehensive metadata for a Word document, including properties like title, author, creation/modification times, and statistics such as paragraph, table, and image counts. Requires the file path as input. ```python # Query document metadata result = client.call_tool("query_document_info", { "file_path": "contract.docx" }) # Returns: # { # "status": "success", # "data": { # "标题": "Annual Report 2024", # "创建者": "John Doe", # "创建时间": "2024-01-15 10:30:00", # "最后修改者": "Jane Smith", # "最后修改时间": "2024-02-20 14:45:00", # "备注": "Draft version", # "大小": "45.23 KB", # "文件格式": "DOCX", # "paragraphs": 42, # "tables": 3, # "images": 5 # } # } ``` -------------------------------- ### Open and Read Word Document Source: https://context7.com/m87shaonv/word_mcp/llms.txt Reads a Word document and returns its content, including paragraph indexing and metadata. Supports both full paths and relative paths when the WORD_MCP_PATH environment variable is set. ```APIDOC ## open_and_read_word_document ### Description Reads a Word document and returns its content, including paragraph indexing and metadata. Supports both full paths and relative paths when the WORD_MCP_PATH environment variable is set. ### Method POST ### Endpoint /open_and_read_word_document ### Parameters #### Request Body - **file_path** (string) - Required - The path to the Word document to read. Can be a full path or a relative path. ### Request Example ```json { "file_path": "/full/path/to/document.docx" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the success of the operation. - **message** (string) - A string containing the document's filename, paragraph count, heading count, and the content of each paragraph indexed by number. #### Response Example ```json { "status": "success", "message": "文件名: document.docx\n段落数: 15\n标题数: 3\n\n[0] First paragraph\n[1] Second paragraph\n..." } ``` ``` -------------------------------- ### Format Text in Document with Python Source: https://context7.com/m87shaonv/word_mcp/llms.txt Applies comprehensive text formatting to specific paragraphs within a Word document, including font name, size, bold, italic, underline, font color, and highlighting. Valid highlight colors are predefined. This tool allows for detailed text styling. ```python # Apply full formatting to paragraph result = client.call_tool("format_text_in_document", { "file_path": "document.docx", "paragraph_index": 3, "font_name": "Arial", "font_size": 14, "bold": True, "italic": False, "underline": True, "font_color": "#FF0000", "highlight_color": "yellow" }) # Returns: {"status": "success", "message": "成功设置文档 document.docx 第 4 段落的格式"} # Minimal formatting - only change color result = client.call_tool("format_text_in_document", { "file_path": "notes.docx", "paragraph_index": 0, "font_color": "#0000FF" }) # Valid highlight colors: yellow, green, blue, red, pink, turquoise, violet, darkblue, teal, darkred, darkgreen ``` -------------------------------- ### Query Document Information Source: https://context7.com/m87shaonv/word_mcp/llms.txt Retrieves comprehensive metadata for a given document, including properties like title, author, creation/modification dates, file size, format, and counts of paragraphs, tables, and images. ```APIDOC ## query_document_info ### Description Retrieves comprehensive metadata for a given document, including properties like title, author, creation/modification dates, file size, format, and counts of paragraphs, tables, and images. ### Method POST ### Endpoint /query_document_info ### Parameters #### Request Body - **file_path** (string) - Required - The path to the document for which to retrieve information. ### Request Example ```json { "file_path": "contract.docx" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the success of the operation. - **data** (object) - An object containing various metadata fields about the document. - **标题** (string) - The title of the document. - **创建者** (string) - The creator of the document. - **创建时间** (string) - The creation timestamp of the document. - **最后修改者** (string) - The last modifier of the document. - **最后修改时间** (string) - The last modification timestamp of the document. - **备注** (string) - Any remarks or comments associated with the document. - **大小** (string) - The file size of the document. - **文件格式** (string) - The format of the document (e.g., DOCX). - **paragraphs** (integer) - The number of paragraphs in the document. - **tables** (integer) - The number of tables in the document. - **images** (integer) - The number of images in the document. #### Response Example ```json { "status": "success", "data": { "标题": "Annual Report 2024", "创建者": "John Doe", "创建时间": "2024-01-15 10:30:00", "最后修改者": "Jane Smith", "最后修改时间": "2024-02-20 14:45:00", "备注": "Draft version", "大小": "45.23 KB", "文件格式": "DOCX", "paragraphs": 42, "tables": 3, "images": 5 } } ``` ``` -------------------------------- ### Add Text to Document Source: https://context7.com/m87shaonv/word_mcp/llms.txt Adds text or headings to a document with options for positioning (front/behind a paragraph), alignment, and whether the added content is a heading. ```APIDOC ## add_text_to_document ### Description Adds text or headings to a document with options for positioning (front/behind a paragraph), alignment, and whether the added content is a heading. ### Method POST ### Endpoint /add_text_to_document ### Parameters #### Request Body - **file_path** (string) - Required - The path to the document to modify. - **text** (string) - Required - The text or heading content to add. - **is_heading** (boolean) - Optional - Defaults to `false`. If true, the text is added as a heading. - **heading_level** (integer) - Optional - Specifies the heading level (1-9) if `is_heading` is true. - **alignment** (string) - Optional - Text alignment. Can be 'left', 'center', 'right', or 'justify'. - **paragraph_index** (integer) - Required - The index of the paragraph to add text before or after. Use -1 to append to the end of the document. - **direction** (string) - Optional - 'front' to add before the specified paragraph, 'behind' to add after. Defaults to 'behind' if `paragraph_index` is not -1, otherwise appends. ### Request Example ```json { "file_path": "report.docx", "text": "Executive Summary", "is_heading": true, "heading_level": 1, "alignment": "center", "paragraph_index": 0, "direction": "front" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the success of the operation. - **message** (string) - A confirmation message about the text addition. #### Response Example ```json { "status": "success", "message": "成功在第 1 段落前添加了标题" } ``` ``` -------------------------------- ### Insert Table into Word Documents (Python) Source: https://context7.com/m87shaonv/word_mcp/llms.txt Creates tables with optional data population and styling. This function allows specifying the number of rows and columns, populating the table with data, defining its position, and applying a style. It can also create an empty table. ```python # Insert table with data result = client.call_tool("insert_table", { "file_path": "report.docx", "rows": 3, "cols": 4, "data": [ ["Header 1", "Header 2", "Header 3", "Header 4"], ["Data A1", "Data A2", "Data A3", "Data A4"], ["Data B1", "Data B2", "Data B3", "Data B4"] ], "after_paragraph": 5, "style": "Table Grid" }) # Returns: {"status": "success", "message": "成功在文档 report.docx 中插入 3x4 的表格", "data": {"table_index": 0, ...}} # Empty table at document end result = client.call_tool("insert_table", { "file_path": "template.docx", "rows": 5, "cols": 3, "after_paragraph": -1 }) ``` -------------------------------- ### Convert Files to DOCX Format (Python) Source: https://context7.com/m87shaonv/word_mcp/llms.txt Converts PDF, TXT, or HTML files to DOCX format. This function takes a file path and an optional new filename to create a Word document from other common file types. ```python # Convert PDF to Word result = client.call_tool("convert_to_docx", { "file_path": "/path/to/scan.pdf", "new_filename": "editable_scan" }) # Returns: {"status": "success", "message": "成功转换文件为DOCX格式: editable_scan.docx", "data": {...}} # Convert plain text result = client.call_tool("convert_to_docx", { "file_path": "readme.txt", "new_filename": "readme_formatted" }) # Convert HTML webpage result = client.call_tool("convert_to_docx", { "file_path": "article.html" }) # Uses original filename if new_filename not provided ``` -------------------------------- ### Read Word Document Content with Python Source: https://context7.com/m87shaonv/word_mcp/llms.txt Opens a Word document and returns its content, including paragraph indexing and document metadata. It supports both absolute file paths and relative paths when the WORD_MCP_PATH environment variable is set. ```python # Read document with paragraph numbers result = client.call_tool("open_and_read_word_document", { "file_path": "/full/path/to/document.docx" }) # Returns: # {"status": "success", "message": "文件名: document.docx\n段落数: 15\n标题数: 3\n\n[0] First paragraph\n[1] Second paragraph\n..."} # Use relative path with WORD_MCP_PATH environment variable result = client.call_tool("open_and_read_word_document", { "file_path": "report.docx" }) # Reads from ${WORD_MCP_PATH}/report.docx ``` -------------------------------- ### Format Text in Document Source: https://context7.com/m87shaonv/word_mcp/llms.txt Applies comprehensive text formatting to a specified paragraph in a document, including font name, size, bold, italic, underline, font color, and highlight color. ```APIDOC ## format_text_in_document ### Description Applies comprehensive text formatting to a specified paragraph in a document, including font name, size, bold, italic, underline, font color, and highlight color. ### Method POST ### Endpoint /format_text_in_document ### Parameters #### Request Body - **file_path** (string) - Required - The path to the document to modify. - **paragraph_index** (integer) - Required - The index of the paragraph to format (0-based). - **font_name** (string) - Optional - The name of the font to apply (e.g., 'Arial', 'Times New Roman'). - **font_size** (integer) - Optional - The font size in points. - **bold** (boolean) - Optional - Set to true to make the text bold. - **italic** (boolean) - Optional - Set to true to make the text italic. - **underline** (boolean) - Optional - Set to true to underline the text. - **font_color** (string) - Optional - The font color in hexadecimal format (e.g., '#FF0000' for red). - **highlight_color** (string) - Optional - The highlight color. Valid options include: 'yellow', 'green', 'blue', 'red', 'pink', 'turquoise', 'violet', 'darkblue', 'teal', 'darkred', 'darkgreen'. ### Request Example ```json { "file_path": "document.docx", "paragraph_index": 3, "font_name": "Arial", "font_size": 14, "bold": true, "underline": true, "font_color": "#FF0000", "highlight_color": "yellow" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the success of the operation. - **message** (string) - A confirmation message about the formatting applied. #### Response Example ```json { "status": "success", "message": "成功设置文档 document.docx 第 4 段落的格式" } ``` ``` -------------------------------- ### Compare Documents API Source: https://context7.com/m87shaonv/word_mcp/llms.txt Compares two documents and identifies added, deleted, and modified content, including formatting differences. ```APIDOC ## POST /tools/compare_documents ### Description Compares two documents to identify differences. ### Method POST ### Endpoint /tools/compare_documents ### Parameters #### Request Body - **doc1_path** (string) - Required - The path to the first document. - **doc2_path** (string) - Required - The path to the second document. ### Request Example ```json { "doc1_path": "/path/to/contract_v1.docx", "doc2_path": "/path/to/contract_v2.docx" } ``` ### Response #### Success Response (200) - **added_paragraphs** (array of strings) - List of paragraphs added in the second document. - **deleted_paragraphs** (array of strings) - List of paragraphs deleted from the first document. - **modified_paragraphs** (array of objects) - Details of modified paragraphs (requires specific structure). - **format_differences** (array of objects) - Details of formatting differences. - **paragraph_index** (integer) - The index of the paragraph where the format difference occurred. - **difference** (string) - Description of the formatting difference. - **original_font_size** (integer) - Font size in the original document. - **modified_font_size** (integer) - Font size in the modified document. #### Response Example ```json { "added_paragraphs": ["New clause about liability", "Additional terms"], "deleted_paragraphs": ["Old outdated section"], "modified_paragraphs": [], "format_differences": [ { "paragraph_index": 5, "difference": "Font size changed", "original_font_size": 11, "modified_font_size": 12 } ] } ``` ``` -------------------------------- ### Set Paragraph Spacing in Word Documents (Python) Source: https://context7.com/m87shaonv/word_mcp/llms.txt Controls paragraph spacing with line spacing rules (multiple, exact, at least). This function allows setting spacing before and after paragraphs, as well as defining line spacing behavior. It takes the file path, paragraph index, spacing values, and line spacing rule as input. ```python # Set comprehensive paragraph spacing result = client.call_tool("set_paragraph_spacing", { "file_path": "essay.docx", "paragraph_index": 2, "before_spacing": 12.0, "after_spacing": 6.0, "line_spacing": 1.5, "line_spacing_rule": "multiple" }) # Returns: {"status": "success", "message": "成功设置文档 essay.docx 第 3 段落的间距"} # Exact line spacing in points result = client.call_tool("set_paragraph_spacing", { "file_path": "legal.docx", "paragraph_index": 0, "line_spacing": 18, "line_spacing_rule": "exact" }) # Minimum line spacing result = client.call_tool("set_paragraph_spacing", { "file_path": "document.docx", "paragraph_index": 5, "line_spacing": 14, "line_spacing_rule": "atLeast" }) ``` -------------------------------- ### Set Page Layout Source: https://context7.com/m87shaonv/word_mcp/llms.txt Configures the page layout for document sections, including orientation (portrait/landscape), margins, and page dimensions (width/height in centimeters). ```python # Set landscape orientation with custom margins result = client.call_tool("set_page_layout", { "file_path": "presentation.docx", "orientation": "landscape", "left_margin": 2.0, "right_margin": 2.0, "top_margin": 1.5, "bottom_margin": 1.5, "section_index": 0 }) # Returns: {"status": "success", "message": "成功设置文档 presentation.docx 第 1 节的页面布局", "data": {...}} # Custom page size (A5) result = client.call_tool("set_page_layout", { "file_path": "booklet.docx", "orientation": "portrait", "page_width": 14.8, "page_height": 21.0 }) # Orientation options: "portrait", "landscape" # Dimensions in centimeters ``` -------------------------------- ### Find and Replace Text in Document Source: https://context7.com/m87shaonv/word_mcp/llms.txt Performs text replacement across an entire Word document, including tables. Offers control over case sensitivity and whole word matching. Can optionally save changes. ```python # Case-insensitive replacement result = client.call_tool("find_and_replace_text", { "file_path": "manual.docx", "find_text": "version 1.0", "replace_text": "version 2.0", "match_case": False, "match_whole_word": False, "save": True }) # Returns: {"status": "success", "message": "成功在文档 manual.docx 中替换了 12 处文本", "data": {"replace_count": 12, ...}} # Whole word matching result = client.call_tool("find_and_replace_text", { "file_path": "legal.docx", "find_text": "party", "replace_text": "contracting party", "match_case": True, "match_whole_word": True }) # Replace in tables too result = client.call_tool("find_and_replace_text", { "file_path": "spreadsheet.docx", "find_text": "Q1", "replace_text": "Q2" }) ``` -------------------------------- ### Save Word Documents to Various Formats (Python) Source: https://context7.com/m87shaonv/word_mcp/llms.txt Converts Word documents to multiple formats (DOCX, PDF, TXT, HTML) with optional renaming. This function facilitates exporting documents in different file types, including specifying a new filename for the output. ```python # Convert to PDF with Chinese font support result = client.call_tool("save_document_as", { "file_path": "contract.docx", "output_format": "pdf", "new_filename": "contract_final" }) # Returns: {"status": "success", "message": "成功将文档导出为PDF: contract_final.pdf", "data": {...}} # Export as plain text result = client.call_tool("save_document_as", { "file_path": "notes.docx", "output_format": "txt" }) # Convert to HTML result = client.call_tool("save_document_as", { "file_path": "article.docx", "output_format": "html", "new_filename": "web_version" }) ``` -------------------------------- ### Assess Document Quality API Source: https://context7.com/m87shaonv/word_mcp/llms.txt Evaluates document readability and format consistency using language-specific metrics. ```APIDOC ## POST /tools/assess_document_quality ### Description Evaluates document readability and format consistency. ### Method POST ### Endpoint /tools/assess_document_quality ### Parameters #### Request Body - **file_path** (string) - Required - The path to the document file. - **language** (string) - Optional - The language of the document (e.g., "en", "zh"). ### Request Example ```json { "file_path": "report.docx", "language": "en" } ``` ### Response #### Success Response (200) - **readability_score** (float) - A score indicating the readability of the document. - **format_consistency** (float) - A score indicating the consistency of formatting. - **issues** (array of strings) - A list of identified issues related to readability or formatting. #### Response Example ```json { "readability_score": 75.5, "format_consistency": 92.0, "issues": ["Inconsistent heading styles", "Long sentences detected"] } ``` ``` -------------------------------- ### Add Text/Headings to Document with Python Source: https://context7.com/m87shaonv/word_mcp/llms.txt Adds text or headings to a Word document at a specified position and with defined alignment. Text can be inserted before or after a given paragraph index, or appended to the end. Heading properties like level and alignment are also configurable. ```python # Add heading at document start result = client.call_tool("add_text_to_document", { "file_path": "report.docx", "text": "Executive Summary", "is_heading": True, "heading_level": 1, "alignment": "center", "paragraph_index": 0, "direction": "front" }) # Returns: {"status": "success", "message": "成功在第 1 段落前添加了标题"} # Add paragraph after specific location result = client.call_tool("add_text_to_document", { "file_path": "report.docx", "text": "This analysis covers Q1-Q4 performance metrics.", "is_heading": False, "alignment": "justify", "paragraph_index": 5, "direction": "behind" }) # Append to end (default) result = client.call_tool("add_text_to_document", { "file_path": "report.docx", "text": "Conclusion section", "paragraph_index": -1 }) ``` -------------------------------- ### Add Header and Footer Source: https://context7.com/m87shaonv/word_mcp/llms.txt Adds custom headers, footers, and automatic page numbers to all sections of a Word document. Supports specifying text for headers and footers, and enabling/disabling page numbers. ```python # Add header, footer, and page numbers result = client.call_tool("add_header_footer", { "file_path": "report.docx", "header_text": "Confidential - Internal Use Only", "footer_text": "Company Name © 2024", "page_numbers": True }) # Returns: {"status": "success", "message": "成功为文档 report.docx 添加页眉页脚", "data": {...}} # Only page numbers in footer result = client.call_tool("add_header_footer", { "file_path": "essay.docx", "page_numbers": True }) # Custom header only result = client.call_tool("add_header_footer", { "file_path": "letter.docx", "header_text": "Official Correspondence" }) ``` -------------------------------- ### Compare Two Word Documents for Differences Source: https://context7.com/m87shaonv/word_mcp/llms.txt The 'compare_documents' tool identifies differences between two Word documents, including added, deleted, and modified paragraphs. It also reports formatting discrepancies at the paragraph level, such as changes in font size. ```python result = client.call_tool("compare_documents", { "doc1_path": "/path/to/contract_v1.docx", "doc2_path": "/path/to/contract_v2.docx" }) ``` ```python result = client.call_tool("compare_documents", { "doc1_path": "draft1.docx", "doc2_path": "draft2.docx" }) ``` -------------------------------- ### Insert Image into Word Documents (Python) Source: https://context7.com/m87shaonv/word_mcp/llms.txt Inserts images into documents with optional size control. This function allows specifying the image path, dimensions (width, height), and its position relative to a paragraph. It supports auto-scaling and maintaining aspect ratio. ```python # Insert image with specific dimensions result = client.call_tool("insert_image", { "file_path": "presentation.docx", "image_path": "/full/path/to/chart.png", "width": 15.0, "height": 10.0, "after_paragraph": 3 }) # Returns: {"status": "success", "message": "成功在文档 presentation.docx 中插入图片 chart.png"} # Insert at document end with auto-scaling result = client.call_tool("insert_image", { "file_path": "report.docx", "image_path": "logo.jpg", "after_paragraph": -1 }) # Maintain aspect ratio - specify only width result = client.call_tool("insert_image", { "file_path": "document.docx", "image_path": "diagram.png", "width": 12.0 }) ``` -------------------------------- ### Extract Document Information (Paragraphs, Tables, Images, etc.) Source: https://context7.com/m87shaonv/word_mcp/llms.txt The 'extract_document_info' tool extracts various structured data from Word documents, including paragraphs, tables, images, headings, and keywords. It supports Chinese language analysis and allows specifying which content types to extract. Keyword extraction can be limited by 'top_n'. ```python result = client.call_tool("extract_document_info", { "file_path": "research.docx", "is_chinese": True, "top_n": 10, "extract_content": ["paragraphs", "tables", "images", "headings", "text", "keywords"] }) ``` ```python result = client.call_tool("extract_document_info", { "file_path": "data_report.docx", "extract_content": ["tables", "images"] }) ``` ```python result = client.call_tool("extract_document_info", { "file_path": "paper.docx", "is_chinese": False, "top_n": 20 }) ``` -------------------------------- ### Complex Query API Source: https://context7.com/m87shaonv/word_mcp/llms.txt Perform searches within documents using regex, keywords, or content containment. Can also count document elements like tables, images, and paragraphs. ```APIDOC ## POST /tools/complex_query ### Description Searches within documents using various query types and counts document elements. ### Method POST ### Endpoint /tools/complex_query ### Parameters #### Request Body - **file_path** (string) - Required - The path to the document file. - **query** (string) - Required - The search query. Can be a regex pattern, a keyword search (e.g., "keyword:indemnification"), a contains search (e.g., "contains:TODO"), or an element type (e.g., "tables", "images", "paragraphs"). ### Request Example ```json { "file_path": "code_doc.docx", "query": "regex:\\b[A-Z]{2,}\\b" } ``` ### Response #### Success Response (200) - **status** (string) - The status of the operation (e.g., "success"). - **data** (object) - Contains the search results or element counts. - **query_type** (string) - The type of query performed (e.g., "regex"). - **total** (integer) - The total number of matches found or elements counted. - **details** (array) - Specific details of the matches (content varies based on query type). #### Response Example ```json { "status": "success", "data": { "query_type": "regex", "total": 15, "details": [] } } ``` ``` -------------------------------- ### Assess English Document Quality with Word MCP Source: https://context7.com/m87shaonv/word_mcp/llms.txt This snippet demonstrates how to assess the quality of an English document using the Word MCP client. It calls the 'assess_document_quality' tool with the file path and sets 'is_chinese' to False. The output includes readability and consistency metrics. ```python result = client.call_tool("assess_document_quality", { "file_path": "whitepaper.docx", "is_chinese": False }) # Returns: { # "readability": { # "average_sentence_length": 18.5, # "readability_score": 65.2 # }, # "consistency": { # "paragraph_alignment": {"WD_ALIGN_PARAGRAPH.LEFT": 45, "WD_ALIGN_PARAGRAPH.CENTER": 3}, # "font_size_consistency": {12.0: 120, 14.0: 8, 16.0: 5} # } # } ``` -------------------------------- ### Extract Document Info API Source: https://context7.com/m87shaonv/word_mcp/llms.txt Extracts structured data from documents, including paragraphs, tables, images, headings, keywords, and full text. ```APIDOC ## POST /tools/extract_document_info ### Description Extracts structured data from documents. ### Method POST ### Endpoint /tools/extract_document_info ### Parameters #### Request Body - **file_path** (string) - Required - The path to the document file. - **is_chinese** (boolean) - Optional - Set to true for Chinese keyword analysis. Defaults to false. - **top_n** (integer) - Optional - The number of top keywords to extract. Defaults to 10. - **extract_content** (array of strings) - Optional - Specifies which content types to extract. Possible values: "paragraphs", "tables", "images", "headings", "text", "keywords". If not provided, defaults to extracting all available content types. ### Request Example ```json { "file_path": "research.docx", "is_chinese": true, "top_n": 10, "extract_content": ["paragraphs", "tables", "images", "headings", "text", "keywords"] } ``` ### Response #### Success Response (200) - **paragraphs** (array of strings) - Extracted paragraphs. - **tables** (array of arrays of arrays) - Extracted tables. - **images** (array of objects) - Extracted image information (index, filename, path). - **headings** (array of objects) - Extracted headings (text, level). - **text** (string) - Full document text. - **keywords** (array of tuples) - Extracted keywords and their scores. - **word_count** (integer) - Total word count of the document. #### Response Example ```json { "paragraphs": ["para1", "para2", ...], "tables": [[["cell1", "cell2"], ...], ...], "images": [{"index": 1, "filename": "img.png", "path": "word/media/img.png"}, ...], "headings": [{"text": "Chapter 1", "level": 1}, ...], "text": "full document text", "keywords": [("关键词", 15), ("研究", 12), ...], "word_count": 5420 } ``` ``` -------------------------------- ### Save to JSON API Source: https://context7.com/m87shaonv/word_mcp/llms.txt Exports extracted document data to a JSON file with UTF-8 encoding. ```APIDOC ## POST /tools/save_to_json ### Description Exports document data to a JSON file. ### Method POST ### Endpoint /tools/save_to_json ### Parameters #### Request Body - **data** (object) - Required - The document data to save. - **output_dir** (string) - Required - The directory to save the JSON file in. - **filename** (string) - Optional - The name of the JSON file. Defaults to "document_info.json". ### Request Example ```json { "data": { "paragraphs": ["First paragraph", "Second paragraph"], "tables": [[["Header1", "Header2"], ["Data1", "Data2"]]], "word_count": 250 }, "output_dir": "analysis_results", "filename": "document_structure.json" } ``` ### Response #### Success Response (200) - **status** (string) - The status of the operation (e.g., "success"). - **message** (string) - A confirmation message including the saved file path. #### Response Example ```json { "status": "success", "message": "结果已保存到 analysis_results/document_structure.json" } ``` ``` -------------------------------- ### Merge Documents Source: https://context7.com/m87shaonv/word_mcp/llms.txt Combines multiple Word documents into a single file, inserting section breaks between the merged documents. Supports specifying file paths for the main document and the list of documents to merge. Uses python-docx as a fallback if win32com is unavailable. ```python # Merge multiple files into main document result = client.call_tool("merge_documents", { "main_file_path": "complete_report.docx", "files_to_merge": [ "chapter1.docx", "chapter2.docx", "chapter3.docx", "appendix.docx" ] }) # Returns: {"status": "success", "message": "成功将 4 个文档合并到 complete_report.docx", "data": {"merged_count": 4, ...}} # Merge with full paths result = client.call_tool("merge_documents", { "main_file_path": "/output/final.docx", "files_to_merge": [ "/source/part1.docx", "/source/part2.docx" ] }) # Note: Uses python-docx fallback if win32com unavailable ``` -------------------------------- ### Complex Replace API Source: https://context7.com/m87shaonv/word_mcp/llms.txt Performs format-preserving text replacement within documents using regex, keyword, or contains matching. ```APIDOC ## POST /tools/complex_replace ### Description Performs format-preserving text replacement in documents. ### Method POST ### Endpoint /tools/complex_replace ### Parameters #### Request Body - **file_path** (string) - Required - The path to the document file. - **replace** (string) - Required - The replacement rule. Format: "[query_type]:[search_pattern]=[replacement_text]" (e.g., "regex:\\d{4}-\\d{2}-\\d{2}=YYYY-MM-DD", "keyword:deprecated=obsolete", "contains:FIXME=RESOLVED"). - **output_path** (string) - Optional - The path to save the modified document. If not provided, a default name is generated (e.g., "original_filename_modified.docx"). ### Request Example ```json { "file_path": "data.docx", "replace": "regex:\\d{4}-\\d{2}-\\d{2}=YYYY-MM-DD", "output_path": "data_anonymized.docx" } ``` ### Response #### Success Response (200) - **status** (string) - The status of the operation (e.g., "success"). - **data** (object) - Contains replacement statistics. - **replace_count** (integer) - The number of replacements made. - **replacement_type** (string) - The type of replacement performed (e.g., "regex"). #### Response Example ```json { "status": "success", "data": { "replace_count": 23, "replacement_type": "regex" } } ``` ``` -------------------------------- ### Perform Regex, Keyword, Contains Search in Documents Source: https://context7.com/m87shaonv/word_mcp/llms.txt Utilizes the 'complex_query' tool to search within specified Word documents. Supports regex, whole-word keyword, and 'contains' matching. Can also count specific elements like tables, images, or paragraphs. ```python result = client.call_tool("complex_query", { "file_path": "code_doc.docx", "query": "regex:\b[A-Z]{2,}\b" }) ``` ```python result = client.call_tool("complex_query", { "file_path": "contract.docx", "query": "keyword:indemnification" }) ``` ```python result = client.call_tool("complex_query", { "file_path": "notes.docx", "query": "contains:TODO" }) ``` ```python result = client.call_tool("complex_query", { "file_path": "report.docx", "query": "tables" }) ``` -------------------------------- ### Save Extracted Document Data to JSON Source: https://context7.com/m87shaonv/word_mcp/llms.txt The 'save_to_json' tool exports extracted document data into a JSON file. Users can specify the output directory and filename. If the filename is omitted, a default name ('document_info.json') is used. ```python extracted_data = { "paragraphs": ["First paragraph", "Second paragraph"], "tables": [[["Header1", "Header2"], ["Data1", "Data2"]]], "word_count": 250 } result = client.call_tool("save_to_json", { "data": extracted_data, "output_dir": "analysis_results", "filename": "document_structure.json" }) ``` ```python extracted_data = { "paragraphs": ["First paragraph", "Second paragraph"], "tables": [[["Header1", "Header2"], ["Data1", "Data2"]]], "word_count": 250 } result = client.call_tool("save_to_json", { "data": extracted_data, "output_dir": "output" }) ``` -------------------------------- ### Save to CSV API Source: https://context7.com/m87shaonv/word_mcp/llms.txt Exports document data to separate CSV files per content type. ```APIDOC ## POST /tools/save_to_csv ### Description Exports document data to separate CSV files for each content type. ### Method POST ### Endpoint /tools/save_to_csv ### Parameters #### Request Body - **data** (object) - Required - The document data to save. Should contain keys like "paragraphs", "tables", "images", "headings", "keywords". - **output_dir** (string) - Required - The directory to save the CSV files in. ### Request Example ```json { "data": { "paragraphs": ["Para 1", "Para 2"], "tables": [[["Q1", "Q2"], ["100", "150"]], [["Name", "Score"], ["Alice", "95"]]], "images": [{"index": 1, "filename": "chart.png", "path": "word/media/chart.png"}], "headings": [{"text": "Introduction", "level": 1}], "keywords": [("analysis", 15), ("data", 12)] }, "output_dir": "csv_export" } ``` ### Response #### Success Response (200) - **status** (string) - The status of the operation (e.g., "success"). - **message** (string) - A confirmation message indicating the export status. #### Response Example ```json { "status": "success", "message": "结果已保存到 csv_export" } ``` *Note: This will create files like paragraphs.csv, table_1.csv, images.csv, etc. in the specified output directory.* ``` -------------------------------- ### Assess Chinese Document Quality with Word MCP Source: https://context7.com/m87shaonv/word_mcp/llms.txt This snippet shows how to assess the quality of a Chinese document using the Word MCP client. It calls the 'assess_document_quality' tool with the file path and sets 'is_chinese' to True. The assessment uses sentence length and lexical diversity for Chinese text. ```python result = client.call_tool("assess_document_quality", { "file_path": "报告.docx", "is_chinese": True }) ``` -------------------------------- ### Save Extracted Document Data to CSV Source: https://context7.com/m87shaonv/word_mcp/llms.txt This tool, 'save_to_csv', exports document data into separate CSV files for each content type (paragraphs, tables, images, headings, keywords). The output directory must be specified. ```python extracted_data = { "paragraphs": ["Para 1", "Para 2"], "tables": [[["Q1", "Q2"], ["100", "150"]], [["Name", "Score"], ["Alice", "95"]]], "images": [{"index": 1, "filename": "chart.png", "path": "word/media/chart.png"}], "headings": [{"text": "Introduction", "level": 1}], "keywords": [("analysis", 15), ("data", 12)] } result = client.call_tool("save_to_csv", { "data": extracted_data, "output_dir": "csv_export" }) ``` -------------------------------- ### Edit Paragraph in Document Source: https://context7.com/m87shaonv/word_mcp/llms.txt Replaces the text of a specified paragraph within a Word document. Supports immediate saving or deferred saving. ```python result = client.call_tool("edit_paragraph_in_document", { "file_path": "article.docx", "paragraph_index": 7, "new_text": "This updated paragraph maintains original formatting while changing content.", "save": True }) # Returns: {"status": "success", "message": "成功编辑文档 article.docx 第 8 段落的内容", "data": {...}} # Edit without immediate save result = client.call_tool("edit_paragraph_in_document", { "file_path": "draft.docx", "paragraph_index": 0, "new_text": "Revised introduction", "save": False }) ``` -------------------------------- ### Replace Paragraph Content in Word Documents (Python) Source: https://context7.com/m87shaonv/word_mcp/llms.txt Replaces entire paragraph content while preserving style and alignment. This function is used to update the text of a specific paragraph in a Word document without altering its formatting. ```python ```