Skip to main content
Glama

docx-comparison-mcp

A3 Landscape Old/New Comparison Table / A4 Portrait Specification Word Document Generation MCP Server

A local MCP server that can be called from any AI framework such as Dify, LangFlow, LangChain, or Claude Desktop.


Design Philosophy: GET schema → POST generate

It adopts the same "get schema first, then generate" pattern as excel-mcp.

However, there is a fundamental difference from excel-mcp:

excel-mcp

docx-mcp

Schema Origin

Reads Excel file header row at runtime (dynamic)

Fixed output format at compile time (static)

"Write Destination"

Fixed Excel file (always the same path)

New generation every time (new document per PDF upload)

Append Concept

Yes (appends to existing rows)

No (1 PDF = 1 new docx)

Positioning in Dify workflows:

[HTTP ノード] GET /schema/comparison
     ↓ prompt_context(列定義の代わりに出力フォーマット定義)
[LLM ノード] アップロードされた PDF を Gemini が読む + schema context を注入
     ↓ { doc_title, sections: [...] } の JSON
[HTTP ノード] POST /generate  { spec: { ... } }
     ↓ download_url
[End]

The prompt_context field is formatted to be pasted directly into the system prompt of a Dify LLM node.


Features

  • A3 landscape, Old/New/Remarks 3-column format (Old/New Comparison Table)

  • A4 portrait, Cover page/Revision history table/Body (Specification)

  • Red text (changes/additions)

  • Blue underlined Word comment anchors

  • Multi-section support (cover page, revision history, individual clauses)

  • stdio mode (for Claude Desktop / Claude Code)

  • HTTP mode (for Dify / LangFlow)


Setup

# 1. 依存パッケージのインストール
npm install

# 2. テスト実行
npm test
# → test-output.docx が生成されます

# 3a. MCP (stdio) モード起動 — Claude Desktop / Claude Code 向け
npm start

# 3b. HTTP モード起動 — Dify / LangFlow / REST 向け
npm run start:http
# → http://localhost:3456 で起動

Registration to Claude Desktop

Add to ~/.claude/claude_desktop_config.json:

{
  "mcpServers": {
    "docx-comparison": {
      "command": "node",
      "args": ["/absolute/path/to/docx-mcp/src/index.js"],
      "env": {
        "OUTPUT_DIR": "/Users/yourname/Desktop/docx-output"
      }
    }
  }
}

List of Endpoints

Method

Path

Description

GET

/health

Server health check

GET

/schema

API documentation (static)

GET

/schema/comparison

Schema for LLM injection for Old/New Comparison Table

GET

/schema/manual

Schema for LLM injection for Specification

POST

/generate

Generate Old/New Comparison Table (local save)

POST

/generate/download

Generate Old/New Comparison Table (direct file stream)

POST

/generate/manual

Generate Specification (local save)

POST

/generate/manual/download

Generate Specification (direct file stream)


GET /schema/comparison — Old/New Comparison Table Schema

Returns the format definition to be injected into the LLM. Please paste the prompt_context field into the system prompt of the Dify LLM node.

Response Overview:

{
  "doc_type": "comparison",
  "description": "新旧比較表(A3横、旧/新/備考 3カラム)Word文書の生成スキーマ",
  "prompt_context": "## 新旧比較表 生成形式\n\nPOST /generate に渡す spec を...",
  "required_fields": ["doc_title", "sections"],
  "sections_schema": { ... },
  "paragraph_schema": { ... },
  "example": { ... }
}

GET /schema/manual — Specification Schema

{
  "doc_type": "manual",
  "description": "仕様書(A4縦、表紙・経歴表・本文)Word文書の生成スキーマ",
  "prompt_context": "## 仕様書 生成形式\n\nPOST /generate/manual に渡す spec を...",
  "required_fields": ["doc_title", "sections"],
  "sections_schema": { ... },
  "history_schema": { ... },
  "example": { ... }
}

Dify Workflow Integration Pattern

Old/New Comparison Table (PDF Comparison)

[ファイルアップロード] ユーザーが PDF をアップロード
     ↓
[HTTP ノード] GET /schema/comparison
     ↓ body.prompt_context を変数に格納
[LLM ノード]
  システムプロンプト: {{schema_prompt_context}}
  ユーザーメッセージ: {{uploaded_pdf_content}}
     ↓ spec JSON(新旧比較表形式)
[HTTP ノード] POST /generate  { "spec": {{llm_output}} }
     ↓ { "download_url": "http://...", "filename": "...", "sections": N }
[End]

Gemini reads the uploaded PDF multimodally. PDF parsing on the server side is not required.

Specification Generation

[HTTP ノード] GET /schema/manual
     ↓ prompt_context
[LLM ノード] 仕様書内容の構造化
[HTTP ノード] POST /generate/manual  { "spec": {...} }

JSON Specification (Old/New Comparison Table)

Paragraph Specs (elements of old_paragraphs / new_paragraphs)

{
  "text": "テキスト(シンプルな場合)",
  "segments": [
    { "text": "通常テキスト" },
    { "text": "赤い変更箇所", "color": "red", "underline": true },
    { "text": "続き" }
  ],
  "bold": false,
  "color": "black",
  "underline": false,
  "align": "justify",
  "indent": 0,
  "sz": 19
}

Use either text or segments. segments is used when multiple formats are mixed within a single paragraph.

Comment Anchors

{
  "anchor": "作業手順確認書類",
  "text": "名称変更:作業手順確認書類→作業安全確認表",
  "column": "old"
}
  • anchor: Text to attach the comment to (exact match)

  • text: Content displayed in the Word comment balloon

  • column: "old" | "new" | "both"


Usage Example in LangFlow / Python

import requests

# 1. スキーマ取得(Dify HTTP ノードの代替)
schema = requests.get("http://localhost:3456/schema/comparison").json()
print(schema["prompt_context"])  # → LLM に注入するテキスト

# 2. 新旧比較表生成
spec = {
  "doc_title": "通信関係請負工事共通仕様書 比較表",
  "sections": [
    {
      "id": "section19",
      "title": "【19.施工方法】",
      "status": "changed",
      "old_paragraphs": [{"text": "19.施工方法および工事工程", "bold": True}],
      "new_paragraphs": [{"text": "20.施工方法および工事工程", "bold": True}],
      "notes": ["・名称変更に伴う見直し"],
      "comments": [{"anchor": "作業手順確認書類", "text": "名称変更", "column": "old"}],
    }
  ]
}

# ローカル保存 + パス返却
response = requests.post("http://localhost:3456/generate", json={
  "spec": spec,
  "output_filename": "比較表_第3回改正",
})
print(response.json())
# → {"success": true, "path": ".../比較表_第3回改正.docx", "download_url": "...", ...}

File Structure

docx-mcp/
├── src/
│   ├── index.js          # MCP stdio サーバー(Claude Desktop / Code)
│   ├── http-server.js    # HTTP REST サーバー(Dify / LangFlow)
│   ├── docx-generator.js # コア: JSON → 新旧比較表 .docx 変換エンジン
│   ├── manual-generator.js # コア: JSON → 仕様書 .docx 変換エンジン
│   ├── schema.js         # Zod バリデーション + LLM 注入用スキーマ定義
│   └── test.js           # テスト
├── docs/
│   └── dify-tool.yaml    # Dify Custom Tool / OpenAPI 定義
├── package.json
└── README.md

Environment Variables

Variable

Default

Description

OUTPUT_DIR

~/Desktop/docx-output

Save destination for generated files

PORT

3456

Port number for HTTP mode

Available Tools

3 tools
generate_comparison_docA

Generate a 新旧比較表 (before/after comparison) Word document (.docx). The document follows A3 landscape layout with 旧/新/備考 three-column format. Supports red text for new content, blue underline anchors, and Word comments. Returns base64-encoded docx and saves to local output directory.

Inputs: spec (required), output_filename.

get_template_schemaA

Returns the JSON schema and a complete example for the generate_comparison_doc tool. Call this first to understand how to structure the spec parameter. Pass doc_type="manual" to get the schema for generate_manual_doc instead.

Inputs: doc_type.

preview_sectionsA

Preview the text content of a document spec without generating a file. Useful for verifying the structure before calling generate_comparison_doc.

Inputs: spec (required).

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A4.2/5.0

    Scored across 3 tools

    Disambiguation5/5

    Each tool has a clearly distinct purpose with no overlap: generate_comparison_doc creates the final document, get_template_schema provides metadata and examples, and preview_sections offers a validation step. The descriptions clearly differentiate their roles in the document generation workflow.

    Naming Consistency5/5

    All tool names follow a consistent snake_case pattern with descriptive verb_noun combinations (generate_comparison_doc, get_template_schema, preview_sections). The naming is uniform and predictable across the set.

    Tool Count5/5

    Three tools is well-scoped for a specialized document comparison server. Each tool serves a distinct, necessary function in the workflow (schema retrieval, preview, and generation), with no redundancy or obvious missing pieces for the stated purpose.

    Completeness5/5

    The toolset provides complete coverage for the document comparison domain: get_template_schema enables understanding the input format, preview_sections allows validation, and generate_comparison_doc handles final output. This creates a logical, end-to-end workflow with no gaps.

    Related MCP Connectors