Docker CI/CD自动化工具

MCP CI/CD代理是一个使用LLM代理运行完整Docker CI/CD管道的服务器,从Git克隆到实时容器部署。

  • by kratosvil
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 kratosvil/mcp-cicd-agent

使用说明

MCP CI/CD代理

MCP服务器,允许LLM代理运行完整的Docker CI/CD管道——从Git克隆到活动容器。

给Claude一个Git仓库URL——它会为您克隆、构建、部署和验证容器



它的作用

你把克劳德指向一个仓库。Claude通过模型上下文协议自主运行整个管道。

"Deploy the latest version of my API from github.com/myorg/myapi"
  User ──► Claude AI ──► MCP Server ──► Docker ──► Running Container
 (prompt)  (orchestrates)  (8 tools)    (build)    (localhost:8080)

特性

  • 一次对话中的完整管道 --克隆、检测、构建、部署、验证、回滚
  • 8个MCP工具 --每个步骤都是一个明确的、可观察的工具调用
  • 港口冲突解决 --自动查找可用端口
  • 部署状态跟踪 --JSON状态文件支持回滚到任何以前的部署
  • 缺省安全 --仅本地主机绑定, no-new-privileges,512 MB内存上限
  • 结构化日志记录 --每个操作的JSON日志,易于管道到任何日志聚合器
  • 101个单元测试 --全面覆盖验证、Git、Docker和设置层

快速开始

先决条件

安装

git clone https://github.com/kratosvil/mcp-cicd-agent.git
cd mcp-cicd-agent
python -m venv .venv

# Windows
.venv\Scripts\activate

# Linux / macOS
source .venv/bin/activate

pip install -e .

配置Claude桌面版

添加到您的Claude Desktop配置文件中:

操作系统 路径
窗户 %APPDATA%\Claude\claude_desktop_config.json
Linux ~/.config/Claude/claude_desktop_config.json
macOS ~/Library/Application Support/Claude/claude_desktop_config.json
{
  "mcpServers": {
    "cicd-agent": {
      "command": "/absolute/path/to/.venv/bin/python",
      "args": ["-m", "mcp_cicd"],
      "env": {
        "GITHUB_TOKEN": "ghp_your_token_here"
      }
    }
  }
}

Windows示例

"command": "C:\\Users\\you\\mcp-cicd-agent\\.venv\\Scripts\\python.exe"

重新启动Claude Desktop,然后尝试:

"Clone https://github.com/myorg/myapi and deploy it"

MCP工具

工具 说明
prepare_repo 将Git存储库克隆或更新到隔离的工作区
detect_project_type 识别Dockerfile与docker组成和暴露端口
build_image 构建具有完整日志捕获功能的Docker镜像
deploy_container 部署具有自动端口冲突解决功能的容器
healthcheck 轮询HTTP端点,直到服务正常或超时
get_logs 检索容器stdout/stderr的最后N行
stop_deployment 停止并移除正在运行的容器
rollback 为给定名称重新部署上次成功的部署

建筑

Claude Desktop
     │
     │  MCP Protocol (JSON-RPC 2.0 via stdio)
     ▼
┌──────────────────────────────────┐
│  MCP CI/CD Server (FastMCP)      │
│                                  │
│  repo_tools   ──► GitPython      │
│  docker_tools ──► Docker SDK     │
│  health_tools ──► httpx          │
│  lifecycle_tools ──► state mgr   │
└──────┬───────────────────────────┘
       │
       ▼
   Docker Engine
   ├── Image build (Dockerfile)
   └── Container run
          └── 127.0.0.1:<port>  (localhost only)
  • 协议:JSON-RPC 2.0通过标准输入
  • 状态:中的原子JSON文件 deployments/ (忽略)
  • 工作区:中的每个提交目录都是隔离的 workspace/ (忽略)
  • 安全: no-new-privileges:true, mem_limit=512m, 127.0.0.1 仅限绑定

测试

# Run all 101 unit tests
pytest tests/unit/ -v

# Run with coverage report
pytest tests/unit/ --cov=src/mcp_cicd --cov-report=term-missing

# Run integration tests (requires Docker daemon)
pytest tests/integration/ -v

# Run a specific group
pytest tests/unit/ -v -k "TestValidateGitUrl"
pytest tests/unit/ -v -k "TestDockerUtils"

单元测试使用模拟的Docker和Git调用——不需要运行Docker实例。

项目结构

mcp-cicd-agent/
├── src/mcp_cicd/
│   ├── tools/             # MCP tool implementations (8 tools)
│   │   ├── repo_tools.py
│   │   ├── docker_tools.py
│   │   ├── health_tools.py
│   │   └── lifecycle_tools.py
│   ├── models/            # Pydantic data models
│   ├── utils/             # Docker, Git, validation, state helpers
│   └── config/            # Settings via pydantic-settings + .env
├── tests/
│   ├── unit/              # 101 unit tests (mocked)
│   ├── integration/       # End-to-end pipeline tests (Docker required)
│   └── fixtures/          # Test app (simple Python HTTP server)
├── workspace/             # Git clone target (gitignored)
├── deployments/           # Deployment state JSON files (gitignored)
└── logs/                  # Application logs (gitignored)

配置

所有设置都可以通过环境变量或 .env 文件:

变量 默认值 描述
GITHUB_TOKEN None 私有仓库的个人访问令牌
MCP_LOG_LEVEL INFO 日志级别(DEBUG, INFO, WARNING, ERROR)
MCP_PORT_RANGE_START 8000 开始自动分配端口范围
MCP_PORT_RANGE_END 9000 自动分配端口范围结束
MCP_ALLOWED_GIT_HOSTS ["github.com","gitlab.com"] 允许的Git主机的JSON列表

技术栈

层 技术
客户端 克劳德桌面
协议 MCP(标准输入,JSON-RPC 2.0)
后端 Python 3.10+/FastMCP
容器 Docker Python SDK
关於 GitPython
HTTP httpx(异步健康检查)
验证 Pydantic v2+Pydantic设置
测试 pytest/pytest异步

许可证

麻省理工学院