docx4j Word documents

io.github.plutext由 GitHub 账号 plutext 发布v0.2.0更新于 Oct 24, 2026

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

已验证STDIO仅桌面效率与工作流文件与存储

概览

AI 生成的概览

让助手读取、转换和填充 Word .docx 文档,包括模板、Markdown、HTML 以及 PDF 输出。

可以做什么
封装 docx4j 引擎,向 MCP 客户端提供 Word 文档处理能力。工具包括用于 OpenDoPE 或邮件合并模板的 describe_template 和 fill_template,以及 convert_to_pdf、markdown_to_docx、docx_to_markdown、html_to_docx、convert_to_html 和 extract_text。数学公式端到端支持:TeX 和 MathML 会变成可编辑的 Word 公式,并在 PDF 和 HTML 输出中渲染。
适用场景
适合助手需要处理 Word 文件的场景:填充合同或信函模板、在 docx、Markdown、HTML 和 PDF 之间转换,或从文档中提取文本。适用于文档存放在本地文件夹、由服务器获准访问的桌面工作流。
运行要求
通过 stdio 在本地运行,需要 PATH 中有 Java 17+。可以以 .mcpb 包、jar、OCI 镜像或 Claude Code 插件形式安装。必须至少指定一个 --root 目录,否则服务器拒绝启动;插件使用 DOCX4J_MCP_JAR,可选 DOCX4J_MCP_ROOTS。未声明认证或 API 密钥。
安装前请注意
每个文件路径都必须解析到已配置的 --root 目录内,因此你授予的文件夹决定了助手能读写什么。写入类工具接受 output_path,除非 overwrite 为 true,否则拒绝覆盖。文件在本地处理;HTML 转换时不会抓取远程图片和样式表。

安装

在 SourceWeft 中

  1. 打开 控制台中的 docx4j Word documents,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

docx4j-mcp

A Model Context Protocol server that exposes docx4j's engine to AI agents: read, convert and fill Word (.docx) documents from Claude Desktop, Claude Code, or any MCP client.

Engine: docx4j 17.1.0 (the server versions independently; the bundled docx4j version is in the pom, the server's startup log, and its MCP instructions).

MCP protocol: 2025-11-25 (Java SDK 2.0.1, the newest available). Clients speaking the 2026-07-28 spec work if they implement its dual-era fallback: the server/discover probe gets a clean JSON-RPC -32601 and the client falls back to initialize (verified over stdio). A modern-only client with no fallback cannot connect until the SDK's 2026-07-28 support (milestone 2.2) ships, at which point this server will migrate.

Status: phase 3 — all tools work over stdio against released docx4j 17.0.4; packaged as a runnable jar, an .mcpb bundle, an OCI image and a Claude Code plugin. The plan, tool surface and phasing are in CR-mcp-server.md.

Build

Requires JDK 17+. All docx4j dependencies (docx4j 17.1.0, ImportXHTML 17.0.4) come from Maven Central.

bash
mvn package            # -> target/docx4j-mcp.jar (shaded, runnable)mvn test               # JUnit 5 tests against the tool handlers directly

Run

bash
java -jar target/docx4j-mcp.jar --root /path/to/documents [--root ...] [--max-inline-chars N]

Bare directory arguments are also accepted as roots (this is what the .mcpb bundle's folder picker passes).

Claude Desktop, one click

Install docx4j-mcp.mcpb from the GitHub release (Settings → Extensions), pick the folders the server may touch, done. Built locally with packaging/build-mcpb.sh. Requires Java 17+ on your PATH.

Docker

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

(paths in tool calls are then container paths under /data; packaging/docker/Dockerfile to build locally).

Claude Code plugin

packaging/claude-plugin/ bundles the server config and a skill for the template/authoring workflows. Set DOCX4J_MCP_JAR (path to the jar) and optionally DOCX4J_MCP_ROOTS.

Releasing

Tag vX.Y.Z: .github/workflows/release.yml builds jar + mcpb, attaches them to the GitHub release, pushes ghcr.io/plutext/docx4j-mcp, and publishes server.json (sha filled in) to the official MCP registry via GitHub OIDC.

Every file path an agent passes must resolve inside one of the --root directories (symlinks are resolved first). There is no default root; the server refuses to start without one. Logging goes to stderr; stdout is the protocol. Tools that return text inline cap it at --max-inline-chars (default 200000) and otherwise write to output_path or truncate with a marker.

Claude Code (.mcp.json in your project)

json
{  "mcpServers": {    "docx4j": {      "command": "java",      "args": ["-jar", "/path/to/docx4j-mcp.jar", "--root", "/path/to/documents"]    }  }}

Claude Desktop (claude_desktop_config.json)

json
{  "mcpServers": {    "docx4j": {      "command": "java",      "args": ["-jar", "/path/to/docx4j-mcp.jar", "--root", "/Users/you/Documents"]    }  }}

Tools

ToolWhat it does
describe_templateWhat 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_templateFill 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_pdfdocx → 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_docxMarkdown → properly styled docx (headings, numbering, GFM tables, footnotes, task lists, TeX math). Optional styles_template_path.
docx_to_markdowndocx → Markdown (structure preserved). Options: tracked_changes accept/markup, image_dir_path.
html_to_docxHTML → 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_htmldocx → standalone HTML (visitor exporter; image_dir_path for images; optional update_toc).
extract_textPlain text, one line per paragraph/table.

Mathematics is supported end to end: TeX math in Markdown ($..$) and MathML in HTML become real, editable Word equations (OMML), and equations render in PDF (via jeuclid/FOP, no LaTeX toolchain) and HTML (native MathML, no JavaScript) output. Known limitation: a very long single display equation is one atomic graphic in PDF and does not line-wrap.

Writers take output_path and refuse to overwrite unless overwrite: true.

Example (Claude Code)

Use describe_template on contracts/nda-template.docx, then fill it for Acme Pty Ltd and write contracts/nda-acme.docx, then convert that to PDF.

The agent gets the skeleton XML (or MERGEFIELD names), fills it, and calls fill_template and convert_to_pdf; the results tell it what was written and which fonts were substituted.

Licence

Apache License 2.0.

来源:README.md,提交 58f53b1

工具

0
SourceWeft 尚未在沙箱中启动过该软件包,因此其工具未知。

版本历史

1
  1. v0.2.0最新Sep 16, 2026

评分

已满足适用检查项的 40%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分

    请在仓库或注册中心条目中声明许可证。