Skip to content

Deployment & Hosting Architecture Overview ​

Deployment MatrixWindows ServerLinux ContainersZero Config

Model Context Gateway (MCG) routes, aggregates, and protects traffic for the Model Context Protocol (MCP). It is engineered as a high-performance C# ASP.NET Core gateway that proxies requests from clients (IDEs, LLMs, AI agents, and web applications) to multiple backend MCP servers.

This section provides an architectural topology overview, zero-configuration defaults, master key resolution mechanics, and hosting options across Linux containers, Windows Server environments, and local home-labs.


🏛️ Executive Architectural Topology ​

The gateway acts as an intelligent intermediary between upstream AI client interfaces and downstream MCP tool providers, running natively on Linux containers, Windows Server (IIS / Windows Service), or standalone developer workstations.


⚖️ Hosting Options Comparison Matrix ​

MCG supports four primary hosting environments tailored to different infrastructure requirements:

Feature & CapabilityLinux Container (Docker)Windows IIS In-ProcessWindows Service (SCM)Standalone Kestrel Console
Primary Use CaseCloud, Kubernetes, Homelab Docker ComposeEnterprise Windows Server, shared web infrastructureDedicated Windows application servers, background daemonsLocal developer testing, debugging, CI pipelines
Hosting ModelContainerized Kestrel behind optional reverse proxyIn-Process inside w3wp.exe via AspNetCoreModuleV2Standalone executable managed by Windows SCMDirect dotnet run or interactive binary
Throughput & LatencyHigh (native Linux network stack)Fastest (direct in-memory execution in IIS worker process)High (direct Kestrel HTTP pipeline)High (development pipeline)
Port Sharing & BindingsContainer port mapping (e.g. 8080:8080)Full HTTP.sys port sharing (ports 80, 443, multiple hosts)Dedicated port binding (e.g. http://0.0.0.0:8080)Dedicated port binding (e.g. http://localhost:5000)
SSL/TLS TerminationUpstream Reverse Proxy (Caddy/Traefik) or KestrelWindows Certificate Store, SNI, win-acme Let's EncryptKestrel certificate binding or upstream reverse proxyDeveloper certificates or HTTP only
SSE Streaming SettingsNative (zero buffering)Supported with responseBufferLimit="0" in web.configNative (zero buffering)Native
Automatic Crash RecoveryDocker restart: unless-stopped / K8s restartIIS Application Pool restart & health monitoringSCM failure restart triggers (sc.exe failure)Manual restart or console loop
Integrated AuthenticationReverse proxy headers (OIDC/SAML) with Oidc:TrustedProxiesNative IIS Negotiate, Kerberos, and NTLM modulesKestrel Negotiate or header authenticationNegotiate or Anonymous
Automated DeploymentDocker Compose recipesDeploy-IIS.ps1Setup-WindowsService.ps1CLI / PowerShell

⚡ Minimal Blank-Slate Startup (Zero-Config Safe Defaults) ​

You can launch Model Context Gateway with zero environment variables or with secure Docker and Kubernetes file secrets. When launched without prior configuration, the gateway automatically applies robust, secure out-of-the-box defaults:

SubsystemAutomatic Safe Default
Database• Defaults to DB_PROVIDER=sqlite.
• Automatically creates ./data/mcg.db.
• Executes schema migrations via Dapper and seeds default tables (Servers, Settings, AppKeys, AccessPolicies, GroupMappings, SecretProviders, AuthProviderConfigs, AuditLogs).
• Sets external auth providers (Active Directory, HeaderAuth, PocketID) and external secret providers (Vault, WindowsRegistry) to IsEnabled = 0 (Disabled) for standalone operation.
Secret Storage• Uses the Built-in Database Secret Provider with AES-256-GCM envelope encryption.
• Encrypts all backend server credentials in SQLite using the resolved master key (./data/.master.key). You do not need external HashiCorp Vault or DPAPI instances.
Authentication• Detects that no external Identity Provider (LDAP or OIDC forward-auth) is active.
• Automatically activates Standalone Mode.
• Treats local loopback (127.0.0.1, ::1) and configured subnets (STANDALONE_ALLOWED_NETWORKS) as Administrator users for Web UI access without requiring an SSO login.
Admin & Client AppKeys• Generates an Admin Application Key (./data/.admin.key with prefix mcp-adm-) and a default Client AppKey (./data/.client.key with prefix mcp-glb-).
• Supports multi-key seeding with scoped permissions through MCG_CLIENT_APP_KEYS.
• Lets remote AI coding assistants (such as Claude, Cursor, Cline, and Windsurf) connect immediately without manual setup.
Docker Discovery• If you mount -v /var/run/docker.sock:/var/run/docker.sock, background discovery registers containers labeled with mcp.enabled=true.

🔐 Master Encryption Key Resolution Hierarchy ​

Model Context Gateway protects backend server secrets at rest using AES-256-GCM envelope encryption. The gateway resolves its 256-bit Master Encryption Key using the following ordered hierarchy:

  1. HashiCorp Vault Key Bootstrapping (KeySource.External): In multi-node cluster deployments configured with VAULT_ADDR, the gateway pulls its master key from Vault (secret/data/mcg/master-key or secret/data/mcp-router/master-key).
  2. Docker or Kubernetes File Secret (MCG_MASTER_KEY_FILE - KeySource.External): Point MCG_MASTER_KEY_FILE to a mounted secret file (e.g., MCG_MASTER_KEY_FILE=/run/secrets/mcg_master_key). The gateway also inspects default Docker secret mount locations (/run/secrets/mcg_master_key, /run/secrets/master_key).
  3. Explicit Environment Variable (MCG_MASTER_KEY - KeySource.External): Provide a 256-bit base64-encoded key directly through MCG_MASTER_KEY=<base64-key>.
  4. Windows DPAPI (IIS / Windows Service): When hosted natively on Windows Server, the gateway can leverage the Windows Data Protection API (DPAPI) machine keys (DataProtectionScope.LocalMachine), eliminating manual key files.
  5. Auto-Generated Persistent Keyfile (./data/.master.key - KeySource.AutoGenerated) (Default): If no key is supplied upon first launch, the gateway generates a cryptographically random 256-bit key, writes it to ./data/.master.key with restricted permissions (chmod 0600), and logs a startup notice. Mounting ./data keeps this key persistent across container recreations.

TIP

Dynamic Database Re-Encryption: If you initially start with an auto-generated key, you can promote a permanent enterprise Master Key later. Administrators can configure this key via the Web Dashboard or Admin MCP Server without service downtime.


🌐 Immediate Live Endpoints ​

Once started, the gateway immediately exposes these core endpoints:

EndpointProtocolDescription
GET /HTTP / HTMLMain Glassmorphic Web Dashboard UI for administration and monitoring.
GET /healthHTTP / JSONStructured liveness and health probe ({"status":"healthy","service":"ModelContextGateway","version":"5.11.0"}).
GET /sseHTTP / SSEMeta-Mode MCP Gateway: Exposes intelligent search_tools and execute_tool router endpoints.
POST /messageHTTP / JSONClient-to-server JSON-RPC message ingestion endpoint for SSE sessions.
GET /admin/sseHTTP / SSEAdmin MCP Server: Administrative tool interface for AI coding assistants (manage_servers, manage_appkeys, etc.).
POST /adminHTTP / JSON-RPCDirect single-request JSON-RPC invocation endpoint for admin automation.
GET /metricsHTTP / PlaintextPrometheus metrics endpoint for active sessions, tool call throughput, and latency histograms.

🧩 Deployment & Authentication Support Matrix Summary ​

Model Context Gateway unifies diverse authentication models across enterprise and container topologies.

Hosting EnvironmentIdentity / Auth MechanismAppKey SupportDownstream Identity DelegationNotes and Limitations
Linux Container (Docker)Reverse Proxy Headers (OIDC, SAML)✅ SupportedOAuth2 On-Behalf-Of JWT or Header Propagation (X-Forwarded-User)Requires configuring Oidc:TrustedProxies. Linux containers do not support Kerberos or NTLM impersonation (S4U2Proxy).
Windows Native (IIS)Active Directory (AD) / Windows Authentication✅ SupportedKerberos / NTLM Impersonation (S4U2Proxy) or Header PropagationIIS application pool must run as a domain account with constrained delegation rights for S4U2Proxy.
Standalone (Kestrel)AppKey Only (Machine-to-Machine)✅ SupportedNone (Executes in router context)Ideal for automated agents, local homelabs, or internal microservices without end-user identity.
Any EnvironmentDynamic Authentication Pass-Through✅ SupportedDirect Target Authentication (X-Target-Auth)MCG intercepts HTTP 401 challenges from backend tools and prompts the client/IDE for credentials.

Downstream Delegation Strategies ​

When MCG forwards tool invocations to downstream MCP servers, it delegates identity using the following matrix:

Inbound Auth MethodOutbound: Header PropagationOutbound: OAuth2 On-Behalf-OfOutbound: Kerberos Impersonation
Proxy SSO Header✅ Supported✅ Supported❌ Not Supported
AppKey⚠️ AppKey Owner Context❌ Not Supported (App is not a user)❌ Not Supported
Windows Auth (AD)✅ Supported❌ Not Supported (No JWT)✅ Supported (Windows Only)

⚠️ Deploy-Time Behavior Change Notice ​

Earlier versions trusted common container subnets (10.0.0.0/8, 172.16.0.0/12) by default. Starting in version 4.5.5, the default configuration trusts loopback addresses only (127.0.0.1 and ::1).

IMPORTANT

If your reverse proxy (such as Caddy, Nginx, Traefik, or IIS) runs on a separate container network or host IP, you MUST set Oidc:TrustedProxies (or Oidc__TrustedProxies) to the proxy IP address. If this value is omitted, the gateway strips incoming identity headers and downgrades requests to guest access.


📖 Modular Deployment Guides Roadmap ​

Select the guide corresponding to your deployment target:

Released under the Apache 2.0 License.