SafeDocX is a local MCP server for editing .docx files with full formatting preservation and tracked changes. It runs via npx -y @usejunior/safe-docx using stdio transport.
SafeDocX runs locally only — no data leaves the machine. All document reads and writes happen on the local filesystem. There is no remote endpoint.
- read_file — Read document content with stable paragraph IDs (
_bk_*). Supportstoon,json, andsimpleoutput formats. Useoffset/limitfor pagination. - grep — Regex search across paragraphs. Returns paragraph anchors with match context. Use
dedupe_by_paragraph(default true) to get one result per paragraph. - get_session_status — Get session metadata including edit count and normalization stats.
- has_tracked_changes — Check whether the document contains tracked-change markers (insertions, deletions, moves, property changes). Read-only.
- batch_edit — Validate and apply multiple edit steps (replace_text, insert_paragraph) in one call. Validates all steps and rejects conflicts (duplicate ids, overlapping replace ranges, insert-slot collisions) before applying anything; an execution-time failure stops at the first failing step and reports which steps completed. Accepts inline
stepsor aplan_file_path.
- replace_text — Find-and-replace within a single paragraph by
_bk_*ID. Preserves formatting across run boundaries. Supports inline tags:<b>,<i>,<u>,<highlighting>. - insert_paragraph — Insert a new paragraph before or after an anchor paragraph by
_bk_*ID. Optionalstyle_source_idto clone formatting from a different paragraph. - add_comment — Add comments or threaded replies anchored to paragraphs.
- get_comments — Get all comments with IDs, authors, dates, anchored paragraphs, and threaded replies. Read-only.
- delete_comment — Delete a comment and all its threaded replies.
- accept_changes — Accept all tracked changes in the document body, producing a clean document.
- get_footnotes — Get all footnotes with IDs, display numbers, text, and anchored paragraph IDs. Read-only.
- add_footnote — Add a footnote anchored to a paragraph with optional positioning via
after_text. - update_footnote — Update the text content of an existing footnote.
- delete_footnote — Delete a footnote and its reference from the document.
- format_layout — Apply deterministic paragraph spacing, table row height, and cell padding without changing text content.
- save — Save edited document as clean output, tracked-changes redline, or both. Default is both.
- compare_documents — Compare two DOCX files and produce a redline with track changes.
- extract_revisions — Extract tracked changes as structured JSON with before/after text per paragraph. Supports pagination.
- clear_session — Clear one session, all sessions for a file, or all sessions.
- Call
read_filewithfile_pathto see content and get_bk_*IDs. - Use
grepto find specific text and get target paragraph IDs. - Call
replace_textwithtarget_paragraph_id,old_string,new_string, andinstruction. - Call
savewithsave_to_local_pathto save (defaults to both clean + tracked outputs).
- Build edit steps as JSON (each with
step_id,operation, and operation-specific fields). - Call
batch_editwithsteps(orplan_file_path) to validate, conflict-check, and apply them in one call.
- Call
compare_documentswithoriginal_file_path,revised_file_path, andsave_to_local_path. - Call
extract_revisionswith the saved redlinefile_pathto get structured diffs.
- Call
extract_revisionswithfile_pathpointing to a document with tracked changes. - Review the structured JSON output with
before_text,after_text, and revision details per paragraph.
- Tools accept
file_pathdirectly for session auto-resolution. - The server auto-resolves sessions per file path, reusing the most recent active session.
- Documents are automatically normalized on open (run merging, redline simplification) for better text matching.