DraftAgent MCP Server for DOCX Automation
DraftAgent is a local Model Context Protocol server for AI-powered DOCX automation. It lets MCP-compatible clients inspect Word documents, apply structured transformations, and render DOCX files as DOCX, HTML, or PDF artifacts.
For installation and general setup, see the DraftAgent documentation. This page describes the MCP tools, request contract, and supported document operations.
Compatibility note: DraftAgent may not preserve all formatting or document features during transformations. Validate results with your documents before relying on them in production workflows.
The current public MCP schema version is 1. It is returned as schemaVersion by capabilities and the capability resources. The DraftAgent package/server version is separate and may change without changing the MCP contract. Check this value when caching schemas or generated prompts.
Quick start
The server communicates over MCP JSON-RPC on standard input and output. Logs are written to stderr; stdout is reserved for protocol traffic.
Set the workspace directory before starting the server:
export DRAFTAGENT_DOCUMENTS_DIRECTORY=/path/to/documents
draftagent-mcp
The workspace must exist and is canonicalized at startup. Tool paths are relative to this directory. Absolute paths, parent traversal, and symlinks are rejected.
Tools
The current server registers six tools. Request and response schemas are available at runtime through capabilities.
list_files
Read-only workspace file listing. It does not return file contents.
recursivetraverses directories whentrue.extensionfilters by file extension.- Each entry includes
filename, bytesize, modification time, and inferredcontentType. - A response is limited to 10,000 files.
document_inspect
Loads a workspace-relative DOCX and returns package statistics, core metadata, and a session-scoped document handle.
detailacceptsoutline,text, orfull.elements: trueincludes model elements.filter.kinds,pathPrefix,textContains,tableIndex, andsectionIndexfilter elements.offsetandlimitpaginate element output.- Text and full detail include an ordered text projection with Unicode-scalar offsets.
- Element IDs and revisions are scoped to the current session.
document_convert
Loads a DOCX and writes a rendered artifact to outputFile. Supported format values are docx, html, and pdf.
The response includes artifact filename, size, content type, URI, and renderer warnings. An optional title is used during rendering. PDF rendering can warn about font substitutions when a requested font is unavailable; warnings do not prevent the artifact from being written. document_transform also returns renderer warnings when producing HTML or PDF.
document_transform
Applies a non-empty, ordered operations array and writes the result to outputFile.
For an existing document, provide exactly one of:
inputFileto load a workspace document or reuse its latest session; ordocumentwithdocumentIdandrevisionto address an inspected session.
A batch containing createDocument may omit both sources and starts from a blank valid DOCX model. Do not combine createDocument with either source. Output defaults to DOCX; set output.format to docx, html, or pdf. Existing document handles must use the latest revision; stale revisions return STALE_REVISION. Set options.validateOnly to preflight a batch without writing an artifact or publishing a revision.
capabilities
Returns the server and schema versions, supported formats, ZIP and response limits, inspection conventions, error conventions, resources, and the complete transformation operation catalog with schemas and examples. The catalog is the authoritative list of supported operation IDs.
read_capability_resource
Reads a capability resource through a tool call for MCP hosts that do not expose resource methods. Supported URIs are:
draftagent://capabilitiesdraftagent://transforms
Transformation operations
Transformation requests are modeled as an ordered, transactional operations array. Each operation has an op ID and operation-specific fields. The canonical operation inventory is used to generate tools/list, the capabilities catalog, and the draftagent://transforms resource.
The following 43 operation IDs are currently supported:
Text and structural blocks
replaceTextreplaces matching visible paragraph text. Its required fields aresearchandreplaceWith;allcontrols whether every match is replaced (defaulttrue). A match may span adjacent DOCX runs; images and tabs delimit searchable text.replaceElementTextreplaces the content of one paragraph identified by a target.appendParagraphadds a paragraph to the end of the document. Supply string text or structuredparagraphcontent; empty paragraphs are supported.insertParagraphinserts a paragraph before or after a target block.insertBlocksinserts model block inputs at a target position.deleteBlock,moveBlock, andcloneBlockdelete, move, or clone a block. Moved blocks retain their IDs; cloned blocks receive fresh IDs.replaceBlockreplaces a block with supplied blocks, andreplaceBlockRangereplaces an inclusive block range.replaceParagraphContentreplaces a paragraph's runs while preserving the paragraph's element ID.
Formatting
setHeadingLevelsets a paragraph heading level from 1 through 9.setRunFormatsets run styling;applyRunFormatapplies a partial patch;removeRunFormatclears selected fields.setParagraphStylesets paragraph styling;applyParagraphFormatapplies a partial patch;removeParagraphFormatclears selected fields.setRunStylesets run styling using the same run-style properties.
Run formatting includes font family, size, color, bold, italic, underline, and strike. Paragraph formatting includes alignment, spacing, indentation, and related paragraph properties. Spacing before, after, and line values use twentieths of a point; lineRule accepts auto, atLeast, or exact. Malformed or unknown paragraph-format fields are rejected. Formatting targets support batches of IDs or paths, and run formatting can also select every matching run by text. Unspecified properties in an apply patch are preserved; use an explicit remove operation to clear a property. Use setRunFormat when setting a run's formatting; applyRunFormat is for partial updates.
Lists
applyListconverts paragraphs tobulletedornumberedlists.setListLevelchanges list nesting level, starting at 0, andremoveListremoves list formatting.insertListItem,moveListItem, anddeleteListIteminsert, move, or delete list items.
Tables
addTable,deleteTable, andmoveTableinsert, delete, or move tables.addRow,insertRow, anddeleteRowmodify table rows.addColumn,insertColumn, anddeleteColumnmodify table columns. Column positions are zero-based.setCellTextreplaces cell text, whilereplaceCellContentreplaces cell blocks.mergeCellsmerges an inclusive rectangular table range, andsplitCellsplits a merged cell.setRowShadingandsetCellShadingset or remove shading. Shading fills use six-digit RGB hexadecimal colors, with an optional pattern.setTableBorderssets table-level borders, andsetCellBorderssets borders on an individual cell. Border sides can includetop,right,bottom,left,insideHorizontal,insideVertical,start, andend; each side can specify style, color, width, and space.
addTable accepts column widths as positive integers measured in twentieths of a point; the number of widths must match the number of columns. It can insert before or after an existing block, or append to a section with position.endOfSection. Table mutations validate grid geometry and report INVALID_TABLE_GEOMETRY for unsupported or inconsistent ranges.
Selectors and validation
Selectors must be one of an element ID or model path string, an object containing only id, an object containing only path, or a table position containing tableIndex and optional row/column indexes. Ambiguous selectors are rejected. The server enforces these rules even when an MCP host does not fully enforce JSON Schema.
document_transform requires exactly one existing-document source: document with a session documentId and revision, or a workspace-relative inputFile; the exception is a batch containing createDocument. The operations array must be non-empty, and operations run sequentially against the state produced by earlier operations. IDs and revisions are session-scoped; stale revisions return STALE_REVISION. Output formats are docx, html, and pdf. Run colors use six-digit hexadecimal RGB values or auto, font sizes must be positive finite numbers, and underline values are limited to those advertised by the tool schema.
Text-format targets can optionally use scope and zero-based occurrence controls. Without an occurrence, every matching run in scope is selected; without a scope, matching runs are searched across the document. Table-specific matching can target a cell, row, or zero-based column. Successful transforms return inserted, modified, and deleted element references; use the returned current paths and IDs for follow-up operations after structural changes.
Features not included in the capability catalog are not supported by document_transform. Use the canonical operation IDs shown by tools/list or capabilities; there are currently no aliases.
Protocol contract
Resources
Resources are enabled alongside tools and expose JSON at draftagent://capabilities and draftagent://transforms. Both capability responses are generated from the canonical operation inventory.
Client compatibility
MCP hosts differ in how completely they enforce JSON Schema features such as oneOf, enum, const, and additionalProperties. Clients should:
- use
tools/listas the invocation schema; - use the canonical operation IDs returned by the schema and catalog;
- treat server-side validation errors as authoritative; and
- check
schemaVersionwhen caching schemas or generated prompts.
Clients that cannot consume the advertised schema can still call capabilities or read the capability resources, but must not infer support for operations absent from tools/list.
Sessions and revisions
document_inspect publishes a document handle and revision. A successful transform advances the revision. Element IDs are scoped to the active document session lineage and should not be treated as durable document identifiers. If a file is loaded into a new session, inspect it again before reusing selectors. Use the latest returned revision for each subsequent transform.
Errors
Invalid requests return structured codes such as INVALID_TARGET, STALE_REVISION, and TRANSFORMATION_FAILED. Transformation diagnostics include severity, code, message, path, part, and operation index where available. Structured errors can include documentation links to the capabilities or transforms resources. A failed batch is transactional: no artifact is written and no new revision is published. validateOnly instead simulates the batch in memory and reports all discoverable failures without writing.
Limits
Tool responses are capped at 2 MiB. ZIP inputs are constrained by configured entry, per-entry, and total-size limits. The active values are returned by capabilities. The server writes only the explicitly requested outputFile; it does not leave preview PDFs or other additional artifacts.
Frequently asked questions
What is the DraftAgent MCP server?
DraftAgent is a local MCP server that allows AI agents and MCP clients to inspect, transform, and render DOCX documents.
Can DraftAgent modify Word documents?
Yes. DraftAgent supports text replacement, structural edits, formatting, lists, tables, shading, and other document transformations.
What output formats does DraftAgent support?
DraftAgent can produce DOCX, HTML, and PDF output artifacts.
Does DraftAgent upload documents to a remote service?
The MCP server runs locally and uses a configured workspace directory for document files.