# qred/qred-mcp-proxy architecture

> Architecture diagram of the GitHub repository qred/qred-mcp-proxy, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/qred/qred-mcp-proxy
- Repository: https://github.com/qred/qred-mcp-proxy

## Overview

1. This repository is a three-layer MCP gateway system: an AWS/CDK infrastructure layer, a Python MCP proxy runtime, and a Python OAuth 2.1 sidecar. The design goal is to present clients with one secure MCP endpoint while hiding the complexity of multiple backend MCP servers and OAuth quirks.

2. The top-level control plane lives in `cdk/mcp-proxy/`, which is a TypeScript AWS CDK app. It defines the deployable infrastructure boundary: ECS services, load balancing, DNS, IAM roles, CloudWatch logging, and Secrets Manager wiring. The CDK stack is the deployment entrypoint for environment-specific configuration such as dev/staging/prod.

3. The main serving component is `docker/mcp_proxy/`. This is the aggregated MCP proxy server, implemented in Python, that sits in front of multiple backend MCP servers. It supports both HTTP and STDIO transports, which matters because different MCP clients connect through different protocols.

4. Inside the proxy service, the architecture is split into server-facing logic and support utilities. The `server/` modules handle request routing, aggregation, OAuth-aware client handling, and server lifecycle concerns. The `utils/` modules handle configuration loading, health checks, startup mitigation, and logging. This indicates the proxy is not just a pass-through; it actively manages backend reachability and startup behavior.

5. The proxy’s core data flow is: MCP client connects to the proxy endpoint, the proxy authenticates the caller, then forwards or aggregates requests to one or more configured backend MCP services. The `servers.json` configuration in the Docker image and the example config under `cdk/mcp-proxy/config/` define which backend servers are exposed through the gateway.

6. Authentication is separated into a dedicated sidecar in `docker/mcp_oauth/`. This service provides OAuth 2.1 discovery, Dynamic Client Registration, callback forwarding for localhost-based clients, and token validation. The sidecar exists specifically to normalize client behavior across MCP clients with uneven OAuth support.

7. The OAuth sidecar’s external dependency boundary is Google Workspace / Google OAuth. The README shows it relies on Google OAuth client credentials, Workspace domain restrictions, and Google Workload Identity Federation. In practice, this means the service authenticates users through Google, validates membership/identity, and then lets the proxy enforce access to the MCP layer.

8. There is also a cross-cloud trust boundary: AWS hosts the runtime, while GCP provides identity and API permissions. The repo’s configuration and documentation emphasize Workload Identity Federation so the AWS ECS task can securely access Google resources without long-lived Google service account keys.

9. The runtime deployment model is container-based. Both services have Dockerfiles and build scripts, and the CDK references container images likely pushed to ECR. This makes ECS the operational unit, with the proxy and OAuth sidecar running as separate containers in the same AWS deployment footprint.

10. Secrets and configuration are intentionally externalized. AWS Secrets Manager stores Google OAuth credentials, Google WIF JSON, and optional upstream API keys for supported MCP backends. This keeps sensitive identity and backend credentials out of image builds and source-controlled config.

11. Client configuration is treated as a separate enterprise distribution concern. The `client-config/deployment/` scripts automate rollout of a single MCP proxy URL into desktop and IDE clients, which reinforces the repository’s “one endpoint for many clients” model rather than per-service client setup.

12. The repository also includes a meaningful testing boundary. `tests/oauth/` covers OAuth endpoints, token validation, refresh behavior, and performance, while `tests/proxy/` covers config loading, lifecycle, and advanced proxy configuration. The CI workflow under `.github/workflows/tests.yml` indicates these components are tested separately, matching the service split in the architecture.

13. At a high level, the architecture diagram should show: MCP clients at the edge; OAuth discovery/DCR flow through the sidecar; authenticated traffic into the MCP proxy; proxy fan-out to multiple backend MCP servers; and AWS/GCP as the operational and identity backplanes supporting the system.

Main entry points: [`cdk/mcp-proxy/lib/mcp-proxy.ts`](https://github.com/qred/qred-mcp-proxy/blob/main/cdk/mcp-proxy/lib/mcp-proxy.ts) (MCP stack), [`docker/mcp_proxy/mcp_proxy/server/proxy_server.py`](https://github.com/qred/qred-mcp-proxy/blob/main/docker/mcp_proxy/mcp_proxy/server/proxy_server.py) (Proxy routing), [`docker/mcp_oauth/mcp_oauth/__main__.py`](https://github.com/qred/qred-mcp-proxy/blob/main/docker/mcp_oauth/mcp_oauth/__main__.py) (OAuth sidecar), [`docker/mcp_proxy/mcp_proxy/__main__.py`](https://github.com/qred/qred-mcp-proxy/blob/main/docker/mcp_proxy/mcp_proxy/__main__.py) (Proxy service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_g_control["Control plane"]
  node_cdk_app["CDK app<br/>infrastructure app<br/>[mcp-proxy.ts]"]
  node_cdk_stack["MCP stack<br/>infrastructure stack<br/>[mcp-proxy.ts]"]
  node_service_construct["Service construct<br/>cdk construct<br/>[service.ts]"]
  node_volume_constructs["Volume wiring<br/>cdk construct<br/>[volumes.ts]"]
  node_config_types["Config types<br/>cdk types<br/>[config.ts]"]
end

subgraph group_g_runtime["Runtime services"]
  node_proxy_main["Proxy service<br/>python runtime<br/>[__main__.py]"]
  node_proxy_server["Proxy routing<br/>server logic<br/>[proxy_server.py]"]
  node_aggregated_proxy["Aggregator<br/>fan-out layer"]
  node_oauth_client["OAuth client<br/>auth-aware client<br/>[oauth_client.py]"]
  node_proxy_utils["Proxy utils<br/>support modules<br/>[config_loader.py]"]
  node_oauth_main["OAuth sidecar<br/>python service<br/>[__main__.py]"]
  node_oauth_server["OAuth server<br/>auth service<br/>[server.py]"]
  node_token_validation["Token validation<br/>validation logic"]
  node_wif_module["WIF module<br/>gcp integration<br/>[google_wif.py]"]
end

subgraph group_g_external["External systems"]
  node_clients(("MCP clients<br/>edge clients"))
  node_proxy_public(("Proxy endpoint<br/>entrypoint"))
  node_backend_servers[("Backend MCPs<br/>upstream services")]
  node_google_idp(("Google OAuth<br/>identity provider"))
  node_aws_platform(("AWS runtime<br/>cloud platform"))
  node_gcp_identity(("Google WIF<br/>trust bridge"))
end

subgraph group_g_distribution["Client rollout"]
  node_client_rollout["Client rollout<br/>deployment script"]
end

node_cdk_app -->|"deploys"| node_cdk_stack
node_cdk_stack -->|"uses"| node_service_construct
node_cdk_stack -->|"wires"| node_volume_constructs
node_cdk_stack -->|"typed by"| node_config_types
node_cdk_stack -->|"runs on"| node_aws_platform
node_cdk_stack -->|"trusts"| node_gcp_identity
node_service_construct -->|"exposes"| node_proxy_public
node_proxy_public -->|"serves"| node_clients
node_client_rollout -->|"configures"| node_clients
node_clients -->|"discovers auth"| node_oauth_server
node_oauth_server -->|"authenticates"| node_google_idp
node_oauth_main -->|"validates"| node_token_validation
node_oauth_main -->|"federates"| node_wif_module
node_oauth_main -->|"forwards"| node_proxy_public
node_proxy_public -->|"routes to"| node_proxy_main
node_proxy_main -->|"boots"| node_proxy_server
node_proxy_server -->|"coordinates"| node_aggregated_proxy
node_proxy_server -->|"authenticates"| node_oauth_client
node_proxy_server -->|"depends on"| node_proxy_utils
node_aggregated_proxy -->|"fans out to"| node_backend_servers
node_oauth_client -->|"calls"| node_backend_servers
node_proxy_utils -->|"loads config for"| node_backend_servers
node_cdk_stack -.->|"packages"| node_proxy_main
node_cdk_stack -.->|"packages"| node_oauth_main

click node_cdk_app "https://github.com/qred/qred-mcp-proxy/blob/main/cdk/mcp-proxy/bin/mcp-proxy.ts"
click node_cdk_stack "https://github.com/qred/qred-mcp-proxy/blob/main/cdk/mcp-proxy/lib/mcp-proxy.ts"
click node_service_construct "https://github.com/qred/qred-mcp-proxy/blob/main/cdk/mcp-proxy/lib/constructs/service.ts"
click node_volume_constructs "https://github.com/qred/qred-mcp-proxy/blob/main/cdk/mcp-proxy/lib/constructs/volumes.ts"
click node_config_types "https://github.com/qred/qred-mcp-proxy/blob/main/cdk/mcp-proxy/lib/types/config.ts"
click node_client_rollout "https://github.com/qred/qred-mcp-proxy/blob/main/client-config/deployment/mcp-config-deployment.sh"
click node_proxy_main "https://github.com/qred/qred-mcp-proxy/blob/main/docker/mcp_proxy/mcp_proxy/__main__.py"
click node_proxy_server "https://github.com/qred/qred-mcp-proxy/blob/main/docker/mcp_proxy/mcp_proxy/server/proxy_server.py"
click node_aggregated_proxy "https://github.com/qred/qred-mcp-proxy/blob/main/docker/mcp_proxy/mcp_proxy/server/aggregated_proxy_server.py"
click node_oauth_client "https://github.com/qred/qred-mcp-proxy/blob/main/docker/mcp_proxy/mcp_proxy/server/oauth_client.py"
click node_proxy_utils "https://github.com/qred/qred-mcp-proxy/blob/main/docker/mcp_proxy/mcp_proxy/utils/config_loader.py"
click node_oauth_main "https://github.com/qred/qred-mcp-proxy/blob/main/docker/mcp_oauth/mcp_oauth/__main__.py"
click node_oauth_server "https://github.com/qred/qred-mcp-proxy/blob/main/docker/mcp_oauth/mcp_oauth/server.py"
click node_token_validation "https://github.com/qred/qred-mcp-proxy/blob/main/docker/mcp_oauth/mcp_oauth/token_validation.py"
click node_wif_module "https://github.com/qred/qred-mcp-proxy/blob/main/docker/mcp_oauth/mcp_oauth/gcp/google_wif.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cdk_app,node_cdk_stack,node_service_construct,node_volume_constructs,node_config_types toneBlue
class node_proxy_main,node_proxy_server,node_aggregated_proxy,node_oauth_client,node_proxy_utils,node_oauth_main,node_oauth_server,node_token_validation,node_wif_module toneAmber
class node_clients,node_proxy_public,node_backend_servers,node_google_idp,node_aws_platform,node_gcp_identity toneMint
class node_client_rollout toneRose
```

## Components

### Control plane

CDK deployment boundary and environment wiring

- [CDK app](https://github.com/qred/qred-mcp-proxy/blob/main/cdk/mcp-proxy/bin/mcp-proxy.ts): infrastructure app · AWS CDK deployment entrypoint and environment selection · `cdk/mcp-proxy/bin/mcp-proxy.ts`
- [MCP stack](https://github.com/qred/qred-mcp-proxy/blob/main/cdk/mcp-proxy/lib/mcp-proxy.ts): infrastructure stack · Defines ECS, load balancing, DNS, IAM, logging, and secrets wiring · `cdk/mcp-proxy/lib/mcp-proxy.ts`
- [Service construct](https://github.com/qred/qred-mcp-proxy/blob/main/cdk/mcp-proxy/lib/constructs/service.ts): cdk construct · Reusable ECS/service wiring and deployment composition · `cdk/mcp-proxy/lib/constructs/service.ts`
- [Volume wiring](https://github.com/qred/qred-mcp-proxy/blob/main/cdk/mcp-proxy/lib/constructs/volumes.ts): cdk construct · Persistent storage and filesystem support for the deployment · `cdk/mcp-proxy/lib/constructs/volumes.ts`
- [Config types](https://github.com/qred/qred-mcp-proxy/blob/main/cdk/mcp-proxy/lib/types/config.ts): cdk types · Typed configuration and interface definitions for the stack · `cdk/mcp-proxy/lib/types/config.ts`

### Runtime services

Containerized MCP proxy and OAuth sidecar

- [Proxy service](https://github.com/qred/qred-mcp-proxy/blob/main/docker/mcp_proxy/mcp_proxy/__main__.py): python runtime · Aggregated MCP proxy server container · `docker/mcp_proxy/mcp_proxy/__main__.py`
- [Proxy routing](https://github.com/qred/qred-mcp-proxy/blob/main/docker/mcp_proxy/mcp_proxy/server/proxy_server.py): server logic · Request routing, transport handling, and proxy lifecycle · `docker/mcp_proxy/mcp_proxy/server/proxy_server.py`
- [Aggregator](https://github.com/qred/qred-mcp-proxy/blob/main/docker/mcp_proxy/mcp_proxy/server/aggregated_proxy_server.py): fan-out layer · Combines requests across multiple backend MCP servers · `docker/mcp_proxy/mcp_proxy/server/aggregated_proxy_server.py`
- [OAuth client](https://github.com/qred/qred-mcp-proxy/blob/main/docker/mcp_proxy/mcp_proxy/server/oauth_client.py): auth-aware client · Client-side handling for authenticated backend calls · `docker/mcp_proxy/mcp_proxy/server/oauth_client.py`
- [Proxy utils](https://github.com/qred/qred-mcp-proxy/blob/main/docker/mcp_proxy/mcp_proxy/utils/config_loader.py): support modules · Configuration loading, health checks, startup mitigation, and logging · `docker/mcp_proxy/mcp_proxy/utils/config_loader.py`
- [OAuth sidecar](https://github.com/qred/qred-mcp-proxy/blob/main/docker/mcp_oauth/mcp_oauth/__main__.py): python service · OAuth 2.1 discovery, DCR, callback forwarding, and token validation · `docker/mcp_oauth/mcp_oauth/__main__.py`
- [OAuth server](https://github.com/qred/qred-mcp-proxy/blob/main/docker/mcp_oauth/mcp_oauth/server.py): auth service · Discovery and callback handling for MCP clients · `docker/mcp_oauth/mcp_oauth/server.py`
- [Token validation](https://github.com/qred/qred-mcp-proxy/blob/main/docker/mcp_oauth/mcp_oauth/token_validation.py): validation logic · Validates access tokens and refresh behavior · `docker/mcp_oauth/mcp_oauth/token_validation.py`
- [WIF module](https://github.com/qred/qred-mcp-proxy/blob/main/docker/mcp_oauth/mcp_oauth/gcp/google_wif.py): gcp integration · Google Workload Identity Federation support · `docker/mcp_oauth/mcp_oauth/gcp/google_wif.py`

### External systems

Clients, backends, and identity providers

- **MCP clients**: edge clients · Desktop and IDE clients connecting to the gateway
- **Proxy endpoint**: entrypoint · Single exposed MCP endpoint for clients
- **Backend MCPs**: upstream services · Multiple configured MCP servers behind the gateway
- **Google OAuth**: identity provider · Google Workspace and OAuth boundary for user authentication
- **AWS runtime**: cloud platform · ECS, load balancing, IAM, logging, and secrets hosting
- **Google WIF**: trust bridge · Workload Identity Federation used by AWS tasks to access Google resources

### Client rollout

Scripts that distribute the shared MCP endpoint

- [Client rollout](https://github.com/qred/qred-mcp-proxy/blob/main/client-config/deployment/mcp-config-deployment.sh): deployment script · Automates distribution of the shared proxy URL to clients · `client-config/deployment/mcp-config-deployment.sh`

## Connections

- CDK app → MCP stack: deploys · CDK entrypoint instantiates the stack
- MCP stack → Service construct: uses · Stack composes ECS/service infrastructure
- MCP stack → Volume wiring: wires · Adds persistent storage and volume support
- MCP stack → Config types: typed by · Configuration and interfaces shape deployment options
- MCP stack → AWS runtime: runs on · Infrastructure is provisioned in AWS
- MCP stack → Google WIF: trusts · AWS runtime federates into Google identity
- Service construct → Proxy endpoint: exposes · Publishes the single MCP endpoint
- Proxy endpoint → MCP clients: serves · Clients connect to the gateway endpoint
- Client rollout → MCP clients: configures · Distributes the shared endpoint into desktop and IDE clients
- MCP clients → OAuth server: discovers auth · OAuth discovery and DCR flow starts at the sidecar
- OAuth server → Google OAuth: authenticates · Sidecar delegates user identity to Google
- OAuth sidecar → Token validation: validates · OAuth sidecar verifies tokens and refresh behavior
- OAuth sidecar → WIF module: federates · Sidecar supports Google workload identity federation
- OAuth sidecar → Proxy endpoint: forwards · Callback and auth completion feed the proxy boundary
- Proxy endpoint → Proxy service: routes to · Authenticated traffic enters the proxy runtime
- Proxy service → Proxy routing: boots · Main module starts the server runtime
- Proxy routing → Aggregator: coordinates · Proxy server uses aggregation for backend fan-out
- Proxy routing → OAuth client: authenticates · Server-facing logic uses OAuth-aware backend clients
- Proxy routing → Proxy utils: depends on · Runtime helpers manage config, health, and startup behavior
- Aggregator → Backend MCPs: fans out to · Requests are forwarded or aggregated across MCP backends
- OAuth client → Backend MCPs: calls · Authenticated backend interactions use the configured MCP servers
- Proxy utils → Backend MCPs: loads config for · Server definitions come from runtime configuration
- MCP stack → Proxy service: packages · Deployment builds the proxy container image into ECS
- MCP stack → OAuth sidecar: packages · Deployment builds the OAuth sidecar image into ECS
