@usejunior/docx-mcp 0.16.0 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,280 +1,28 @@
1
1
  # @usejunior/docx-mcp
2
2
 
3
- [![npm version](https://img.shields.io/npm/v/%40usejunior%2Fdocx-mcp)](https://www.npmjs.com/package/@usejunior/docx-mcp)
4
- [![CI](https://github.com/UseJunior/safe-docx/actions/workflows/ci.yml/badge.svg)](https://github.com/UseJunior/safe-docx/actions/workflows/ci.yml)
5
- [![License: Apache 2.0](https://img.shields.io/badge/license-Apache--2.0-green.svg)](https://github.com/UseJunior/safe-docx/blob/main/LICENSE)
3
+ MCP tools for reading, editing, and comparing `.docx` and `.odt` files.
6
4
 
7
- **Install via the canonical package:** `npx -y @usejunior/safe-docx` — [see setup guide](../../README.md)
5
+ [![npm](https://img.shields.io/npm/v/%40usejunior%2Fdocx-mcp)](https://www.npmjs.com/package/@usejunior/docx-mcp)
6
+ [![Apache 2.0](https://img.shields.io/badge/license-Apache--2.0-green.svg)](../../LICENSE)
8
7
 
9
- Local MCP server for surgical editing of existing Microsoft Word `.docx` files with coding agents. The same tool surface also services OpenDocument `.odt` files — including `compare_documents` redlines (two files, or a live session against its original) written as native ODF tracked changes with inline (run-level) granularity.
10
-
11
- Safe Docx is built for brownfield paperwork workflows: apply accepted AI edits to real Word documents while preserving formatting and review semantics.
12
-
13
- Mission: enable coding agents to do paperwork too. This package focuses on deterministic brownfield edits to existing Word documents rather than from-scratch generation.
14
-
15
- For end-user installation, use the canonical wrapper package: `npx -y @usejunior/safe-docx`.
16
-
17
- ## Why This Package
18
-
19
- - purpose-built MCP tool surface for existing-document operations
20
- - local-first runtime with no Python/LibreOffice requirement for supported paths
21
- - auditable behavior through tests, traceability, and conformance assets
22
-
23
- ## Quickstart
24
-
25
- ```bash
26
- npx -y @usejunior/safe-docx
27
- ```
28
-
29
- Add to your MCP client:
30
-
31
- - Command: `npx`
32
- - Args: `["-y", "@usejunior/safe-docx"]`
33
- - Transport: `stdio`
34
-
35
- ## Primary Workflows
36
-
37
- - Apply targeted edits while preserving formatting (`replace_text`, `insert_paragraph`, `format_layout`)
38
- - Produce clean and tracked variants for human review (`save`)
39
- - Compare original vs revised documents into tracked output (`compare_documents`)
40
- - Extract revisions as structured JSON (`extract_revisions`)
41
- - Manage comments and footnotes as first-class operations
42
-
43
- ## Tool Categories
44
-
45
- - Read/Search: `read_file`, `grep`, `has_tracked_changes`, `get_session_status`
46
- - Edit/Layout: `replace_text`, `insert_paragraph`, `format_layout`, `accept_changes`
47
- - Batch: `batch_edit`
48
- - Compare/Revision: `compare_documents`, `extract_revisions`, `save`
49
- - Comments/Footnotes: `add_comment`, `get_comments`, `delete_comment`, `get_footnotes`, `add_footnote`, `update_footnote`, `delete_footnote`
50
- - Session/Safety: `clear_session`, path-policy + archive guardrails
51
-
52
- ## Heading detection in `read_file(format="json")`
53
-
54
- Each paragraph node in the JSON output may expose a top-level `heading` object:
55
-
56
- ```ts
57
- heading?: {
58
- text: string;
59
- source: 'word_style' | 'run_in_header' | 'title_with_period' | 'title_with_colon' | 'title_caps_centered' | 'title_bare';
60
- level: number | null;
61
- }
62
- ```
63
-
64
- Use `node.heading != null` as the canonical heading check.
65
-
66
- - `source: 'word_style'` wins whenever `paragraph_style_id` matches `/^Heading([1-6])$/` exactly, and only then. Inherited styles like `HeadingPara1` do not count.
67
- - Heuristic sources (`run_in_header`, `title_with_period`, `title_with_colon`, `title_caps_centered`, `title_bare`) always emit `level: null`.
68
- - Body paragraphs omit the `heading` key entirely.
69
-
70
- `list_metadata.header_style` remains the per-detector explanation layer, not the canonical "is heading" predicate. See [`skills/docx-editing/SKILL.md`](../../skills/docx-editing/SKILL.md) for the full precedence rule and the Google Docs asymmetry: the GDocs path only emits `heading` for built-in heading styles and does not run the Word heuristics.
71
-
72
- ## Document Families
73
-
74
- ### Automated fixture coverage in this repo
75
-
76
- - Common Paper style mutual NDA fixtures
77
- - Bonterms mutual NDA fixture
78
- - Letter of Intent fixture
79
- - ILPA limited partnership agreement redline fixtures
80
-
81
- ### Designed for complex legal and business `.docx` classes
82
-
83
- - NVCA financing forms
84
- - YC SAFEs
85
- - Offering memoranda
86
- - Order forms and services agreements
87
- - Limited partnership agreements
88
-
89
- ## Install By Client
90
-
91
- ### Claude Desktop
92
-
93
- Add to `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS) or `%APPDATA%\\Claude\\claude_desktop_config.json` (Windows):
94
-
95
- ```json
96
- {
97
- "mcpServers": {
98
- "safe-docx": {
99
- "command": "npx",
100
- "args": ["-y", "@usejunior/safe-docx"]
101
- }
102
- }
103
- }
104
- ```
105
-
106
- ### Claude Code
8
+ End users should run the wrapper package:
107
9
 
108
10
  ```bash
109
- claude mcp add safe-docx -- npx -y @usejunior/safe-docx
110
- ```
111
-
112
- ### Gemini CLI
113
-
114
- Install from the extension gallery, or add manually:
115
-
116
- ```json
117
- {
118
- "mcpServers": {
119
- "safe-docx": {
120
- "command": "npx",
121
- "args": ["-y", "@usejunior/safe-docx"]
122
- }
123
- }
124
- }
125
- ```
126
-
127
- ### Cline / VS Code
128
-
129
- Add to `cline_mcp_settings.json`:
130
-
131
- ```json
132
- {
133
- "mcpServers": {
134
- "safe-docx": {
135
- "command": "npx",
136
- "args": ["-y", "@usejunior/safe-docx"]
137
- }
138
- }
139
- }
11
+ npm install --global @usejunior/safe-docx
12
+ safe-docx
140
13
  ```
141
14
 
142
- ## Trust Boundary
143
-
144
- Safe Docx in this package is local runtime only:
145
-
146
- - Runs as a local process on your machine
147
- - Reads/writes local filesystem paths allowed by path policy
148
- - Does not expose a hosted Safe Docx editor endpoint
149
-
150
- More detail:
151
-
152
- - `docs/safe-docx/trust-checklist.md`
153
- - `docs/safe-docx/mcp-docs-checklist.md`
154
-
155
- Runtime safety guardrails:
156
-
157
- - Path policy defaults to `HOME` and system temp roots
158
- - Symlink-resolved paths must remain inside allowed roots
159
- - `.docx` archive guardrails reject suspicious archives:
160
- - `SAFE_DOCX_MAX_ARCHIVE_ENTRIES` (default `2000`)
161
- - `SAFE_DOCX_MAX_UNCOMPRESSED_BYTES` (default `209715200`)
162
- - `SAFE_DOCX_MAX_ENTRY_UNCOMPRESSED_BYTES` (default `52428800`)
163
- - `SAFE_DOCX_MAX_COMPRESSION_RATIO` (default `200`)
164
-
165
- Build-time tooling for advanced rendering is optional and not required by default `npx` runtime usage.
15
+ See [installation and verification](../../docs/installation.md) for pinned versions, package inspection, source builds, and MCP client configuration.
166
16
 
167
- ## Where It Runs
17
+ ## Tools
168
18
 
169
- No native binaries and no .NET prerequisite for supported runtime usage. Safe Docx operates on `Uint8Array` / `Buffer` inputs via `jszip` + `@xmldom/xmldom`:
19
+ - read and search document content;
20
+ - apply text, paragraph, formatting, comment, and footnote edits;
21
+ - inspect and accept tracked changes;
22
+ - save clean and tracked copies;
23
+ - compare two documents;
24
+ - export documents and structured revisions.
170
25
 
171
- - Local MCP server (default)
172
- - Cloudflare Workers / Durable Objects
173
- - Vercel Functions / workflow steps
174
- - AWS Lambda / Lambda@Edge
175
- - Docker / any container runtime
176
- - Any V8 isolate or Node.js process
26
+ See the [generated tool reference](docs/tool-reference.generated.md) for the complete schemas.
177
27
 
178
- If you need direct library imports in app code, use `@usejunior/docx-core`.
179
-
180
- ## Paragraph Identity
181
-
182
- `read_file` returns paragraphs with `id` fields like `_bk_a3f29c10b8e4`. These identifiers are **deterministic and stable**, not session-scoped.
183
-
184
- | Field | Role | Editable anchor? | Stability |
185
- |-------|------|------------------|-----------|
186
- | `id` (`_bk_<12hex>`) | Canonical edit anchor — only thing edit tools accept | ✅ | Byte-identical across reopens, machines, and processes for **identical stored DOCX/OOXML bytes**. Intrinsic branch (Word 2010+ `w14:paraId`) is robust to text edits; fallback branch changes when paragraph or neighbor text changes. |
187
- | `content_fingerprint` (opt-in) | Portable normalized-text hash for citation/reconciliation systems | ❌ — read-only metadata | Same normalized text → same hash on any machine. Changes when normalized text changes. **Not unique per paragraph** — two paragraphs with identical normalized text fingerprint identically. |
188
-
189
- Consumers MAY persist `_bk_*` identifiers in indexes, citation databases, and other external stores keyed off the same source document.
190
-
191
- For citation systems that want a portable hash whose canonicalization is documented and recomputable independent of safe-docx internals, pass `include_fingerprint: true` to `read_file` with `format: "json"`:
192
-
193
- ```jsonc
194
- {
195
- "id": "_bk_a3f29c10b8e4",
196
- "content_fingerprint": "sha256:nfkc:5d2e8f1a4c5b7d2e8f1a4c5b7d2e8f1a",
197
- "clean_text": "The Company shall indemnify the Customer."
198
- }
199
- ```
200
-
201
- The fingerprint is computed as `"sha256:nfkc:" + sha256( stripCfInvisibles(NFKC(visibleText)).replace(/\s+/g, " ").trim() )`, truncated to 32 hex chars. Case is preserved; curly quotes and dashes are NOT folded to ASCII. Cf-category invisibles (soft hyphen, ZWJ/ZWNJ, LRM/RLM, bidi controls, variation selectors, BOM) are stripped so byte-level round-trip noise does not change the hash. The flag has no effect on `format: "toon"` or `format: "simple"`, and is silently ignored for Google Docs sessions.
202
-
203
- `content_fingerprint` is a content hash, not a paragraph key. Paragraphs with identical normalized visible text produce identical fingerprints by design; use `_bk_*` IDs whenever you need per-paragraph identity. Edit tools (`replace_text`, `insert_paragraph`, `batch_edit`, etc.) accept ONLY `_bk_*` IDs as anchors — `content_fingerprint` is never an edit anchor. The `sha256:nfkc:` prefix is intentional version reservation; future algorithm bumps will emit a different prefix (e.g. `sha256:nfkc-strip:`), so consumers should store and compare the full prefixed string.
204
-
205
- ## Reliability and Evidence
206
-
207
- - Tool catalog source: `packages/docx-mcp/src/tool_catalog.ts`
208
- - Generated tool reference: `packages/docx-mcp/docs/tool-reference.generated.md`
209
- - OpenSpec traceability matrix: `packages/docx-mcp/src/testing/SAFE_DOCX_OPENSPEC_TRACEABILITY.md`
210
- - Assumption matrix: `packages/docx-mcp/assumptions.md`
211
- - Conformance assets: `packages/docx-mcp/conformance/README.md`
212
- - Conformance guide: `docs/safe-docx/sprint-3-conformance.md`
213
-
214
- Commands:
215
-
216
- ```bash
217
- npm run conformance:smoke -w @usejunior/docx-mcp
218
- npm run conformance:run -w @usejunior/docx-mcp
219
- ```
220
-
221
- Optional OpenAgreements fixture root:
222
-
223
- ```bash
224
- SAFE_DOCX_CONFORMANCE_OPEN_AGREEMENTS_ROOT=/path/to/open-agreements npm run conformance:run -w @usejunior/docx-mcp
225
- ```
226
-
227
- ## FAQ
228
-
229
- ### Is this for editing existing Word files or generating new ones?
230
-
231
- This package is for editing existing `.docx` files. For from-scratch generation, use packages such as [`docx`](https://www.npmjs.com/package/docx).
232
-
233
- ### Does it preserve formatting?
234
-
235
- That is a core objective. The edit tools are built for surgical mutation while preserving run/paragraph formatting semantics.
236
-
237
- ### Is TOON output token-efficient for agent workflows?
238
-
239
- Yes. `read_file` supports `toon` output specifically for compact, agent-friendly reads of existing documents.
240
-
241
- ### Does this require Python, .NET, or LibreOffice?
242
-
243
- No for supported runtime paths. The default MCP runtime is TypeScript/Node-based.
244
-
245
- ### Can it add and delete comment bubbles?
246
-
247
- Yes. Use `add_comment`, `get_comments`, and `delete_comment`.
248
-
249
- ### Can it add and delete footnotes?
250
-
251
- Yes. Use `get_footnotes`, `add_footnote`, `update_footnote`, and `delete_footnote`.
252
-
253
- ### Can it produce tracked changes for review?
254
-
255
- Yes. `save`'s redline is the session's own write-time tracked markup, serialized directly as authored — the edits your tools made are recorded as `w:ins`/`w:del` with a stable author and revision ids, and any pre-existing third-party revisions are preserved. The clean variant is that same document with the AI author's edits accepted; paragraphs the AI never touched stay byte-identical to the source. For a standalone redline between two arbitrary documents (or a session against its original), use `compare_documents` — comparison is opt-in there, not a step baked into every save.
256
-
257
- ### Is processing local-only?
258
-
259
- Yes for this package. It runs as a local process and does not require a hosted Safe Docx editor endpoint.
260
-
261
- ### What document families are explicitly fixture-tested here?
262
-
263
- Mutual NDA variants, Letter of Intent, and ILPA redline fixtures.
264
-
265
- ### Is this only for legal teams?
266
-
267
- No. It is useful anywhere teams edit DOCX paperwork with agents: legal, procurement, sales ops, finance, and HR.
268
-
269
- ## Golden Prompts
270
-
271
- Use these known-good prompt patterns:
272
-
273
- - `packages/docx-mcp/docs/golden-prompts.md`
274
-
275
- ## Development
276
-
277
- ```bash
278
- npm run build -w @usejunior/docx-mcp
279
- npm run test:run -w @usejunior/docx-mcp
280
- ```
28
+ See the [architecture](../../docs/architecture.md), [installation guide](../../docs/installation.md), and [generated tool reference](docs/tool-reference.generated.md).