docx_mcp_server_ts
DOCX MCP Server
完全な OOXML サポートを備えた、TypeScript ベースの包括的な MCP (Model Context Protocol) サーバーです。テキスト、表、画像、ヘッダー/フッター、SDT、コメントなどをサポートし、Word 文書をプログラムで処理します。
機能
完全な OOXML アクセス: 完全な名前空間サポートを備え、ZIP レベルで DOCX パーツを読み書き
テキスト操作: 最小限の差分保持でテキストの抽出、検索、置換
表管理: 行の挿入/削除、セルの変更、結合/分割操作
画像処理: EMU ベースのサイズ指定でインライン/配置画像を追加
構造化データタグ (SDT): タグまたはエイリアスでコンテンツコントロールにアクセス
ヘッダー/フッター: セクションのヘッダーとフッターを一覧表示および変更
変更履歴: リビジョンの承認/拒否、挿入/削除の処理
コメント: 文書コメントの管理
メタデータ: コアおよびアプリのプロパティを読み書き
LRU キャッシュ: パーツキャッシュによる効率的なメモリ管理
ロスレス XML: fast-xml-parser で文書構造を保持
Related MCP server: InkPaw
インストール
npm install
npm run buildクイックスタート
サーバーの起動
npm startサーバーは MCP プロトコルメッセージを stdin/stdout で待ち受けます。
インストールと設定
Claude Code CLI
claude mcp install docx \
--command node \
--args /full/path/to/docx_mcp_server_ts/dist/index.js \
--env LOG_LEVEL=INFO~/.claude.json (Claude Code 用)
~/.claude.json を編集し、"projects" セクションに追加します:
{
"projects": {
"/full/path/to/docx_mcp_server_ts": {
"mcpServers": {
"docx": {
"command": "node",
"args": ["/full/path/to/docx_mcp_server_ts/dist/index.js"],
"env": {
"LOG_LEVEL": "INFO"
}
}
}
}
}
}Linux/WSL の例:
{
"projects": {
"/mnt/c/Users/pavelk/Desktop/Projects/MCP-servers/docx_mcp_server_ts": {
"mcpServers": {
"docx": {
"command": "node",
"args": ["/mnt/c/Users/pavelk/Desktop/Projects/MCP-servers/docx_mcp_server_ts/dist/index.js"],
"env": {
"LOG_LEVEL": "INFO"
}
}
}
}
}
}MCP ツール
文書管理
docx.open
ファイルまたは base64 バッファから DOCX 文書を開きます。
入力:
{
"path": "/path/to/document.docx",
"bufferBase64": "..." // OR provide base64 data
}出力:
{
"docId": "uuid-string",
"parts": ["word/document.xml", ...],
"props": { "core": {}, "app": {} }
}docx.close
文書を閉じてリソースを解放します。
入力: { "docId": "uuid" }
docx.save
文書をファイルに保存するか、base64 として返します。
入力:
{
"docId": "uuid",
"path": "/output/path.docx", // optional
"returnBase64": true // optional
}docx.list_parts
文書内のすべてのパーツを一覧表示します。
docx.part_read / docx.part_write
低レベルアクセス用に個々の XML パーツを読み書きします。
テキスト操作
docx.get_text
文書からすべてのテキストを抽出します。
入力: { "docId": "uuid", "scope": "document|headers|footers|all" }
docx.replace_text
ラン構造を保持してテキストを置換します。
入力:
{
"docId": "uuid",
"match": "search text",
"replace": "replacement",
"mode": "literal|regex",
"where": "document|headers|footers|all"
}出力: { "replaced": 5 }
docx.find
コンテキスト付きでテキストを検索します。
出力:
{
"hits": [
{
"text": "found text",
"context": "...found text...",
"offset": 150
}
]
}表操作
docx.tables_list
寸法付きで全表を一覧表示します。
出力:
{
"tables": [
{
"tableXPath": "//w:tbl[1]",
"rows": 5,
"colsApprox": 3
}
]
}docx.table_edit
表操作を実行します。
入力:
{
"docId": "uuid",
"tableXPath": "//w:tbl[1]",
"op": {
"kind": "setCellText",
"row": 0,
"col": 0,
"text": "new value"
}
}サポートされている操作:
{ "kind": "setCellText", "row": number, "col": number, "text": string }{ "kind": "insertRow", "at": number }{ "kind": "deleteRow", "at": number }{ "kind": "insertCol", "at": number }{ "kind": "deleteCol", "at": number }
構造化データタグ (SDT)
docx.sdt_get
コンテンツコントロールの内容を取得します。
入力: { "docId": "uuid", "tagOrAlias": "control_tag" }
出力:
{
"xml": "<w:p>...</w:p>",
"textPreview": "Control content..."
}docx.sdt_put
コンテンツコントロールを更新します。
入力:
{
"docId": "uuid",
"tagOrAlias": "control_tag",
"xmlFragment": "<w:p>...</w:p>"
}画像操作
docx.images_list
メタデータ付きで全画像を一覧表示します。
出力:
{
"images": [
{
"rId": "rId4",
"path": "word/media/image1.png",
"sizeEMU": { "cx": 914400, "cy": 914400 }
}
]
}docx.image_add
インラインまたはアンカー付きで画像を挿入します。
入力:
{
"docId": "uuid",
"target": {
"afterParagraphXPath": "//w:p[1]",
"sdtTagOrAlias": "imageControl" // OR use SDT
},
"image": {
"path": "/local/image.png",
"base64": "...", // OR base64 data
"filename": "image.png",
"contentType": "image/png"
},
"placement": {
"kind": "inline" // OR { "kind": "anchor", "xEMU": 0, "yEMU": 0 }
},
"size": {
"widthMM": 50,
"heightMM": 50
},
"altText": "Description"
}docx.image_update_position
アンカー付き画像の位置/サイズを更新します。
高度な操作
docx.styles_get / docx.styles_set
styles.xml を読み書き
docx.numbering_get / docx.numbering_set
numbering.xml を読み書き
docx.headers_footers_list
セクション情報付きでヘッダーとフッターを一覧表示します。
docx.headers_footers_get / docx.headers_footers_set
特定のヘッダーまたはフッターを読み書きします。
docx.comments_list / docx.comments_add / docx.comments_delete
文書コメントを管理します。
docx.changes_accept_all
すべての変更履歴を承認します (w:del を削除、w:ins を展開)。
出力: { "removedDel": 3, "flattenedIns": 5 }
docx.metadata_get / docx.metadata_set
文書プロパティ (core.xml、app.xml) を読み書きします。
サイズ変換
サーバーは EMU (English Metric Unit) 変換を内部的に処理します:
1 インチ = 914,400 EMU
1 mm ≈ 36,000 EMU
1 ポイント ≈ 12,700 EMU
例
テキストの抽出と置換
// Open document
const openResult = await client.call('docx.open', {
path: '/tmp/document.docx'
});
const docId = openResult.docId;
// Get text
const textResult = await client.call('docx.get_text', { docId });
console.log(textResult.text);
// Replace text
await client.call('docx.replace_text', {
docId,
match: 'old text',
replace: 'new text',
mode: 'literal'
});
// Save
await client.call('docx.save', {
docId,
path: '/tmp/document-modified.docx'
});
// Close
await client.call('docx.close', { docId });表の変更
// List tables
const tablesResult = await client.call('docx.tables_list', { docId });
const tableXPath = tablesResult.tables[0].tableXPath;
// Update cell
await client.call('docx.table_edit', {
docId,
tableXPath,
op: {
kind: 'setCellText',
row: 0,
col: 0,
text: 'Updated Value'
}
});
// Insert row
await client.call('docx.table_edit', {
docId,
tableXPath,
op: {
kind: 'insertRow',
at: 1
}
});画像の追加
const fs = require('fs').promises;
const imageBuffer = await fs.readFile('/path/to/image.png');
const base64 = imageBuffer.toString('base64');
await client.call('docx.image_add', {
docId,
target: {
afterParagraphXPath: '//w:p[1]'
},
image: {
base64,
filename: 'image.png',
contentType: 'image/png'
},
placement: {
kind: 'inline'
},
size: {
widthMM: 100,
heightMM: 75
},
altText: 'My image'
});アーキテクチャ
src/
├── index.ts # MCP server entry point
├── logger.ts # Logging utility
├── errors.ts # Error types and codes
├── ooxml/
│ ├── namespaces.ts # OOXML constants and namespaces
│ ├── emu.ts # Unit conversion utilities
│ ├── dom.ts # XML DOM utilities (xmldom + fontoxpath)
│ ├── xmlParser.ts # FXP parser with order preservation
│ ├── parts.ts # ZIP part reading/writing
│ ├── rels.ts # Relationship management
│ ├── text.ts # Text operations with diff-match-patch
│ ├── tables.ts # Table manipulation
│ ├── sdt.ts # Structured Data Tags
│ ├── drawings.ts # Image handling
│ ├── headersFooters.ts # Header/footer operations
│ ├── comments.ts # Comment management
│ ├── changes.ts # Track changes handling
│ ├── styles.ts # Styles XML access
│ └── numbering.ts # Numbering XML access
├── store/
│ ├── types.ts # Store type definitions
│ └── docStore.ts # Document store with LRU cache
└── mcp/
└── tools.ts # MCP tool implementationsパフォーマンス
メモリ: LRU キャッシュにより文書ごとのパーツをキャッシュ 50 項目に制限
合計サイズ: 最大 100MB の文書をメモリ内でサポート
部分アクセス: 要求されたパーツのみ ZIP から解析
最小限の差分: 可能な場合、テキスト置換はラン構造を保持
制限事項
ページレイアウトの計算は実行されません (Word のレンダリングエンジンが必要)
高度な DrawingML 変換は読み取り専用
VBA マクロと埋め込み OLE オブジェクトはサポートされていません
極端に大きな文書 (>500MB) はストリーミングが必要な場合があります
開発
# Install dependencies
npm install
# Type check
npm run type-check
# Build
npm run build
# Run dev server
npm run dev
# Debug with inspector
npm run dev:debugロギング
環境変数でログレベルを制御:
LOG_LEVEL=DEBUG npm start # Verbose
LOG_LEVEL=INFO npm start # Default
LOG_LEVEL=WARN npm start # Warnings only
LOG_LEVEL=ERROR npm start # Errors onlyプロトコルサポート
トランスポート: stdio
プロトコル: MCP (Model Context Protocol)
ハンドラー: @modelcontextprotocol/sdk
ライセンス
MIT
リソース
Available Tools
29 toolsdocx.changes_accept_allB
Accept all changes
Inputs: no named parameters.
docx.closeB
Close a DOCX document and free resources
Inputs: docId.
docx.comments_addD
Add comment
Inputs: no named parameters.
docx.comments_deleteD
Delete comment
Inputs: no named parameters.
docx.comments_listC
List comments
Inputs: no named parameters.
docx.findB
Find text in document
Inputs: no named parameters.
docx.get_textC
Get all text from document
Inputs: docId.
docx.image_addC
Add image
Inputs: no named parameters.
docx.images_listA
List all images
Inputs: no named parameters.
docx.image_update_positionD
Update image position
Inputs: no named parameters.
docx.list_partsB
List all parts (XML files) in a DOCX document
Inputs: docId.
docx.metadata_getC
Get metadata
Inputs: no named parameters.
docx.metadata_setC
Set metadata
Inputs: no named parameters.
docx.numbering_getC
Get numbering
Inputs: no named parameters.
docx.numbering_setC
Set numbering
Inputs: no named parameters.
docx.openB
Open a DOCX document from file or buffer
Inputs: path, bufferBase64.
docx.part_readB
Read a specific XML part from the document
Inputs: docId, partPath.
docx.part_writeC
Write/update a specific XML part in the document
Inputs: xml, docId, partPath.
docx.replace_textB
Replace text in document
Inputs: no named parameters.
docx.saveC
Save a DOCX document to file or get as base64
Inputs: path, docId, returnBase64.
docx.sdt_getC
Get SDT content
Inputs: no named parameters.
docx.sdt_putC
Set SDT content
Inputs: no named parameters.
docx.styles_getC
Get styles
Inputs: no named parameters.
docx.styles_setC
Set styles
Inputs: no named parameters.
docx.table_editD
Edit table
Inputs: no named parameters.
docx.tables_listB
List all tables
Inputs: no named parameters.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 29 tools
Each tool has a clear, distinct purpose (e.g., get_text vs. find vs. replace_text), with no overlapping functionality. The split between list/get/set operations across different document parts (tables, headers, styles) avoids ambiguity.
All tools follow a consistent verb_noun pattern (e.g., list_parts, part_read, table_edit) and share the 'docx.' prefix. The naming is uniform, lowercase with underscores, making it predictable and easy to navigate.
With 29 tools, the count is higher than the typical 3-15 range, but it is justified by the comprehensive scope of DOCX manipulation (text, tables, images, styles, metadata, comments, etc.). It feels extensive rather than bloated, though slightly over the ideal range.
The tool set covers a wide range of DOCX operations including open/save, text handling, tables, images, styles, numbering, headers/footers, comments, changes, and metadata. Minor gaps exist (e.g., no explicit delete for tables or images, no create-new-document operation), but agents can likely work around these using existing tools.
Maintenance
Related MCP Connectors
Document processing over MCP: merge, split and compress PDFs, run OCR, extract document text.
Parse, convert and create Office and PDF documents. OAuth at /mcp/connect/, API key at /mcp/.
Convert DOCX documents to and from PDF, TXT, HTML, ODT, JPG and RTF.
Document conversion MCP server: PDF to Markdown, image OCR, spreadsheet parsing.
Related MCP Servers
- AlicenseDqualityDmaintenanceEnables reading, writing, editing, and converting Office documents (ODT, DOCX, ODS, XLSX, PDF, etc.) using MCP tools, with no external dependencies.1117 npmMIT
- AlicenseNot gradedqualityDmaintenanceEnables AI agents to generate, edit, validate, and render Word documents programmatically via MCP, ensuring correct OOXML structure and style.3MIT
- AlicenseBqualityCmaintenanceProvides MCP tools for working with Microsoft Word documents, enabling reading, editing with tracked changes, formatting, table manipulation, comments, and PDF conversion via direct OOXML manipulation.37MIT
- FlicenseCqualityDmaintenanceEnables comprehensive DOCX/OOXML document manipulation via MCP, covering text, tables, images, content controls, comments, tracked changes, and metadata.34-