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.
Status: Active development. Tool schemas, operation support, response shapes, limits, and resource contents may change. Query
tools/listandcapabilitiesat runtime instead of hard-coding the operation catalog.
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.
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.
document_transform
Applies a non-empty, ordered operations array and writes the result to outputFile.
Provide either:
inputFileto load a workspace document or reuse its latest session; ordocumentwithdocumentIdandrevisionto address an inspected session.
Output defaults to DOCX. Set output.format to docx, html, or pdf. Writes use a temporary file followed by rename. Existing document handles must use the latest revision; stale revisions return STALE_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.
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 40 operation IDs are currently supported:
Text and structural blocks
replaceTextreplaces matching text in runs. Its required fields aresearchandreplaceWith;allcontrols whether every match is replaced (defaulttrue). Text split across separate DOCX runs is not matched as one string.replaceElementTextreplaces the content of one paragraph identified by a target.appendParagraphadds a paragraph to the end of the document. Supply non-emptytextorparagraphcontent.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. 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. setRunFormat is the canonical MCP ID; internal Rust names such as apply_run_format are not MCP operation IDs.
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.
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 source: document with a session documentId and revision, or a workspace-relative inputFile. The operations array must be non-empty. 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.
Unsupported operations from lower-level transformation crates are not included in capability discovery and must not be submitted to document_transform. There are currently no supported aliases for the public operation IDs.
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 intended for the latest session revision and should not be treated as durable document identifiers.
Errors
Invalid requests return structured codes such as INVALID_TARGET, STALE_REVISION, and TRANSFORMATION_FAILED. Transformation diagnostics include code, message, path, part, and operation.
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.
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.