Metadata-Version: 2.5
Name: korean-docs-mcp
Version: 0.1.1
Summary: MCP server that lets Claude, Cursor and other agents search local Korean documents (HWP, HWPX, Markdown) with morpheme-aware BM25.
Project-URL: Homepage, https://github.com/RionHwang0/korean-docs-mcp
Project-URL: Issues, https://github.com/RionHwang0/korean-docs-mcp/issues
Author: Rion Hwang
License-Expression: MIT
License-File: LICENSE
Keywords: bm25,hwp,hwpx,kiwi,korean,mcp,rag,search
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Natural Language :: Korean
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Text Processing :: Indexing
Requires-Python: >=3.10
Requires-Dist: kohybrid>=0.2.1
Requires-Dist: mcp<3,>=2.3
Requires-Dist: unhwp>=0.1
Provides-Extra: dev
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
Requires-Dist: pytest>=8; extra == 'dev'
Description-Content-Type: text/markdown

# korean-docs-mcp

<!-- mcp-name: io.github.RionHwang0/korean-docs-mcp -->

[![CI](https://github.com/RionHwang0/korean-docs-mcp/actions/workflows/ci.yml/badge.svg)](https://github.com/RionHwang0/korean-docs-mcp/actions/workflows/ci.yml)
[![PyPI](https://img.shields.io/pypi/v/korean-docs-mcp)](https://pypi.org/project/korean-docs-mcp/)

An MCP server that lets Claude, Cursor and other agents search a folder of
Korean documents (**HWP, HWPX**, Markdown, text) on your own machine.

- **Reads HWP and HWPX directly.** Tables come back as Markdown tables with
  their rows intact, not as a run of cell text.
- **Search that understands Korean.** Text is split into morphemes with
  [Kiwi](https://github.com/bab2min/kiwipiepy) before it is indexed, so
  `예산을`, `예산의` and `국가예산` all match `예산`. Ranking is BM25.
- **Local and zero-config.** One SQLite file, no server, no API key, no
  embeddings to pay for. Documents never leave your machine.
- **Incremental.** Re-indexing a folder only re-reads files that changed and
  drops files that were deleted.

Design notes and measurements (in Korean):
[Claude가 내 컴퓨터의 HWP 공문서를 검색하게 만들기](https://ai-dev.selfdeveloper01.com/posts/korean-docs-mcp/).

```text
You: 2027년 예산안에서 디지털 교과서 예산 얼마였는지 찾아줘
Claude: → search("디지털 교과서 예산")
        ← 2027 예산.hwpx, chunk 0
          | 분야 | 사업명 | 예산(억 원) |
          | 교육 | 디지털 교과서 | 495 |
        디지털 교과서 예산은 495억 원입니다 (2027 예산.hwpx 표 기준).
```

## Setup

You need [uv](https://docs.astral.sh/uv/getting-started/installation/)
(`brew install uv` or `pipx install uv`). The first start installs the
package with its Kiwi model (about 130 MB in total), so it takes a minute;
later starts are immediate.

**Claude Code**

```bash
claude mcp add korean-docs -- uvx korean-docs-mcp
```

**Claude Desktop** (`claude_desktop_config.json`), **Cursor** (`.cursor/mcp.json`)
and other clients that take the same format:

```json
{
  "mcpServers": {
    "korean-docs": {
      "command": "uvx",
      "args": ["korean-docs-mcp"]
    }
  }
}
```

Then ask the agent to index a folder, e.g. *"~/Documents/공문서 폴더 색인해줘"*,
and search it in plain Korean.

To index folders when the server starts, add them to `args`:
`["korean-docs-mcp", "--index", "/Users/me/Documents/공문서"]`.

## Tools

| Tool | What it does |
|---|---|
| `index_documents(folder, recursive=True)` | Index `.hwp`, `.hwpx`, `.md`, `.txt` files under a folder. Only new or changed files are parsed. |
| `search(query, limit=8, folder=None, match_all=False)` | BM25 search over morphemes. Each hit has the chunk text, its heading, document path and chunk number. |
| `read_document(path, chunk=None, max_chars=6000)` | Read a document as Markdown, from the start or around a search hit. Long documents page with `next_offset`. |
| `list_documents(folder=None)` | Indexed documents with titles and sizes. |

## Search quality

KorQuAD 1.0 dev: for each of 5,774 questions, find the paragraph it was
written from among 964 paragraphs. Every row is SQLite FTS5 with its built-in
BM25; only the way text is split into terms changes.

| Method | Recall@1 | Recall@5 | Recall@10 | MRR@10 |
|---|---|---|---|---|
| FTS5 `unicode61` (SQLite default) | 0.761 | 0.887 | 0.911 | 0.816 |
| FTS5 `trigram` | 0.716 | 0.859 | 0.882 | 0.776 |
| **korean-docs-mcp** (Kiwi morphemes) | **0.896** | **0.980** | **0.988** | **0.933** |

Morpheme analysis costs about 0.5 ms per query. Reproduce with
[`benchmarks/korquad.py`](benchmarks/korquad.py).

Indexing 50 real government press releases (HWP and HWPX from korea.kr)
takes about 3 seconds, and a search takes under 1 ms.

## How it works

1. **Parse.** HWP and HWPX are converted to Markdown with
   [unhwp](https://pypi.org/project/unhwp/), which scored best overall in
   [hwp-parser-bench](https://github.com/RionHwang0/hwp-parser-bench)
   (100% text and 95.5% table cells on public HWPX files).
2. **Chunk.** Paragraphs are grouped into chunks of up to 1,200 characters
   under their nearest heading. A table is always its own chunk; a long table
   is split by rows with its header repeated in every piece.
3. **Analyze.** [kohybrid](https://github.com/RionHwang0/kohybrid)'s
   `KoreanTokenizer` keeps nouns, numbers, foreign words and dictionary-form
   verbs and adjectives, and drops particles and endings.
4. **Index.** The lexemes go into an SQLite FTS5 table. Document titles are
   indexed with double weight. The original Markdown is stored for display.

The index lives at `~/.local/share/korean-docs-mcp/index.sqlite3`. Change it
with `--db` or the `KOREAN_DOCS_DB` environment variable.

## Limits

- Merged table cells are left empty in all but their first row, as the
  parser emits them; a search for a row's group label may miss later rows.
- Images, charts and scanned pages are not read.
- No vector search yet. BM25 over morphemes handles keyword-style questions
  well; paraphrased questions with no shared words are not found.

## Development

```bash
git clone https://github.com/RionHwang0/korean-docs-mcp && cd korean-docs-mcp
python -m venv .venv && . .venv/bin/activate
pip install -e ".[dev]"
pytest
```

`tests/test_server.py` starts the server over stdio and drives it with the
MCP Python client.

## License

MIT
