MCP-powered knowledge base — Agent writes, humans read. Structured wiki with compiled truth, timeline, entity registry, and LLM audit.
Agent 写、人读 — 一个让 AI Agent 自动维护结构化知识库的系统。
Wiki KB 是一个基于纯 Markdown 文件的结构化知识库,通过 MCP (Model Context Protocol) 暴露操作接口,让 AI Agent(如 Claude、GPT、GLM 等)能在对话中主动读写知识。
现有的 AI 知识管理方案各有明显短板:
| 方案 | 问题 |
|---|---|
| Notion / Confluence | AI 只能"读",不能"写"。知识维护成本全在人身上。数据锁定在私有平台。 |
| Obsidian / Logseq | 人能编辑,但 AI 无法在对话中主动写入。需要额外插件/脚本桥接。 |
| RAG (向量数据库) | 只有检索,没有知识沉淀。每次对话结束,知识就丢了。 |
| Dify / Coze / LangChain | 绑定特定框架和 LLM。知识结构被工具的 data model 决定,不够灵活。 |
| 让 AI 写 Notion/Obsidian | 知识没有结构化规范,AI 写的内容质量参差不齐,缺乏矛盾检测和来源追溯。 |
Agent 写、人读。
大多数知识管理系统的设计假设人是知识的生产者,AI 是消费者。Wiki KB 反过来——AI Agent 是知识的日常维护者,人只需要在需要时审阅和编辑。
这意味着:
1. Compiled Truth + Timeline — 解决 AI 幻觉问题
传统知识库只存"当前结论",AI 生成的内容无法追溯来源。Wiki KB 的每个页面分两层:
当上层结论和下层证据矛盾时,以 Timeline 为准。这从根本上解决了 AI 生成内容不可信的问题——不是靠"更好的 prompt",而是靠结构约束。
2. MCP 原生 — 不绑定任何 Agent 框架
Wiki KB 是一个标准 MCP Server。任何支持 MCP 的 Agent(Claude Desktop、Cursor、Hermes、OpenHands 等)都能直接调用它的 11 个 tools。不需要 SDK、不需要适配器、不需要改 Agent 代码。
这意味着你今天用 Claude,明天换 GPT,后天换开源模型——知识库不变,换 Agent 零成本。
3. 纯 Markdown + 文件系统 — 数据永远属于你
所有知识就是 .md 文件。你可以:
没有数据库、没有私有格式、没有平台锁定。哪怕 Wiki KB 项目停止维护,你的知识仍然完整可用。
4. 自动化质量保证
知识由 AI 维护,但质量不能靠运气:
5. 渐进式复杂度
不需要一次性用全部功能:
每一步都是可选的,不会因为缺少某个组件就无法启动。
| 维度 | Wiki KB | Notion AI | Obsidian + AI | RAG 向量库 |
|---|---|---|---|---|
| AI 能否主动写入 | ✅ 核心功能 | ❌ 只能读 | ⚠️ 需插件 | ❌ 只能检索 |
| 知识结构规范 | ✅ Schema v3 | ✅ Database Schema | ❌ 自由格式 | ❌ 无结构 |
| 来源追溯 | ✅ Timeline | ❌ | ⚠️ 部分插件 | ❌ |
| 数据自主性 | ✅ 纯 Markdown | ❌ 平台锁定 | ✅ 纯 Markdown | ⚠️ 取决于实现 |
| Agent 框架绑定 | ❌ MCP 标准 | ✅ 绑定 Notion | ✅ 绑定 Obsidian | ✅ 绑定框架 |
| 自动质量审计 | ✅ Dream Cycle | ❌ | ❌ | ❌ |
| 离线可用 | ✅ 纯文件 | ❌ | ✅ | ⚠️ 取决于向量库 |
| 多 Agent 兼容 | ✅ 任何 MCP 客户端 | ❌ | ❌ | ⚠️ 取决于框架 |
Wiki-KB 是 Agent 记忆系统中的结构化长期记忆层,与 Persistent Memory、OpenViking、Skills 协同工作:

数据流转:
wiki_create / wiki_update 写入 Wikimemory_to_wiki.py 从 OpenViking 提取记忆回写 Wikidream_cycle.py 用 LLM 审计 Wiki 质量auto_index.py → 将 Wiki 页面同步到 OpenViking(语义搜索).md 文件
git clone https://github.com/yourname/wiki-kb.git
cd wiki-kb
# 创建环境配置
cp .env.example .env
# 编辑 .env 填入你的配置(见下方环境变量说明)mkdir -p wiki/{concepts,entities,people,projects,meetings,ideas,comparisons,queries}
mkdir -p wiki/{logs/dream-reports,src/{articles,audio,images,pdfs,videos}}
mkdir -p scriptsdocker compose up -d --build
# 等待健康检查通过(约 30 秒)
docker ps --filter name=wiki-brain --format "{{.Status}}"curl -s -X POST http://localhost:8764/mcp \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}}}'wiki-kb/
├── scripts/ # 核心脚本(bind mount 到容器)
│ ├── wiki_mcp_server.py # MCP Server 主程序(11 个 tools)
│ ├── wiki_config.py # 集中配置模块(dataclass + 环境变量层级)
│ ├── entity_registry.py # 实体注册表(CLI + API)
│ ├── auto_index.py # 自动索引 + OpenViking 同步
│ ├── dream_cycle.py # LLM 知识审计
│ ├── memory_to_wiki.py # 对话记忆 → Wiki 同步
│ ├── wiki-to-notion.py # Wiki ↔ NAS (WebDAV) ↔ Notion 同步
│ ├── migrate_wiki_schema.py # v2 → v3 Schema 迁移工具
│ └── wiki-backup.sh # 备份脚本
├── wiki/ # 知识库数据(bind mount 到容器)
│ ├── concepts/ # 心智模型、框架、技术概念
│ ├── entities/ # 产品、组织、公司、平台
│ ├── people/ # 人物
│ ├── projects/ # 项目
│ ├── meetings/ # 会议记录
│ ├── ideas/ # 创意、想法
│ ├── comparisons/ # 对比分析
│ ├── queries/ # 查询记录
│ ├── src/ # 原始素材(不参与索引)
│ │ ├── articles/ # 文章存档
│ │ ├── images/ # 图片
│ │ ├── pdfs/ # PDF 文档
│ │ ├── audio/ # 音频
│ │ └── videos/ # 视频
│ ├── logs/ # 日志和审计报告
│ ├── SCHEMA.md # 页面结构规范
│ ├── RESOLVER.md # 分类路由规则
│ ├── graph.json # 知识图谱
│ ├── registry.json # 实体注册表
│ └── index.md # 内容目录
├── Dockerfile
├── docker-compose.yml
├── .env.example
└── README.mdWiki KB 暴露 11 个 MCP tools:
| Tool | 说明 |
|---|---|
wiki_search | 语义搜索 wiki 页面(支持 type 过滤) |
wiki_get | 读取页面完整内容(返回结构化 sections) |
wiki_create | 创建新页面(自动路由目录 + 注册实体) |
wiki_update | 更新指定 section(executive_summary / key_facts / relations) |
wiki_append_timeline | 追加 Timeline 条目(自动格式化 + 更新日期) |
wiki_list | 列出页面(支持 type / status 过滤) |
| Tool | 说明 |
|---|---|
entity_resolve | 通过名称/别名解析实体 |
entity_register | 注册新实体 |
entity_list | 列出实体(支持 type 过滤) |
entity_merge | 合并两个实体 |
| Tool | 说明 |
|---|---|
wiki_stats | 返回统计信息 + OpenViking 连通状态 |
在 MCP 客户端配置中添加:
{
"mcpServers": {
"wiki-kb": {
"url": "http://localhost:8764/mcp",
"timeout": 60
}
}
}Claude Desktop (claude_desktop_config.json):
{
"mcpServers": {
"wiki-kb": {
"url": "http://localhost:8764/mcp"
}
}
}Cursor / VS Code (settings.json):
{
"mcp.servers": {
"wiki-kb": {
"url": "http://localhost:8764/mcp"
}
}
}每个 wiki 页面遵循 Compiled Truth + Timeline 模式:
---
title: 实体名
created: 2026-01-15
updated: 2026-04-13
type: entity
tags: [ai-product, agent]
sources: [src/articles/xxx.md]
status: active
---
# 实体名
## Executive Summary
当前最佳理解。新信息到来时整体重写,不是追加。
## Key Facts
- 事实1(结构化,可被 agent 直接引用)
- 事实2
## Relations
| 关系 | 目标 | 说明 |
|------|------|------|
| uses | [[openviking]] | 语义搜索后端 |
| related | [[hermes-agent]] | 集成 |
---
## Timeline
- **2026-01-15** | 页面创建
[Source: wiki_mcp_server]
- **2026-03-20** | 新版本发布
[Source: 官方博客, 2026-03-20]| 区域 | 操作 | 说明 |
|---|---|---|
| Frontmatter | REWRITE | 结构化元数据 |
| Executive Summary | REWRITE | 当前最佳理解,整体重写 |
| Key Facts | REWRITE | 结构化事实列表 |
| Relations | REWRITE | 关系表 |
--- (分隔线) | 固定 | 不可删除 |
| Timeline | APPEND-ONLY | 严格只追加,永远不修改 |
| type | 目录 | 说明 |
|---|---|---|
person | people/ | 人物 |
project | projects/ | 项目(有明确目标和时间线) |
entity | entities/ | 产品/组织/公司/平台 |
concept | concepts/ | 心智模型/框架/技术概念 |
meeting | meetings/ | 会议记录/决策记录 |
idea | ideas/ | 创意/想法/待探索方向 |
comparison | comparisons/ | 对比分析 |
query | queries/ | 查询记录 |
| 关系 | 含义 |
|---|---|
uses | 使用/依赖 |
part-of | 属于/子集 |
related | 相关 |
contrasts | 对比/竞争 |
implements | 实现/落地 |
created-by | 创建者 |
evolved-from | 演化自 |
draft → active → archived
draftactive定期用 LLM 审计知识库质量,检测:
# 手动运行审计(dry-run)
docker exec wiki-brain python3 /app/scripts/dream_cycle.py
# 应用审计建议
docker exec wiki-brain python3 /app/scripts/dream_cycle.py --apply检测文件变更,自动生成 graph.json(节点 + 边),可选同步到 OpenViking。
docker exec wiki-brain python3 /app/scripts/auto_index.py从 OpenViking memories 提取实体和事件,写回 Wiki 页面。
docker exec wiki-brain python3 /app/scripts/memory_to_wiki.py# 每日 03:00 — 对话记忆同步
0 3 * * * docker exec wiki-brain python3 /app/scripts/memory_to_wiki.py >> /path/to/wiki/logs/cron.log 2>&1
# 每日 03:10 — Dream Cycle 审计
10 3 * * * docker exec wiki-brain python3 /app/scripts/dream_cycle.py --apply >> /path/to/wiki/logs/cron.log 2>&1
# 每日 03:30 — 自动索引 + OpenViking 同步
30 3 * * * docker exec wiki-brain python3 /app/scripts/auto_index.py --sync >> /path/to/wiki/logs/cron.log 2>&1
# 每日 04:00 — 备份
0 4 * * * /path/to/wiki-kb/scripts/wiki-backup.sh >> /path/to/wiki/logs/backup.log 2>&1| 变量 | 必需 | 默认值 | 说明 |
|---|---|---|---|
WIKI_ROOT | 否 | /data | Wiki 数据根目录(容器内) |
MCP_PORT | 否 | 8764 | MCP Server 端口 |
OPENVIKING_ENDPOINT | 否 | http://localhost:1933 | OpenViking 完整 URL |
OPENVIKING_API_KEY | 否 | — | OpenViking API Key(不设置则跳过 OV 集成) |
OPENVIKING_ACCOUNT | 否 | hermes | OpenViking 账户名 |
OPENVIKING_USER | 否 | default | OpenViking 用户名 |
MCP_API_KEY | 否 | — | MCP API Key(不设置则跳过认证) |
GLM_API_KEY | Dream Cycle | — | LLM API Key(Dream Cycle / Memory Sync 用) |
GLM_BASE_URL | Dream Cycle | — | LLM API Base URL |
DREAM_CYCLE_MODEL | Dream Cycle | glm-4-flash | Dream Cycle 使用的 LLM 模型 |
MEMORY_TO_WIKI_MODEL | Memory Sync | glm-4-flash | Memory Sync 使用的 LLM 模型 |
NOTION_API_KEY | Notion Sync | — | Notion API Key(不设置则跳过 Notion 同步) |
NOTION_DB_ENTITY | Notion Sync | — | Notion Entity 数据库 ID |
NOTION_DB_CONCEPT | Notion Sync | — | Notion Concept 数据库 ID |
NOTION_DB_COMPARISON | Notion Sync | — | Notion Comparison 数据库 ID |
NOTION_DB_QUERY | Notion Sync | — | Notion Query 数据库 ID |
WEBDAV_BASE_URL | NAS Sync | — | NAS WebDAV 地址 |
WEBDAV_USER | NAS Sync | — | WebDAV 用户名 |
WEBDAV_PASS | NAS Sync | — | WebDAV 密码 |
# === MCP Server ===
MCP_PORT=8764
# MCP_API_KEY=*** # 不设置则跳过认证(内网环境推荐)
# === OpenViking (可选) ===
# OPENVIKING_ENDPOINT=http://localhost:1933
# OPENVIKING_API_KEY=***
# OPENVIKING_ACCOUNT=hermes
# OPENVIKING_USER=default
# === LLM (Dream Cycle + Memory Sync 需要) ===
# GLM_API_KEY=***
# GLM_BASE_URL=https://open.bigmodel.cn/api/paas/v4
# DREAM_CYCLE_MODEL=glm-4-flash
# MEMORY_TO_WIKI_MODEL=glm-4-flash
# === Notion (可选) ===
# NOTION_API_KEY=***
# NOTION_DB_ENTITY=ntn_xxxxxxxx
# NOTION_DB_CONCEPT=ntn_xxxxxxxx
# NOTION_DB_COMPARISON=ntn_xxxxxxxx
# NOTION_DB_QUERY=ntn_xxxxxxxx
# === WebDAV / NAS (可选) ===
# WEBDAV_BASE_URL=http://nas:5005/wiki
# WEBDAV_USER=***
# WEBDAV_PASS=***services:
wiki-brain:
build: .
container_name: wiki-brain
restart: unless-stopped
ports:
- "0.0.0.0:8764:8764"
volumes:
- ./wiki:/data # Wiki 数据
- ./scripts:/app/scripts # 脚本(热更新,无需 rebuild)
- ./.env:/app/.env:ro # 环境变量
env_file:
- .env
environment:
- PYTHONPATH=/app/scripts
- PYTHONUNBUFFERED=1
deploy:
resources:
limits:
memory: 512M
cpus: "0.5"
logging:
driver: json-file
options:
max-size: "10m"
max-file: "3"与 OpenViking 联合部署(可选):
services:
wiki-brain:
build: .
container_name: wiki-brain
restart: unless-stopped
ports:
- "0.0.0.0:8764:8764"
volumes:
- ./wiki:/data
- ./scripts:/app/scripts
- ./.env:/app/.env:ro
env_file:
- .env
environment:
- PYTHONPATH=/app/scripts
- PYTHONUNBUFFERED=1
networks:
- wiki-net
openviking:
image: openviking/openviking:latest
container_name: openviking
restart: unless-stopped
ports:
- "0.0.0.0:1933:1933"
volumes:
- ./openviking-data:/data
networks:
- wiki-net
networks:
wiki-net:
driver: bridge内置实体管理系统,维护唯一 ID + 别名索引:
{
"entities": {
"ent_a1b2c3": {
"id": "ent_a1b2c3",
"canonical_name": "OpenViking",
"aliases": ["openviking", "ov", "viking"],
"type": "entity",
"primary_page": "entities/openviking.md",
"created": "2026-01-15",
"updated": "2026-04-13"
}
},
"alias_index": {
"openviking": "ent_a1b2c3",
"ov": "ent_a1b2c3"
},
"stats": {
"total_entities": 18,
"total_aliases": 42
}
}# 扫描所有 wiki 页面,自动注册未注册的实体
docker exec wiki-brain python3 -m entity_registry scan
# 列出所有实体
docker exec wiki-brain python3 -m entity_registry list
# 搜索实体
docker exec wiki-brain python3 -m entity_registry search "openviking"
# 检测重复实体
docker exec wiki-brain python3 -m entity_registry dedup
# 合并实体
docker exec wiki-brain python3 -m entity_registry merge ent_a1b2c3 ent_d4e5f6
# 重建索引
docker exec wiki-brain python3 -m entity_registry rebuildOpenViking 不可用时,自动 fallback 到本地文件搜索(substring 匹配)。
配置 OpenViking 后,wiki_search 使用向量语义搜索:
auto_index.py --sync 将 wiki 页面同步到 OpenVikingwiki_search 调用 OpenViking API 返回语义相关结果# 手动备份
docker exec wiki-brain bash /app/scripts/wiki-backup.sh
# 保留最近 3 个备份
docker exec wiki-brain bash /app/scripts/wiki-backup.sh --keep 3备份排除 logs/、__pycache__/、.git/、src/agency-agents/ 等大文件目录。
如果你不需要语义搜索,可以只部署 Wiki KB MCP Server:
# docker-compose.minimal.yml
services:
wiki-brain:
build: .
container_name: wiki-brain
restart: unless-stopped
ports:
- "0.0.0.0:8764:8764"
volumes:
- ./wiki:/data
- ./.env:/app/.env:ro
env_file:
- .env
deploy:
resources:
limits:
memory: 256M
cpus: "0.25"对应的 .env:
MCP_PORT=8764
# 不设置 OPENVIKING_* 变量,搜索自动 fallback 到文件搜索
# 不设置 GLM_* 变量,Dream Cycle 不可用但 Wiki CRUD 正常cd wiki-kb
# 安装依赖
pip install mcp pyyaml requests
# 设置环境变量
export WIKI_ROOT=./wiki
export MCP_PORT=8764
# 启动 MCP Server
python scripts/wiki_mcp_server.pyscripts/ 目录创建新脚本wiki_config.py 的 load_config() 读取配置(或直接用 WIKI_ROOT 环境变量)sys.path.insert(0, str(Path(__file__).parent))编辑 scripts/wiki_mcp_server.py,然后:
# scripts/ 是 bind mount,修改后只需重启容器
docker compose restartMCP StreamableHTTP 使用有状态 session。长时间空闲后 session 可能过期。
已内置修复:wiki_mcp_server.py 通过 monkey-patch 将 session_idle_timeout 设为 24 小时。
如果问题仍然出现,客户端侧应实现自动重连逻辑。
FastMCP StreamableHTTP 模式下,HTTP_AUTHORIZATION 环境变量可能不被正确设置。
解决方案:
MCP_API_KEY=,跳过认证headers: { Authorization: "Bearer <key>" }如果 Wiki KB 和客户端不在同一台机器上,确保端口绑定 0.0.0.0 而不是 127.0.0.1。
auto_index.py --sync 使用两步 API:
POST /api/v1/resources/temp_upload — 上传文件POST /api/v1/resources — 添加到 OpenViking确保 OPENVIKING_API_KEY、OPENVIKING_ACCOUNT、OPENVIKING_USER 配置正确。
MIT
SonicBotMan/wiki-kb
April 13, 2026
April 13, 2026
Python