使用说明
MCPserve
基本的MCP(模型上下文协议)服务器,在Python中实现FastAPI。通过 MCP HTTP 协议提供用于 Web 搜索、翻译和提示优化的 AI 工具。
🚀 功能
可用工具
- 🏓 拼: 基本的“pong”响应工具(已实现)
- 🌍 translate_devel使用 DeepL API 在多种语言之间进行高级翻译(计划)
高级资源
- 📡 Protocolo MCP HTTP通过HTTP完整实现模型上下文协议
- 🐳 容器化Docker with Python 3.12 和 uv 用于依赖关系管理
- 设置使用 Pydantic 和环境变量的配置系统
- 📝 结构化日志使用 structlog 结构化的日志
- 🗄️ 缓存带 Redis 缓存系统(可选)和内存备份
️ 项目状态
✅ 实施
- 基本功能HTTP服务器
- 端点
/mcp支持方法:initialize,tools/list,tools/call - 工具
ping功能 - 非史密斯自动部署
- API 密钥配置(DeepL)
- 智能缓存系统
- Docker 容器
在开发中
- 实现完整的工具(fetch,search,translate)
- 监控 Web 界面
- 认证系统
- 速率限制和高级安全
📋 下一步
- 执行工具
fetch搜索 web 内容 - 执行工具
search用于网络搜索 - 执行工具
translate_deepl用于翻译 - 添加仪表板 Web 界面
- 实施身份验证系统和速率限制
- 添加自动测试
- 完整的 API 文档
📦 安装
通过PyPI(未来)
pip install enhanced-mcp-server
通过源代码
git clone https://github.com/your-org/enhanced-mcp-server.git
cd enhanced-mcp-server
pip install -e .[web,cache]
📦 安装
通过史密瑟里(推荐)
npx -y @smithery/cli install @dronreef2/MCPserve --client claude
通过源代码
git clone https://github.com/dronreef2/MCPserve.git
cd MCPserve
pip install -e .
码头工人
# Construir e executar
docker-compose up --build
# Apenas o servidor MCP
docker run mcpserve python -m enhanced_mcp_server.main
⚙️ 配置
在文件中配置环境变量 .env:
# API Keys (obrigatórias para funcionalidades específicas)
DEEPL_API_KEY=your_deepl_api_key_here
# Cache (opcional)
REDIS_URL=redis://localhost:6379
# Logging
LOG_LEVEL=INFO
# Web Interface
WEB_HOST=0.0.0.0
WEB_PORT=8001
# Segurança
ENABLE_AUTH=true
RATE_LIMIT_REQUESTS=100
RATE_LIMIT_WINDOW=60
🏃♂️ 执行
MCP模式(标准输入)
# Verificar configuração
python -m enhanced_mcp_server.main --check-config
# Executar servidor MCP
python -m enhanced_mcp_server.main
界面Web
# Executar aplicação web
python -m enhanced_mcp_server.web.app
# Ou usar o script direto
enhanced-mcp-web
Acesse:http://localhost:8001
码头工人
# Construir e executar
docker-compose up --build
# Apenas o servidor MCP
docker run enhanced-mcp-server python -m enhanced_mcp_server.main
🧪 测试
# Todos os testes
pytest
# Testes específicos
pytest tests/test_tools.py
pytest tests/test_cache.py
pytest tests/test_auth.py
# Com cobertura
pytest --cov=enhanced_mcp_server --cov-report=html
📊 监测
界面Web
- 仪表盘: http://localhost:8001
- 健康检查: http://localhost:8001/health
- 缓存统计信息: http://localhost:8001/cache/stats
日志
# Visualizar logs em tempo real
tail -f logs/app.log
# Logs estruturados (JSON)
jq . logs/app.log
🏗️ 建筑
enhanced-mcp-server/
├── enhanced_mcp_server/
│ ├── core/ # Servidor MCP principal
│ ├── tools/ # Implementação das ferramentas
│ ├── prompts/ # Templates de otimização
│ ├── cache/ # Sistema de cache inteligente
│ ├── auth/ # Autenticação e autorização
│ ├── config/ # Configurações centralizadas
│ ├── utils/ # Utilitários (logging, etc.)
│ └── web/ # Interface web FastAPI
├── tests/ # Testes unitários e integração
├── templates/ # Templates HTML
├── static/ # Arquivos estáticos
└── docs/ # Documentação
⚡ 缓存e性能
混合缓存系统
- 瑞迪斯高性能分布式缓存
- 内存Redis 不可用时自动回退
- 智能TTL不同内容类型的生命周期
- 压缩大结果自动压缩
缓存设置
# Cache automático com decorador
@cache.cached(ttl=3600)
async def expensive_operation():
return await api_call()
🔐 安全和身份验证
API系统密钥
from enhanced_mcp_server.auth import auth_manager
# Gerar nova chave
key = auth_manager.generate_api_key("user@example.com", role="user")
# Validar chave
user = auth_manager.validate_api_key(api_key)
访问级别
- 管理员全面访问系统
- 用户访问 MCP 工具
- 只读只读访问
🌐 出版社 / Smithery
自动部署
项目从分支中的推送自动部署到 Smithery main.O部署美国O smithery.yaml 工厂功能 enhanced_mcp_server.core.server:create_server.
本地校验
# Instalar Smithery CLI
npm install -g @smithery/cli
# Verificar configuração local
smithery inspect @dronreef2/MCPserve
# Executar servidor localmente para testes
smithery run @dronreef2/MCPserve --config '{"DEEPL_API_KEY":"your_key"}'
# Abrir playground para testes interativos
smithery playground --key your_smithery_key
手动部署说明(如有必要)
-
配置秘密没有Smithery:
DEEPL_API_KEYDeepL API 密钥(翻译需要)REDIS_URLRedis URL(可选,如果未定义,则使用内存缓存)
-
配置环境变量:
WEB_PORT服务器端口(默认:8001)LOG_LEVEL日志级别(INFO、DEBUG等)
-
健康检查:
- 配置活性探针:
GET /health - 配置就绪探针:
GET /health
- 配置活性探针:
-
资源:
- 记忆体:512Mi
- CPU:0.5 vCPU
- 展览门:8001(TCP)
出版清单
- [x] smithery.yaml配置com服务器工厂
- [x] pyproject.toml com服务器
- [x] Dockerfile多阶段并行构建otimizado
- [x] 端点/健康参数探针
- [x] 机密配置(DEEPL_API_KEY)
- [x] 基本测试通过
- [x] 已启用结构化日志
使用Smithery CLI开发
# Iniciar servidor de desenvolvimento com hot-reload (usa smithery.config.js)
smithery dev --port 8001 --key your_dev_key
# Construir para produção
smithery build --out dist/server.cjs --transport shttp
# Testar instalação local
smithery install @dronreef2/MCPserve --client claude --config '{"DEEPL_API_KEY":"test_key"}'
背板: 文件 smithery.config.js 使用 Smithery CLI 进行本地开发,允许热重载和集成测试。
🧪 工具测试
使用范例
# Buscar conteúdo web
result = await fetch("https://example.com")
# Pesquisar na web
results = await search("tecnologia MCP")
# Traduzir texto
translation = await translate("Hello world", "en", "pt")
# Otimizar prompt
optimized = optimize_prompt("Como criar um servidor MCP?")
🤝 贡献
- 分叉工程
- 创建分支 :
git checkout -b feature/nova-funcionalidade - 提交您的更改:
git commit -am 'Adiciona nova funcionalidade' - 按下一个分支:
git push origin feature/nova-funcionalidade - Abra um Pull请求
准则
- 遵循PEP 8进行Python代码
- 添加新功能测试
- 更新文档
- 使用提交semânticos
📄 许可证
麻省理工学院许可证-veja 许可证 为了细节。
🙏 致谢
- yiGmMk/mcp服务器 初始灵感
- dronreef2/MCPserve - 工程基础
- 模型上下文协议 MCP 协议
- 史密瑟里 - 出版平台
📞 支持
⭐ 如果您觉得这个仓库有用,请点击此处!
