docx_mcp_server_ts
DOCX MCP Server
완전한 OOXML 지원으로 범용 DOCX 처리를 제공하는 TypeScript 기반의 포괄적인 MCP(Model Context Protocol) 서버입니다. 텍스트, 표, 이미지, 머리글/바닥글, SDT, 주석 등을 지원하며 Word 문서를 프로그래밍 방식으로 처리할 수 있습니다.
기능
완전한 OOXML 액세스: 전체 네임스페이스 지원과 함께 ZIP 수준에서 DOCX 파트를 읽고 씁니다.
텍스트 작업: 최소 diff 보존으로 텍스트를 추출, 찾기 및 바꿉니다.
표 관리: 행 삽입/삭제, 셀 수정, 병합/분할 작업
이미지 처리: EMU 기반 크기 조정으로 인라인/위치 지정 이미지 추가
구조화된 데이터 태그(SDT): 태그 또는 별칭으로 콘텐츠 컨트롤에 액세스
머리글/바닥글: 섹션 머리글과 바닥글 나열 및 수정
변경 내용 추적: 수정 사항 수락/거부, 삽입/삭제 처리
주석: 문서 주석 관리
메타데이터: 핵심(core) 및 앱(app) 속성 읽기/쓰기
LRU 캐싱: 파트 캐싱을 통한 효율적인 메모리 관리
무손실 XML: fast-xml-parser로 문서 구조 보존
Related MCP server: InkPaw
설치
npm install
npm run build빠른 시작
서버 시작
npm start서버는 stdin/stdout에서 MCP 프로토콜 메시지를 수신 대기합니다.
설치 및 구성
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
run 구조를 보존하면서 텍스트를 바꿉니다.
입력:
{
"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
이미지를 인라인 또는 고정(anchored) 방식으로 삽입합니다.
입력:
{
"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
고정(anchored) 이미지의 위치/크기를 업데이트합니다.
고급 작업
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에서 구문 분석됩니다.
최소 Diff: 가능한 경우 텍스트 바꾸기가 run 구조를 보존합니다.
제한 사항
페이지 레이아웃 계산은 수행되지 않습니다(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-