Skip to main content
Glama

corpus-mcp

一个本地 MCP 服务器,让智能体通过统一接口,干净、高效地访问离线 ZIM 归档组成的本地知识语料库——涵盖 Wikipedia、医学类(MDWiki)、开发者文档(DevDocs)和 Stack Exchange。无需互联网、无需 embedding、无需向量数据库:libzim 全文搜索,再加上服务器内确定性的内容清洗。

对外暴露的 MCP 接口恰好只有两个工具:

search(query, limit?)
fetch(ref, sections?)

语料库的配置是运维者的事,不是智能体的事。智能体只会:

discover  →  search()
select    →  fetch()

语料族

语料

kind

文档

章节模型

Wikipedia、MDWiki

article

词条

标题树(h2+),导语章节 id 为 ""

DevDocs(C、CMake、Python)

documentation

文档页

标题树;剥离页内目录和导航装帧

Stack Exchange

thread

帖子

合成章节:questionaccepted-answeranswer-<id>

所有语料识别、路由、ZIM 访问、HTML 解析、内容清洗、排序、重定向处理与规范化依然由服务端负责。智能体完全不需要去解析 HTML、消化重定向、构造或解析引用,也不需要了解任何关于 libzim、ZIM 命名空间或语料存储内部的信息。

Related MCP server: mcpzim

引用

search() 返回的结果里携带不透明的 ref(例如 corpus://Wikipedia/Bell_test);fetch() 消费它。智能体绝不能构造、解析或修改 ref,也不能凭某个 ref 去推断它来自哪个语料库:

search() produces ref      fetch() consumes ref

架构

Local agent
    │  MCP / Streamable HTTP  →  http://127.0.0.1:8000/mcp
    ▼
┌──────────────────────────────────────────────┐
│ Corpus MCP Server                            │
│  search()  fetch()                           │
│  ├─ CorpusManager (routing, cache,          │
│  │   bounded-concurrency fan-out)           │
│  ├─ federated ranking (RRF + lexical title  │
│  │   reranking + diversity)                 │
│  ├─ adapters: mediawiki / devdocs /         │
│  │   stackexchange                           │
│  ├─ HTML cleaner → Markdown, section trees  │
│  └─ GlobalRef codec (opaque refs)           │
└─────────────┬────────────────────────────────┘
              ▼
      per-library ZIM service (only libzim touchpoint,
      one search lock per archive)
              ▼
      corpus/  (read-only volume, N .zim archives)
      corpus.toml  (manifest: name, adapter, path)

MCP 接口层不存在任何 libzim 概念:没有命名空间、簇 ID、初始件、MIME 类型、原始 HTML。

前置条件

  • Docker 与 Docker Compose

  • ZIM 归档(见下文)

  • 本地跑测试套件(可选):Python 3.12 + uv(直接用 pip 也行)

语料布局

服务器自身绝不下载归档档——语料获取与启动期解耦。默认布局:

corpus/
  wikipedia/wikipedia_en_all_nopic_*.zim
  medical/mdwiki_en_all_maxi_*.zim
  devdocs/devdocs_en_cpp_*.zim
  devdocs/devdocs_en_cmake_*.zim
  devdocs/devdocs_en_python_*.zim
  stackexchange/stackoverflow.com_en_all_*.zim
  stackexchange/security.stackexchange.com_en_all_*.zim
  stackexchange/softwareengineering.stackexchange.com_en_all_*.zim
corpus.toml

corpus.toml 申报每条文库、对应适配器、路径(相对于语料根目录):

version = 1

[[library]]
name = "Wikipedia"
path = "wikipedia/wikipedia_en_all_nopic_2026-06.zim"
adapter = "mediawiki"

[[library]]
name = "CMake-Docs"
path = "devdocs/devdocs_en_cmake_2026-08.zim"
adapter = "devdocs"

校验规则:文库名必须唯一、适配器必须已知、路径不能离开语料根目录。启动服务器之前请先校验一次语料库:

make validate-corpus   # opens every archive, reports metadata
make corpus-list       # list configured libraries

启动 / 停止

make start           # build + start (docker compose, detached)
make logs            # tail logs
make ps              # container status
make stop            # stop (keep containers)
make down            # stop + remove
make restart
make build

服务器启动后,MCP 端点开放于 http://127.0.0.1:8000/mcp(Streamable HTTP)。宿主机端口默认仅回环绑定;容器内部监听 0.0.0.0:8000

如果任何一个配置的 ZIM 无法打开,服务器整体启动失败并指明出问题的库——不存在降级完全可行的半功能模式。

工具模式

search(query: str, limit?: int)

在所有已配置文库的全文索引上检索(有界并发,每个归档一个 worker),用 Reciprocal Rank Fusion 融合排序列表,再对跨库同分为候选值做标题词序覆盖的重新排序,然后执一轮确定性的多样性筛选,最后返回干净的结果。limit 默认为 5;服务端硬性上限为 SEARCH_MAX_LIMIT(默认 10)。

{
  "results": [
    {
      "ref": "corpus://Wikipedia/Bell_test",
      "library": "Wikipedia",
      "kind": "article",
      "title": "Bell test",
      "snapshot": "2026-06",
      "snippet": "To close the detection loophole, an apparatus with a high detection efficiency is needed.",
      "relevant_sections": [
        { "id": "Notable_experiments", "title": "Notable experiments" },
        { "id": "Loopholes", "title": "Loopholes" }
      ]
    }
  ]
}
  • ref —— 不透明的全局标识符;原样回传给 fetch()

  • library / kind / snapshot —— 出处:哪个库、哪类文档、以及哪个快照(从归档 metadata 得到)。

  • relevant_sections — 0–3 条确定性词法提示(无明显的匹配则为空数组)。节 ID 服务器构造;智能体就不要自己去猜。

一条库打不开只是降级这一条搜索结果(其余库照常回答),它不会让搜索整体失败。

fetch(ref: str, sections?: list[str])

在干净化后,以 Markdown 结构返回文档。

  • 不带 sections —— 返回整篇文档(受 MAX_FETCH_CHARS 限制;如果恰在某节边界处截断,则 truncated: true)。

  • sections —— 只给出这些节(以及子孙子树)。节 ID 取自 search() 的提示或 available_sections。导语/引言节的 id 是 ""。对帖子来说,节 ID 固定为 questionaccepted-answeranswer-<id>;它们的 metadata 里带着分数、接受状态与标签。

{
  "ref": "corpus://Wikipedia/Bell_test",
  "library": "Wikipedia",
  "kind": "article",
  "title": "Bell test",
  "snapshot": "2026-06",
  "sections": [
    { "id": "Loopholes", "title": "Loopholes", "content": "## Loopholes\n\n..." }
  ],
  "available_sections": [
    { "id": "", "title": "Bell test" },
    { "id": "Background", "title": "Background" },
    { "id": "Loopholes", "title": "Loopholes" }
  ],
  "truncated": false
}

错误回传内容简短、可采纳意见:

{ "error": "invalid_ref", "message": "invalid reference: ..." }
{ "error": "not_found", "message": "Document not found in Wikipedia: Foo_bar" }
{
  "error": "section_not_found",
  "missing_sections": ["Experiments"],
  "available_sections": [ { "id": "Loopholes", "title": "Loopholes" }, "..." ]
}

完整智能体流程示例

search("Bell experiment loopholes")
    ↓
fetch("corpus://Wikipedia/Bell_test", ["Notable_experiments", "Loopholes"])

配置

环境变量(以下是运行于容器内的默认值):

变量

默认值

含义

CORPUS_ROOT

/corpus

容器内语料根目录(必填)

CORPUS_CONFIG

/config/corpus.toml

容器内清单(Manifest)路径(必填)

MCP_HOST

0.0.0.0

容器内监听地址

MCP_PORT

8000

容器内监听端口

SEARCH_LIMIT

5

search() 的默认 limit

SEARCH_MAX_LIMIT

10

search(limit=…) 的硬性上限

MAX_FETCH_CHARS

100000

fetch 输出内容预算

SEARCH_WORKERS

8

搜索组广播阶段并发的归档线程数

SEARCH_MAX_CONSECUTIVE

0

多样度:同一文库最多连续多少条

LOG_QUERIES

true

是否记录搜索词条(隐私相关)

ZIM_CHECK

false

启动时执行 libzim 的校验和完整验证(这会读全部语料;可选,对大体积归档慢)

宿主侧的 Compose 变量:CORPUS_ROOT(默认 ./corpus)与 CORPUS_CONFIG(默认 ./corpus.toml)。

配置无效服务器会发生 fail fast。

测试

make test     # unit + integration + MCP surface tests (needs .venv)
make lint
make format

本地测试执行的准备步骤:

uv venv .venv --python 3.12
uv pip install -e . --python .venv/bin/python
uv pip install --python .venv/bin/python pytest pytest-asyncio ruff
make test

测试用 libzim 提供的 writer 构建最小的 ZIM 夹具(每种语料族一个),不需要真实语料。MCP 回归测试(兼容面回归)断言服务器时恰好只暴露 searchfetch 两个工具,而且 connectng 没有 prompts、也没有伪装资源。

安全姿态

按设计它就是本地服务:只绑回环、只读卷、容器内非 root、没有 UID、不开特权、没有 Docker socket、没有任意文件路径访问、不拉取 URL、不调度 shell。

本工具也不会把文件路径、URL、命令或别的可执行内容当参数接受——它们只能收不透明的 ref 作为标识。

F
license - not found
Not graded
quality - not tested
B
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • A
    license
    A
    quality
    A
    maintenance
    Enables AI models to access and search offline Wikipedia and other knowledge bases stored in ZIM format files. Provides intelligent content retrieval, structured browsing, advanced search capabilities, and metadata extraction for comprehensive offline knowledge access.
    1
    118
    MIT
  • A
    license
    A
    quality
    B
    maintenance
    An MCP server that provides offline access to ZIM file archives, including Wikipedia, medical knowledge, and maps. It dynamically exposes tools like search, article retrieval, and driving route planning based on available ZIM files.
    4
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables large language models to directly access and search content in ZIM files, allowing offline question answering and information retrieval from resources like Wikipedia.
    19
    MIT
  • A
    license
    Not graded
    quality
    B
    maintenance
    Enables offline CRUD and semantic search on Wikipedia ZIM archives via MCP tools for reading, writing, editing, deleting, and searching articles.
    1
    MIT

View all related MCP servers

Related MCP Connectors

  • Shared, peer-validated knowledge archive for AI agents — search, contribute, and validate via MCP

  • Agentic search over your Dewey document collections from any MCP-compatible client.

  • Agent-native MCP server over the public saagarpatel.dev corpus. Read-only, stateless.

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/MagoDelBlocco/mcp-wiki'

If you have feedback or need assistance with the MCP directory API, please join our Discord server