基于FastAPI的本地知识库MCP服务器,集成FAISS向量库
Project description
zhdddd-mcp-knowledge-server
基于FastAPI的本地知识库MCP服务器,集成FAISS向量库,支持文档上传、向量检索和MCP协议接口。
功能特性
- 文档上传与解析:支持上传文档并自动拆分为文本块,提高检索精度
- 向量检索:使用FAISS向量库实现高效的相似度搜索
- MCP协议接口:支持标准的MCP协议,供大模型调用
- 工具列表与调用:实现了
/tools/list和/tools/call接口,符合MCP规范 - 健康检查:提供服务健康状态检查接口
安装方法
从PyPI安装
pip install zhdddd-mcp-knowledge-server
使用uvx启动
uvx zhdddd-mcp-knowledge-server
快速开始
-
启动服务器:
zhdddd-mcp-knowledge-server
或使用uvx:
uvx zhdddd-mcp-knowledge-server -
服务默认运行在:
http://0.0.0.0:8000
主要接口
健康检查
- GET
/health- 检查服务状态
文档上传
- POST
/upload/document- 上传文档并解析入库
向量检索
- POST
/retrieve- 检索相似文档
MCP协议接口
- POST
/mcp/invoke- MCP协议调用接口 - GET
/mcp/info- 服务信息和工具列表
工具接口(标准MCP规范)
- GET
/tools/list- 获取可用工具列表 - POST
/tools/call- 调用指定工具
集合信息
- GET
/collection/info- 获取知识库信息
示例使用
上传文档
curl -X POST "http://localhost:8000/upload/document" \
-F "file=@example.txt"
检索文档
curl -X POST "http://localhost:8000/retrieve" \
-H "Content-Type: application/json" \
-d '{"query": "ESOP是什么"}'
MCP工具调用
curl -X POST "http://localhost:8000/tools/call" \
-H "Content-Type: application/json" \
-d '{"tool": "retrieve_knowledge", "parameters": {"query": "ESOP是什么"}}'
配置说明
服务默认配置:
- 主机:0.0.0.0
- 端口:8000
- 向量维度:768
- 文档拆分大小:500字符
- 文本块重叠:100字符
依赖项
- fastapi
- uvicorn
- faiss-cpu
- numpy
- packaging
- python-multipart
- pydantic
- pydantic-settings
- python-dotenv
许可证
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file zhdddd_mcp_knowledge_server-0.1.1.tar.gz.
File metadata
- Download URL: zhdddd_mcp_knowledge_server-0.1.1.tar.gz
- Upload date:
- Size: 9.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
72a54f2cde84ee3d63f2fff7a83989bb7b8d23c13f530b913d8a9ad3c705ea48
|
|
| MD5 |
8e528e1adf831589f51292bd674588c7
|
|
| BLAKE2b-256 |
36a444639466a19676487bd885ea241425125f407d82b9db1322c28a8ff357af
|
File details
Details for the file zhdddd_mcp_knowledge_server-0.1.1-py3-none-any.whl.
File metadata
- Download URL: zhdddd_mcp_knowledge_server-0.1.1-py3-none-any.whl
- Upload date:
- Size: 8.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0fef25798b83b2edf4d0852b7a7dcdc2ad69312d2246686e543e7255f641a99b
|
|
| MD5 |
752f2fe01d1ab3bd2a613ddf5187504e
|
|
| BLAKE2b-256 |
60848b40b5888a98ceaaa3b9d5cc49ebc31754d4704b34d0ec9478bb5caaf80f
|