loading…
Search for a command to run...
loading…
Enables querying and analysis of public GitHub repositories for statistics, contributor data, and commit history. It provides both a RESTful API and an MCP inte
Enables querying and analysis of public GitHub repositories for statistics, contributor data, and commit history. It provides both a RESTful API and an MCP interface for seamless integration with AI agents.
Query, analyze, and visualize any public GitHub repository — from the command line, browser, or AI agent.
GitHub Analytics MCP Server is a production-ready microservice that turns the GitHub API into a simple, self-hosted analytics endpoint. Point it at any public repository and instantly get structured data on stars, forks, contributors, commit history, and language distribution.
It exposes two interfaces: a RESTful API (FastAPI with auto-generated Swagger docs) for direct HTTP access, and a Model Context Protocol (MCP) server that lets AI agents like Claude Desktop query GitHub data as a native tool.
The entire stack — API gateway, MCP server, container orchestration, infrastructure provisioning, and CI/CD — is included and deployable with a single command.
This project also serves as an architecture reference implementation: every layer is accompanied by design-decision documentation explaining why it is structured this way, not just what it does.
| Concern | This Project | Traditional Approach |
|---|---|---|
| Setup | docker-compose up or make k8s-deploy |
Manual server provisioning |
| Scalability | Auto-scaling with K8s HPA (2–5 replicas) | Manual capacity planning |
| Infrastructure | terraform apply — one command |
Multiple manual steps |
| High Availability | Multi-replica with health checks | Complex setup required |
| Monitoring | Liveness & readiness probes built in | Separate monitoring stack |
| Deployment | Automated CI/CD on every push | Manual release process |
| Portability | Runs anywhere Docker/K8s runs | Environment-dependent |
| API Docs | Auto-generated OpenAPI (Swagger UI) | Manual documentation |
This is not just a tool — it is a reference implementation designed for studying architecture patterns. Every layer includes design-decision documentation explaining the reasoning behind its structure.
graph TB
subgraph "User Interface"
A[Web Browser / CLI]
end
subgraph "API Layer"
B[FastAPI Gateway<br/>Port 8080]
C[MCP Server<br/>stdio mode]
end
subgraph "Container Orchestration"
D[Kubernetes Cluster]
E[Docker Containers]
F[Auto-scaling HPA]
end
subgraph "External Services"
G[GitHub API]
end
subgraph "Infrastructure"
H[Terraform IaC]
I[CI/CD Pipeline]
end
A -->|HTTP/REST| B
A -->|MCP Protocol| C
B -->|GitHub Token| G
C -->|GitHub Token| G
B -.->|Deployed in| D
C -.->|Deployed in| D
D -->|Manages| E
D -->|Auto-scales| F
H -.->|Provisions| D
I -.->|Deploys to| D
GitHubClient is the single business-logic layer. The MCP Server and FastAPI Gateway are both thin adapters — they translate between their respective protocols and the shared core. Neither contains business logic, and neither duplicates the other.
Why two interfaces: MCP serves AI agents over stdio; REST serves humans and programs over HTTP. Two protocols, two adapters, zero duplicated logic.
Custom exception hierarchy (RepositoryNotFoundError, AuthenticationError, RateLimitError) translates GitHub HTTP status codes into semantic domain errors. The MCP server converts these into user-friendly text messages; the FastAPI gateway converts them into the corresponding HTTP status codes (404/401/429/502). Callers never need to know how the GitHub API works internally.
docker-compose up) starts everything.k8s/) — direct kubectl apply. Good for learning K8s and quick testing.terraform/) — state management, drift detection, multi-environment support. For production.All three coexist intentionally. Each serves a different stage of the deployment lifecycle.
docker-compose --profile with-cache up to demonstrate Docker Compose profiles, but not wired into the application.For deeper dives into specific decisions:
# 1. Clone and configure
git clone https://github.com/Pyroxyl/github-analytics-mcp.git
cd github-analytics-mcp
cp .env.example .env
# Edit .env and add your GITHUB_TOKEN
# 2. Start services
docker-compose up -d
# 3. Test the API
curl http://localhost:8080/health
curl http://localhost:8080/api/v1/repo/facebook/react/stats | jq
# 1. Build and deploy
make build
make k8s-deploy
# 2. Access the API (LoadBalancer on port 80)
curl http://localhost/health
curl http://localhost/api/v1/repo/facebook/react/stats | jq
cd terraform
cp terraform.tfvars.example terraform.tfvars
# Edit terraform.tfvars
terraform init
terraform plan
terraform apply
curl "http://localhost/api/v1/repo/facebook/react/stats" | jq
{
"repository": "facebook/react",
"stars": 242591,
"forks": 50472,
"open_issues": 1138,
"watchers": 6690,
"description": "The library for web and native user interfaces.",
"language": "JavaScript"
}
curl "http://localhost/api/v1/repo/anthropics/anthropic-sdk-python/commits?limit=3" | jq
curl "http://localhost/api/v1/repo/kubernetes/kubernetes/contributors?top_n=5" | jq
curl "http://localhost/api/v1/repo/microsoft/vscode/languages" | jq
{
"repository": "microsoft/vscode",
"languages": {
"TypeScript": 95.54,
"CSS": 1.49,
"JavaScript": 1.0,
"Rust": 0.61
}
}
# Compare stars across projects
curl -s "http://localhost/api/v1/repo/facebook/react/stats" | jq '.stars'
curl -s "http://localhost/api/v1/repo/vuejs/vue/stats" | jq '.stars'
🌐 Live API Docs: http://localhost/docs (or http://localhost:8080/docs for Docker Compose)
FastAPI auto-generates interactive Swagger UI where you can:
Add to your MCP client configuration (e.g., Claude Desktop):
{
"mcpServers": {
"github-analytics": {
"command": "python",
"args": ["-m", "src.server"],
"cwd": "/path/to/github-analytics-mcp",
"env": {
"GITHUB_TOKEN": "your_token_here"
}
}
}
}
Or using Docker:
{
"mcpServers": {
"github-analytics": {
"command": "docker",
"args": ["run", "--rm", "-i", "--env-file", ".env", "github-analytics-mcp"],
"cwd": "/path/to/github-analytics-mcp"
}
}
}
| Layer | Technology |
|---|---|
| Backend | Python 3.11+, FastAPI, PyGithub |
| Protocol | Model Context Protocol (MCP) |
| Containerization | Docker (multi-stage builds), Docker Compose |
| Orchestration | Kubernetes — Deployments, Services, HPA, Ingress |
| Infrastructure | Terraform |
| CI/CD | GitHub Actions (lint → test → build → deploy) |
github-analytics-mcp/
├── src/ # MCP Server
│ ├── server.py # MCP protocol entry point
│ ├── github_client.py # GitHub API client wrapper
│ └── tools/ # MCP tool implementations
│ ├── repo_stats.py # get_repo_stats
│ ├── commits.py # list_recent_commits
│ ├── contributors.py # analyze_contributors
│ └── languages.py # get_language_breakdown
├── api/ # FastAPI Gateway
│ ├── main.py # App entry point
│ ├── routes.py # API route definitions
│ ├── models.py # Pydantic models
│ └── dependencies.py # Dependency injection
├── k8s/ # Kubernetes manifests
│ ├── namespace.yaml
│ ├── configmap.yaml
│ ├── secret.yaml
│ ├── deployment-api.yaml # API gateway (2 replicas)
│ ├── deployment-mcp.yaml # MCP server
│ ├── service-api.yaml # LoadBalancer service
│ ├── hpa-api.yaml # Horizontal Pod Autoscaler
│ ├── ingress.yaml
│ └── deploy.sh # Deployment script
├── terraform/ # Infrastructure as Code
│ ├── main.tf
│ ├── kubernetes.tf
│ ├── providers.tf
│ ├── variables.tf
│ └── outputs.tf
├── .github/workflows/ # CI/CD pipelines
│ ├── ci.yml # Lint & test
│ ├── docker-build.yml # Build & push image
│ └── cd.yml # Deploy to K8s
├── tests/ # Unit tests
├── Dockerfile # Multi-stage container build
├── docker-compose.yml # Local multi-service setup
├── Makefile # Convenience commands
├── requirements.txt
└── .env.example # Environment template
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
# Run the MCP server
python -m src.server
# Run the API gateway
uvicorn api.main:app --reload --port 8080
# Run tests
pytest tests/
| Command | Description |
|---|---|
make build |
Build Docker image |
make run |
Start with Docker Compose |
make stop |
Stop all containers |
make logs |
View container logs |
make k8s-deploy |
Deploy to Kubernetes |
make k8s-status |
Check K8s pod/service status |
make clean |
Remove containers and images |
make help |
Show all available commands |
Push/PR → [CI] Lint + Test → [Docker Build] → ghcr.io → [CD] → Kubernetes
ruff lint and pytest on every push/PR (Python 3.11 & 3.12)See .github/workflows/README.md for details.
See CONTRIBUTING.md for development workflow and guidelines.
This project is licensed under the MIT License — see the LICENSE file for details.
Built with Model Context Protocol by Anthropic, FastAPI, and PyGithub.
⭐ If you find this project useful, please star it on GitHub!
Добавь это в claude_desktop_config.json и перезапусти Claude Desktop.
{
"mcpServers": {
"github-analytics-mcp-server": {
"command": "npx",
"args": []
}
}
}