mdcx
Converts document collections to verified Markdown, packages them into encrypted .mdcx files, and exposes search, info, and document retrieval tools via the Model Context Protocol.
README
mdcx
<!-- mcp-name: io.github.jorgell23-sys/markdown-document-search -->
Convert a document collection to verified Markdown, package it into a single encrypted file, and make it queryable by agents through the Model Context Protocol.
The problem
An agent answering questions about a document collection has two options. It can receive the documents in its context window, which is expensive and bounded by the window size. Or it can query a component that already knows where each item is.
Measuring one specific query — where the minimum pipe diameter to be modelled in 3D is stated — over a real collection of 99 documents and 180 MB, using the cl100k_base tokenizer:
| Model tokens | Local tokens | |
|---|---|---|
| Reading the originals | 2,265,488 | 2,265,327 |
| Querying the package | 435 | 2,688,861 |
The 435 comprise 20 for the question, 274 for the retrieved passage and 141 for the answer.
The first row costs the entire collection for a concrete reason: a PDF cannot be searched, it is a binary, and without prior conversion there is no way to know which of the 99 documents holds the answer. They all have to be extracted and read.
This is one measurement, not an average: the saving depends on how much text an answer requires. What does not vary is the shape of the change. The work does not disappear, it moves from the context window — which is billed and finite — to the CPU, which is not. That is why the local column rises rather than falls.
The three stages
Conversion. Each document is converted to Markdown and checked against the text the original actually exposes, read with a library independent from the engine that performed the conversion. Content the structured engine omits is appended verbatim rather than reported as lost.
Over the collection used during development — 99 documents, 1,144,553 reference words — 594 words were not recovered, a global coverage of 99.948%. Of the 184 documents exposing text, 116 came out at exactly 100% and none below 99.5%. The remaining four are scanned drawings containing no text at all in the file: they were read by optical character recognition and are marked as unverifiable, because no text original exists to measure them against.
Packaging. The corpus, its search index and the provenance of every passage
fit into a single .mdcx file, encrypted with AES-256-GCM, whose header can be
read without the key. From 8.8 MB of Markdown to 3.9 MB in one file.
Retrieval. A query returns the passages that answer it with their exact source. Over the 20 real queries used for tuning, the correct document appears within the top five results in 19 cases and within the top ten in all 20.
Installation
The package separates querying from conversion, because they have very different requirements.
| Command | Installs | Size |
|---|---|---|
pip install mdcx |
query and read .mdcx packages |
~10 MB |
pip install "mdcx[mcp]" |
the above plus the MCP server | ~50 MB |
pip install "mdcx[convert]" |
document conversion (Docling, PyTorch) | ~1.4 GB |
pip install "mdcx[all]" |
everything, including OCR | ~1.5 GB |
Conversion is what pulls in the heavy dependencies. Someone who receives an
.mdcx file and only needs to query it installs neither Docling nor PyTorch.
Converting a collection
pip install "mdcx[convert]"
mdcx-convert --input ./Documents --output ./Documents_md
The output mirrors the input directory structure, adds a global index, and records for each file the coverage achieved against its original.
Packaging and querying
mdcx pack --output ./Documents_md --target corpus.mdcx --key "..."
mdcx info corpus.mdcx
mdcx search corpus.mdcx "where is the minimum diameter stated" --key "..."
mdcx export corpus.mdcx --target ./restored --key "..."
info reads the header without the key, so the issuer and the integrity of a
file can be checked before opening it. export rebuilds the original folder: a
format that cannot be left is a trap, however well intended.
Using it as an MCP server
The server requires Python and this package. It does not require the conversion stack, so the footprint is about 50 MB.
{
"mcpServers": {
"mdcx": {
"command": "python",
"args": ["-m", "mdcx.mcp_server"],
"env": {
"MDCX_FILE": "/path/to/corpus.mdcx",
"MDCX_KEY": "package-key"
}
}
}
}
Alternatively, with uv the server runs without a prior installation, which is the usual arrangement for Python MCP servers:
{
"mcpServers": {
"mdcx": {
"command": "uvx",
"args": ["--from", "mdcx[mcp]", "python", "-m", "mdcx.mcp_server"],
"env": {
"MDCX_FILE": "/path/to/corpus.mdcx",
"MDCX_KEY": "package-key"
}
}
}
}
Three tools are exposed. search returns the passages answering a question, each
with its source document and portable path. info describes the corpus and the
fidelity of its conversion. document returns a full document when passages are
not enough.
The server verifies the package before it starts listening, so a wrong path or key is reported immediately rather than on the first query.
Tests
pip install pytest
python -m pytest tests/ -v
The suite covers hostile inputs: empty and corrupted files, names in other alphabets, malformed queries including SQL injection attempts, truncated and tampered packages, and compaction against content loss.
Paths
No output contains absolute paths. Every document is identified by a pseudopath
beginning with @/, resolved against the folder or package containing it, so a
corpus remains valid wherever it is stored: local disk, network share or cloud.
Signing
A package can be signed so that its issuer can be proven rather than merely declared. The signature covers the digest of the encrypted body, so it attests both origin and content, and is verified without the encryption key.
mdcx keygen
mdcx pack --output ./Documents_md --target corpus.mdcx --key "..." \
--issuer "Acme Ltd" --signing-key <private-key>
mdcx verify corpus.mdcx --public-key <public-key>
Verification also requires the body to be intact: a signature covering only the recorded digest would otherwise accept a package whose contents had been replaced while its header was left untouched.
The issuer field alone is free text and proves nothing. Only a signature does.
Encryption
The package encrypts at rest and decrypts in memory when opened; nothing is written to disk in clear. This protects a file in transit. It is not the same as searching over encrypted data without ever decrypting it, which is a separate field with documented leakage attacks and per-query costs measured in seconds.
The key is derived with scrypt, which makes guessing slow: about 8 attempts per second, each requiring 32 MB of memory, which prevents parallelisation on a GPU. Even so, the real strength is the passphrase: a dictionary password falls in a day.
Authorship
Conceived and directed by Jorge Ellena G., programmed with the assistance of Claude (Anthropic).
Every decision in this package was made against measurements rather than convention: which conversion engine to use, which licence permits which, how to rank a search, which optimisations to accept and which to discard. Several were discarded precisely because they were measured — reducing the search candidate pool appeared to be ten times faster and in fact lowered accuracy from 19 to 17 out of 20 — and those measurements are recorded alongside the decisions they justify.
Citation
Archived on Zenodo with a permanent identifier. The concept DOI always resolves to the latest version:
https://doi.org/10.5281/zenodo.22015991
Licence
Apache 2.0. The software may be used, modified and sold, provided the copyright notice is retained.
PyMuPDF was deliberately avoided: its AGPL licence would require anyone using this software to publish their own under AGPL, including those offering it only as a network service.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。