|
| 1 | +# Project Overview |
| 2 | + |
| 3 | +## What this project is |
| 4 | + |
| 5 | +`contextforge-gateway-rs` is a Rust-based MCP (Model Context Protocol) gateway — the **dataplane** component of ContextForge. It acts as a scalable, secure proxy layer that routes AI tool calls from MCP clients to one or more backend MCP servers. |
| 6 | + |
| 7 | +It is paired with the external ContextForge control plane at [`IBM/mcp-context-forge`](https://github.com/IBM/mcp-context-forge). The two components have a strict division of responsibility: |
| 8 | + |
| 9 | +| Layer | Owns | |
| 10 | +| --- | --- | |
| 11 | +| **This repo (dataplane)** | Request routing, auth enforcement, backend fan-out, session ownership | |
| 12 | +| **Control plane** | IAM, UI, metrics storage, legacy MCP client compatibility | |
| 13 | + |
| 14 | +The dataplane must never take on control-plane concerns. |
| 15 | + |
| 16 | +## Goals and objectives |
| 17 | + |
| 18 | +- Provide a **production-grade, low-latency routing layer** between MCP clients and backend MCP servers. |
| 19 | +- Target **MCP protocol version `2026-07-28`** over Streamable HTTP as the sole downstream contract. |
| 20 | +- Enforce a clean **dataplane/control-plane boundary** — no IAM, UI, or metrics storage logic in this repo. |
| 21 | +- Keep config access behind the **`UserConfigStore` abstraction** (backed by Redis/MessagePack). |
| 22 | +- Remain in the right architectural shape during early development, prioritising correctness over backward compatibility. |
| 23 | + |
| 24 | +## Key stakeholders and users |
| 25 | + |
| 26 | +- **Platform teams** — deploy and operate the gateway as infrastructure. |
| 27 | +- **AI application developers** — use the gateway as the MCP proxy layer for their applications. |
| 28 | +- **Internal contributors** — engineers evolving the dataplane toward the `2026-07-28` protocol target. |
| 29 | + |
| 30 | +## Key modules and architecture |
| 31 | + |
| 32 | +The architecture book at [`docs/book/src/`](../../docs/book/src/) is the authoritative reference. Key pages: |
| 33 | + |
| 34 | +| Page | Covers | |
| 35 | +| --- | --- | |
| 36 | +| [`system-shape.md`](../../docs/book/src/system-shape.md) | Crate layout, pipeline shape, state ownership, module boundaries | |
| 37 | +| [`request-flow.md`](../../docs/book/src/request-flow.md) | Startup, middleware order, fan-out, response path | |
| 38 | +| [`mcp-routing-semantics.md`](../../docs/book/src/mcp-routing-semantics.md) | Backend prefix namespace and routing contract | |
| 39 | +| [`authentication-and-user-config.md`](../../docs/book/src/authentication-and-user-config.md) | JWT validation, config keying, cache behavior | |
| 40 | +| [`architectural-choices.md`](../../docs/book/src/architectural-choices.md) | Invariants and tradeoffs that must not change accidentally | |
| 41 | + |
| 42 | +**Crate structure:** |
| 43 | +- `contextforge-gateway-rs-lib` — all product/routing logic lives here. |
| 44 | +- Binary crate — thin entrypoint only. Dataplane logic must not accumulate here. |
| 45 | + |
| 46 | +**Key invariants:** |
| 47 | +- Redis/config access goes through `UserConfigStore` only — never leak Redis details into routing code. |
| 48 | +- The backend prefix naming contract must not change without updating merge logic, split logic, and tests. |
| 49 | +- When behavior on the hot path changes, the matching book page must be updated in the same change. |
| 50 | + |
| 51 | +## Active work (near-term) |
| 52 | + |
| 53 | +- **Protocol migration**: replacing all remaining legacy MCP paths (SSE transport, `initialize`/session shims) with `2026-07-28` equivalents over Streamable HTTP. |
| 54 | +- Legacy SSE transport and old session behavior are **being removed**, not maintained. Do not build new behavior on temporary shims. |
| 55 | +- New tests and examples should use `server/discover`, per-request client metadata, and protocol version `2026-07-28`. |
| 56 | + |
| 57 | +## System topology |
| 58 | + |
| 59 | +All external traffic enters through **nginx**, which fans out to either the dataplane or the control plane: |
| 60 | + |
| 61 | +```mermaid |
| 62 | +flowchart LR |
| 63 | + client(["client"]) --> nginx["nginx"] |
| 64 | + nginx --> dataplane["data-plane"] |
| 65 | + nginx --> controlplane["control-plane"] |
| 66 | + dataplane --> redis["redis"] |
| 67 | + controlplane --> redis |
| 68 | + controlplane --> postgres["postgres\n(via pgbouncer)"] |
| 69 | + dataplane --> fastts["fast_time_server"] |
| 70 | +``` |
| 71 | + |
| 72 | +### How the control plane publishes config to the dataplane |
| 73 | + |
| 74 | +The control plane and dataplane do **not** communicate over HTTP. Config is exchanged exclusively through Redis: |
| 75 | + |
| 76 | +1. The control plane runs **`dataplane_publisher.py`** — a publisher script that writes dataplane configuration (user config, backend definitions, etc.) into Redis. |
| 77 | +2. The dataplane reads that config from Redis via the **`UserConfigStore`** abstraction (MessagePack-encoded `UserConfig`). |
| 78 | + |
| 79 | +This means: |
| 80 | +- The dataplane is a **pure reader** of Redis config. It never writes back to the control-plane's Redis keys. |
| 81 | +- The control plane is the **sole writer** of dataplane config; the dataplane has no direct dependency on the control-plane process at runtime. |
| 82 | +- Config changes from the control plane are picked up by the dataplane through normal cache refresh / Redis reads — no restart or direct RPC required. |
| 83 | + |
| 84 | +### Per-component responsibilities |
| 85 | + |
| 86 | +| Component | Role | Persistence | |
| 87 | +| --- | --- | --- | |
| 88 | +| **nginx** | TLS termination, routing fan-out | — | |
| 89 | +| **dataplane** (`contextforge-gateway-rs`) | MCP routing, auth enforcement, fan-out to backends | Redis (read-only for config) | |
| 90 | +| **control-plane** (`IBM/mcp-context-forge`) | IAM, UI, metrics, legacy MCP clients, config publishing | Redis (write) + PostgreSQL (via pgbouncer) | |
| 91 | +| **redis** | Runtime config store, inter-component pub/sub channel | In-memory + persistence | |
| 92 | +| **postgres** (via pgbouncer) | Control-plane relational store | Durable | |
| 93 | +| **fast_time_server** | High-resolution time source used by the dataplane | — | |
| 94 | + |
| 95 | +## External dependencies and integration points |
| 96 | + |
| 97 | +- **Redis** — runtime config store (MessagePack-encoded `UserConfig`). Populated by `dataplane_publisher.py` on the control plane; read by the dataplane via `UserConfigStore`. |
| 98 | +- **Control plane** (`IBM/mcp-context-forge`) — owns legacy MCP client routes and publishes dataplane config via `dataplane_publisher.py`. Does not route through this dataplane at runtime. |
| 99 | +- **fast_time_server** — high-resolution time source consumed by the dataplane. |
| 100 | +- **Tokio + Axum** — fixed async runtime and web framework. |
0 commit comments