MCP Knowledge Service
Provides hybrid retrieval (dense + BM25 + RRF) with collection-based isolation and document ingestion for private knowledge access via MCP.
README
MCP Knowledge Service
Reusable MCP-based knowledge retrieval service for domain-specific document ingestion and cited hybrid retrieval.
可复用的 MCP 知识检索服务,通过 collection 隔离不同业务知识库,提供文档导入、混合检索和来源引用。
Overview / 项目概述
MCP Knowledge Service is a domain-neutral retrieval server exposed through the Model Context Protocol. It ingests documents into named collections, builds Dense Retrieval and BM25 indexes, fuses results with RRF, and returns cited search results to MCP clients.
该服务不绑定具体业务。examples/salon/ 只是一个可运行的示例,用于展示业务项目如何通过 collection 接入自己的知识库。
Core Capabilities / 核心能力
| Capability | English | 中文说明 |
|---|---|---|
| MCP stdio server | Uses the official MCP Python SDK and stdio JSON-RPC transport. | 通过标准 MCP stdio transport 暴露工具,便于被业务系统作为独立进程调用。 |
| Ingestion | Imports PDF / Markdown knowledge sources into a selected collection. | 支持把指定知识源导入到指定 collection,不把业务域写死在服务代码中。 |
| Collection isolation | Collections are selected through CLI arguments, MCP tool input, environment, or config. | 不同业务知识库通过 collection 隔离,例如 knowledge_hub、salon_knowledge。 |
| Hybrid Retrieval | Combines ChromaDB Dense Retrieval, BM25, and RRF Fusion. | 同时利用向量检索和关键词检索,再通过 RRF 融合排序。 |
| Citations | Returns source metadata for cited answers. | 检索结果带来源信息,方便上层应用展示引用。 |
| OpenAI-compatible provider | Supports Qwen-compatible OpenAI API configuration. | 可通过 OpenAI-compatible 配置接入 Qwen embedding 或其他兼容 Provider。 |
Architecture / 系统架构
- Ingestion: converts PDF / Markdown into vector and BM25 retrieval data under a selected collection.
- MCP Serving: an MCP Client calls tools exposed by the MCP Server through stdio.
- Query:
query_knowledge_hubuses Dense Retrieval, BM25, and RRF to return Retrieved Answer with Citations.
中文说明:导入阶段把 PDF / Markdown 转换为 collection 下的向量和 BM25 检索数据;在线阶段由 MCP Client 通过 stdio 调用 MCP Server 暴露的 tools;query_knowledge_hub 使用 Dense Retrieval、BM25 和 RRF 返回 citations。
Collection Isolation / Collection 隔离
Collection names isolate domain-specific knowledge retrieval. Examples:
knowledge_hubsalon_knowledgeemail_knowledgeinternal_policy_knowledge
Collection names must be passed through CLI arguments, MCP tool arguments, environment variables, or config. Service code should not hardcode a business-specific collection.
Quick Start / 快速启动
python3.11 -m venv .venv
source .venv/bin/activate
pip install -e '.[dev]'
cp .env.example .env
cp config/settings.example.yaml config/settings.yaml
Fill local provider values in .env or shell environment before real embedding or provider-backed ingestion. Do not commit .env or config/settings.yaml.
真实执行 embedding 或 Provider 驱动的 ingestion 前,在本地 .env 或 shell 环境中填入私有 Key;不要提交这些配置。
MCP server entry point:
python -m src.mcp_server.server
python -m src.mcp_server.server starts an stdio JSON-RPC server, not an interactive CLI.
For normal application use, let the MCP client launch it automatically.
For standalone verification, start it through an MCP client or verification script that sends initialize, tools/list, and tool calls.
The server uses stdio transport. Stdout is reserved for MCP protocol messages; logs are written to stderr.
python -m src.mcp_server.server 启动的是 stdio JSON-RPC Server,不是可直接交互查询的 CLI。
正常业务运行时,应由 MCP Client 自动拉起该进程。
单独验证时,应通过 MCP Client 或验证脚本发送 initialize、tools/list 和 tool call,而不是只在终端直接运行该命令。
Ingestion / 知识导入
Ingest documents into a selected collection:
python scripts/ingest.py \
--path <SOURCE_PATH> \
--collection knowledge_hub \
--force
Dry run:
python scripts/ingest.py \
--path <SOURCE_PATH> \
--collection knowledge_hub \
--dry-run
Real ingestion requires provider configuration for embeddings and writable runtime storage. Do not commit runtime ChromaDB, BM25, SQLite, logs, traces, or local reports.
MCP Tools / MCP 工具
Expected tools from tools/list:
query_knowledge_hublist_collectionsget_document_summary
MCP tool input for query_knowledge_hub:
{
"query": "What is this collection about?",
"top_k": 4,
"collection": "knowledge_hub"
}
CLI query:
python scripts/query.py \
--query "What is this collection about?" \
--collection knowledge_hub \
--top-k 4
Verified Public Scope / 已验证公开范围
- MCP initialize
tools/listquery_knowledge_hub- citations
- salon example ingestion: 7 PDFs, 24 chunks, 24 vectors, 24 BM25 documents
smoke_test_collectionproves collection is not hardcoded- runtime data is intentionally excluded from Git
The salon example verification is an integration check, not a general retrieval-quality benchmark.
Example Integration / 示例集成
The examples/salon/ directory contains a complete example used by AI Hair Salon Agent:
- 7 source Markdown files
- generated PDFs
- ingestion instructions
- example collection:
salon_knowledge
It is an integration example, not the default domain of this repository.
Related Repository / 关联项目
AI Hair Salon Agent: https://github.com/hyh0620/ai-hair-salon-agent
AI Hair Salon Agent is a reference consumer that calls this service through an MCP client with collection=salon_knowledge.
AI Hair Salon Agent 是该服务的参考消费者,通过 MCP Client 调用 salon_knowledge collection。
Verification / 验证方式
Static dependency check:
.venv/bin/python -m pip check
Unit and integration tests:
pytest
Real MCP verification:
initialize -> tools/list -> query_knowledge_hub
Real ingestion verification:
python scripts/ingest.py \
--path <SOURCE_PATH> \
--collection <COLLECTION_NAME> \
--force
Some real ingestion and provider tests require local provider configuration, API credentials, and runtime storage. Keep those local files out of Git.
Known Limits / 当前限制
| Limit | 中文说明 |
|---|---|
| No authentication or authorization layer is claimed. | 当前公开范围不声明认证、授权或企业级租户安全控制。 |
| No Dashboard, Rerank, Ragas, multimodal, or Vision claim. | 未验证高级模块不作为公开能力。 |
| Runtime ChromaDB, BM25, SQLite, logs, and traces are not committed. | 运行时数据不进入 Git,复现时需本地重新导入。 |
| The salon example is not the default business domain. | 根服务是通用知识检索服务,理发店只是示例集成。 |
Documentation / 文档
Skills / 项目工作流
Operational skills are under .github/skills/:
setup-environmentingest-knowledgeverify-mcp-serverevaluate-retrievalpackage-clean
They describe repeatable operational workflows and do not contain credentials.
Security / 安全说明
Do not commit .env, API keys, config/settings.yaml, local runtime databases, ChromaDB files, BM25 indexes, logs, trace files, or raw local evaluation dumps.
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。