Skip to content

burakkeless/Auto-PR

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitLab PR Review System with AutoGen Multi-Agent Team

An intelligent MCP (Model Context Protocol) server that provides automated PR review capabilities using AutoGen multi-agent teams. The system integrates GitLab, Jira, and Outline to perform comprehensive code reviews with context-aware analysis.

Overview

This project implements a multi-agent system for automated GitLab merge request reviews. It uses:

  • MCP Server: Exposes tools for GitLab, Jira, and Outline integration
  • AutoGen Agents: Specialized agents for different review aspects
  • Multi-Team Orchestration: Supports RoundRobin, Selector, MagenticOne, and Swarm patterns

Architecture

MCP Tools Layer (src/tools/)

  • GitLab Tools: PR details, file reading, git blame, commit details, PR review posting
  • Jira Tools: Board listing, epic retrieval, task details
  • Outline Tools: Document collections, tree navigation, content retrieval

Agent Layer (src/agents/)

  • context_analyzer_agent: Analyzes PR metadata, commits, and categorizes changes
  • code_quality_agent: Performs deep code analysis and identifies technical debt
  • impact_analyzer_agent: Identifies cross-file impacts and breaking changes
  • jira_explorer_agent: Extracts Jira ticket context and epic relationships
  • outline_exp_agent: Retrieves PR templates and documentation
  • publisher_agent: Formats and posts review to GitLab
  • queen_agent (Swarm only): Orchestrator for Swarm-based workflow

Orchestration Layer (src/host/)

  • main.py: RoundRobin, Selector, and MagenticOne teams
  • swarm_host.py: Swarm-based team with handoff capabilities
  • tool_pointer.py: MCP client wrappers for tool invocation
  • model_clients.py: LLM client configurations (GPT-4, Claude)

Setup

1. Install uv

Follow the official installation instructions at: https://docs.astral.sh/uv/getting-started/installation/

2. Install Dependencies

# Install all dependencies
uv sync

# Or install with dev dependencies for testing
uv sync --all-extras

3. Configure Environment Variables

Create a .env file in the project root:

# GitLab Configuration
GITLAB_API_BASE_URL=https://your-gitlab-instance.com/api/v4
GITLAB_PERSONAL_ACCESS_TOKEN=your_gitlab_token

# Jira Configuration
JIRA_BASE_URL=https://your-jira-instance.atlassian.net
JIRA_EMAIL=your-email@example.com
JIRA_API_TOKEN=your_jira_token

# Outline Configuration
OUTLINE_BASE_URL=https://your-outline-instance.com/api
OUTLINE_API_TOKEN=your_outline_token

# OpenAI Configuration
OPENAI_API_KEY=your_openai_api_key

# Anthropic Configuration
ANTHROPIC_API_KEY=your_anthropic_api_key

4. Start the MCP Server

# Start the MCP server on localhost:8000
python -m src.server

The server exposes MCP tools at http://localhost:8000/mcp

Usage

Running a PR Review Team

# Run the Selector team (recommended)
python -m src.host.main

# Run the Swarm team
python -m src.host.swarm_host

Team Configurations

1. RoundRobin Team (review_team)

Agents execute in fixed sequential order:

  1. context_analyzer → 2. code_quality → 3. impact_analyzer → 4. jira_agent → 5. outline_agent → 6. publisher_agent

2. Selector Team (selector)

LLM-driven agent selection with termination on "published" keyword

  • Termination: Stops when any agent mentions "published"
  • Best for: Dynamic workflows where agent order may vary

3. MagenticOne Team (magentic)

Built-in orchestrator with intelligent agent coordination

4. Swarm Team (swarm)

Handoff-based pattern with queen_agent orchestrator

  • queen_agent delegates tasks to specialized agents
  • Agents can hand off to each other based on workflow needs

Available MCP Tools

GitLab Tools

  • get_gitlab_pr_detail(pr_url) - Get PR metadata, commits, changes
  • read_gitlab_repository_file(repo_url, file_path, ref) - Read file content
  • get_gitlab_git_blame(repo_url, file_path, line_number, ref) - Get blame info
  • get_gitlab_commit_detail(repo_url, commit_hash) - Get commit details
  • get_gitlab_repository_tree(repo_url, parent_folder, ref) - Get folder tree
  • create_gitlab_pr_review(pr_url, markdown_content) - Post review comment

Jira Tools

  • get_jira_boards() - List all boards
  • get_jira_epics(board_id) - Get epics from board
  • get_jira_task_detail(task_key) - Get task details
  • get_jira_epic_tasks(board_id, epic_id) - Get tasks in epic

Outline Tools

  • get_collection() - Get document collections
  • get_outline_tree(document_id) - Get document outline tree
  • get_outline_document_content(document_id) - Get document content

Workflow Example

  1. User Request: "Review PR https://gitlab.com/project/-/merge_requests/123 on feature-branch"

  2. context_analyzer_agent:

    • Fetches PR details (title, description, commits, changed files)
    • Categorizes PR (Bug Fix / Feature / Refactor)
    • Outputs structured summary
  3. code_quality_agent:

    • Reads changed files
    • Performs git blame analysis
    • Identifies code smells, security issues, technical debt
    • Outputs findings with file paths and line numbers
  4. impact_analyzer_agent:

    • Analyzes cross-file dependencies
    • Identifies breaking changes
    • Checks architectural violations
  5. jira_explorer_agent:

    • Extracts Jira ticket key from PR
    • Fetches ticket details and epic context
  6. outline_exp_agent:

    • Retrieves appropriate PR template (bug/feature)
    • Fetches relevant documentation
  7. publisher_agent:

    • Aggregates all findings
    • Formats review in markdown
    • Posts to GitLab PR

Testing

# Run unit tests
uv run pytest tests/ -v

# Run specific test file
uv run pytest tests/test_server.py -v

Project Structure

MCP-burak/
├── src/
│   ├── server.py              # MCP server entry point
│   ├── config.py              # Environment configuration
│   ├── agents/                # Agent implementations
│   │   ├── gitlab/           # GitLab-specific agents
│   │   │   ├── context_analyzer.py
│   │   │   ├── code_quality.py
│   │   │   ├── impact_analyzer.py
│   │   │   └── publisher.py
│   │   ├── jira/             # Jira agent
│   │   │   └── jira_explorer.py
│   │   ├── outline/          # Outline agent
│   │   │   └── outline_explorer.py
│   │   └── queen.py          # Swarm orchestrator
│   ├── host/                 # Team orchestration
│   │   ├── main.py          # RoundRobin/Selector/MagenticOne
│   │   ├── swarm_host.py    # Swarm team
│   │   ├── tool_pointer.py  # MCP client wrappers
│   │   └── model_clients.py # LLM configurations
│   └── tools/               # MCP tool implementations
│       ├── Gitlab/
│       │   ├── gitlab_service.py
│       │   └── gitlab_model.py
│       ├── Jira/
│       │   ├── jira_service.py
│       │   └── jira_model.py
│       └── Outline/
│           ├── outline_service.py
│           ├── outline_model.py
│           └── outline_document_traverser.py
├── tests/                   # Unit tests
├── pyproject.toml          # Project dependencies
├── .env                    # Environment variables
└── README.md

Configuration Options

Model Clients

Edit src/host/model_clients.py to configure LLM models:

  • GPT-4 for code analysis agents (fast, cost-effective)
  • Claude Sonnet for orchestration and complex reasoning

Team Parameters

  • max_turns: Maximum conversation rounds (default: 13)
  • termination_condition: Custom termination logic
  • allow_repeated_speaker: Allow same agent multiple times

Tool Timeouts

Configure MCP client timeout in src/host/tool_pointer.py:

MCP_SERVER_TIMEOUT = 30.0  # seconds

Troubleshooting

Error: "Expecting value: line 1 column 1 (char 0)"

This JSON parsing error occurs when MCP tools return empty/malformed responses. Check:

  1. MCP server is running (python -m src.server)
  2. Environment variables are correctly set
  3. API tokens have proper permissions

Team Doesn't Terminate After Publisher

Ensure termination condition is set:

termination_condition=TextMentionTermination("published")

Agent Not Receiving Tool Results

Verify MCP client connection in tool_pointer.py and check server logs.

Development

Adding a New Agent

  1. Create agent file in src/agents/
  2. Define system prompt and tools
  3. Add to team configuration in src/host/main.py or swarm_host.py

Adding a New MCP Tool

  1. Implement tool in src/tools/<category>/
  2. Register tool in src/server.py
  3. Create wrapper in src/host/tool_pointer.py
  4. Add to agent's tools list

License

[Add your license here]

Contributing

[Add contributing guidelines here]

About

PR Review System with Agent Orchestratıon

Resources

Stars

Watchers

Forks

Contributors

Languages