Backend Architecture
The MCP Gatekeeper backend is built with FastAPI and provides REST APIs, WebSocket support, and MCP server management.
Technology Stack
- Python 3.9+
- FastAPI - Async web framework
- SQLAlchemy - ORM for database operations
- SQLite - Local database storage
- Pydantic - Data validation
- httpx - HTTP client for proxy
Application Structure
app/
├── api/ # API route handlers
│ ├── agents.py
│ ├── http_servers.py
│ ├── agent_http_servers.py
│ ├── packages.py
│ ├── servers.py
│ ├── metrics.py
│ ├── logs.py
│ └── websocket.py
├── core/ # Core configuration
│ ├── config.py
│ ├── database.py
│ └── middleware.py
├── models/ # Database models
│ ├── server.py
│ ├── metric.py
│ ├── log.py
│ └── http_server.py
├── schemas/ # Pydantic schemas
├── services/ # Business logic
│ ├── mcp_client.py
│ ├── http_proxy.py
│ ├── package_manager.py
│ └── agent_config_scanner.py
└── main.py # Application entry point
Key Components
FastAPI Application
- Binds to
127.0.0.1:8000(localhost only) - Supports CORS for frontend at
localhost:5173 - Auto-generated OpenAPI docs at
/docs
Database Models
- Server: MCP server configurations
- Metric: Performance and usage metrics
- Log: Server execution logs
- HttpMcpServer: HTTP server configurations
- HttpServerMetric: HTTP proxy metrics
Services
- MCP Client: JSON-RPC communication with STDIO servers
- HTTP Proxy: Transparent proxy for HTTP MCP servers
- Package Manager: npm package installation
- Agent Config Scanner: Detects and modifies agent configs
Authentication
- Token-based auth via
X-MCPGK-Tokenheader - Default token:
dev-token-change-in-production - Configurable via environment variable
WebSocket
- Real-time metrics broadcasting
- Endpoint:
/api/ws/metrics - JSON message format
For API details, see API Reference.