# ibm/mcp-context-forge architecture

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

- Interactive diagram: https://gitdiagram.com/ibm/mcp-context-forge
- Repository: https://github.com/ibm/mcp-context-forge

## Overview

ContextForge is a federated gateway: clients reach a unified MCP-facing service, which applies access controls and routes tool, agent, API, and LLM requests to registered backends. Its documented capabilities also include virtualizing REST/gRPC APIs, transport alternatives, plugins, administration, and telemetry. The graph emphasizes those product stages and the supported LLM and observability internals; many unsampled subsystems are represented at their exact enclosing directory, with links omitted where wiring was not shown.

Main entry points: [`mcpgateway/main.py`](https://github.com/ibm/mcp-context-forge/blob/main/mcpgateway/main.py) (Gateway application), [`mcpgateway/services/llm_provider_service.py`](https://github.com/ibm/mcp-context-forge/blob/main/mcpgateway/services/llm_provider_service.py) (LLM provider registry), [`mcpgateway/instrumentation/sqlalchemy.py`](https://github.com/ibm/mcp-context-forge/blob/main/mcpgateway/instrumentation/sqlalchemy.py) (SQL instrumentation), [`mcpgateway/services/llm_proxy_service.py`](https://github.com/ibm/mcp-context-forge/blob/main/mcpgateway/services/llm_proxy_service.py) (LLM proxy)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_gateway["Gateway and transports"]
  node_gateway["Gateway application<br/>[main.py]"]
  node_transports["MCP transports"]
  node_llmproxy["LLM proxy"]
  node_llmhttp["Provider HTTP client"]
end

subgraph group_registry["Federation and registries"]
  node_toolsvc["Tool registry and routing<br/>[tool_service.py]"]
  node_promptsvc["Prompt registry<br/>[prompt_service.py]"]
  node_resourcesvc["Resource registry"]
  node_catalog["Federated catalog<br/>[catalog_service.py]"]
  node_a2a["A2A agent integration<br/>[a2a_service.py]"]
  node_restgrpc["REST and gRPC adapters<br/>[grpc_service.py]"]
  node_llmchat["LLM chat<br/>[llmchat_router.py]"]
  node_llmproviders["LLM provider registry"]
end

subgraph group_governance["Governance and administration"]
  node_access["Authentication and RBAC<br/>[rbac.py]"]
  node_pluginmgr["Plugin manager"]
  node_adminui["Admin UI<br/>[app.js]"]
  node_adminroutes["Admin API routes"]
  node_security["Validation and credentials<br/>[validators.py]"]
  node_config["Runtime configuration<br/>[config.py]"]
end

subgraph group_operations["Storage and observability"]
  node_database[("Gateway database<br/>[db.py]")]
  node_logging["Structured logging<br/>[logging_service.py]"]
  node_otel["OpenTelemetry"]
  node_sqlinstrumentation["SQL instrumentation<br/>[sqlalchemy.py]"]
  node_redis[("Redis federation and cache")]
end

node_client(("AI client"))
node_upstreams["MCP and API backends"]

node_client -->|"sends requests"| node_gateway
node_gateway -->|"serves via"| node_transports
node_gateway -.->|"enforces access"| node_access
node_gateway -.->|"routes tool calls"| node_toolsvc
node_gateway -->|"exposes prompts"| node_promptsvc
node_gateway -->|"exposes resources"| node_resourcesvc
node_gateway -->|"federates services"| node_catalog
node_gateway -->|"routes agents"| node_a2a
node_gateway -->|"virtualizes APIs"| node_restgrpc
node_toolsvc -->|"invokes backends"| node_upstreams
node_a2a -->|"connects agents"| node_upstreams
node_restgrpc -->|"adapts services"| node_upstreams
node_gateway -->|"supports plugins"| node_pluginmgr
node_client -->|"starts chat"| node_llmchat
node_llmchat -->|"uses providers"| node_llmproviders
node_llmproviders -->|"routes completions"| node_llmproxy
node_llmproxy -->|"sends HTTP requests"| node_llmhttp
node_llmhttp -.->|"calls provider APIs"| node_upstreams
node_adminui -.->|"calls admin routes"| node_adminroutes
node_adminroutes -->|"manages providers"| node_llmproviders
node_llmproviders -->|"persists records"| node_database
node_gateway -.->|"loads settings"| node_config
node_gateway -.->|"validates inputs"| node_security
node_gateway -.->|"records events"| node_logging
node_gateway -->|"emits telemetry"| node_otel
node_sqlinstrumentation -->|"records query spans"| node_otel
node_sqlinstrumentation -->|"observes queries"| node_database
node_gateway -->|"uses federation cache"| node_redis

click node_gateway "https://github.com/ibm/mcp-context-forge/blob/main/mcpgateway/main.py"
click node_transports "https://github.com/ibm/mcp-context-forge/tree/main/mcpgateway/transports"
click node_access "https://github.com/ibm/mcp-context-forge/blob/main/mcpgateway/middleware/rbac.py"
click node_toolsvc "https://github.com/ibm/mcp-context-forge/blob/main/mcpgateway/services/tool_service.py"
click node_promptsvc "https://github.com/ibm/mcp-context-forge/blob/main/mcpgateway/services/prompt_service.py"
click node_resourcesvc "https://github.com/ibm/mcp-context-forge/blob/main/mcpgateway/services/resource_service.py"
click node_catalog "https://github.com/ibm/mcp-context-forge/blob/main/mcpgateway/services/catalog_service.py"
click node_a2a "https://github.com/ibm/mcp-context-forge/blob/main/mcpgateway/services/a2a_service.py"
click node_restgrpc "https://github.com/ibm/mcp-context-forge/blob/main/mcpgateway/services/grpc_service.py"
click node_pluginmgr "https://github.com/ibm/mcp-context-forge/blob/main/mcpgateway/plugins/gateway_plugin_manager.py"
click node_llmchat "https://github.com/ibm/mcp-context-forge/blob/main/mcpgateway/routers/llmchat_router.py"
click node_llmproviders "https://github.com/ibm/mcp-context-forge/blob/main/mcpgateway/services/llm_provider_service.py"
click node_llmproxy "https://github.com/ibm/mcp-context-forge/blob/main/mcpgateway/services/llm_proxy_service.py"
click node_llmhttp "https://github.com/ibm/mcp-context-forge/blob/main/mcpgateway/services/http_client_service.py"
click node_adminui "https://github.com/ibm/mcp-context-forge/blob/main/mcpgateway/admin_ui/app.js"
click node_adminroutes "https://github.com/ibm/mcp-context-forge/blob/main/mcpgateway/routers/llm_admin_router.py"
click node_security "https://github.com/ibm/mcp-context-forge/blob/main/mcpgateway/common/validators.py"
click node_config "https://github.com/ibm/mcp-context-forge/blob/main/mcpgateway/config.py"
click node_database "https://github.com/ibm/mcp-context-forge/blob/main/mcpgateway/db.py"
click node_logging "https://github.com/ibm/mcp-context-forge/blob/main/mcpgateway/services/logging_service.py"
click node_otel "https://github.com/ibm/mcp-context-forge/blob/main/mcpgateway/services/observability_service.py"
click node_sqlinstrumentation "https://github.com/ibm/mcp-context-forge/blob/main/mcpgateway/instrumentation/sqlalchemy.py"
click node_redis "https://github.com/ibm/mcp-context-forge/tree/main/mcpgateway/cache"

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_gateway,node_transports,node_llmproxy,node_llmhttp,node_client toneBlue
class node_toolsvc,node_promptsvc,node_resourcesvc,node_catalog,node_a2a,node_restgrpc,node_llmchat,node_llmproviders toneAmber
class node_access,node_pluginmgr,node_adminui,node_adminroutes,node_security,node_config,node_upstreams toneMint
class node_database,node_logging,node_otel,node_sqlinstrumentation,node_redis toneRose
```

## Components

### Gateway and transports

- [Gateway application](https://github.com/ibm/mcp-context-forge/blob/main/mcpgateway/main.py): `mcpgateway/main.py`
- [MCP transports](https://github.com/ibm/mcp-context-forge/tree/main/mcpgateway/transports): `mcpgateway/transports`
- [LLM proxy](https://github.com/ibm/mcp-context-forge/blob/main/mcpgateway/services/llm_proxy_service.py): `mcpgateway/services/llm_proxy_service.py`
- [Provider HTTP client](https://github.com/ibm/mcp-context-forge/blob/main/mcpgateway/services/http_client_service.py): `mcpgateway/services/http_client_service.py`

### Federation and registries

- [Tool registry and routing](https://github.com/ibm/mcp-context-forge/blob/main/mcpgateway/services/tool_service.py): `mcpgateway/services/tool_service.py`
- [Prompt registry](https://github.com/ibm/mcp-context-forge/blob/main/mcpgateway/services/prompt_service.py): `mcpgateway/services/prompt_service.py`
- [Resource registry](https://github.com/ibm/mcp-context-forge/blob/main/mcpgateway/services/resource_service.py): `mcpgateway/services/resource_service.py`
- [Federated catalog](https://github.com/ibm/mcp-context-forge/blob/main/mcpgateway/services/catalog_service.py): `mcpgateway/services/catalog_service.py`
- [A2A agent integration](https://github.com/ibm/mcp-context-forge/blob/main/mcpgateway/services/a2a_service.py): `mcpgateway/services/a2a_service.py`
- [REST and gRPC adapters](https://github.com/ibm/mcp-context-forge/blob/main/mcpgateway/services/grpc_service.py): `mcpgateway/services/grpc_service.py`
- [LLM chat](https://github.com/ibm/mcp-context-forge/blob/main/mcpgateway/routers/llmchat_router.py): `mcpgateway/routers/llmchat_router.py`
- [LLM provider registry](https://github.com/ibm/mcp-context-forge/blob/main/mcpgateway/services/llm_provider_service.py): `mcpgateway/services/llm_provider_service.py`

### Governance and administration

- [Authentication and RBAC](https://github.com/ibm/mcp-context-forge/blob/main/mcpgateway/middleware/rbac.py): `mcpgateway/middleware/rbac.py`
- [Plugin manager](https://github.com/ibm/mcp-context-forge/blob/main/mcpgateway/plugins/gateway_plugin_manager.py): `mcpgateway/plugins/gateway_plugin_manager.py`
- [Admin UI](https://github.com/ibm/mcp-context-forge/blob/main/mcpgateway/admin_ui/app.js): `mcpgateway/admin_ui/app.js`
- [Admin API routes](https://github.com/ibm/mcp-context-forge/blob/main/mcpgateway/routers/llm_admin_router.py): `mcpgateway/routers/llm_admin_router.py`
- [Validation and credentials](https://github.com/ibm/mcp-context-forge/blob/main/mcpgateway/common/validators.py): `mcpgateway/common/validators.py`
- [Runtime configuration](https://github.com/ibm/mcp-context-forge/blob/main/mcpgateway/config.py): `mcpgateway/config.py`

### Storage and observability

- [Gateway database](https://github.com/ibm/mcp-context-forge/blob/main/mcpgateway/db.py): `mcpgateway/db.py`
- [Structured logging](https://github.com/ibm/mcp-context-forge/blob/main/mcpgateway/services/logging_service.py): `mcpgateway/services/logging_service.py`
- [OpenTelemetry](https://github.com/ibm/mcp-context-forge/blob/main/mcpgateway/services/observability_service.py): `mcpgateway/services/observability_service.py`
- [SQL instrumentation](https://github.com/ibm/mcp-context-forge/blob/main/mcpgateway/instrumentation/sqlalchemy.py): `mcpgateway/instrumentation/sqlalchemy.py`
- [Redis federation and cache](https://github.com/ibm/mcp-context-forge/tree/main/mcpgateway/cache): `mcpgateway/cache`

### Other components

- **AI client**
- **MCP and API backends**

## Connections

- AI client → Gateway application: sends requests
- Gateway application → MCP transports: serves via
- Gateway application → Authentication and RBAC: enforces access
- Gateway application → Tool registry and routing: routes tool calls
- Gateway application → Prompt registry: exposes prompts
- Gateway application → Resource registry: exposes resources
- Gateway application → Federated catalog: federates services
- Gateway application → A2A agent integration: routes agents
- Gateway application → REST and gRPC adapters: virtualizes APIs
- Tool registry and routing → MCP and API backends: invokes backends
- A2A agent integration → MCP and API backends: connects agents
- REST and gRPC adapters → MCP and API backends: adapts services
- Gateway application → Plugin manager: supports plugins
- AI client → LLM chat: starts chat
- LLM chat → LLM provider registry: uses providers (evidence: `mcpgateway/routers/llmchat_router.py`)
- LLM provider registry → LLM proxy: routes completions (evidence: `mcpgateway/services/llm_proxy_service.py`)
- LLM proxy → Provider HTTP client: sends HTTP requests (evidence: `mcpgateway/services/llm_proxy_service.py`)
- Provider HTTP client → MCP and API backends: calls provider APIs
- Admin UI → Admin API routes: calls admin routes
- Admin API routes → LLM provider registry: manages providers (evidence: `mcpgateway/routers/llm_admin_router.py`)
- LLM provider registry → Gateway database: persists records (evidence: `mcpgateway/services/llm_provider_service.py`)
- Gateway application → Runtime configuration: loads settings
- Gateway application → Validation and credentials: validates inputs
- Gateway application → Structured logging: records events
- Gateway application → OpenTelemetry: emits telemetry
- SQL instrumentation → OpenTelemetry: records query spans (evidence: `mcpgateway/instrumentation/sqlalchemy.py`)
- SQL instrumentation → Gateway database: observes queries (evidence: `mcpgateway/instrumentation/sqlalchemy.py`)
- Gateway application → Redis federation and cache: uses federation cache
