How aarora79/mcp-gateway works
Project Type & Purpose
• This is a full-stack, containerized microservice application that implements an MCP (Model Context Protocol) Gateway and Registry.
• The Gateway is an Nginx reverse-proxy that fronts one or more MCP servers (local Python “servers/*” services, remote EKS/EKS-backed services, or API Gateway+Lambda).
• The Registry is a FastAPI/Uvicorn app (registry/main.py) with Jinja2 templates (registry/templates), static assets, health‐check scheduler, dynamic Nginx config generator, and a web UI that manages and monitors the MCP servers.
File Structure Clues
• Top‐level Dockerfile, docker/entrypoint.sh, nginx_rev_proxy.conf → container + reverse proxy.
• registry/ → Registry app, templates, static CSS, server metadata files, Nginx config template.
• servers/* → Sample MCP servers (currenttime, fininfo, mcpgw, realserverfaketools), each with server.py and client.py.
• agents/agent.py → example AI Agent using MCP clients.
• build_and_push.sh, .github/workflows → CI/CD and container build scripts.
Main Components
a. AI Agents (agents/agent.py or any external agent)
b. Gateway & Registry container
– Nginx Reverse Proxy (docker/nginx_rev_proxy.conf)
– FastAPI/Uvicorn app (registry/main.py)
– Jinja2 Web UI (registry/templates + registry/static)
– Background health-check/task scheduler (periodically polls /sse on each service)
– Dynamic Nginx config generator (registry/nginx_mcp_revproxy.conf → Nginx reload)
– File-based state store (registry/servers/*.json + registry/server_state.json)
c. Local MCP Servers (servers/currenttime, fininfo, mcpgw, realserverfaketools)
d. Remote MCP Services (EKS cluster or API Gateway + AWS Lambda, optional)
e. External Data Sources & APIs (Polygon API, databases, third-party APIs)
Relationships & Data Flows
• AI Agent → (MCP Protocol, SSE or streamable HTTP) → Nginx Reverse Proxy → multiplex routes to the correct MCP Server.
• MCP Server → responds via SSE/HTTP streaming → Nginx → back to Agent.
• Registry UI → (HTTP & WebSocket /ws/health_status) → Uvicorn app → serves HTML, JSON, WebSocket updates.
• Background task in Registry → polls each service’s /sse health endpoint → updates server_state.json → regenerates registry/nginx_mcp_revproxy.conf → triggers Nginx reload.
• MCP Servers → interact with external data sources (Polygon API, DBs, external APIs).
Architectural Patterns & Design Principles
• Microservices: Each MCP server is an independent Python service.
• Reverse-proxy pattern: Nginx routes based on path (/currenttime, /fininfo, etc.).
• MVC‐like Registry:
– Model: JSON metadata, server_state.json
– View: Jinja2 templates, static CSS, JS for WebSocket updates
– Controller: FastAPI endpoints, WebSocket endpoint, register/edit/toggle APIs
• Dynamic configuration: The Registry writes Nginx config fragments based on enabled/disabled services.
• Containerization & DevOps: Dockerfile, build_and_push.sh, CI workflows, .dockerignore.
• Event-driven updates: WebSockets for real-time UI updates on health status.