Build a production Model Context Protocol (MCP) server that connects to GitHub, fetches pull request diffs, runs LLM-powered code review, and posts structured review comments back. Exposes MCP tools any MCP client (Claude Desktop, Cursor) can call.
Start learning at learnwithparam.com. Regional pricing available with discounts of up to 60%.
- MCP server architecture with stdio and HTTP transports
- Exposing tools and resources through MCP SDK decorators
- Fetching pull request diffs with PyGithub
- Structured review generation with Pydantic schemas
- Posting review comments back to GitHub programmatically
- Running a dual-mode container that serves both an MCP server and a FastAPI inspector
- Python MCP SDK (
mcp) - Official Model Context Protocol server library - FastAPI - Companion HTTP inspection service on top of the same business logic
- PyGithub - GitHub REST API client for diffs and reviews
- Pydantic - Typed request/response schemas for structured reviews
- LLM Provider Pattern - Supports Fireworks, OpenRouter, Gemini, OpenAI
- Docker - Containerized development
- Python 3.11+
- uv (installed automatically by
make setup) - A GitHub personal access token with
reposcope - An API key from any supported LLM provider
# One command to set up and run the FastAPI inspector
make dev
# Or step by step:
make setup # Create .env and install dependencies
# Edit .env with your API key and GITHUB_TOKEN
make run # Start the FastAPI servermake mcp # Runs `python mcp_server.py` over stdioAdd this to your claude_desktop_config.json so Claude Desktop can spawn the MCP server over stdio and call its tools directly:
{
"mcpServers": {
"pr-review": {
"command": "uv",
"args": ["run", "python", "mcp_server.py"],
"cwd": "/absolute/path/to/mcp-pr-review-server",
"env": {
"GITHUB_TOKEN": "ghp_...",
"OPENAI_API_KEY": "sk-..."
}
}
}
}Restart Claude Desktop and the fetch_pr_diff, review_pr, and post_review_comments tools will appear in the tool picker. Cursor and any other MCP client follow the same pattern.
make build # Build the Docker image
make up # Start the container
make logs # View logs
make down # Stop the containerOnce the FastAPI service is running, open http://localhost:8000/docs for the interactive Swagger UI. The /inspect/{owner}/{repo}/{pr_number} endpoint is handy for debugging the pipeline outside an MCP client.
Work through these incrementally to build the full application:
- MCP Server Skeleton - Stand up an MCP server with
list_toolsand a health check - fetch_pr_diff Tool - Expose a tool that takes
owner,repo, andpr_numberand returns the unified diff - review_pr Tool - Feed the diff to the LLM provider and return a structured review
- ReviewComment Schema - Model line-level comments with
file,line,severity, andsuggestion - post_review_comments Tool - Post the structured review back to GitHub via PyGithub
- FastAPI Inspector - Add
/inspect/{owner}/{repo}/{pr_number}to debug the pipeline without an MCP client
make help Show all available commands
make setup Initial setup (create .env, install deps)
make dev Setup and run (one command!)
make run Start FastAPI server
make mcp Run MCP server over stdio
make build Build Docker image
make up Start container
make down Stop container
make clean Remove venv and cache
- Start the course: learnwithparam.com/courses/mcp-pr-review-server
- AI Bootcamp for Software Engineers: learnwithparam.com/ai-bootcamp
- All courses: learnwithparam.com/courses