This project is a sample agent created with Python. It can be run locally or using Docker, with Docker being the primary method for interacting with the GitHub MCP Server. It also includes a feature to review GitHub Pull Requests using AI.
Before running the agent, especially for the Pull Request Reviewer functionality or MCP server interaction, you need to configure the following environment variables:
-
GITHUB_PERSONAL_ACCESS_TOKEN:- Purpose: Required for interacting with the GitHub API. This token is used to fetch pull request details, post comments on pull requests, and for the MCP server to interact with GitHub on your behalf.
- Permissions: Ensure the token has the necessary scopes. For public repositories,
public_repomight be sufficient for PR reviews. For private repositories,reposcope is typically needed. For MCP server interactions (like theget_metool),read:usermight be required. The token should have at least read access to PR content and write access for posting comments if using the review feature. - Creation: You can create one here.
-
GEMINI_API_KEY:- Purpose: Required for accessing Google's Gemini API to generate AI-powered code reviews for the Pull Request Reviewer feature.
- Acquisition: You'll need to obtain an API key from Google AI Studio or your Google Cloud project.
Example (bash):
export GITHUB_PERSONAL_ACCESS_TOKEN="your_github_pat_here"
export GEMINI_API_KEY="your_gemini_api_key_here"Note on Docker: If you are running the agent within a Docker container, these environment variables need to be passed into the Docker container (e.g., using the -e flag with docker run).
These steps are relevant if you want to run the agent directly using Python for development or perform type checking.
-
Clone the repository (if you haven't already):
# git clone <repository-url> # cd my_agent_project
-
Install uv (if you don't have it): Follow the official installation instructions for uv: https://github.com/astral-sh/uv#installation Alternatively, if you have pipx:
pipx install uv
Or, if you have pip:
pip install uv
-
Create and activate a virtual environment: Navigate to the project root directory (
my_agent_project) and run:uv venv source .venv/bin/activate # On Windows use: .venv\Scripts\activate
-
Install dependencies:
uv pip install -r requirements.txt
This agent can leverage the GitHub MCP Server to interact with GitHub APIs. This setup uses Docker to run both the agent and the MCP server.
- Docker: Ensure Docker is installed and the Docker daemon is running (if using Docker-based workflows).
- Environment Variables: Ensure
GITHUB_PERSONAL_ACCESS_TOKEN(andGEMINI_API_KEYif using the PR reviewer) are set as described in the "Configuration" section.
Navigate to the project root directory and run:
docker build -t prebid-agent-mcp .To run the agent and have it interact with the MCP server, execute the following command:
docker run --rm \
-v /var/run/docker.sock:/var/run/docker.sock \
-e GITHUB_PERSONAL_ACCESS_TOKEN=$GITHUB_PERSONAL_ACCESS_TOKEN \
# -e GEMINI_API_KEY=$GEMINI_API_KEY # Uncomment if using PR reviewer via this Docker setup
prebid-agent-mcpExplanation of the command:
--rm: Automatically removes the container when it exits.-v /var/run/docker.sock:/var/run/docker.sock: This mounts the Docker socket from your host into the container. It's required because the agent script itself executesdocker runto start theghcr.io/github/github-mcp-serverDocker image.- The
-eflags pass the necessary API keys into the agent's container. The agent script then uses these tokens. prebid-agent-mcp: The name of the image you built.
The agent will then start. If run without arguments, it invokes the GitHub MCP server (by running its Docker image), calls the get_me tool via the MCP server, and prints a greeting. If run with --pr-url, it will perform the PR review.
You can also run the agent directly using Python if you have set up your environment as described in the "Setup" section.
For MCP Server Interaction (Default Behavior):
python src/agent.pyNote: When run this way for MCP interaction, the src/agent.py script will attempt to use docker commands to launch the MCP server (ghcr.io/github/github-mcp-server). This means:
- Docker must be installed and the Docker daemon running.
- The
GITHUB_PERSONAL_ACCESS_TOKENenvironment variable must be set in your current shell session (see "Configuration"). If Docker is not available or the MCP server container cannot be launched, this mode will fail.
For Pull Request Reviewer:
python src/agent.py --pr-url "https://github.com/owner/repo/pull/PULL_NUMBER"Ensure GITHUB_PERSONAL_ACCESS_TOKEN and GEMINI_API_KEY are set in your environment as per the "Configuration" section.
The Dockerized setup is the primary method for running the agent with MCP integration. The local Python execution is suitable for development, testing, and running the PR reviewer.
This agent includes a feature to automatically review GitHub Pull Requests using AI.
When provided with a GitHub Pull Request URL, the agent will:
- Fetch the PR details (title, body, and diff) from the GitHub API.
- Generate a code review using Google's Gemini model.
- Post the generated review as a comment back to the original Pull Request on GitHub.
To trigger the PR review functionality, run the agent with the --pr-url command-line argument:
python src/agent.py --pr-url "https://github.com/owner/repo/pull/PULL_NUMBER"This command should be run from an environment where the necessary environment variables are set (see "Configuration" section).
To check types using mypy (ensure you've followed the "Setup" section first):
mypy src/agent.pyOr to check all files in the src directory:
mypy srcThe command should report Success: no issues found if everything is correctly typed.
This project demonstrates an agent interacting with the GitHub MCP server.