# docx4j Word documents [Health: Active]

**Category:** 🏢 Workplace & Productivity  
**Repository:** https://github.com/plutext/docx4j-mcp  
**GitHub Stars:** 0  
**Views:** 3  
**Installs:** 0  
**Upvotes:** 0  
**Directory Page:** https://allmcps.com/mcp/docx4j-word-documents

## Description
Read, convert and fill Word (.docx) documents: templates, Markdown/HTML in and out, PDF with math.

## Tools
Capabilities this server exposes over MCP:

- **describe_template** — What data a template wants: skeleton XML + xpaths/conditions (OpenDoPE, bound content controls) or MERGEFIELD names and format switches (mail merge). Call before `fill_template`.
- **fill_template** — Fill a template, preserving its formatting. `data` is an XML string (OpenDoPE / bound controls; repeats and conditions processed) or a JSON object (mail merge).
- **convert_to_pdf** — docx → PDF via XSL-FO / Apache FOP; equations and WMF/EMF drawings rendered as vectors; optional `update_toc`; reports font substitutions. Bundles metric-compatible fonts (Carlito, Caladea, Liberation, Tinos…).
- **markdown_to_docx** — Markdown → properly styled docx (headings, numbering, GFM tables, footnotes, task lists, TeX math). Optional `styles_template_path`.
- **docx_to_markdown** — docx → Markdown (structure preserved). Options: `tracked_changes` accept/markup, `image_dir_path`.
- **html_to_docx** — HTML → docx via docx4j-ImportXHTML. Loose HTML accepted (normalised with jsoup); `h1`–`h6` map to heading styles; optional `styles_template_path`; `mode: altchunk` embeds the HTML for Word to convert on open. Remote images/stylesheets are never fetched.
- **convert_to_html** — docx → standalone HTML (visitor exporter; `image_dir_path` for images; optional `update_toc`).
- **extract_text** — Plain text, one line per paragraph/table.

## Claude Desktop Quick Installation
No generated config for this server: it installs through its own setup steps.

The project's own setup steps (from https://github.com/plutext/docx4j-mcp), copied verbatim. Follow them in order; they are not an mcpServers config.

1. Install:

```sh
mvn package            # -> target/docx4j-mcp.jar (shaded, runnable)
```

2. Start the server:

```sh
docker run -i --rm -v /path/to/documents:/data ghcr.io/plutext/docx4j-mcp
```

## Documentation

## What docx4j Word documents does

The docx4j Word documents MCP server exposes docx4j document-processing functions to MCP-compatible AI clients. It works with Word `.docx` files stored on the local filesystem and can inspect templates, populate them, convert them to PDF or HTML, and move content between DOCX and Markdown or HTML.

Template workflows support both OpenDoPE or bound content controls and traditional mail merge fields. The server can report a template’s expected data before filling it, including skeleton XML, XPath expressions, conditions, field names, and format switches. Filled documents retain the template’s formatting. Repeating sections and conditional content are processed for the XML-based template format.

## How it works

Run the packaged Java application over stdio and provide one or more permitted document directories with `--root`. Tool paths are checked against those roots after symlink resolution; the server has no default root and will not start without one. Protocol messages go to stdout, while logs go to stderr.

The docx4j Word documents MCP server writes generated files only when the requested output path is within an allowed root. Writers do not overwrite an existing file unless `overwrite: true` is supplied. Text returned directly to the client is limited by `--max-inline-chars`, which defaults to 200,000 characters. Larger results can be written to an output path or truncated with a marker.

## Setup and configuration

Build requirements are JDK 17 or newer and Maven. `mvn package` produces a runnable shaded JAR, and `mvn test` runs the JUnit 5 tests. The application can be started with a command such as:

```bash
java -jar target/docx4j-mcp.jar --root /path/to/documents
```

The project also provides an `.mcpb` bundle for Claude Desktop, a Docker image, and a Claude Code plugin. Docker mounts a host directory at `/data`; paths passed to tools then use the container path. The Claude Code plugin can use `DOCX4J_MCP_JAR` and optionally `DOCX4J_MCP_ROOTS`.

## Tools and capabilities

The docx4j Word documents MCP server provides these tools:

- `describe_template` identifies data requirements for OpenDoPE, bound controls, and mail merge templates.
- `fill_template` applies XML or JSON data while preserving document formatting.
- `convert_to_pdf` uses XSL-FO and Apache FOP, supports table-of-contents updates, and reports font substitutions.
- `markdown_to_docx` handles headings, numbering, GFM tables, footnotes, task lists, and TeX math.
- `docx_to_markdown` preserves document structure and can accept or mark tracked changes.
- `html_to_docx` normalizes loose HTML, maps heading elements to Word styles, and supports an `altchunk` mode.
- `convert_to_html` produces standalone HTML and can export images separately.
- `extract_text` returns plain text from paragraphs and tables.

Math can travel through supported conversions: TeX in Markdown and MathML in HTML become editable Word equations, while PDF output renders equations and WMF/EMF drawings as vectors. HTML output uses native MathML without JavaScript.

## Limitations and notes

Remote images and stylesheets are not fetched during HTML import. A very long single display equation is treated as one atomic PDF graphic and does not wrap. PDF conversion includes metric-compatible fonts such as Carlito, Caladea, Liberation, and Tinos, but the tool reports substitutions when requested fonts are unavailable. The documented license is Apache License 2.0.

_Full upstream README: https://allmcps.com/mcp/docx4j-word-documents/readme_

