LokeshBolisetty/GerritMCPServer
If you are the rightful owner of GerritMCPServer and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
A Model Context Protocol (MCP) server for Gerrit that enables AI assistants to interact with Gerrit code reviews, create comments, and publish reviews.
Gerrit MCP Server
A Model Context Protocol (MCP) server for Gerrit that enables AI assistants to interact with Gerrit code reviews, create comments, and publish reviews.
Overview
This server implements the Model Context Protocol (MCP) for interacting with Gerrit Code Review. It enables AI models to retrieve commit messages, create draft comments, and publish reviews through well-defined tools.
Features
- Get commit messages for Gerrit changes
- Create single or multiple draft comments
- Publish review comments directly
- Full support for line-specific and multi-line comments
- Support for unresolved/resolved comment status
Requirements
- Gerrit instance (Cloud, Server, or DC)
- HTTP credentials for authentication
- Python 3.8+
Setup
1. Clone or navigate to this directory
cd /home/cohesity/workspace/GerritMCPServer
2. Install dependencies
This project uses the shared virtual environment from JiraMCPServer:
source /home/cohesity/workspace/JiraMCPServer/venv/bin/activate
pip install -r requirements.txt
Alternatively, create a new virtual environment:
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
3. Configure environment variables
Create a .env file in the project root:
cp .env.example .env
Edit .env and fill in your Gerrit credentials:
GERRIT_HOST=your-gerrit-host.com
GERRIT_USERNAME=your-username
GERRIT_PASSWORD=your-http-password
Note: To generate an HTTP password:
- Go to your Gerrit instance
- Click your profile icon → Settings
- Navigate to HTTP Credentials
- Generate a new password
Usage
Testing with MCP Inspector
The easiest way to test the server is using the built-in MCP inspector:
source /home/cohesity/workspace/JiraMCPServer/venv/bin/activate
mcp dev gerrit_mcp_server.py
This will launch the MCP Inspector in your browser. To connect:
-
In the "Command" field, enter the path to your Python executable:
/home/cohesity/workspace/JiraMCPServer/venv/bin/python -
In the "Args" field, enter the full path to the server script:
/home/cohesity/workspace/GerritMCPServer/gerrit_mcp_server.py -
Click "Connect" to start the MCP server
-
Test the available tools in the inspector interface
Running the Server
To run the server directly:
python gerrit_mcp_server.py
Integration with Claude Desktop
Add to your claude_desktop_config.json:
{
"mcpServers": {
"gerrit": {
"command": "/home/cohesity/workspace/JiraMCPServer/venv/bin/python",
"args": [
"/home/cohesity/workspace/GerritMCPServer/gerrit_mcp_server.py"
]
}
}
}
Important: Use the full absolute paths for both the Python binary and the server script.
Available Tools
This MCP server provides 4 main tools for interacting with Gerrit:
- get_commit_message - Retrieve commit message for a change revision
- create_draft_comment - Create a single draft comment
- create_draft_comments - Create multiple draft comments at once
- publish_review - Publish comments immediately (not as drafts)
For detailed documentation of all available tools, including parameters, return values, and usage examples, see .
Available Prompts
This MCP server provides prompts to guide AI assistants in performing code reviews:
- code_review_instructions - Comprehensive step-by-step code review workflow for monolithic microservices repositories (Go, C++, Shell, Protocol Buffers)
How to Use the Prompt
In Claude Desktop or compatible AI assistants, invoke it with a change ID:
Use the code_review_instructions prompt with change_id=12345
Or more naturally:
Review Gerrit change 12345 using the code_review_instructions prompt
Parameters:
change_id(required): The Gerrit change ID or number to reviewrevision_id(optional): The revision to review (default: "current")
Example:
Use code_review_instructions prompt for change 12345, revision 2
The prompt includes:
- Pre-filled change ID and revision in instructions
- Step-by-step workflow from understanding context to generating feedback
- Integration with Gerrit and JIRA MCP tools
- Language-specific best practices (Go, C++, Shell Scripts, Protocol Buffers)
- Microservices architecture guidelines
- Structured JSON output format for review feedback
Example Use Cases
Get Commit Message
get_commit_message(
change_id="12345",
revision_id="current"
)
Create Draft Comments
create_draft_comments(
change_id="12345",
revision_id="current",
comments=[
{
"path": "src/main.py",
"line": 42,
"message": "Consider using a more descriptive variable name",
"unresolved": True
},
{
"path": "src/util.py",
"line": 15,
"message": "Good refactoring!",
"unresolved": False
}
]
)
Publish Review with Comments
publish_review(
change_id="12345",
revision_id="current",
comments={
"src/main.py": [
{"line": 10, "message": "Fix this bug", "unresolved": True},
{"line": 20, "message": "Good work"}
]
},
review_message="Overall looks good, a few minor issues to address"
)
Project Structure
GerritMCPServer/
├── gerrit_client/
│ ├── __init__.py
│ ├── client.py # Gerrit API client with authentication
│ └── changes.py # Change/revision operations
├── models/
│ └── __init__.py # Data models and schemas
├── gerrit_mcp_server.py # Main MCP server with tool definitions
├── requirements.txt # Python dependencies
├── .env.example # Environment variable template
├── .gitignore # Git ignore rules
├── README.md # This file
└── TOOLS.md # Detailed tool documentation
Architecture
- gerrit_mcp_server.py: Main server implementation using FastMCP
- gerrit_client/client.py: HTTP client for Gerrit API with authentication
- gerrit_client/changes.py: Business logic for change operations
- models/: Data models and constants
Error Handling
The server includes comprehensive error handling:
- 401 Unauthorized: Invalid credentials
- 404 Not Found: Change or revision doesn't exist
- Network errors: Connection timeouts and failures
- Validation errors: Invalid parameters or data
All errors are logged to stderr and returned in a structured format.
Technical Details
Gerrit API Specifics
- Base URL:
https://{GERRIT_HOST}/a/(authenticated endpoint) - XSSI Protection: Gerrit prepends
)]}'to responses, which is automatically stripped - Authentication: HTTP Basic Auth with username and password
- Draft comments: Created using PUT method
- Review publishing: Uses POST to the review endpoint
Comment Structure
Comments support the following fields:
{
"path": "file/path.ext", # Required
"line": 42, # Required
"message": "Comment text", # Required
"unresolved": True, # Optional (default: True)
"range": { # Optional (for multi-line comments)
"start_line": 40,
"start_character": 0,
"end_line": 45,
"end_character": 10
}
}
Contributing
This server follows the MCP specification and the architecture patterns established by JiraMCPServer and ConfluenceMCPServer.
Related Projects
- - MCP server for Jira
- - MCP server for Confluence
- - AI-powered Gerrit review assistant
License
MIT License