kordoc

kordoc

An MCP server that parses South Korean document formats like HWP, HWPX, and PDF into Markdown. It features specialized table reconstruction and security-hardened extraction optimized for administrative and public institution files.

Category
访问服务器

README

kordoc

모두 파싱해버리겠다 — Parse any Korean document to Markdown.

npm version license node

HWP, HWPX, PDF — 대한민국 문서라면 남김없이 파싱해버립니다.

한국어

kordoc demo


Why kordoc?

South Korea's government runs on HWP — a proprietary word processor the rest of the world has never heard of. Every day, 243 local governments and thousands of public institutions produce mountains of .hwp files. Extracting text from them has always been a nightmare: COM automation that only works on Windows, proprietary binary formats with zero documentation, and tables that break every existing parser.

kordoc was born from that document hell. Built by a Korean civil servant who spent 7 years buried under HWP files at a district office. One day he snapped — and decided to parse them all. Its parsers have been battle-tested across 5 real government projects, processing school curriculum plans, facility inspection reports, legal annexes, and municipal newsletters. If a Korean public servant wrote it, kordoc can parse it.


Features

  • HWP 5.x Binary Parsing — OLE2 container + record stream + UTF-16LE. No Hancom Office needed.
  • HWPX ZIP Parsing — OPF manifest resolution, multi-section, nested tables.
  • PDF Text Extraction — Y-coordinate line grouping, table reconstruction, image PDF detection.
  • 2-Pass Table Builder — Correct colSpan/rowSpan via grid algorithm. No broken tables.
  • Broken ZIP Recovery — Corrupted HWPX? Scans raw Local File Headers.
  • 3 Interfaces — npm library, CLI tool, and MCP server (Claude/Cursor).
  • Cross-Platform — Pure JavaScript. Runs on Linux, macOS, Windows.

Supported Formats

Format Engine Features
HWPX (한컴 2020+) ZIP + XML DOM Manifest, nested tables, merged cells, broken ZIP recovery
HWP 5.x (한컴 레거시) OLE2 + CFB 21 control chars, zlib decompression, DRM detection
PDF pdfjs-dist Line grouping, table detection, image PDF warning

Installation

npm install kordoc

# PDF support requires pdfjs-dist (optional peer dependency)
npm install pdfjs-dist

pdfjs-dist is an optional peer dependency. Not needed for HWP/HWPX parsing.

Usage

As a Library

import { parse } from "kordoc"
import { readFileSync } from "fs"

const buffer = readFileSync("document.hwpx")
const result = await parse(buffer.buffer)

if (result.success) {
  console.log(result.markdown)
}

Format-Specific

import { parseHwpx, parseHwp, parsePdf } from "kordoc"

const hwpxResult = await parseHwpx(buffer)   // HWPX
const hwpResult  = await parseHwp(buffer)    // HWP 5.x
const pdfResult  = await parsePdf(buffer)    // PDF

Format Detection

import { detectFormat } from "kordoc"

detectFormat(buffer) // → "hwpx" | "hwp" | "pdf" | "unknown"

As a CLI

npx kordoc document.hwpx                    # stdout
npx kordoc document.hwp -o output.md        # save to file
npx kordoc *.pdf -d ./converted/            # batch convert
npx kordoc report.hwpx --format json        # JSON with metadata

As an MCP Server

Works with Claude Desktop, Cursor, Windsurf, and any MCP-compatible client.

{
  "mcpServers": {
    "kordoc": {
      "command": "npx",
      "args": ["-y", "kordoc-mcp"]
    }
  }
}

Tools exposed:

Tool Description
parse_document Parse HWP/HWPX/PDF file → Markdown
detect_format Detect file format via magic bytes

API Reference

parse(buffer: ArrayBuffer): Promise<ParseResult>

Auto-detects format and converts to Markdown.

interface ParseResult {
  success: boolean
  markdown?: string
  fileType: "hwpx" | "hwp" | "pdf" | "unknown"
  isImageBased?: boolean     // scanned PDF detection
  pageCount?: number         // PDF only
  error?: string
}

Types

import type { ParseResult, ParseSuccess, ParseFailure, FileType } from "kordoc"

Internal types (IRBlock, IRTable, IRCell, CellContext) and utilities (KordocError, sanitizeError, isPathTraversal, buildTable, blocksToMarkdown) are not part of the public API.

Requirements

  • Node.js >= 18
  • pdfjs-dist >= 4.0.0 — Optional. Only needed for PDF. HWP/HWPX work without it.

Security

Production-grade security hardening:

  • ZIP bomb protection — Entry count validation, 100MB decompression limit, 500 entry cap

    Known limitation: Pre-check reads declared sizes from ZIP Central Directory, which an attacker can falsify. The primary defense is per-file cumulative size tracking during actual decompression. For fully untrusted input where streaming decompression is required, consider wrapping kordoc behind a size-limited sandbox.

  • XXE/Billion Laughs prevention — Internal DTD subsets fully stripped from HWPX XML
  • Decompression bomb guardmaxOutputLength on HWP5 zlib streams, cumulative 100MB limit across sections
  • PDF resource limits — MAX_PAGES=5,000, cumulative text size 100MB cap, doc.destroy() cleanup
  • HWP5 record cap — Max 500,000 records per section, prevents memory exhaustion from crafted files
  • Table dimension clamping — rows/cols read from HWP5 binary clamped to MAX_ROWS/MAX_COLS before allocation
  • colSpan/rowSpan clamping — Crafted merge values clamped to grid bounds (MAX_COLS=200, MAX_ROWS=10,000)
  • Path traversal guard — Backslash normalization, .., absolute paths, Windows drive letters all rejected
  • MCP error sanitization — Allowlist-based error filtering, unknown errors return generic message
  • MCP path restriction — Only .hwp, .hwpx, .pdf extensions allowed, symlink resolution
  • File size limit — 500MB max in MCP server and CLI
  • HWP5 section limit — Max 100 sections in both primary and fallback paths
  • HWP5 control char fix — Character code 10 (footnote/endnote) now correctly handled

How It Works

┌─────────────┐     Magic Bytes      ┌──────────────────┐
│  File Input  │ ──── Detection ────→ │  Format Router   │
└─────────────┘                       └────────┬─────────┘
                                               │
                    ┌──────────────────────────┼──────────────────────────┐
                    │                          │                          │
              ┌─────▼─────┐            ┌───────▼───────┐          ┌──────▼──────┐
              │   HWPX    │            │    HWP 5.x    │          │     PDF     │
              │  ZIP+XML  │            │  OLE2+Record  │          │  pdfjs-dist │
              └─────┬─────┘            └───────┬───────┘          └──────┬──────┘
                    │                          │                          │
                    │       ┌──────────────────┤                          │
                    │       │                  ��                          │
              ┌─────▼───────▼─────┐            │                          │
              │  2-Pass Table     │            │                          │
              │  Builder (Grid)   │            │                          │
              └─────────┬─────────┘            │                          │
                        │                      │                          │
                  ┌─────▼──────────────────────▼──────────────────────────▼─────┐
                  │                      IRBlock[]                              │
                  │              (Intermediate Representation)                  │
                  └────────────────────────┬───────────────────────────────────┘
                                           │
                                    ┌──────▼──────┐
                                    │  Markdown   │
                                    │   Output    │
                                    └─────────────┘

Credits

Production-tested across 5 Korean government technology projects:

  • School curriculum plans (학교교육과정)
  • Facility inspection reports (사전기획 보고서)
  • Legal document annexes (법률 별표)
  • Municipal newsletters (소식지)
  • Public data extraction tools (공공데이터)

Thousands of real government documents parsed without breaking a sweat.

License

MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选