使用 FastMCP 构建的强大文档搜索服务器,使AI系统能够智能地跨多个流行的框架和库文档进行搜索。此工具确保AI模型可以通过统一接口快速访问并检索来自各种文档源的相关信息。
📚 多库支持:跨多个库搜索文档:
🔍 智能搜索
⚡ 性能特性
🛡️ 健壮的错误处理
git clone <repository-url>
cd mcp-server
python -m venv .venv
# 在Windows上:
.venv\Scripts\activate
# 在Unix或MacOS上:
source .venv/bin/activate
pip install -r requirements.txt
python main.py
from main import get_docs
# 搜索 Framer Motion 文档
result = await get_docs(
query="如何在滚动时进行动画",
library="framer-motion"
)
# 搜索 Next.js 文档
result = await get_docs(
query="如何使用应用路由器",
library="next"
)
该系统智能处理各种库名格式:
# 所有这些调用方式都会产生相同的效果
await get_docs(query="动画", library="framer")
await get_docs(query="动画", library="framermotion")
await get_docs(query="动画", library="framer-motion")
await get_docs(query="动画", library="motion")
该项目包含一个全面的测试套件,以确保可靠性和正确性。测试分为三个主要类别:
单元测试:独立测试各个组件
test_utils.py:测试库名规范化和URL检索test_services.py:测试网络搜索和服务内容获取集成测试:测试组件协同工作情况
test_main.py:测试主API函数 get_docs要运行所有测试:
python -m pytest
要运行特定的测试模块:
python -m pytest tests/test_utils.py
python -m pytest tests/test_services.py
python -m pytest tests/test_main.py
要运行带有详细输出的测试:
python -m pytest -v
测试覆盖:
项目使用自定义的 run_async 辅助函数,在同步测试环境中测试异步代码。这种方法允许在不需复杂测试设置的情况下测试异步函数。
mcp-server/
├── main.py # 入口点和FastMCP工具定义
├── config.py # 配置设置和常量
├── services.py # 网络搜索和服务内容获取服务
├── utils.py # 库名处理的实用函数
├── tests/ # 测试套件
│ ├── test_utils.py # 测试实用函数
│ ├── test_services.py # 测试网络服务
│ ├── test_main.py # 测试主API
│ └── conftest.py # Pytest配置
├── requirements.txt # 项目依赖
└── README.md # 文档
添加新库:
config.py 中添加文档URL:DOCS_URLS = {
"新库": "https://docs.new-library.com",
# ... 已有的条目
}
LIBRARY_ALIASES = {
"新库别名": "新库",
# ... 已有的条目
}
在 config.py 中修改:
HTTP_TIMEOUT = 30.0 # 超时时间(秒)
MAX_SEARCH_RESULTS = 2 # 获取的搜索结果数量
我们欢迎贡献!以下是您可以帮助的方式:
config.py 中的 DOCS_URLSLIBRARY_ALIASES 中添加相关别名常见问题及解决方案:
config.py 中的 HTTP_TIMEOUT本项目采用MIT许可证 - 查看LICENSE文件了解详情。