使用说明
Azure OpenAI Code Review PoC
Azure OpenAI Code Review is a proof of concept that demonstrates automated code review using FastAPI and Azure OpenAI.
The FastAPI service accepts merge request diffs or code snippets through an HTTP API, sends the submitted content to a configured Azure OpenAI model deployment, and returns structured review findings and recommendations.
The current implementation follows an MCP-inspired client-and-agent interaction pattern but does not implement the official Model Context Protocol or use the official MCP SDK.
Purpose
This proof of concept is designed to:
- Explore how large language models can automate merge request code reviews.
- Validate communication between the FastAPI service and Azure OpenAI endpoints.
- Evaluate the generation of structured, context-aware code review recommendations.
- Establish a foundation for a future production-grade solution with enhanced context management, security guardrails, observability, and scalability.
Note: The current implementation uses a FastAPI-based HTTP interface and does not implement the official Model Context Protocol or use the official MCP SDK.
Future Roadmap: MCP Server Integration
This PoC provides the foundation for a scalable, production-grade AI Code Review Assistant.
Future versions are expected to implement an official MCP server architecture to support:
- Standardized communication between MCP clients and the code review service.
- MCP tools for reviewing merge request diffs and code snippets.
- Integration with GitLab merge requests and GitHub pull requests.
- Improved repository and project-level context handling.
- Configurable coding standards and review policies.
- Security, privacy, and responsible AI guardrails.
- Authentication, authorization, monitoring, and audit logging.
- Scalable deployment and automated CI/CD integration.
Table of Contents
- Features
- Prerequisites
- Installation
- Running Locally
- Kubernetes Deployment
- Environment Variables & Secrets
- API Usage
- Sample Test
- Troubleshooting
- Contributing
- License
Features
- Review Merge Requests automatically using Azure OpenAI.
- Detects code issues, typos, and provides suggestions.
- REST API endpoint for integration with other tools.
- Can run locally or in Kubernetes.
Prerequisites
- Python 3.11+
- Docker (optional for containerization)
- Kubernetes cluster (for deployment i.e. local setup using minikube)
- Azure OpenAI subscription and deployed model
kubectland Helm installed if deploying to Kubernetes
Installation
- Clone the repository:
git clone <repo-url>
cd <repo-directory>
- Create a Python virtual environment:
python -m venv venv
source venv/bin/activate # Linux/macOS
venv\Scripts\activate # Windows
- Install dependencies:
pip install -r requirements.txt
Environment Variables & Secrets
This project requires the following environment variables. Store them in a .env file at the root of your project:
# .env file
# Your Azure OpenAI API key
AZURE_OPENAI_KEY=your_azure_openai_key_here
# Your Azure OpenAI endpoint URL
AZURE_OPENAI_ENDPOINT=https://your-resource-name.cognitiveservices.azure.com/
# The deployed model name in Azure OpenAI
MODEL_NAME=gpt-4o-mini-2
Running Locally
Start the FastAPI application:
uvicorn app.main:app --host 0.0.0.0 --port 8080 --reload
Access the API:
- Health check: http://localhost:8080/health
Kubernetes Deployment
- Build Docker image:
docker build -t code-review-mcp:latest .
- Push to container registry (optional):
docker tag code-review-mcp:latest <registry-url>/code-review-mcp:latest
docker push <registry-url>/code-review-mcp:latest
- Deploy using Helm:
# Create or overwrite helm/values.yaml with the required configuration
cat <<EOF > helm/values.yaml
image:
repository: image.registry.com/code-review-mcp
tag: latest
service:
port: 8000
azureOpenAI:
endpoint: "https://your-azure-openai-endpoint.openai.azure.com/"
key: "your-azure-openai-key"
model_name: "gpt-4o-mini-2"
EOF
helm install code-review-mcp ./helm-chart -n ai-review --create-namespace
- Verify pod status:
kubectl get pods -n ai-review
kubectl logs -f pod/<pod-name> -n ai-review
Sample Test
Run the following curl command to test locally:
curl -X POST http://localhost:8080/mcp/tool-call \
-H "Content-Type: application/json" \
-d '{"tool":"review_merge_request","arguments":{"diff":"print(\"prinf(hello)\")"}}'
### Merge Request Review Summary
It looks like you've shared a line from a GitLab Merge Request (MR) diff.
In the code snippet, there's a small typo in the `print` function — it’s incorrectly written as `prinf`.
### **Suggested Change**
print("hello")
Troubleshooting
-
SSL Issues with Azure OpenAI:
Make sure the pod or local machine can reach the Azure endpoint. For Kubernetes, consider using host networking or check firewall rules. -
Internal Server Error (500):
Check logs:kubectl logs -f pod/<pod-name> -n ai-reviewEnsure that environment variables are correctly set and loaded.
-
Curl connection fails:
Verify network connectivity to*.cognitiveservices.azure.com.
Contributing
- Fork the repository
- Create a feature branch:
git checkout -b feature/my-feature - Commit changes:
git commit -m 'Add new feature' - Push branch:
git push origin feature/my-feature - Open a Pull Request
