
MCP Knowledge Base
A local knowledge base system based on ChromaDB that supports automatic chunking, vector storage, and efficient similarity retrieval of txt and pdf documents, with MCP protocol support allowing AI assistants to directly access knowledge management functions.
README
基于ChromaDB的本地知识库系统
项目简介
本项目是一个基于 ChromaDB 的本地知识库系统,支持 txt 和 pdf 文档的自动分块、向量化存储与高效相似度检索。适合个人、企业、内网环境下的知识管理。
新增功能: 已支持 MCP(Model Context Protocol),让AI助手可以直接调用知识库功能!
功能特点
- 基于 ChromaDB,支持高效向量检索
- 支持 txt 和 pdf 文件(PDF 需安装 PyPDF2 或 PyMuPDF)
- 自动分块、嵌入向量化、余弦相似度检索
- 本地持久化存储,数据安全可控
- 命令行一键添加、查询、删除、统计
- 文档去重、分块管理
- MCP工具支持 - AI助手可直接调用知识库功能
安装依赖
推荐使用 Python 3.10 及以上(3.12最佳),并安装如下依赖:
pip install chromadb PyPDF2 PyMuPDF
如需更强嵌入效果,可安装 sentence-transformers(首次需联网下载模型):
pip install sentence-transformers
目录结构
向量数据库/
├── knowledge_base_chromadb.py # 主程序(ChromaDB版)
├── mcp_server.py # MCP服务器实现
├── mcp_knowledge_base.py # MCP工具包装器
├── mcp_server_config.json # MCP服务器配置
├── documents/ # 存放待导入文档
│ └── example.txt # 示例文档
├── knowledge_base/ # ChromaDB数据库文件夹
├── README.md # 说明文档
├── 使用指南.md # 详细使用指南
└── MCP使用说明.md # MCP工具使用说明
快速开始
命令行使用
-
准备文档
- 将 txt/pdf 文件放入
documents/
目录
- 将 txt/pdf 文件放入
-
添加文档到知识库
python knowledge_base_chromadb.py add documents/example.txt # 或 py -3.12 knowledge_base_chromadb.py add documents/example.txt
-
查询知识库
python knowledge_base_chromadb.py search "人工智能"
-
列出所有文档
python knowledge_base_chromadb.py list
-
删除文档
python knowledge_base_chromadb.py delete 文档名
-
查看统计信息
python knowledge_base_chromadb.py stats
MCP工具使用
AI助手现在可以直接调用知识库功能:
用户: "请帮我搜索关于人工智能的文档"
AI助手: 我来搜索知识库中关于人工智能的文档。
[调用 search_documents 工具]
用户: "请添加这个文档到知识库"
AI助手: 我来帮您添加文档到知识库。
[调用 add_document 工具]
用户: "知识库里有哪些文档?"
AI助手: 让我查看一下知识库中的文档列表。
[调用 list_documents 工具]
命令行用法
- 添加文档:
add <文件路径>
- 检索知识:
search <查询内容> [--top-k N]
- 列出文档:
list
- 删除文档:
delete <文档名>
- 统计信息:
stats
- 指定数据库:
--db <数据库文件夹>
MCP工具
支持的MCP工具
add_document
- 添加文档到知识库search_documents
- 搜索知识库list_documents
- 列出所有文档delete_document
- 删除文档get_stats
- 获取统计信息batch_add_documents
- 批量添加文档
MCP配置
在MCP客户端配置中添加:
{
"mcpServers": {
"knowledge-base": {
"command": "python",
"args": ["mcp_server.py"],
"env": {
"PYTHONPATH": "."
}
}
}
}
常见问题
- PDF无法读取:请确保已安装 PyPDF2 或 PyMuPDF
- 检索无结果:请确认已成功添加文档
- 数据库损坏:可删除 knowledge_base 文件夹重新初始化
- 编码问题:请确保文档为 UTF-8 编码
- MCP连接失败:检查Python路径和依赖安装
如需详细命令示例和进阶用法,请参见 使用指南.md
和 MCP使用说明.md
。
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.