使用说明
🐳 MCP服务器模板
具有Docker、双传输支持和自动化CI/CD的生产就绪MCP服务器模板。
✨ 特性
- 符合MCP 2025-06-18标准 -最新协议规范
- 双重运输 -stdio和流式HTTP
- Docker就绪 -具有安全最佳实践的多拱集装箱
- CI/CD管道 -自动测试并发布到GitHub容器注册表
- 模板就绪 -点击“使用此模板”开始
🚀 快速开始
Docker(推荐)
# Pull from GitHub Container Registry
docker pull ghcr.io/your-username/mcp-server-template:latest
# Or build locally
docker build -t mcp-server .
# Run stdio mode (for MCP clients)
docker run -i --rm mcp-server
# Run HTTP mode (for web integration)
docker run -p 8000:8000 -e MODE=http mcp-server
直接Python
# stdio mode
python3 server.py
# HTTP mode
python3 server.py --http --port 8000
🔧 MCP客户端集成
亚马逊Q/Claude桌面
添加到MCP客户端配置中:
{
"mcpServers": {
"my-server": {
"command": "docker",
"args": ["run", "-i", "--rm", "ghcr.io/your-username/mcp-server-template:latest"]
}
}
}
HTTP客户端
curl http://localhost:8000/mcp \
-H "Content-Type: application/json" \
-H "MCP-Protocol-Version: 2025-06-18" \
-H "Accept: application/json, text/event-stream" \
-d '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}'
🛠️ 发展
项目结构
├── src/ # Source code
│ ├── server.py # MCP server implementation
│ └── entrypoint.sh # Transport mode switching
├── scripts/ # Development scripts
│ └── setup-hooks.sh # Git hooks setup
├── examples/ # Usage examples
│ └── client-config.json # Amazon Q configuration
├── docs/ # Documentation
│ └── SETUP.md # Setup guide
├── .github/workflows/ # CI/CD automation
├── Dockerfile # Production container
├── Makefile # Development commands
└── README.md # This file
可用命令
make build # Build Docker image
make test # Run all tests
make test-stdio # Test stdio transport
make test-http # Test HTTP transport
make clean # Clean up containers
添加工具
编辑 src/server.py 并将您的工具添加到 handle_request 功能:
elif method == 'tools/list':
return {
"jsonrpc": "2.0",
"id": request.get('id'),
"result": {
"tools": [
{"name": "your_tool", "description": "Your tool description",
"inputSchema": {"type": "object", "properties": {...}}}
]
}
}
📋 内置工具
- 回声 -回显消息
- get_env -获取环境变量
🧪 测试
CI管道自动测试:
- ✅ MCP协议合规性(2024-11-05和2025-06-18)
- ✅ stdio传输功能
- ✅ 带有正确标头的HTTP传输
- ✅ 工具执行和响应
- ✅ Docker容器安全
🚢 部署
GitHub容器注册表(自动)
推到 main 分支或创建标签以自动构建和发布:
git tag v1.0.0
git push origin v1.0.0
手动部署
# Build multi-arch image
docker buildx build --platform linux/amd64,linux/arm64 -t your-registry/mcp-server .
# Push to registry
docker push your-registry/mcp-server
🔒 安全
- 以非root用户身份运行
- 默认情况下,HTTP服务器绑定到localhost
- 协议版本验证
- 输入净化
📄 许可证
MIT许可证-有关详细信息,请参阅许可证文件。
🎯 准备好构建MCP服务器了吗? 点击“使用此模板”开始!
