Skip to main content
Glama

多智能体开发自动化系统 — 智能体化 CI/CD 流水线

一个使用 FastAPI、Claude 驱动的智能体和模型上下文协议(MCP)的自动化智能体化 CI/CD 流水线,用于自动分析 GitHub 拉取请求、运行单元测试和检查文件。

项目架构

devagent/
├── agents/             # Claude-powered agents
│   ├── base_agent.py      # Base agent with tool execution loop
│   ├── reviewer_agent.py  # Reviewer agent parsing PR diffs
│   └── prompts.py         # System prompts
├── app/                # FastAPI application
│   ├── api/routes/        # API endpoints (health)
│   ├── services/          # Claude integration service
│   ├── config.py          # Settings and environment config
│   └── main.py            # FastAPI main entrypoint
├── mcp_server/         # MCP Server
│   ├── server.py          # MCPServer registration and endpoints
│   └── tools/             # MCP tools (fetch_pr_diff, lint, run_tests, search)
├── tests/              # Test suite (pytest)
│   ├── test_agents.py
│   ├── test_health.py
│   └── test_mcp_tools.py
├── .env.example        # Environment template
├── .gitignore          # Git ignore files
└── requirements.txt    # Python dependencies

Related MCP server: code-review-mcp-server

功能与 MCP 工具

  • BaseAgent:使用 Anthropic API(Claude 3.5 Sonnet)执行工具调用循环,以递归收集代码库信息。

  • ReviewerAgent:对 PR 差异执行代码审查,查找正确性缺陷、安全漏洞和代码质量问题。

  • MCP 工具:

    • fetch_pr_diff:获取 GitHub PR 的变更文件和补丁。

    • search_codebase:使用模式或文本搜索来搜索本地文件。

    • run_tests:在目标仓库中使用 pytest 运行单元测试。

    • lint_code:对目标文件运行 Ruff 检查器。

安装与设置

  1. 克隆仓库(推送到 GitHub 后)。

  2. 创建并激活虚拟环境:

    python -m venv .venv
    # Windows:
    .venv\Scripts\activate
    # Linux/macOS:
    source .venv/bin/activate
  3. 安装依赖:

    pip install -r requirements.txt
  4. 配置环境变量: 从模板创建 .env 文件并填写你的密钥:

    cp .env.example .env

    添加你的 ANTHROPIC_API_KEY,并可选择添加 GITHUB_TOKEN。

运行项目

运行 FastAPI 应用

uvicorn app.main:app --reload

在 http://localhost:8000/docs 访问 API 文档。

运行 MCP 服务器

要直接运行 MCP 服务器:

python mcp_server/server.py

运行测试

要运行所有测试并验证系统是否正常工作:

python -m pytest

Related MCP Connectors

Related MCP Servers