MCP维基百科服务器
一个生产就绪的模型上下文协议(MCP)服务器,使用FastMCP和Python 3.11提供维基百科搜索和内容检索工具。
  
🚀 快速开始
# 1. Set up environment (one-time setup)
./setup.sh
# 2. Start the server
source .venv311/bin/activate
cd src/mcp_server && python mcp_server.py
# 3. Test with example client
python example_client.py🎯 特性
- 维基百科搜索:通过智能搜索查找文章并获得全面的摘要
- 章节列表:从任何维基百科文章中提取所有章节标题
- 内容检索:获取具有适当格式的特定章节内容
- MCP协议:AI助手集成的完全模型上下文协议兼容性
- FastMCP框架:基于高效的FastMCP库构建,实现最佳性能
- Python 3.11:具有最新功能和性能改进的现代Python
📚 文档
🛠️ 可用工具
| 工具 | 目的 | 示例用法 |
|---|---|---|
fetch_wikipedia_info | 搜索维基百科并获取文章摘要 | 搜索“Python编程” |
list_wikipedia_sections | 从文章中获取所有章节标题 | 列出“机器学习”的章节 |
get_section_content | 检索特定部分内容 | 从“人工智能”中获取“历史”部分 |
🏗️ 项目结构
MCPClientServer/
├── 📁 src/mcp_server/ # Core server implementation
│ ├── mcp_server.py # Main MCP Wikipedia server
│ └── mcp_client.py # Example MCP client
├── 📁 tests/ # Comprehensive test suite
│ ├── test_server.py # Unit tests (pytest)
│ ├── test_integration.py # Integration tests
│ ├── test_performance.py # Performance benchmarks
│ ├── test_mcp_compliance.py # MCP protocol compliance
│ ├── quick_test.py # Fast validation script
│ ├── run_tests.py # Unified test runner
│ └── README.md # Testing documentation
├── 📁 .venv311/ # Python 3.11 virtual environment
├── 🔧 setup.sh # Automated setup script
├── 💡 example_client.py # Usage examples and demos
├── 📖 GUIDE.md # Complete documentation
├── ⚡ QUICK_REF.md # Quick reference
├── 📄 pytest.ini # Test configuration
├── 📄 requirements-test.txt # Test dependencies
└── 📄 pyproject.toml # Project configuration🚦 先决条件
- macOS (在苹果硅和英特尔上测试)
- Python 3.11+ (建议通过pyenv安装)
- Git (用于版本控制)
📦 安装选项
选项1:自动设置(推荐)
chmod +x setup.sh
./setup.sh选项2:手动设置
# Set up Python 3.11 environment
pyenv install 3.11.10
pyenv local 3.11.10
# Create and activate virtual environment
python -m venv .venv311
source .venv311/bin/activate
# Install dependencies
pip install --upgrade pip
pip install wikipedia mcp fastmcp🔌 集成示例
使用克劳德桌面(MCP客户端)
{
"mcpServers": {
"wikipedia": {
"command": "python",
"args": ["/path/to/MCPClientServer/src/mcp_server/mcp_server.py"],
"env": {
"PYTHONPATH": "/path/to/MCPClientServer/.venv311/lib/python3.11/site-packages"
}
}
}
}直接使用Python
from mcp_client import WikipediaClient
client = WikipediaClient()
result = await client.search_wikipedia("Artificial Intelligence")
print(result)🧪 测试
快速测试
# Fast validation (10 seconds)
python tests/quick_test.py
# Comprehensive test suite (5 minutes)
python tests/run_tests.py高级测试
# Install test dependencies
pip install -r requirements-test.txt
# Run specific test suites
python tests/run_tests.py --unit # Unit tests only
python tests/run_tests.py --integration # Integration tests only
python tests/run_tests.py --performance # Performance benchmarks
python tests/run_tests.py --mcp # MCP compliance tests
# Using pytest directly
python -m pytest tests/test_server.py -v --cov=src测试套件概述
- 单元测试:单个功能和组件测试
- 集成测试:端到端工作流验证
- 性能测试:响应时间和负载基准
- MCP合规性:协议规范验证
- 95%以上的代码覆盖率:全面的测试覆盖率
看 测试/README.md 获取完整的测试文档。
🐛 故障排除
| 问题 | 解决方案 |
|---|---|
ModuleNotFoundError: No module named 'mcp' | 快跑 pip install mcp fastmcp 在活化环境中 |
Python version issues | 确保Python 3.11+ python --version |
Server won't start | 检查端口是否可用,验证依赖关系 |
Wikipedia API errors | 检查互联网连接,尝试不同的搜索词 |
有关详细的故障排除,请参阅 GUIDE.md.
🤝 贡献
- 分叉存储库
- 创建要素分支(
git checkout -b feature/amazing-feature) - 提交您的更改(
git commit -m 'Add amazing feature') - 推到分支(
git push origin feature/amazing-feature) - 打开拉取请求
📄 许可证
此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。
🔗 资源
🌟 支持
如果你觉得这个项目有帮助,请考虑给它一颗星⭐ 在GitHub上!
______________________________________________________________________
由以下材料制成❤️ 对于MCP社区
