Skip to main content
Glama
Mavline

docx_mcp_server_ts

by Mavline

DOCX MCP Server

完全な OOXML サポートを備えた、TypeScript ベースの包括的な MCP (Model Context Protocol) サーバーです。テキスト、表、画像、ヘッダー/フッター、SDT、コメントなどをサポートし、Word 文書をプログラムで処理します。

機能

  • 完全な OOXML アクセス: 完全な名前空間サポートを備え、ZIP レベルで DOCX パーツを読み書き

  • テキスト操作: 最小限の差分保持でテキストの抽出、検索、置換

  • 表管理: 行の挿入/削除、セルの変更、結合/分割操作

  • 画像処理: EMU ベースのサイズ指定でインライン/配置画像を追加

  • 構造化データタグ (SDT): タグまたはエイリアスでコンテンツコントロールにアクセス

  • ヘッダー/フッター: セクションのヘッダーとフッターを一覧表示および変更

  • 変更履歴: リビジョンの承認/拒否、挿入/削除の処理

  • コメント: 文書コメントの管理

  • メタデータ: コアおよびアプリのプロパティを読み書き

  • LRU キャッシュ: パーツキャッシュによる効率的なメモリ管理

  • ロスレス XML: fast-xml-parser で文書構造を保持

Related MCP server: mcp-office-parser

インストール

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

リソース

Install Server
A
license - permissive license
C
quality
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • A
    license
    B
    quality
    A
    maintenance
    An MCP server for reading, editing, and validating Microsoft Word documents with specialized support for track changes, comments, and footnotes. It enables structural auditing, heading extraction, and precise OOXML-level document manipulation through natural language tools.
    100
    42
    MIT
  • A
    license
    D
    quality
    D
    maintenance
    Enables reading, writing, editing, and converting Office documents (ODT, DOCX, ODS, XLSX, PDF, etc.) using MCP tools, with no external dependencies.
    11
    31
    MIT
  • A
    license
    C
    quality
    D
    maintenance
    A unified MCP server for document processing that enables creating, editing, and converting Word documents (DOCX), PDFs, Markdown, and images, with support for templates, formatting, and batch operations.
    100
    MIT
  • A
    license
    Not graded
    quality
    B
    maintenance
    Enables AI agents to generate, edit, validate, and render Word documents programmatically via MCP, ensuring correct OOXML structure and style.
    3
    MIT

View all related MCP servers

Related MCP Connectors

  • Use your own Word templates to convert Markdown → DOCX/PDF/HTML from any MCP-compatible AI.

  • Google Docs MCP Pack — read, create, and edit Google Docs via OAuth.

  • Normalize and convert more than 400 file types via TweekIT's hosted MCP streamable HTTP endpoint.

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Mavline/docx_mcp_server_ts'

If you have feedback or need assistance with the MCP directory API, please join our Discord server