Overview
Let a model read and edit DOCX: comments, tracked changes, redlining. Run against a live editor, headless in Node, or over MCP.
@eigenpal/docx-editor-agents lets a language model read and edit a Word document: pull out paragraphs, leave comments, suggest tracked changes, apply formatting. The same tools run in three places: a live editor in the browser, a headless reviewer on the server, or an MCP server. You point them at whatever model you already run; the tool definitions are plain JSON Schema, with adapters for the Vercel AI SDK, OpenAI-style function calling, React, and Vue.
npm install @eigenpal/docx-editor-agentsIntegration shapes
1. Live editor panel. Tool calls execute against a <DocxEditor> running in the user's browser. Comments and tracked changes appear in the open document. In this setup your API route sees chat messages, tool names, arguments, and tool results; the DOCX file stays client-side.
const { tools, executeToolCall, getContext } = useDocxAgentTools({
editorRef,
author: 'Assistant',
});Full walkthrough: AI editing with the Vercel AI SDK.
2. Headless DocxReviewer on the server. Parse a buffer, run a review, serialize the modified DOCX back. No DOM, no editor instance. Fits a queue worker, Lambda, or CI bot.
import { DocxReviewer } from '@eigenpal/docx-editor-agents';
const reviewer = await DocxReviewer.fromBuffer(buffer, 'Reviewer');
reviewer.addComment({ paragraphIndex: 5, text: 'This cap seems too low.' });
reviewer.replace({ paragraphIndex: 5, search: '$50k', replaceWith: '$500k' });
const out = await reviewer.toBuffer();Reference: DocxReviewer.
3. MCP server. Expose the tool catalog over JSON-RPC for any MCP-compatible client. Transport-agnostic core; you own auth, storage, and the transport.
import { McpServer } from '@eigenpal/docx-editor-agents/mcp';
import { createReviewerBridge } from '@eigenpal/docx-editor-agents';
const server = new McpServer(createReviewerBridge(reviewer), {
name: 'acme-review',
version: '1.0.0',
});Reference: MCP server.
Which shape to pick
| Live editor | Headless DocxReviewer | MCP server | |
|---|---|---|---|
| Where the agent runs | Your API route; tools execute in the browser | Your server process | Wherever the MCP client points |
| Where the document lives | The user's browser, in the open editor | A buffer you load and save | A buffer your host loads per request |
| User watches it happen | Yes, live | No, batch | No |
Pages (read_page / read_pages) | Yes | No (no layout, zero pages) | No (reviewer-backed) |
| Typical use | AI writing assistant, in-editor review | Contract review API, CI bot, bulk redlining | Existing MCP-speaking agent or platform |
If you are building a product UI, start with the live editor. If you have documents and no UI, start with DocxReviewer. Pick MCP only when the client already supports MCP.
The tools
- Locate:
read_document,read_selection,read_page,read_pages,find_text,read_comments,read_changes - Mutate:
add_comment,reply_comment,resolve_comment,suggest_change,apply_formatting,set_paragraph_style - Navigate:
scroll
The pattern is locate-then-mutate, mirroring Word's JS API: locate tools return paragraphs tagged with a stable paraId, and mutate tools address by it (how paraId anchoring works). Full parameter and return shapes: tools reference.
Subpaths
| Subpath | Use when |
|---|---|
@eigenpal/docx-editor-agents | DocxReviewer, agentTools, getToolSchemas, executeToolCall, createReviewerBridge |
/react | useDocxAgentTools, useAgentChat, chat UI components |
/vue | useAgentBridge, Vue chat UI components |
/server | Backend routes that need tool schemas without MCP |
/bridge | createEditorBridge for non-React/Vue hosts |
/mcp | McpServer, runStdioServer |
/ai-sdk/server | getAiSdkTools() for Vercel AI SDK streamText |
/ai-sdk/react, /ai-sdk/vue | toAgentMessages() to feed useChat output into <AgentChatLog> |
Each subpath tree-shakes independently. The /ai-sdk/* entries import ai, which is an optional peer dependency; skip them if you are not on the AI SDK.
AI editing tutorial
Wire model tool calls to the live editor with the Vercel AI SDK.
AI redlining
Tracked-change review the human accepts or rejects, live or in batch.
Tools reference
Every tool: parameters, return shapes, examples.
Word JS API parity
The Office.js verb mapping, enforced at compile time.