luiccian-word-mcp

v3.2.0
luiccian-word-mcp Checked 1 day ago Published 14 days ago

High-performance Model Context Protocol (MCP) server for Word (.docx) document generation and manipulation

Word MCP Server High-performance Model Context Protocol (MCP) server for programmatic Word (.docx) document generation and manipulation Designed from the ground up for maximum token efficiency, it replaces chatty micro-iterations with single-pass document construction, saving over 90% of model tokens and conversational turns. No manual clone or virtual environment management required. Run the server directly using Astral uv:

Summary extracted from the README.

PyPI Version Python Version uv CodeQL Security Policy Rules for AI License MCP Compatible

Word MCP Server (word-mcp, PyPI: luiccian-word-mcp) is a high-performance Python server implementing the Model Context Protocol (MCP) to provide token-optimized Word document (.docx) creation, batch synthesis, and inspection capabilities for AI assistants (Claude Desktop, Claude Code, Cursor, VS Code / GitHub Copilot, Antigravity, Windsurf, Cline).

Designed from the ground up for maximum token efficiency, it replaces chatty micro-iterations with single-pass document construction, saving over 90% of model tokens and conversational turns.


Key Architectural Highlights

  • Compound Mode & Single-Turn Discovery (v3.2.0): Registers 9 tools by default (build_document, create_from_markdown, batch_add_content, plus 6 action-dispatched domain tools: word_document, word_content, word_format, word_protection, word_footnote, word_property) to reduce tool-schema context overhead by 77.5%. Calling any domain tool with action="help" returns full required and optional parameter schemas for all actions in a single call. Set WORD_MCP_TOOLS=full (or granular) to expose all 40 individual tools.
  • Single-Pass Document Builder: Create complete, publication-ready documents (headers, footers, dynamic PAGE numbers, margins, headings, markdown styling, styled callout boxes, tables, TOCs, images, and lists) in one single MCP call (build_document).
  • Markdown Direct Generation: Turn structured Markdown into styled Word documents in one pass (create_from_markdown), including tables, nested lists, inline links, and GitHub-style alert callouts (> [!NOTE], > [!TIP], > [!IMPORTANT], > [!WARNING], > [!CAUTION]).
  • Visual Design Presets: Built-in typography and spacing standards (modern, formal, academic, compact, report, apa) with optional font_name, font_size, and page_size overrides.
  • Lightweight Outline Inspection: Extract paragraph previews and table counts without dumping full body text (get_document_outline), saving thousands of context tokens.
  • Batch Content Ingestion: Append multiple sections, tables, callouts, and lists to existing documents in a single atomic operation (batch_add_content).
  • Sandbox Security, Atomic Persistence & Unified Errors: Enforces WORD_MCP_DIRS across all 40 tools and secondary path parameters (SecurityError), stages writes through same-directory temporary files with atomic os.replace, and standardizes all failures under OperationError. Includes msoffcrypto password encryption, editing restrictions, signature markers, and headless PDF export.
  • Complete Tool Reference: See docs/TOOLS.md for every tool signature, return shape, and parameter contract.
  • Zero-Install Execution: Instant launch with uvx luiccian-word-mcp.

No manual clone or virtual environment management required. Run the server directly using Astral uv:

# Run with stdio transport (default for AI IDEs)
uvx luiccian-word-mcp

# Or run with SSE transport
uvx luiccian-word-mcp --transport sse --host 127.0.0.1 --port 8000

MCP Client Configuration

Configure your AI client by passing environment variables directly in the client's env block (no .env file is required). By default, the server starts in compound mode (9 tools); set "WORD_MCP_TOOLS": "full" in env to expose all 40 granular tools.

1. Claude Desktop (claude_desktop_config.json)

{
  "mcpServers": {
    "word-mcp": {
      "command": "uvx",
      "args": ["luiccian-word-mcp"],
      "env": {
        "WORD_MCP_DIRS": "/path/to/your/documents"
      }
    }
  }
}

[!TIP] Windows path example: Use forward slashes or escaped backslashes (e.g., "C:/Users/YourName/Documents"). You can allow multiple roots separated by commas.

Local checkout: If running from a local git repository instead of PyPI:

{
  "mcpServers": {
    "word-mcp": {
      "command": "uv",
      "args": ["run", "--directory", "/path/to/word-mcp", "luiccian-word-mcp"],
      "env": {
        "WORD_MCP_DIRS": "/path/to/your/documents"
      }
    }
  }
}

2. Cursor (.cursor/mcp.json)

{
  "mcpServers": {
    "word-mcp": {
      "command": "uvx",
      "args": ["luiccian-word-mcp"],
      "env": {
        "WORD_MCP_DIRS": "${workspaceFolder}"
      }
    }
  }
}

3. VS Code / GitHub Copilot (.vscode/mcp.json)

VS Code uses a top-level "servers" key and explicit "type": "stdio":

{
  "servers": {
    "word-mcp": {
      "type": "stdio",
      "command": "uvx",
      "args": ["luiccian-word-mcp"],
      "env": {
        "WORD_MCP_DIRS": "${workspaceFolder}"
      }
    }
  }
}

4. Antigravity / Windsurf (mcp_config.json)

{
  "mcpServers": {
    "word-mcp": {
      "command": "uvx",
      "args": ["luiccian-word-mcp"],
      "env": {
        "WORD_MCP_DIRS": "/path/to/your/documents"
      }
    }
  }
}

5. Cline / Roo Code (cline_mcp_settings.json)

{
  "mcpServers": {
    "word-mcp": {
      "command": "uvx",
      "args": ["luiccian-word-mcp"],
      "env": {
        "WORD_MCP_DIRS": "/path/to/your/documents"
      }
    }
  }
}

6. Claude Code CLI

claude mcp add word-mcp \
  -e WORD_MCP_DIRS="/path/to/your/documents" \
  -- uvx luiccian-word-mcp

Environment Variables

All runtime configuration is supplied via standard OS environment variables or the MCP client's env object:

Variable Default Description
WORD_MCP_DIRS ./documents Comma-separated list of allowed root directories for reading, writing, and listing .docx, .pdf, and image files across all primary and secondary path arguments. Legacy MCP_ALLOWED_DIRECTORIES remains supported as a fallback.
WORD_MCP_TOOLS compound Tool surface mode: compound (9 tools: 3 single-pass + 6 domain dispatchers) or full (or granular, all 40 tools). Legacy WORD_MCP_TOOL_MODE remains supported as a fallback.
WORD_MCP_LOG_LEVEL INFO Logging verbosity (DEBUG, INFO, WARNING, ERROR, CRITICAL) written strictly to stderr.
WORD_MCP_DEV_MODE false Set to true to default logging to DEBUG and log full exception tracebacks to stderr.

Token Optimization: Single-Pass vs. Legacy

Metric Legacy Micro-Calls Word MCP Single-Pass
Tool Calls 15 - 35 calls per document 1 single call (build_document)
Token Usage ~15,000 - 30,000 tokens ~800 - 1,500 tokens (90%+ savings)
Disk Operations Multiple file writes Single in-memory assembly and write
Generation Time 30 - 60 seconds Single in-memory assembly

Visual Design Presets

Preset Font Family Body Size Line Spacing Margins Best For
modern (Default) Calibri 11.0 pt 1.15 2.5 cm Executive summaries, business proposals, corporate reports
formal Times New Roman 12.0 pt 1.50 Top/Bottom 2.5 cm, Left 3.0 cm Legal contracts, official letters, meeting minutes
report Cambria 11.0 pt 1.20 Top/Bottom 2.5 cm, Left 3.0 cm, Right 2.2 cm Engineering deliverables, technical audits, structured reports
academic Times New Roman 12.0 pt 2.00 (Double) 2.54 cm (1 inch) University papers, research articles, theses (APA/MLA)
apa Times New Roman 12.0 pt 2.00 (Double) 2.54 cm (1 inch) APA 7th edition manuscripts with hanging-indent references
compact Arial 10.0 pt 1.00 (Single) 2.0 cm Invoices, datasheets, internal memos

Default Compound Tool Surface (WORD_MCP_TOOLS=compound)

By default, word-mcp exposes 9 high-efficiency tools. Call any of the 6 domain tools with action="help" to retrieve all action schemas in a single turn:

Tool Type Actions / Purpose
build_document Single-Pass Build complete documents with presets, margins, headers/footers, page numbers, TOC, callouts, tables, and lists.
create_from_markdown Single-Pass Convert Markdown (including GitHub alerts > [!NOTE] and tables) into a styled .docx in one call.
batch_add_content Single-Pass Append multiple content elements atomically to an existing .docx.
word_document Compound Dispatcher create, copy, info, text, outline, list, merge, paragraph_text, find_text, to_pdf, read_range, get_tables, help.
word_content Compound Dispatcher add_heading, add_paragraph, add_picture, add_table, add_page_break, delete_paragraph, search_and_replace, add_toc, add_hyperlink, add_bookmark, batch_edit, help.
word_format Compound Dispatcher format_text, create_style, format_table, add_header, add_footer, help.
word_protection Compound Dispatcher protect, unprotect, restrict_editing, add_signature, verify, help.
word_footnote Compound Dispatcher add_footnote, add_endnote, convert_to_endnotes, customize_style, help.
word_property Compound Dispatcher get_properties, set_properties, set_page_layout, help.

Modular Skills Ecosystem

The repository provides 3 modular, specialized skills in skills/ for LLMs:

  • word-document-creator: Instructs the model to build complete documents in 1 single pass with headers, footers, pagination, tables, callouts, and presets.
  • word-document-editor: Focuses on lightweight outline inspection, batch mutations, search and replace, and document merging.
  • word-document-security: Handles password locking, editing restrictions, and PDF export for distribution.

Security

  • Security Policy: See SECURITY.md for vulnerability disclosure, protection metadata, and threat modeling.
  • Rules for AI Assistants: See AGENTS.md for official development directives, coding standards, and token optimization rules.
  • Directory Isolation: Set WORD_MCP_DIRS to restrict document operations strictly to designated folders. Path canonicalization prevents directory traversal.
  • Trusted Publishing: Tag-driven PyPI releases (v*.*.*) use GitHub Actions OIDC and PEP 740 artifact attestation.

Development

# Clone the repository
git clone https://github.com/LuiccianDev/word-mcp.git
cd word-mcp

# Install dependencies with Astral uv
uv sync --all-groups

# Run server locally
uv run luiccian-word-mcp

# Run linting and type checking
uv run ruff check src tests scripts
uv run mypy src

# Run test suite
uv run pytest

License

This project is licensed under the MIT License. See the LICENSE file for details.