Safe Docx
@UseJunior
About Safe Docx
Edit Word (.docx) documents with tracked changes, redlines, and formatting preservation. Built for AI coding agents. Surgical text replacement, comments, footnotes, and document comparison — all local, no cloud upload. MIT licensed.
Config
Add this server to your MCP-compatible client using the configuration below.
{
"mcpServers": {
"safe-docx": {
"command": "npx",
"args": [
"-y",
"@usejunior/safe-docx"
]
}
}
}Tools
26Read document content (DOCX, ODT, or Google Doc). Output is token-limited (~14k tokens) by default with pagination metadata (has_more, next_offset). Use offset/limit to paginate.
Get a compact structural map of a document's headings (DOCX only). Each entry is `{paragraph_id, text, level, source}`. Deterministic sources are `word_style`, `list_metadata`, and `outline_level`, selected in that precedence order and included by default. Heuristic sources are `run_in_header`, `title_with_period`, `title_with_colon`, `title_caps_centered`, and `title_bare`; set include_heuristic_headings=true to include them. JSON preserves levels 1-9; Markdown clamps visual ATX depth to 6. Read-only.
Search paragraphs with regex. Use file_path for session-based search, file_paths for stateless multi-file search, or google_doc_id for Google Docs. ODT supported via file_path (single-file) only.
Single-agent front door for applying multiple edit steps (replace_text, insert_paragraph) to a document in one call. Validates all steps first, rejects conflicts before applying anything, then executes valid steps sequentially. Accepts inline steps or a plan_file_path JSON array. Surface: revisionable — every applied step emits native OOXML tracked changes.
Replace text in a paragraph by provider paragraph id, preserving formatting where supported. Supports DOCX, ODT, and Google Docs. Surface: revisionable — DOCX edits emit native OOXML tracked changes (w:ins/w:del/w:rPrChange).
Insert a paragraph before/after an anchor paragraph by paragraph id. Supports DOCX, ODT, and Google Docs. (ODT paragraph ids are positional and shift after insertion — re-read before further edits.) Surface: revisionable — DOCX insertions emit native OOXML tracked changes.
Persist the current in-memory document session. For DOCX: saves clean and/or tracked changes output. For ODT: saves an .odt package. For Google Docs: checkpoint (default) returns revisionId, or snapshot exports as DOCX. Surface: revisionable — the save report lists both the AI revisions applied and a non-revision change manifest of any package-level mutations (comment/footnote side parts, relationships) that have no tracked-change wrapper.
Export a document to a portable rendering (Markdown, semantic HTML, or plain text). Writes an output file (default: source path with the format extension, e.g. .md, .html, or .txt) and returns its path, byte count, and the rendered content (under `content`). Intentionally lossy (no round-trip); HTML is the semantic tier, not pixel-faithful. DOCX only — Google Docs is not supported.
Convert a DOCX document to OpenDocument Text (.odt) using the native model-to-model converter (no LibreOffice involved). Writes the .odt (default: source path with the .odt extension), validates ODF packaging safety before writing, and returns the output path plus a `lossiness` summary itemizing every downgraded construct. Conversion is semantic and intentionally lossy: text, headings, bold/italic/underline, hyperlinks, lists, and tables are mapped; richer styling, tracked changes, comments, and headers/footers are not. DOCX in, ODT out — Google Docs and .odt inputs are not supported.
Apply layout controls (paragraph spacing, table row height, cell padding). Google Docs supports paragraph spacing only. Surface: revisionable — DOCX geometry edits emit native property-change revisions (w:pPrChange/w:trPrChange/w:tcPrChange).
Accept all tracked changes in the document body, producing a clean document with no revision markup. Returns acceptance stats.
Selectively accept tracked changes by revision id or author in the in-memory session, leaving all other (e.g. third-party reviewer) revisions byte-untouched. This does not write file_path; call save to persist the mutation. Provide revision_ids (array of w:id values) to target specific revisions, or author to accept every revision by one actor. Sweeps document.xml and supported side-story parts (footnotes, endnotes, comments). An ambiguous overlap — a targeted revision structurally containing, or contained by, a non-targeted revision (nested ins/del/move) — hard-errors with code AMBIGUOUS_REVISION_OVERLAP and a structured `overlaps` list unless normalize_first is set (best-effort, no byte-identical promise).
Selectively reject tracked changes by revision id or author in the in-memory session (restoring their pre-edit state), leaving all other revisions byte-untouched. This does not write file_path; call save to persist the mutation. Symmetric to accept_ai_edits: provide revision_ids or author, sweeps document.xml and supported side-story parts, and hard-errors on an ambiguous overlap (code AMBIGUOUS_REVISION_OVERLAP with a structured `overlaps` list) unless normalize_first is set.
Check whether the document body contains tracked-change markers (insertions, deletions, moves, and property-change records). Read-only.
Get file/session metadata including edit count, normalization stats, and cache info. Supports DOCX, ODT, and Google Docs.
Close an open file session, or close all sessions with explicit confirmation. Supports DOCX, ODT, and Google Docs.
Add a comment or threaded reply to a document. Provide target_paragraph_id + anchor_text for root comments, or parent_comment_id for replies. Supports DOCX and ODT (ODT backs comments with office:annotation; threaded replies are DOCX-only). Surface: revisionable + package-mutation — the body-story comment reference is tracked (w:ins), while comment text and author metadata are recorded in the save report non-revision change manifest.
Get all comments from the document with IDs, authors, dates, text, and anchored paragraph IDs. Range-anchored DOCX comments also expose optional end_paragraph_id, start_run_index, start_char_offset, end_run_index, and end_char_offset fields describing the covered span. Includes threaded replies (DOCX). Supports DOCX and ODT. Read-only.
Delete a comment and all its threaded replies from the document. Cascade-deletes all descendants. Surface: revisionable + package-mutation — the body-story comment reference removal is tracked (w:del), while comment/reply text cleanup is recorded in the save report non-revision change manifest.
Compare two documents and produce a tracked-changes output document. Provide original_file_path + revised_file_path for standalone comparison, or file_path to compare session edits against the original. DOCX and ODF (.odt) support both modes. DOCX stats count insertions/deletions as contiguous ranges, expose atom totals as insertedAtoms/deletedAtoms, and report formatChanges separately from modifiedParagraphs. ODF compares at inline granularity (a modified paragraph is marked up in place — only the changed spans are struck or inserted).
Get all footnotes from the document with IDs, display numbers, text, and anchored paragraph IDs. Read-only.
Add a footnote anchored to a paragraph. Optionally position the reference after specific text using after_text. Note: [^N] markers in read_file output are display-only and not part of the editable text used by replace_text. Surface: revisionable + package-mutation — the footnote reference and note text are tracked (w:ins), while footnote-part creation and registration are recorded in the save report non-revision change manifest.
Update the text content of an existing footnote. Surface: revisionable — note-text changes emit native OOXML tracked changes (w:ins/w:del) inside the footnote body.
Delete a footnote and its reference from the document. Surface: revisionable — the reference and note text are removed as native OOXML tracked deletions (w:del).
Clear specific run-level formatting (bold, italic, underline, highlight, color, font) from paragraphs. Surface: revisionable — clearing emits a native run-property-change revision (w:rPrChange).
Extract tracked changes as structured JSON with before/after text per paragraph, revision details, and comments. Supports pagination via offset and limit. Read-only - does not modify the document.
Overview
What is Safe Docx?
Safe Docx is an open-source TypeScript stack for surgical editing of existing Microsoft Word .docx files. It is optimized for coding-agent workflows that need deterministic, formatting‑preserving edits on existing documents, where a human still must review changes.
How to use Safe Docx?
Install and run via npx -y @usejunior/safe-docx. For MCP clients (Claude Code, Claude Desktop, Gemini CLI, or any stdio‑based MCP client), configure the MCP server with command npx and args ["-y", "@usejunior/safe-docx"]. The server provides typed MCP tools that agents call automatically — no manual integration code needed.
Key features of Safe Docx
- Deterministic, formatting‑preserving text replacement and paragraph insertion
- Tracked‑changes outputs for human review
- Comment and footnote workflows
- Revision extraction as structured JSON
- TypeScript runtime — no .NET, Python, or LibreOffice required
- Auditable behavior with test evidence and traceability artifacts
Use cases of Safe Docx
- Editing an NDA to change governing law and outputting both a clean and tracked‑changes copy
- Multistep contract translation pipelines in law firms
- Automated contract markup review (e.g., 22M+ tokens processed by a 150‑lawyer firm)
- Brownfield
.docxediting in HR, procurement, finance, sales ops, and legal workflows - Generating comparison documents and revision artifacts from existing Word files
FAQ from Safe Docx
What document types has Safe Docx been tested on?
In‑repo fixtures include mutual NDAs (Common Paper‑ and Bonterms‑style), Letters of Intent, and ILPA limited partnership agreement redline files.
Does Safe Docx require .NET, Python, or LibreOffice in normal runtime usage?
No. Supported runtime usage is JavaScript/TypeScript with jszip and @xmldom/xmldom.
Does Safe Docx preserve formatting during edits?
That is a core design goal. The tool surface uses surgical operations like replace_text and insert_paragraph that preserve document structure and formatting as much as possible.
Can Safe Docx generate contracts from scratch?
Not the primary focus. For from‑scratch generation, use packages such as docx. Safe Docx is optimized for editing existing documents.
Where does document data live and how is it transported?
Safe Docx runs entirely on your local machine. No document content is sent to external servers. MCP transport is stdio.
Frequently asked questions
What document types has Safe Docx been tested on?
In‑repo fixtures include mutual NDAs (Common Paper‑ and Bonterms‑style), Letters of Intent, and ILPA limited partnership agreement redline files.
Does Safe Docx require .NET, Python, or LibreOffice in normal runtime usage?
No. Supported runtime usage is JavaScript/TypeScript with `jszip` and `@xmldom/xmldom`.
Does Safe Docx preserve formatting during edits?
That is a core design goal. The tool surface uses surgical operations like `replace_text` and `insert_paragraph` that preserve document structure and formatting as much as possible.
Can Safe Docx generate contracts from scratch?
Not the primary focus. For from‑scratch generation, use packages such as `docx`. Safe Docx is optimized for editing existing documents.
Where does document data live and how is it transported?
Safe Docx runs entirely on your local machine. No document content is sent to external servers. MCP transport is stdio.
Basic information
More Files & Storage MCP servers
WORK IN PROGRESS - USE WITH CAUTION - Windows:
hanwegMCP server for working with PDF files
Filesystem MCP Server SSE
ysthinkThe SSE version of the MCP service is modified from the Filesystem MCP server
MCP File System Server
MarcusJellinghausMCP Workspace Server: A secure Model Context Protocol server providing file, git, and GitHub tools for AI assistants within a sandboxed project directory.
PDF Extraction MCP Server (Claude Code Fork)
xraywuMCP server to extract contents from a PDF file
Claude Document MCP Server
alejandroBallesterosCA lightweight MCP server for processing, editing, and interacting with PDF, Word, Excel, and CSV documents.
Comments