🚀 HWPX MCP Server - 拡張版

🚀 元プロジェクトをフォークし、安定性と機能を大幅に改善したバージョンです。
AIツール(Claudeなど)と連携して、韓国語(HWPX)文書を自動的に編集できるMCP(Model Context Protocol)サーバーです。
🚀 クイックスタート
AIツール(Claudeなど)と連携して、韓国語(HWPX)文書を自動的に編集できるMCP(Model Context Protocol)サーバーです。
✨ 主な機能
🌍 クロスプラットフォーム対応
すべてのオペレーティングシステムで動作します!
| OS |
MCPサーバー |
HWPX編集 |
結果確認 |
| ✅ Windows |
✅ |
✅ |
ハングルオフィス |
| ✅ macOS |
✅ |
✅ |
ハングルオフィス Mac |
| ✅ Linux |
✅ |
✅ |
ハングルオフィス Linux / LibreOffice* |
なぜ可能なのですか?
HWPXファイルは ZIP + XML構造 です。ハングルソフトウェアがなくても、Node.jsだけで完全に読み書きできます。
*LibreOfficeはHWPXを制限的にサポートしています。完全な互換性のために、ハングルオフィスの使用をお勧めします。
✨ 拡張機能
元のプロジェクトと比較して、次のような 重要な問題を解決 しました。
🔧 重大なバグ修正
| 問題 |
元の状態 |
改善後 |
| テーブル保存失敗 |
セルを編集して保存しても変更が失われる |
✅ 完全に保存されます |
| テキストの重なり現象 |
保存後にハングルで開くと文字が重なって表示される |
✅ 正常に表示されます |
| ファイル損傷 |
保存時にファイルが損傷することがある |
✅ 原子的な書き込みにより100%安全 |
| 複数セルの損傷 |
同じ行に複数のセルを編集するとXMLが損傷する |
✅ インデックス管理により安全 |
| 文字間隔/行間隔の損失 |
保存後にスタイル情報が失われる |
✅ すべてのスタイルが保存されます |
🛠 技術的な改善
-
原子的なファイル書き込み
- 一時ファイル → ZIP検証 → 原子的な移動
- 保存中にエラーが発生しても元のファイルが保護されます
-
スマートな行レイアウトのリセット
- テキストを編集すると
lineseg が自動的にリセットされます
- ハングルソフトウェアを開くと自動的に改行が再計算されます
- テキストの重なり現象が完全に解消されます
-
深さベースのXMLパーシング
- 既存の遅延正規表現の入れ子構造の誤認識問題を解決します
- 複雑なテーブル(入れ子テーブル、サブリストなど)を完全にサポートします
-
完全なスタイル保存
charPr、spacing などの元のスタイルを100%維持します
- 不完全なシリアル化ロジックを削除してデータの整合性を保証します
-
安全な複数セルの更新
- 同じ行(row)の複数のセルを同時に編集しても安全です
- 行ごとのグループ化 + 逆順処理によりインデックスの損傷を防止します
📦 インストール
1. MCPサーバーのインストール
git clone https://github.com/Dayoooun/hwpx-mcp.git
cd hwpx-mcp/mcp-server
npm install
npm run build
2. MCPクライアントの設定
以下から使用するクライアントを選択してください。
🖥️ Claude Desktop
設定ファイルの場所:
| OS |
パス |
| Windows |
%APPDATA%\Claude\claude_desktop_config.json |
| macOS |
~/Library/Application Support/Claude/claude_desktop_config.json |
| Linux |
~/.config/Claude/claude_desktop_config.json |
設定内容:
{
"mcpServers": {
"hwpx-mcp": {
"command": "node",
"args": ["C:/path/to/hwpx-mcp/mcp-server/dist/index.js"]
}
}
}
⚠️ Windowsではパスに \\ または / を使用してください(例: C:/Users/username/hwpx-mcp/...)
💻 Claude Code (CLI)
方法1: プロジェクトごとの設定 (.mcp.json ファイルをプロジェクトのルートに作成)
{
"mcpServers": {
"hwpx-mcp": {
"command": "node",
"args": ["/path/to/hwpx-mcp/mcp-server/dist/index.js"]
}
}
}
方法2: グローバル設定 (~/.claude/settings.json)
{
"mcpServers": {
"hwpx-mcp": {
"command": "node",
"args": ["/path/to/hwpx-mcp/mcp-server/dist/index.js"]
}
}
}
方法3: CLIコマンドで追加
claude mcp add hwpx-mcp node /path/to/hwpx-mcp/mcp-server/dist/index.js
🔷 Cursor
設定ファイル: ~/.cursor/mcp.json (ない場合は作成)
{
"mcpServers": {
"hwpx-mcp": {
"command": "node",
"args": ["/path/to/hwpx-mcp/mcp-server/dist/index.js"]
}
}
}
または Cursor Settings > MCP から直接追加することもできます。
🆚 VS Code (MCP拡張を使用する場合)
設定ファイル: .vscode/mcp.json (プロジェクトフォルダ内)
{
"servers": {
"hwpx-mcp": {
"command": "node",
"args": ["${workspaceFolder}/../hwpx-mcp/mcp-server/dist/index.js"]
}
}
}
${workspaceFolder} 変数を使用すると相対パスを指定できます
🛠️ その他のMCPクライアント
一般的なMCP設定形式:
{
"mcpServers": {
"hwpx-mcp": {
"command": "node",
"args": ["/absolute/path/to/hwpx-mcp/mcp-server/dist/index.js"]
}
}
}
パスの例:
| OS |
パスの例 |
| Windows |
C:/Users/username/hwpx-mcp/mcp-server/dist/index.js |
| macOS |
/Users/username/hwpx-mcp/mcp-server/dist/index.js |
| Linux |
/home/username/hwpx-mcp/mcp-server/dist/index.js |
3. インストールの確認
クライアントを再起動した後、MCPツールのリストに hwpx-mcp サーバーと77個のツールが表示されれば成功です!
💻 使用例
基本的な使用法
await mcp.open_document({ file_path: "report.hwpx" })
await mcp.update_table_cell({
doc_id: "...",
section_index: 0,
table_index: 0,
row: 0,
col: 1,
text: "修正された内容"
})
await mcp.insert_nested_table({
doc_id: "...",
section_index: 0,
parent_table_index: 0,
row: 1,
col: 2,
nested_rows: 2,
nested_cols: 2,
data: [["A1", "A2"], ["B1", "B2"]]
})
await mcp.render_mermaid({
doc_id: "...",
mermaid_code: "graph TD; A-->B; B-->C;",
after_index: 0,
theme: "default"
})
await mcp.save_document({ doc_id: "..." })
高度な使用法
テーブルセルの検索/置換ワークフロー
同じテキストが複数の場所にある場合、特定の位置 のみを編集する方法:
const results = await mcp.search_text({
doc_id: "...",
query: "修正対象",
include_tables: true
})
await mcp.replace_text_in_cell({
doc_id: "...",
section_index: 0,
table_index: 2,
row: 3,
col: 1,
old_text: "修正対象",
new_text: "新しい内容"
})
📚 ドキュメント
🔌 MCPツール (77個)
📁 文書管理 (Document Management) - 5個
| ツール |
説明 |
主なパラメータ |
create_document |
新しい空のHWPX文書を作成する |
title?, creator? |
open_document |
HWPX文書を開く |
file_path |
close_document |
開いている文書を閉じる |
doc_id |
save_document |
文書を保存する(バックアップ/整合性検証をサポート) |
doc_id, output_path?, create_backup?, verify_integrity? |
list_open_documents |
現在開いている文書のリストを取得する |
- |
📄 文書情報 (Document Info) - 5個
| ツール |
説明 |
主なパラメータ |
get_document_text |
文書全体のテキストを抽出する |
doc_id |
get_document_structure |
文書の構造を取得する(セクション/段落/テーブル/画像の数) |
doc_id |
get_document_metadata |
メタデータを取得する(タイトル、作成者、日付など) |
doc_id |
set_document_metadata |
メタデータを編集する |
doc_id, title?, creator?, subject?, description? |
get_word_count |
文字数/単語数の統計を取得する |
doc_id |
📝 段落 (Paragraphs) - 8個
| ツール |
説明 |
主なパラメータ |
get_paragraphs |
段落のリストを取得する(テキスト/スタイルを含む) |
doc_id, section_index? |
get_paragraph |
特定の段落の詳細情報を取得する |
doc_id, section_index, paragraph_index |
insert_paragraph |
新しい段落を挿入する |
doc_id, section_index, after_index, text |
delete_paragraph |
段落を削除する |
doc_id, section_index, paragraph_index |
update_paragraph_text |
段落のテキスト内容を編集する |
doc_id, section_index, paragraph_index, text, run_index? |
append_text_to_paragraph |
既存の段落にテキストを追加する |
doc_id, section_index, paragraph_index, text |
copy_paragraph |
段落を別の位置にコピーする |
doc_id, source_section, source_paragraph, target_section, target_after |
move_paragraph |
段落を別の位置に移動する |
doc_id, source_section, source_paragraph, target_section, target_after |
🎨 テキストスタイル (Text Styling) - 4個
| ツール |
説明 |
主なパラメータ |
get_text_style |
文字の書式を取得する(フォント/サイズ/色など) |
doc_id, section_index, paragraph_index, run_index? |
set_text_style |
文字の書式を設定する |
doc_id, section_index, paragraph_index, bold?, italic?, underline?, strikethrough?, font_name?, font_size?, font_color?, background_color? |
get_paragraph_style |
段落の書式を取得する(配置/行間隔/余白など) |
doc_id, section_index, paragraph_index |
set_paragraph_style |
段落の書式を設定する |
doc_id, section_index, paragraph_index, align?, line_spacing?, margin_*?, first_line_indent? |
🔍 検索/置換 (Search & Replace) - 4個
| ツール |
説明 |
主なパラメータ |
search_text |
文書内のテキストを検索する(正規表現をサポート、テーブルセルを含む) |
doc_id, query, case_sensitive?, regex?, include_tables? |
replace_text |
テキストを検索して置換する |
doc_id, old_text, new_text, case_sensitive?, regex?, replace_all? |
replace_text_in_cell |
特定のテーブルセル内のテキストを置換する |
doc_id, section_index, table_index, row, col, old_text, new_text |
batch_replace |
複数のテキストを一括で置換する |
doc_id, replacements[](old_text, new_textのペアの配列) |
📊 テーブル (Tables) - 12個
| ツール |
説明 |
主なパラメータ |
get_tables |
文書内のすべてのテーブルのリストを取得する |
doc_id |
get_table |
特定のテーブルの全データを取得する |
doc_id, section_index, table_index |
get_table_cell |
特定のセルの内容を取得する |
doc_id, section_index, table_index, row, col |
update_table_cell |
セルの内容を編集する(スタイルを保持) |
doc_id, section_index, table_index, row, col, text, char_shape_id? |
set_cell_properties |
セルのプロパティを設定する(サイズ/背景色/配置) |
doc_id, section_index, table_index, row, col, width?, height?, background_color?, vertical_align? |
insert_table |
新しいテーブルを挿入する |
doc_id, section_index, after_index, rows, cols, width? |
insert_table_row |
テーブルに行を挿入する |
doc_id, section_index, table_index, after_row, cell_texts? |
delete_table_row |
テーブルから行を削除する |
doc_id, section_index, table_index, row_index |
insert_table_column |
テーブルに列を挿入する |
doc_id, section_index, table_index, after_col |
delete_table_column |
テーブルから列を削除する |
doc_id, section_index, table_index, col_index |
insert_nested_table |
セル内に入れ子テーブルを挿入する(表の中に表) |
doc_id, section_index, parent_table_index, row, col, nested_rows, nested_cols, data? |
get_table_as_csv |
テーブルをCSV形式で抽出する |
doc_id, section_index, table_index, delimiter? |
📐 ページ設定 (Page Settings) - 2個
| ツール |
説明 |
主なパラメータ |
get_page_settings |
ページ設定を取得する(用紙サイズ/余白) |
doc_id, section_index? |
set_page_settings |
ページ設定を変更する |
doc_id, section_index?, width?, height?, margin_*?, orientation? |
🖼️ 画像 (Images) - 5個
| ツール |
説明 |
主なパラメータ |
get_images |
文書内のすべての画像のリストを取得する |
doc_id |
insert_image |
画像ファイルを挿入する(BinDataを自動登録) |
doc_id, section_index, after_index, image_path, width?, height? |
update_image_size |
既存の画像のサイズを変更する |
doc_id, section_index, image_index, width, height |
delete_image |
画像を削除する |
doc_id, section_index, image_index |
render_mermaid |
Mermaidダイアグラムを画像として挿入する |
doc_id, mermaid_code, after_index, section_index?, width?, height?, theme?, background_color? |
✏️ 図形 (Shapes) - 3個
| ツール |
説明 |
主なパラメータ |
insert_line |
線の図形を挿入する |
doc_id, section_index, after_index, x1, y1, x2, y2, stroke_color?, stroke_width? |
insert_rect |
四角形の図形を挿入する |
doc_id, section_index, after_index, x, y, width, height, fill_color?, stroke_color? |
insert_ellipse |
楕円の図形を挿入する |
doc_id, section_index, after_index, cx, cy, rx, ry, fill_color?, stroke_color? |
📑 ヘッダー/フッター (Header/Footer) - 4個
| ツール |
説明 |
主なパラメータ |
get_header |
ヘッダーの内容を取得する |
doc_id, section_index? |
set_header |
ヘッダーを設定する |
doc_id, text, section_index?, apply_page_type? (both/even/odd) |
get_footer |
フッターの内容を取得する |
doc_id, section_index? |
set_footer |
フッターを設定する |
doc_id, text, section_index?, apply_page_type? (both/even/odd) |
📌 脚注/章末注 (Footnotes/Endnotes) - 4個
| ツール |
説明 |
主なパラメータ |
get_footnotes |
文書内のすべての脚注のリストを取得する |
doc_id |
insert_footnote |
特定の位置に脚注を挿入する |
doc_id, section_index, paragraph_index, text |
get_endnotes |
文書内のすべての章末注のリストを取得する |
doc_id |
insert_endnote |
特定の位置に章末注を挿入する |
doc_id, section_index, paragraph_index, text |
🔗 ブックマーク/ハイパーリンク (Bookmarks/Hyperlinks) - 4個
| ツール |
説明 |
主なパラメータ |
get_bookmarks |
文書内のすべてのブックマークのリストを取得する |
doc_id |
insert_bookmark |
特定の位置にブックマークを挿入する |
doc_id, section_index, paragraph_index, name |
get_hyperlinks |
文書内のすべてのハイパーリンクのリストを取得する |
doc_id |
insert_hyperlink |
ハイパーリンクを挿入する |
doc_id, section_index, paragraph_index, url, text |
➗ 数式 (Equations) - 2個
| ツール |
説明 |
主なパラメータ |
get_equations |
文書内のすべての数式のリストを取得する |
doc_id |
insert_equation |
数式を挿入する(HWP数式スクリプト形式) |
doc_id, section_index, after_index, script |
💬 メモ (Memos/Comments) - 3個
| ツール |
説明 |
主なパラメータ |
get_memos |
文書内のすべてのメモ/コメントのリストを取得する |
doc_id |
insert_memo |
メモ/コメントを挿入する |
doc_id, section_index, paragraph_index, content, author? |
delete_memo |
メモ/コメントを削除する |
doc_id, memo_id |
📚 セクション (Sections) - 5個
| ツール |
説明 |
主なパラメータ |
get_sections |
文書内のすべてのセクションのリストを取得する |
doc_id |
insert_section |
新しいセクションを挿入する |
doc_id, after_index |
delete_section |
セクションを削除する |
doc_id, section_index |
get_section_xml |
セクションのRaw XMLを取得する(AI文書操作向け) |
doc_id, section_index? |
set_section_xml |
セクションのRaw XMLを置き換える(HWPML形式が必要) |
doc_id, xml, section_index?, validate? |
🎭 スタイル定義 (Style Definitions) - 4個
| ツール |
説明 |
主なパラメータ |
get_styles |
文書に定義されたスタイルのリストを取得する |
doc_id |
get_char_shapes |
文字の形状(CharShape)定義のリストを取得する |
doc_id |
get_para_shapes |
段落の形状(ParaShape)定義のリストを取得する |
doc_id |
apply_style |
段落にスタイルを適用する |
doc_id, section_index, paragraph_index, style_id |
📰 段設定 (Column Layout) - 2個
| ツール |
説明 |
主なパラメータ |
get_column_def |
段(Column)の設定を取得する |
doc_id, section_index? |
set_column_def |
段の設定を変更する(多段編集) |
doc_id, count, section_index?, type?, same_size?, gap? |
📤 エクスポート (Export) - 2個
| ツール |
説明 |
主なパラメータ |
export_to_text |
文書をテキストファイルにエクスポートする |
doc_id, output_path |
export_to_html |
文書をHTMLファイルにエクスポートする |
doc_id, output_path |
↩️ 元に戻す/やり直す (Undo/Redo) - 2個
| ツール |
説明 |
主なパラメータ |
undo |
最後の変更を元に戻す |
doc_id |
redo |
元に戻した変更をやり直す |
doc_id |
📋 サポートされる形式
| 形式 |
拡張子 |
読み取り |
書き込み |
| HWPX |
.hwpx |
✅ |
✅ |
| HWP |
.hwp |
❌ |
❌ |
注意: HWP(バイナリ)ファイルはサポートされていません。ハングルオフィスでHWPXに変換してから使用してください。
📝 リリースノート
v0.4.0 (拡張検索とダイアグラムサポート)
- 🆕 新機能:
search_text に include_tables オプションを追加 - テーブルセル内のテキストも検索できます
- 🆕 新機能:
replace_text_in_cell - 特定のテーブルセル内のテキストのみを精密に置換できます
- 🆕 新機能:
render_mermaid - Mermaidダイアグラムを画像として文書に挿入できます
- フローチャート、シーケンス、クラス図など、すべてのMermaid文法をサポートします
- テーマを選択できます(default, dark, forest, neutral)
- 🆕 新機能:
get_section_xml / set_section_xml - セクションのRaw XMLを直接操作できます
- AIベースの高度な文書編集シナリオをサポートします
- 🔧 改善:
insert_image を完全に改善しました
- BinDataフォルダに画像を自動保存します
- content.hpfマニフェストを自動登録します
- ファイル損傷なしで画像を挿入できます
v0.3.0 (入れ子テーブルのサポート)
- 🆕 新機能:
insert_nested_table - テーブルセル内に入れ子テーブルを挿入する機能
- 親テーブルの特定のセルに新しいテーブルを挿入できます
- 初期データを指定できます(2D配列)
- HWPX標準構造(
treatAsChar, hp:subList)を完全に遵守します
- 🔧 改善: charSpacingのパーシングを改善しました(属性の順序に関係なく処理します)
v0.2.1 (重大な修正)
- 🔥 重大な修正: 同じ行に複数のセルを同時に編集する際のファイル損傷問題を完全に解決しました
- 行(row)ごとの更新をグループ化してインデックスの不一致を防止します
- 逆順(descending)処理により安全なXML編集を保証します
v0.2.0 (拡張版)
- 🔥 主要な修正: テキストを編集する際にlinesegを自動的にリセットして、重なり現象を完全に解消しました
- 🔧 バグ修正: 入れ子テーブル構造でのXML要素の境界の誤認識問題を修正しました
- 🛡️ 安定性: 原子的なファイル書き込みによりファイル損傷を防止します
- 📦 保存: 元のcharPr/spacingスタイルを完全に保存します
v0.1.0 (元のバージョン)
- 最初のリリース(mjyoo2/hwp-extension)
🙏 クレジット
📄 ライセンス
MIT
🤝 コントリビューション
バグレポートや機能リクエストは、GitHub Issues で行ってください。