docx/

directory
v1.5.175 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 29, 2026 License: MIT

README

Golder docx MCP extension

golder-docx is a separate MCP stdio executable for reading, creating and editing .docx files inside the current workspace. It uses docxgo v2 for document construction and template replacement, with a security layer in front: workspace-confined paths, ZIP/XML resource limits, macro/embedded-content rejection, image re-encoding and atomic output.

Build

GOWORK=off go build -o .build/golder-docx ./extension/plugins/docx/cmd/golder-docx

Install from the desktop GUI

Open Extensions → DOCX → Install & enable. No TOML edit is required. The menu downloads the matching signed helper, shows the current phase and byte progress, and then asks for the normal explicit source approval.

Download order is:

  1. direct GitHub release asset;
  2. every mirror prefix configured in GOLDER_MIRROR (space-separated), one at a time;
  3. the helper bundled with the desktop app, if the release or network is unavailable.

Checksums come from the same release. Mirror checksum copies must agree, and the archive and extracted binary are verified before installation. A failed mirror is skipped and the next source is attempted; progress shows the source host and source N/M. Set GOLDER_MIRROR=off to disable mirror fallback.

The installed helper lives under the protected Golder state directory. The source is written disabled and is enabled only by the explicit GUI action.

Generate a disabled source table and merge it into $GOLDER_HOME/config.toml:

.build/golder-docx print-config
[mcp.servers.docx]
enabled = false
transport = "stdio"
command = "/abs/path/golder-docx"
args = ["serve"]
allowed_tools = ["docx_read", "docx_create", "docx_edit", "docx_render"]
call_timeout = "30s"
network = false

The workspace root is the process working directory. Use --root <dir> only when the host does not start the plugin in the project directory; the root is part of the source fingerprint and must be re-approved after a change.

golder mcp inspect docx
golder mcp enable docx --yes

Tools

docx_read (read-only)
{"path": "docs/report.docx", "format": "markdown", "max_chars": 200000}

format is text, markdown or outline. Returns paragraphs, table text and image metadata (format, pixel size, alt text). It does not return image bytes, execute macros, follow external links, or download anything. Document text is untrusted data, not instructions.

docx_create
{
  "path": "docs/report.docx",
  "title": "Quarterly report",
  "blocks": [
    {"type": "heading", "level": 1, "text": "Summary"},
    {"type": "paragraph", "text": "Revenue grew."},
    {"type": "bullets", "items": ["one", "two"]},
    {"type": "table", "rows": [["Name", "Value"], ["A", "1"]]},
    {"type": "image", "path": "logo.png", "width_px": 240, "height_px": 120}
  ],
  "overwrite": false
}

Images are decoded, pixel-limited, re-encoded as PNG and embedded. Headings use the built-in Heading1..Heading6 styles. Output is written through a sibling temp file and renamed into place; an existing file is kept unless overwrite=true.

docx_edit
{
  "path": "docs/template.docx",
  "output": "docs/filled.docx",
  "replacements": {"{{name}}": "Alice"},
  "append": [{"type": "paragraph", "text": "Generated by golder"}],
  "overwrite": false
}

Replacement is literal and case-sensitive. The input is never modified in place; the output is a separate workspace-relative .docx. Macro-enabled, encrypted, OLE, altChunk, ActiveX and embedded-object packages are rejected before parsing.

docx_render

Render a table-based report into a copy of a workspace template, preserving the template's formatting:

{
  "path": "templates/report.docx",
  "output": "reports/filled.docx",
  "data": {
    "policyNo": "P-123",
    "title": "投保流程",
    "steps": [
      {"description": "1.提示进入投保流程", "images": ["shots/1.png"]},
      {"description": "2.填写被保人信息", "images": ["shots/2a.png", "shots/2b.png"]}
    ]
  },
  "images_per_row": 2,
  "image_width_px": 180
}

The template must contain one 2-column table:

  • row 1: policy label and value
  • row 2: report title (may span both columns)
  • row 3: prototype step row; its right cell must contain one inline drawing

Each data.steps item clones the prototype row. The left cell gets description; the right cell receives its images, images_per_row at a time. Images are decoded, pixel-limited, re-encoded as PNG, deduplicated by path and given unique relationships. Empty steps keeps only the two header rows. Output is atomic; overwrite=true replaces an existing file.

Security boundary

Control Limit
Input .docx 25 MiB
ZIP entries 1024
Single extracted part 32 MiB
Total extracted 128 MiB
Compression ratio 200:1
XML part 32 MiB, depth 128
Image 20 MiB, 25 megapixels, 64 per document
Read output 2M chars
Output .docx 50 MiB
Table 200 rows × 50 columns, 20k cells

Paths must be workspace-relative, end in .docx (images: PNG/JPEG/GIF), and must not be symlinks. Absolute paths, .., NUL and backslash separators are rejected. Output parents must resolve inside the workspace. Writes are atomic and mode 0600.

The plugin does not use docxgo's JSON-RPC/CLI mode and does not perform a byte-for-byte round-trip of untrusted input; it reads standard body content and creates new documents from the structured model. The audit and threat model are in docs/docx-plugin-design.md.

Tests

GOWORK=off go test ./extension/plugins/docx/...

The suite covers path traversal, symlinks, macro/.docm rejection, OLE packages, deep XML, unsafe/duplicate part names, ZIP entry limits, overwrite guards, read truncation, and create/read/edit round-trips with an image.

Versioning

The helper version lives in version/version.go and is reported by golder-docx --version and MCP initialization. The docxgo dependency is pinned to v2.16.0.

Directories

Path Synopsis
cmd
golder-docx command
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL