Architecture Overview
The MCP Gateway (ContextForge) is a production-grade gateway, proxy, and registry for Model Context Protocol (MCP) servers and A2A Agents. It acts as a unified entry point for tools, resources, prompts, and servers, federating local and remote nodes into a coherent MCP-compliant interface.
High-Level Architecture Summary
MCP Gateway (ContextForge) is a comprehensive production-grade gateway built on modern Python technologies with a performance-first approach. For a detailed visual diagram of the high-performance components (Rust-powered libraries, async patterns, caching layers, and Kubernetes scaling), see the Performance Architecture Diagram.
Design Diagrams
The following diagrams are generated by make docs and provide a quick visual reference for the codebase structure:
Core Technology Stack
1. Python FastAPI Application with Modern Stack
- Built with FastAPI (async web framework) for high-performance REST/JSON-RPC endpoints
- Uses Pydantic 2.11+ for runtime validation and Pydantic Settings for environment-based configuration
- Requires Python 3.11-3.13 with full async/await support throughout
- Deployed via Uvicorn (dev) or Gunicorn (production) ASGI servers
2. Multi-Database ORM Layer with SQLAlchemy 2.0
- SQLAlchemy 2.0 ORM with async support for database operations
- Supports PostgreSQL (via psycopg3), SQLite (default, file-based), and MariaDB/MySQL (via pymysql)
- Alembic for schema migrations and version control
- Connection pooling with configurable pool sizes (200 default), overflow (10), and recycling (3600s)
3. Multi-Transport Protocol Gateway
- Native MCP (Model Context Protocol) server implementation supporting protocol version 2025-03-26
- Transport mechanisms: HTTP/JSON-RPC, Server-Sent Events (SSE) with keepalive, WebSocket, stdio (for CLI integration), and streamable-HTTP
- JSON-RPC 2.0 compliant message handling with bidirectional communication
4. Federation & Registry Architecture
- Acts as an MCP Registry that federates multiple peer gateways
- Auto-discovery via mDNS/Zeroconf or manual configuration
- Redis-backed caching and federation for multi-cluster deployments (optional, can use memory or database caching)
- Health checking with configurable intervals (60s default) and failure thresholds
5. Virtual Server Composition System
- Wraps non-MCP REST/gRPC services as virtual MCP servers
- Composes tools, prompts, and resources from multiple backends into unified virtual servers
- Supports REST-to-MCP tool adaptation with automatic JSON Schema extraction
- Tool, resource, and prompt registries with versioning and rollback capabilities
6. Multi-Tenant RBAC & Authentication
- Email-based authentication with Argon2id password hashing (time_cost=3, memory_cost=65536 KiB)
- JWT authentication (HS256/RS256) with configurable expiration and audience verification
- SSO integration: GitHub OAuth, Google OAuth, Microsoft Entra ID, IBM Security Verify, Okta, Keycloak, generic OIDC
- OAuth 2.0 with Dynamic Client Registration (DCR) per RFC 7591 and RFC 8414 discovery
- Teams and RBAC: Personal teams, team invitations, role-based permissions (global/team/personal scopes)
7. Plugin Framework
- Extensible plugin system with pre/post request/response hooks
- Built-in plugins: PII filter, deny filter, regex filter, resource filter
- Plugin configuration via YAML with hot-reload support
- CLI tools for plugin management (
mcpplugins command)
8. Admin UI & Observability
- HTMX + Alpine.js web UI for real-time management and configuration
- Real-time log viewer with filtering, search, and export (in-memory buffer with 1MB default size)
- OpenTelemetry observability with support for Jaeger, Zipkin, Phoenix, and OTLP backends
- Support bundle generation for troubleshooting (logs, config, system stats - auto-sanitized)
9. Agent-to-Agent (A2A) Integration
- Integrates external AI agents (OpenAI, Anthropic, custom) as tools within virtual servers
- Auto-tool creation for associated A2A agents with invocation routing
- Comprehensive metrics collection for agent interactions
- Configurable timeouts (30s default), retries (3 max), and agent limits (100 max)
10. Security & Rate Limiting
- Configurable authentication schemes: Basic Auth, JWT Bearer, custom headers
- Rate limiting with configurable tool rate limits (100 req/min default) and concurrent limits (10)
- Security headers (HSTS, X-Frame-Options, CSP, X-Content-Type-Options, X-XSS-Protection, Referrer-Policy), CORS with domain whitelisting
- Input validation with JSON Schema, length limits, and dangerous pattern detection
- mTLS support for plugin client-server communication
11. Resource & Content Management
- URI-based resource access with MIME detection and content negotiation
- Resource caching (1000 items, 3600s TTL) with size limits (10MB default)
- Support for text, markdown, HTML, JSON, XML, images (PNG/JPEG/GIF)
- Jinja2 template rendering for prompts with multimodal support
12. Development & Testing Infrastructure
- Comprehensive test suite: unit, integration, e2e, security, fuzz, Playwright UI tests
- VS Code Dev Container support with pre-configured environment
- Hot-reload development mode with debug logging
- Extensive linting: Black, isort, Ruff, Flake8, Bandit, Pylint, mypy (strict mode)
- Coverage tracking with HTML reports and pytest-cov integration
13. Deployment & Scalability
- Docker/Podman container images with rootless support
- Kubernetes-ready with Redis-backed federation for multi-cluster deployments
- IBM Cloud Code Engine deployment automation via Makefile targets
- Environment-based configuration (
.env files) with 100+ configurable parameters
- Production-ready logging (JSON/text formats) with rotation support
14. Well-Known URI & Standards Compliance
- Implements
.well-known/mcp endpoint for MCP discovery
- Configurable
robots.txt, security.txt, and custom well-known files
- Standards compliance: RFC 5424 (syslog), RFC 7591 (DCR), RFC 8414 (OAuth discovery), JSON-RPC 2.0
15. MCP Server Catalog & Service Discovery
- MCP Server Catalog feature for centralized server registry
- YAML-based catalog configuration with auto-health checking
- Pagination support (100 items/page default) with caching (3600s TTL)
Performance-Optimized Foundation
ContextForge leverages cutting-edge Rust-powered components for maximum throughput and minimal latency:
- orjson (Rust-Powered JSON Serialization): High-performance JSON parsing and serialization using Rust internals, delivering 5-6x faster serialization and 1.5-2x faster deserialization compared to Python's standard library, with 7% smaller output size. Enables sub-millisecond JSON-RPC responses even for large payloads.
- Pydantic V2 (Rust-Core Validation): Runtime validation and data serialization powered by Pydantic 2.11+ with its Rust-based pydantic-core engine, providing 5-50x performance improvements over Pydantic V1 for schema validation, type coercion, and model serialization.
- PyO3 Rust Plugins: Extensible plugin framework supporting Rust modules via PyO3, enabling native-speed Python extensions for performance-critical operations. Rust plugins provide near-native performance for compute-intensive tasks while integrating seamlessly with the Python ecosystem.
This performance-first architecture enables ContextForge to handle high-throughput workloads while maintaining low latency for tool invocations, resource access, and federation operations.
CI/CD Pipeline with GitHub Actions
Automated Quality Assurance & Security
The project maintains production-grade quality through comprehensive GitHub Actions workflows:
Build & Package Workflows:
- Python Package Build (
python-package.yml): Multi-version builds (Python 3.10-3.12) with wheel/sdist creation, metadata validation (twine), manifest checking, and package quality assessment (pyroma)
- Docker Release (
docker-release.yml): Automated container image releases to GitHub Container Registry (GHCR) with semantic versioning
Testing & Coverage:
- Tests & Coverage (
pytest.yml): Comprehensive test suite across Python 3.11-3.12 with pytest, branch coverage measurement (80% threshold), doctest validation (40% threshold), and coverage reporting
- Playwright UI Tests: End-to-end browser automation testing for admin UI workflows
Security Scanning:
- Bandit Security (
bandit.yml): Python static analysis for security vulnerabilities (MEDIUM+ severity, HIGH confidence), SARIF upload for GitHub Security tab, weekly scheduled scans
- CodeQL Advanced (
codeql.yml): Multi-language analysis (JavaScript/TypeScript, Python, GitHub Actions), security vulnerability detection, code quality checks, weekly scheduled scans (Wednesday 21:15 UTC)
- Dependency Review (
dependency-review.yml): Automated dependency vulnerability scanning on pull requests
Container Security:
Code Quality & Linting:
Deployment:
- IBM Cloud Code Engine (
ibm-cloud-code-engine.yml): Automated deployment to IBM Cloud with environment configuration and health checks
Key CI/CD Features:
- SARIF Integration: All security tools upload findings to GitHub Security tab for centralized vulnerability management
- Artifact Management: Build artifacts (wheels, coverage reports, SBOMs) uploaded and versioned
- Fail-Safe Design: Continue-on-error for non-blocking scans with final quality gates
- Scheduled Scans: Weekly security scans to catch newly disclosed CVEs
- Multi-Version Testing: Matrix builds across Python 3.10-3.13 to ensure compatibility
- Cache Optimization: Pip cache, BuildKit cache, and dependency caching for faster runs
This architecture supports both small single-instance deployments (SQLite + memory cache) and large-scale multi-cluster deployments (PostgreSQL + Redis + federation), making it suitable for development, staging, and production environments.
Deployment Flexibility: Why Not Envoy/Istio?
ContextForge is architected for maximum deployment flexibility, from standalone Python modules to multi-regional container orchestration. This design philosophy fundamentally differs from service mesh architectures like Envoy/Istio.
Modular Standalone Execution
The ContextForge ecosystem consists of independently deployable modules that can run standalone or be composed together:
Core Gateway:
mcp-contextforge-gateway-core - FastAPI gateway with 33 services, 11 routers (~150K lines)
mcp-contextforge-gateway-ui - HTMX + Alpine.js admin interface
Independent Utilities (Zero Gateway Dependencies):
mcp-contextforge-translate - Protocol bridge: stdio ↔ SSE ↔ HTTP ↔ gRPC
mcp-contextforge-wrapper - MCP client wrapper
mcp-contextforge-reverse-proxy - NAT/firewall traversal proxy
Plugin Ecosystem:
mcp-contextforge-plugins-python - 40+ Python plugins
mcp-contextforge-plugins-rust - High-performance PyO3 plugins
MCP Servers (Zero Gateway Dependencies):
Sample servers:
mcp-contextforge-mcp-servers-python - 4 Python servers
mcp-contextforge-mcp-servers-go - 5 Go servers (static binaries, 5-15 MB)
mcp-contextforge-mcp-servers-rust - Rust servers (static binaries, 3-10 MB)
Agent Runtimes:
Sample runtimes:
mcp-contextforge-agent-runtimes - LangChain + future runtimes
Infrastructure:
mcp-contextforge-helm - Kubernetes Helm charts (OCI registry)
mcp-contextforge-deployment-scripts - Terraform, Ansible, Docker Compose
Deployment Spectrum
Standalone Execution:
- Single Python module:
python -m mcpgateway
- CLI tools:
mcptranslate, mcpwrapper, mcpreverseproxy
- No external dependencies (SQLite + memory cache)
- Can be imported and embedded in other Python applications
Serverless-Native:
- IBM Cloud Code Engine (native deployment automation via Makefile)
- AWS Lambda (event-driven functions)
- Google Cloud Run (containerized serverless)
- Azure Container Apps
Container Orchestration:
- Kubernetes (vanilla, HPA, StatefulSets)
- Red Hat OpenShift (enterprise K8s)
- Docker Compose (local multi-container)
- Podman (rootless containers)
- Multi-arch container images (amd64, arm64, s390x, ppc64le)
Multi-Regional Deployments:
- Federation across geographic regions
- Redis Cluster for distributed caching
- PostgreSQL HA with replication
- Multi-cluster service mesh (optional)
Why This Matters: Envoy/Istio Comparison
Envoy/Istio Service Mesh Requires:
- Container infrastructure (no standalone mode)
- Kubernetes control plane (overhead for simple deployments)
- Service mesh complexity (sidecar injection, mTLS configuration)
- External proxy layer (additional network hop, increased latency)
- Minimum resource overhead (sidecar per pod)
ContextForge Provides:
- Built-in proxy/gateway capabilities - No external proxy needed
- Application-level MCP routing - Protocol-aware, not just HTTP
- Embedded observability - OpenTelemetry, Prometheus built-in
- Native compression and caching - No sidecar required (Brotli/Zstd/GZip)
- Zero-infrastructure dev mode - SQLite + memory cache
- Modular composition - 14 independently deployable modules
- Multi-format packaging - PyPI packages, container images with multi-arch support, Helm charts, and binaries
When to Use What
Use Envoy/Istio When:
- You need advanced service mesh features across ALL services (mutual TLS, canary deployments, complex traffic routing)
- You have existing service mesh infrastructure
- You're running polyglot microservices requiring unified traffic management
- Compliance requires external traffic control
Use ContextForge Standalone When:
- Lightweight MCP gateway without infrastructure overhead
- Development, testing, serverless deployments
- Edge deployments with minimal resources
- Embedded use cases (Python application integration)
- Single-node or small-scale deployments
Use Both Together When:
- Running in enterprise Kubernetes with service mesh requirements
- ContextForge modules handle MCP protocol concerns
- Envoy/Istio handle infrastructure concerns (mTLS, observability, traffic routing)
- Example: ContextForge gateway behind Istio ingress with mTLS between services
Modular Composition with Envoy
Each ContextForge module can integrate with Envoy independently:
# Example: ContextForge Translate + Envoy
apiVersion: v1
kind: Service
metadata:
name: mcp-translate
spec:
selector:
app: mcp-translate
---
# Envoy handles external mTLS, rate limiting, load balancing
# ContextForge Translate handles MCP protocol bridging
The key architectural decision is application-level intelligence (MCP-aware routing, tool invocation, resource management) embedded in ContextForge modules, not delegated to infrastructure proxies. This enables:
- Protocol intelligence: MCP-specific routing, federation, tool registry
- Deployment flexibility: From
python -m mcpgateway to multi-regional K8s
- Packaging options: PyPI, containers, binaries, Helm charts
- Optional composition: Works standalone OR with Envoy/Istio when needed
This architecture supports both small single-instance deployments (SQLite + memory cache) and large-scale multi-cluster deployments (PostgreSQL + Redis + federation), making it suitable for development, staging, and production environments.
System Architecture
graph TD
subgraph Clients
ui["Admin UI (Browser)"]
cli["CLI Tools"]
sdk["SDK / Scripts"]
end
subgraph Gateway
app["FastAPI App"]
auth["Auth Middleware<br/>(JWT + Basic)"]
router["Transport Router<br/>(HTTP / WS / SSE / stdio / streamable-HTTP)"]
services["Service Layer<br/>(Tool / Resource / Prompt / Server)"]
db["Async DB<br/>(SQLAlchemy + Alembic)"]
cache["Cache Backend<br/>(memory / redis / db)"]
metrics["Metrics API<br/>(/metrics, admin-only)"]
end
subgraph Federation
discovery["Federation Sync<br/>(configured peers)"]
peers["Remote Gateways"]
end
ui --> app
cli --> router
sdk --> router
app --> auth --> router
router --> services
services --> db
services --> cache
services --> metrics
services --> discovery
discovery --> peers
Each service (ToolService, ResourceService, etc.) operates independently with unified auth/session/context layers.
Additional Architecture Documentation
- Export/Import System Architecture - Technical design of configuration management system
- Plugin Framework Specification - Technical design of the gateway plugin system
ADRs and Design Decisions
We maintain a formal set of Architecture Decision Records documenting all major design tradeoffs and rationale.
📜 See the full ADR Index →
1---2name: architecture-overview-153description: The MCP Gateway (ContextForge) is a production-grade gateway, proxy, and registry for Model Context Protocol (MCP) servers and A2A Agents.4---5# Architecture Overview67The **MCP Gateway** (ContextForge) is a production-grade gateway, proxy, and registry for Model Context Protocol (MCP) servers and A2A Agents. It acts as a unified entry point for tools, resources, prompts, and servers, federating local and remote nodes into a coherent MCP-compliant interface.89## High-Level Architecture Summary1011**MCP Gateway (ContextForge)** is a comprehensive production-grade gateway built on modern Python technologies with a performance-first approach. For a detailed visual diagram of the high-performance components (Rust-powered libraries, async patterns, caching layers, and Kubernetes scaling), see the [Performance Architecture Diagram](performance-architecture.md).1213## Design Diagrams1415The following diagrams are generated by `make docs` and provide a quick visual reference for the codebase structure:161718192021### Core Technology Stack2223**1. Python FastAPI Application with Modern Stack**2425- Built with **FastAPI** (async web framework) for high-performance REST/JSON-RPC endpoints26- Uses **Pydantic 2.11+** for runtime validation and **Pydantic Settings** for environment-based configuration27- Requires **Python 3.11-3.13** with full async/await support throughout28- Deployed via **Uvicorn** (dev) or **Gunicorn** (production) ASGI servers2930**2. Multi-Database ORM Layer with SQLAlchemy 2.0**3132- **SQLAlchemy 2.0** ORM with async support for database operations33- Supports **PostgreSQL** (via psycopg3), **SQLite** (default, file-based), and **MariaDB/MySQL** (via pymysql)34- **Alembic** for schema migrations and version control35- Connection pooling with configurable pool sizes (200 default), overflow (10), and recycling (3600s)3637**3. Multi-Transport Protocol Gateway**3839- Native **MCP (Model Context Protocol)** server implementation supporting protocol version 2025-03-2640- Transport mechanisms: **HTTP/JSON-RPC**, **Server-Sent Events (SSE)** with keepalive, **WebSocket**, **stdio** (for CLI integration), and **streamable-HTTP**41- JSON-RPC 2.0 compliant message handling with bidirectional communication4243**4. Federation & Registry Architecture**4445- Acts as an **MCP Registry** that federates multiple peer gateways46- **Auto-discovery** via mDNS/Zeroconf or manual configuration47- **Redis-backed caching and federation** for multi-cluster deployments (optional, can use memory or database caching)48- Health checking with configurable intervals (60s default) and failure thresholds4950**5. Virtual Server Composition System**5152- Wraps non-MCP REST/gRPC services as **virtual MCP servers**53- Composes tools, prompts, and resources from multiple backends into unified virtual servers54- Supports REST-to-MCP tool adaptation with automatic JSON Schema extraction55- Tool, resource, and prompt registries with versioning and rollback capabilities5657**6. Multi-Tenant RBAC & Authentication**5859- **Email-based authentication** with **Argon2id** password hashing (time_cost=3, memory_cost=65536 KiB)60- **JWT authentication** (HS256/RS256) with configurable expiration and audience verification61- **SSO integration**: GitHub OAuth, Google OAuth, Microsoft Entra ID, IBM Security Verify, Okta, Keycloak, generic OIDC62- **OAuth 2.0 with Dynamic Client Registration (DCR)** per RFC 7591 and RFC 8414 discovery63- **Teams and RBAC**: Personal teams, team invitations, role-based permissions (global/team/personal scopes)6465**7. Plugin Framework**6667- Extensible plugin system with pre/post request/response hooks68- Built-in plugins: PII filter, deny filter, regex filter, resource filter69- Plugin configuration via YAML with hot-reload support70- CLI tools for plugin management (`mcpplugins` command)7172**8. Admin UI & Observability**7374- **HTMX + Alpine.js** web UI for real-time management and configuration75- Real-time log viewer with filtering, search, and export (in-memory buffer with 1MB default size)76- **OpenTelemetry observability** with support for Jaeger, Zipkin, Phoenix, and OTLP backends77- Support bundle generation for troubleshooting (logs, config, system stats - auto-sanitized)7879**9. Agent-to-Agent (A2A) Integration**8081- Integrates external AI agents (OpenAI, Anthropic, custom) as tools within virtual servers82- Auto-tool creation for associated A2A agents with invocation routing83- Comprehensive metrics collection for agent interactions84- Configurable timeouts (30s default), retries (3 max), and agent limits (100 max)8586**10. Security & Rate Limiting**8788- Configurable authentication schemes: Basic Auth, JWT Bearer, custom headers89- Rate limiting with configurable tool rate limits (100 req/min default) and concurrent limits (10)90- Security headers (HSTS, X-Frame-Options, CSP, X-Content-Type-Options, X-XSS-Protection, Referrer-Policy), CORS with domain whitelisting91- Input validation with JSON Schema, length limits, and dangerous pattern detection92- mTLS support for plugin client-server communication9394**11. Resource & Content Management**9596- URI-based resource access with MIME detection and content negotiation97- Resource caching (1000 items, 3600s TTL) with size limits (10MB default)98- Support for text, markdown, HTML, JSON, XML, images (PNG/JPEG/GIF)99- **Jinja2 template rendering** for prompts with multimodal support100101**12. Development & Testing Infrastructure**102103- Comprehensive test suite: unit, integration, e2e, security, fuzz, Playwright UI tests104- **VS Code Dev Container** support with pre-configured environment105- Hot-reload development mode with debug logging106- Extensive linting: Black, isort, Ruff, Flake8, Bandit, Pylint, mypy (strict mode)107- Coverage tracking with HTML reports and pytest-cov integration108109**13. Deployment & Scalability**110111- **Docker/Podman container images** with rootless support112- **Kubernetes-ready** with Redis-backed federation for multi-cluster deployments113- **IBM Cloud Code Engine** deployment automation via Makefile targets114- Environment-based configuration (`.env` files) with 100+ configurable parameters115- Production-ready logging (JSON/text formats) with rotation support116117**14. Well-Known URI & Standards Compliance**118119- Implements `.well-known/mcp` endpoint for MCP discovery120- Configurable `robots.txt`, `security.txt`, and custom well-known files121- Standards compliance: RFC 5424 (syslog), RFC 7591 (DCR), RFC 8414 (OAuth discovery), JSON-RPC 2.0122123**15. MCP Server Catalog & Service Discovery**124125- **MCP Server Catalog** feature for centralized server registry126- YAML-based catalog configuration with auto-health checking127- Pagination support (100 items/page default) with caching (3600s TTL)128129### Performance-Optimized Foundation130131ContextForge leverages cutting-edge Rust-powered components for maximum throughput and minimal latency:132133- **orjson (Rust-Powered JSON Serialization)**: High-performance JSON parsing and serialization using Rust internals, delivering 5-6x faster serialization and 1.5-2x faster deserialization compared to Python's standard library, with 7% smaller output size. Enables sub-millisecond JSON-RPC responses even for large payloads.134- **Pydantic V2 (Rust-Core Validation)**: Runtime validation and data serialization powered by Pydantic 2.11+ with its Rust-based pydantic-core engine, providing 5-50x performance improvements over Pydantic V1 for schema validation, type coercion, and model serialization.135- **PyO3 Rust Plugins**: Extensible plugin framework supporting Rust modules via PyO3, enabling native-speed Python extensions for performance-critical operations. Rust plugins provide near-native performance for compute-intensive tasks while integrating seamlessly with the Python ecosystem.136137This performance-first architecture enables ContextForge to handle high-throughput workloads while maintaining low latency for tool invocations, resource access, and federation operations.138139### CI/CD Pipeline with GitHub Actions140141**Automated Quality Assurance & Security**142143The project maintains production-grade quality through comprehensive GitHub Actions workflows:144145**Build & Package Workflows:**146147- **Python Package Build** (`python-package.yml`): Multi-version builds (Python 3.10-3.12) with wheel/sdist creation, metadata validation (twine), manifest checking, and package quality assessment (pyroma)148- **Docker Release** (`docker-release.yml`): Automated container image releases to GitHub Container Registry (GHCR) with semantic versioning149150**Testing & Coverage:**151152- **Tests & Coverage** (`pytest.yml`): Comprehensive test suite across Python 3.11-3.12 with pytest, branch coverage measurement (80% threshold), doctest validation (40% threshold), and coverage reporting153- **Playwright UI Tests**: End-to-end browser automation testing for admin UI workflows154155**Security Scanning:**156157- **Bandit Security** (`bandit.yml`): Python static analysis for security vulnerabilities (MEDIUM+ severity, HIGH confidence), SARIF upload for GitHub Security tab, weekly scheduled scans158- **CodeQL Advanced** (`codeql.yml`): Multi-language analysis (JavaScript/TypeScript, Python, GitHub Actions), security vulnerability detection, code quality checks, weekly scheduled scans (Wednesday 21:15 UTC)159- **Dependency Review** (`dependency-review.yml`): Automated dependency vulnerability scanning on pull requests160161**Container Security:**162163- **Secure Docker Build** (`docker-image.yml`):164165 - Dockerfile linting with **Hadolint** (SARIF reports)166 - Image linting with **Dockle** (SARIF reports)167 - SBOM generation with **Syft** (SPDX format)168 - Vulnerability scanning with **Trivy** and **Grype** (CRITICAL CVEs)169 - Image signing and attestation with **Cosign** (keyless OIDC)170 - BuildKit layer caching for faster rebuilds171 - Weekly scheduled scans (Tuesday 18:17 UTC)172173**Code Quality & Linting:**174175- **Lint & Static Analysis** (`lint.yml`): Comprehensive multi-tool linting matrix176177 - **Syntax & Format**: yamllint, JSON validation (jq), TOML validation (tomlcheck)178 - **Python Analysis**: Flake8, Ruff, Unimport, Vulture (dead code), Pylint (errors-only), Interrogate (100% docstring coverage), Radon (complexity metrics)179 - **Web Assets**: HTML/CSS/JS linting (`lint-web.yml`)180 - Each linter runs in isolated matrix jobs for fast-fail visibility181182**Deployment:**183184- **IBM Cloud Code Engine** (`ibm-cloud-code-engine.yml`): Automated deployment to IBM Cloud with environment configuration and health checks185186**Key CI/CD Features:**187188- **SARIF Integration**: All security tools upload findings to GitHub Security tab for centralized vulnerability management189- **Artifact Management**: Build artifacts (wheels, coverage reports, SBOMs) uploaded and versioned190- **Fail-Safe Design**: Continue-on-error for non-blocking scans with final quality gates191- **Scheduled Scans**: Weekly security scans to catch newly disclosed CVEs192- **Multi-Version Testing**: Matrix builds across Python 3.10-3.13 to ensure compatibility193- **Cache Optimization**: Pip cache, BuildKit cache, and dependency caching for faster runs194195This architecture supports both small single-instance deployments (SQLite + memory cache) and large-scale multi-cluster deployments (PostgreSQL + Redis + federation), making it suitable for development, staging, and production environments.196197## Deployment Flexibility: Why Not Envoy/Istio?198199ContextForge is architected for **maximum deployment flexibility**, from standalone Python modules to multi-regional container orchestration. This design philosophy fundamentally differs from service mesh architectures like Envoy/Istio.200201### Modular Standalone Execution202203The ContextForge ecosystem consists of **independently deployable modules** that can run standalone or be composed together:204205**Core Gateway:**206207- `mcp-contextforge-gateway-core` - FastAPI gateway with 33 services, 11 routers (~150K lines)208- `mcp-contextforge-gateway-ui` - HTMX + Alpine.js admin interface209210**Independent Utilities (Zero Gateway Dependencies):**211212- `mcp-contextforge-translate` - Protocol bridge: stdio ↔ SSE ↔ HTTP ↔ gRPC213- `mcp-contextforge-wrapper` - MCP client wrapper214- `mcp-contextforge-reverse-proxy` - NAT/firewall traversal proxy215216**Plugin Ecosystem:**217218- `mcp-contextforge-plugins-python` - 40+ Python plugins219- `mcp-contextforge-plugins-rust` - High-performance PyO3 plugins220221**MCP Servers (Zero Gateway Dependencies):**222223Sample servers:224225- `mcp-contextforge-mcp-servers-python` - 4 Python servers226- `mcp-contextforge-mcp-servers-go` - 5 Go servers (static binaries, 5-15 MB)227- `mcp-contextforge-mcp-servers-rust` - Rust servers (static binaries, 3-10 MB)228229**Agent Runtimes:**230231Sample runtimes:232233- `mcp-contextforge-agent-runtimes` - LangChain + future runtimes234235**Infrastructure:**236237- `mcp-contextforge-helm` - Kubernetes Helm charts (OCI registry)238- `mcp-contextforge-deployment-scripts` - Terraform, Ansible, Docker Compose239240### Deployment Spectrum241242**Standalone Execution:**243244- Single Python module: `python -m mcpgateway`245- CLI tools: `mcptranslate`, `mcpwrapper`, `mcpreverseproxy`246- No external dependencies (SQLite + memory cache)247- Can be imported and embedded in other Python applications248249**Serverless-Native:**250251- **IBM Cloud Code Engine** (native deployment automation via Makefile)252- **AWS Lambda** (event-driven functions)253- **Google Cloud Run** (containerized serverless)254- **Azure Container Apps**255256**Container Orchestration:**257258- **Kubernetes** (vanilla, HPA, StatefulSets)259- **Red Hat OpenShift** (enterprise K8s)260- **Docker Compose** (local multi-container)261- **Podman** (rootless containers)262- Multi-arch container images (amd64, arm64, s390x, ppc64le)263264**Multi-Regional Deployments:**265266- Federation across geographic regions267- Redis Cluster for distributed caching268- PostgreSQL HA with replication269- Multi-cluster service mesh (optional)270271### Why This Matters: Envoy/Istio Comparison272273**Envoy/Istio Service Mesh Requires:**274275- Container infrastructure (no standalone mode)276- Kubernetes control plane (overhead for simple deployments)277- Service mesh complexity (sidecar injection, mTLS configuration)278- External proxy layer (additional network hop, increased latency)279- Minimum resource overhead (sidecar per pod)280281**ContextForge Provides:**282283- **Built-in proxy/gateway capabilities** - No external proxy needed284- **Application-level MCP routing** - Protocol-aware, not just HTTP285- **Embedded observability** - OpenTelemetry, Prometheus built-in286- **Native compression and caching** - No sidecar required (Brotli/Zstd/GZip)287- **Zero-infrastructure dev mode** - SQLite + memory cache288- **Modular composition** - 14 independently deployable modules289- **Multi-format packaging** - PyPI packages, container images with multi-arch support, Helm charts, and binaries290291### When to Use What292293**Use Envoy/Istio When:**294295- You need advanced service mesh features across ALL services (mutual TLS, canary deployments, complex traffic routing)296- You have existing service mesh infrastructure297- You're running polyglot microservices requiring unified traffic management298- Compliance requires external traffic control299300**Use ContextForge Standalone When:**301302- Lightweight MCP gateway without infrastructure overhead303- Development, testing, serverless deployments304- Edge deployments with minimal resources305- Embedded use cases (Python application integration)306- Single-node or small-scale deployments307308**Use Both Together When:**309310- Running in enterprise Kubernetes with service mesh requirements311- ContextForge modules handle MCP protocol concerns312- Envoy/Istio handle infrastructure concerns (mTLS, observability, traffic routing)313- Example: ContextForge gateway behind Istio ingress with mTLS between services314315### Modular Composition with Envoy316317Each ContextForge module can integrate with Envoy independently:318319```yaml320# Example: ContextForge Translate + Envoy321apiVersion: v1322kind: Service323metadata:324 name: mcp-translate325spec:326 selector:327 app: mcp-translate328---329# Envoy handles external mTLS, rate limiting, load balancing330# ContextForge Translate handles MCP protocol bridging331```332333The key architectural decision is **application-level intelligence** (MCP-aware routing, tool invocation, resource management) embedded in ContextForge modules, not delegated to infrastructure proxies. This enables:3343351. **Protocol intelligence**: MCP-specific routing, federation, tool registry3362. **Deployment flexibility**: From `python -m mcpgateway` to multi-regional K8s3373. **Packaging options**: PyPI, containers, binaries, Helm charts3384. **Optional composition**: Works standalone OR with Envoy/Istio when needed339340This architecture supports both small single-instance deployments (SQLite + memory cache) and large-scale multi-cluster deployments (PostgreSQL + Redis + federation), making it suitable for development, staging, and production environments.341342## System Architecture343344```mermaid345graph TD346 subgraph Clients347 ui["Admin UI (Browser)"]348 cli["CLI Tools"]349 sdk["SDK / Scripts"]350 end351352 subgraph Gateway353 app["FastAPI App"]354 auth["Auth Middleware<br/>(JWT + Basic)"]355 router["Transport Router<br/>(HTTP / WS / SSE / stdio / streamable-HTTP)"]356 services["Service Layer<br/>(Tool / Resource / Prompt / Server)"]357 db["Async DB<br/>(SQLAlchemy + Alembic)"]358 cache["Cache Backend<br/>(memory / redis / db)"]359 metrics["Metrics API<br/>(/metrics, admin-only)"]360 end361362 subgraph Federation363 discovery["Federation Sync<br/>(configured peers)"]364 peers["Remote Gateways"]365 end366367 ui --> app368 cli --> router369 sdk --> router370 app --> auth --> router371 router --> services372 services --> db373 services --> cache374 services --> metrics375 services --> discovery376 discovery --> peers377378```379380> Each service (ToolService, ResourceService, etc.) operates independently with unified auth/session/context layers.381382## Additional Architecture Documentation383384- [Export/Import System Architecture](export-import-architecture.md) - Technical design of configuration management system385- [Plugin Framework Specification](plugins.md) - Technical design of the gateway plugin system386387## ADRs and Design Decisions388389We maintain a formal set of [Architecture Decision Records](adr/index.md) documenting all major design tradeoffs and rationale.390391📜 See the [full ADR Index →](adr/index.md)