使用说明
MCP文档搜索服务器
使用FastMCP构建的强大文档搜索服务器,使AI系统能够智能地搜索多个流行的框架和库文档。该工具确保人工智能模型可以使用统一的界面从各种文档源快速访问和检索相关信息。
🌟 特性
-
📚 多库支持:跨多个库搜索文档:
-
🔍 智能搜索
- 库变体的智能名称解析
- DuckDuckGo支持搜索以获得准确结果
- 针对特定网站的搜索目标
-
⚡ 性能特点
- 异步处理
- 高效的web请求处理
- 并行内容提取
-
🛡️ 稳健的错误处理
- 网络超时管理
- 输入验证无效
- HTTP错误处理
- 请求故障恢复
📋 需求
- Python 3.8+
- pip或uv包管理器
- 虚拟环境(推荐)
🚀 快速开始
- 克隆存储库
git clone <repository-url>
cd mcp-server
- 设置虚拟环境
python -m venv .venv
# On Windows:
.venv\Scripts\activate
# On Unix or MacOS:
source .venv/bin/activate
- 再进行
pip install -r requirements.txt
- 运行服务器
python main.py
💻 用法
基本用法
from main import get_docs
# Search Framer Motion documentation
result = await get_docs(
query="how to animate on scroll",
library="framer-motion"
)
# Search Next.js documentation
result = await get_docs(
query="how to use app router",
library="next"
)
库名称变化
该系统智能地处理各种库名称格式:
# All these calls will work the same way
await get_docs(query="animations", library="framer")
await get_docs(query="animations", library="framermotion")
await get_docs(query="animations", library="framer-motion")
await get_docs(query="animations", 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
测试覆盖率
测试包括:
- ✅ 库名称规范化和验证
- ✅ 不同库的URL检索
- ✅ 网络搜索功能
- ✅ 内容获取和错误处理
- ✅ 文档搜索集成
- ✅ API输入验证和错误处理
- ✅ 不同库名称格式的别名解析
异步测试
该项目使用自定义 run_async 辅助函数,用于在同步测试环境中测试异步代码。这种方法允许测试异步函数,而不需要复杂的测试设置。
🏗️ 项目结构
mcp-server/
├── main.py # Entry point and FastMCP tool definition
├── config.py # Configuration settings and constants
├── services.py # Web search and content fetching services
├── utils.py # Utility functions for library name handling
├── tests/ # Test suite
│ ├── test_utils.py # Tests for utility functions
│ ├── test_services.py # Tests for web services
│ ├── test_main.py # Tests for main API
│ └── conftest.py # Pytest configuration
├── requirements.txt # Project dependencies
└── README.md # Documentation
🔧 配置
支持的库
要添加新库,请执行以下操作:
- 在中添加文档URL
config.py:
DOCS_URLS = {
"new-library": "https://docs.new-library.com",
# ... existing entries
}
- 添加常用别名:
LIBRARY_ALIASES = {
"new-lib": "new-library",
# ... existing entries
}
HTTP设置
修改 config.py:
HTTP_TIMEOUT = 30.0 # Timeout in seconds
MAX_SEARCH_RESULTS = 2 # Number of search results to fetch
🤝 贡献
我们欢迎捐款!以下是您可以提供帮助的方式:
- 分叉存储库
- 创建要素分支
- 进行更改
- 添加新功能的测试
- 确保所有测试通过
- 提交拉取请求
添加新库
- 更新
DOCS_URLS在……里面config.py - 在中添加相关别名
LIBRARY_ALIASES - 测试集成
- 更新文档
- 提交拉取请求
🐛 故障排除
常见问题和解决方案:
- 超时错误:增加
HTTP_TIMEOUT在……里面config.py - 没有结果:尝试不同的搜索词或验证库名称
- HTTP错误:检查您的互联网连接和文档URL
📄 许可证
此项目根据MIT许可证获得许可-有关详细信息,请参阅许可证文件。
🙏 致谢
- FastMCP 对于核心功能
- DuckDuckGo 搜索功能
- pytest 用于测试框架
- 所有支持的文档提供程序