Model Context Gateway (MCG)¶
Model Context Gateway (MCG) is a high-performance C# ASP.NET Core gateway, OAuth 2.0 provider, and semantic proxy for the Model Context Protocol (MCP).
It aggregates hundreds of tools from isolated backend servers (Docker, Home Assistant, Plex, Actual Budget, Excel, custom APIs, STDIO subprocesses) and proxies them to AI clients (Claude Desktop, Cursor, Cline, Windsurf, Antigravity) via a single unified connection.

⚡ Core Architecture Highlights¶
flowchart LR
subgraph Clients["AI Clients & IDEs"]
Claude["Claude Desktop"]
Cursor["Cursor / Windsurf"]
Agents["Autonomous Agents"]
end
subgraph Gateway["Model Context Gateway (MCG)"]
Auth["OAuth / Reverse Proxy Auth / AppKey"]
MetaMode["Meta-Mode Router\n(search_tools / execute_tool)"]
Vector["Semantic Vector Search\n(Local ONNX / OpenAI)"]
AdminMCP["Admin MCP Server\n(/admin, /mcg-admin)"]
Secrets["Secret Providers\n(Vault / DPAPI / AES)"]
end
subgraph Backends["Downstream MCP Servers"]
DockerSrv["Docker Containers\n(Auto-Discovery)"]
SSESrv["Remote SSE / HTTP Servers"]
StdioSrv["Subprocess STDIO\n(Node / Python / uv / bun)"]
end
Clients -->|Bearer / SSE| Auth
Auth --> MetaMode
Auth --> AdminMCP
MetaMode <--> Vector
MetaMode --> Secrets
Secrets --> DockerSrv
Secrets --> SSESrv
Secrets --> StdioSrv
- 🧠 Meta-Mode Dynamic Tool Filtering: Exposes only
search_toolsandexecute_toolon/sseby default, eliminating context window bloat in LLMs while dynamically discovering and routing across hundreds of backend tools on demand. - 🛡️ Multi-Tenant Auth & Zero-Config Standalone: Native Active Directory LDAP / Kerberos, OIDC reverse proxy headers (
Remote-User,Remote-Groupsfrom Authentik, Authelia, Keycloak), scoped AppKeys (mcp-adm-,mcp-usr-,mcp-srv-), and trusted local loopback for personal home-labs. - 🤖 In-Process Admin MCP Control Plane (
/admin,/mcg-admin): Autonomous AI agents can manage providers, servers, RBAC policies, group mappings, vector search, and personal AppKeys via standard MCP tool calls without manual UI operations. - 🔍 Dual-Provider Semantic Vector Search: Local in-process CPU vector embeddings (
all-MiniLM-L6-v2viaMicrosoft.ML.Tokenizers) or remote OpenAI-compatible API providers stored securely in SQLCipher/AES encrypted databases. - 🔐 Enterprise Secrets & Key Lifecycle: Just-in-time secret retrieval from HashiCorp Vault (KV v2), Windows Registry (DPAPI), or Environment Variables with AES-256-GCM envelope encryption and dynamic master key rotation.
- 🐳 Docker Label Auto-Discovery: Mounts
/var/run/docker.sockto dynamically discover and register containers withmcp.enabled=truelabels with zero manual registration. - 🗄️ Multi-Database Support: First-class stored procedure suites across SQLite, Microsoft SQL Server, and MySQL via Dapper.
🧭 Documentation Portal Navigation¶
-
Blank-slate Docker, Docker Compose, Windows IIS setup, environment variables, master encryption keys, and zero-config deployment.
-
Authentication & Identity Architecture
Active Directory SIDs, OIDC reverse proxy SSO, standalone loopback trust, AppKey scopes, and token exchange flows.
-
Enterprise Administration Guide
Operational administration, provider configuration, group mappings, master key rotation, and system management.
-
Autonomous agent administration via the
mcg-adminskill, control plane tools, and programmatic provisioning. -
Interactive dashboard walkthrough, server registration, RBAC management, client configuration, and test bench usage.
-
Scenario-driven integration recipes for Bearer auth, Custom Headers, Vault, BYOK, Pass-Through, and Identity-Forwarding.
-
Complete enterprise architecture specification, sequence diagrams, component models, and AES-256-GCM encryption pipelines.
-
Database Providers & Data Model
Canonical 12-table ERD, dialect specifications for SQLite, MSSQL, and MySQL, stored procedures, and migration guide.
-
Scope grammar (
*,server:*,category:*,tool:*), evaluation pipeline, least-privilege personas, and token hashing. -
Secret Providers & Key Management
HashiCorp Vault KV v2 JIT renewal, Windows DPAPI, Master Key lifecycle, and secure credential storage.
-
SSE, HTTP/streamable, subprocess STDIO security policies, environment secret injection, and process tree isolation.
-
Living Software Requirements Specification, requirement taxonomy (
AUTH,MCP,SEC,GUARD), and test verification matrix.
⚡ Quickstart: Zero-Config Startup¶
Run the gateway container with zero required configuration. On first boot, the gateway automatically generates a 256-bit AES Master Key in ./data/.master.key and initializes a secure SQLite database:
Live Endpoints¶
- Web UI Dashboard:
http://localhost:8080/ - Health Check:
http://localhost:8080/health→{"status":"healthy","service":"ModelContextGateway","version":"5.0.0"} - Meta-Mode Gateway:
http://localhost:8080/sse - Admin MCP Server:
http://localhost:8080/admin/sse(orPOST /admin/GET /mcg-admin/sse) - Direct Backend Proxy:
http://localhost:8080/{targetServerId}
🤖 Connecting AI Clients¶
1. Claude Desktop (claude_desktop_config.json)¶
2. Cursor / Windsurf / Cline (mcp.json / cline_mcp_settings.json)¶
{
"mcpServers": {
"mcg": {
"url": "http://localhost:8080/sse",
"headers": {
"Authorization": "Bearer mcp-usr-my-developer-token-123"
}
}
}
}
🛠️ Verification & Quality Assurance¶
All features, security guardrails, and authentication flows are enforced by automated test suites:
- xUnit Backend Suite: 670+ integration & unit tests (
ModelContextGateway.Tests) - Vitest Frontend Suite: Component and state store test coverage (
frontend/src/test) - Playwright E2E Suite: End-to-end browser automation (
frontend/e2e) - Living Requirements Matrix: Zero-drift catalog generation via
dotnet run --project scripts/CatalogGenerator -- --verify-only(SRS Catalog)