MCP Context Forge is a feature-rich, FastAPI-driven Model Context Protocol (MCP) gateway open-sourced by IBM. It unifies and federates tools, resources, prompts, servers, and peer gateways, wrapping any REST API as an MCP-compliant tool or virtual server. The project supports exposing all functionalities through HTTP/JSON-RPC, WebSocket, Server-Sent Events (SSE), and stdio transport protocols. It also provides a rich interactive management UI, packaged as a container, and supports any SQLAlchemy-supported database.
The project adopts a modular architecture design:
┌─────────────────┐ ┌──────────────────┐
│ 🖥️ Admin UI │ │ 🔐 Authentication │
│ Management UI │ │ JWT + Basic │
└─────────────────┘ └──────────────────┘
│ │
└────────┬─────────────────┘
│
┌─────────────▼─────────────────┐
│ 🚪 MCP Gateway Core │
│ Protocol Initialization Ping Complete │
│ Federation Manager │
│ Transport Protocols HTTP WS SSE Stdio │
└─────────────┬─────────────────┘
│
┌─────────────▼─────────────────┐
│ Service Layer │
│ 🧰 Tool Service 📁 Resource Service │
│ 📝 Prompt Service 🧩 Server Service │
└─────────────┬─────────────────┘
│
┌─────────────▼─────────────────┐
│ Persistence Layer │
│ 💾 Database SQLAlchemy │
│ ⚡ Cache Redis/Memory │
└───────────────────────────────┘
/health
endpoint and latency metrics decorator.# Application basic configuration
APP_NAME=MCP Gateway
HOST=0.0.0.0
PORT=4444
DATABASE_URL=sqlite:///./mcp.db
APP_ROOT_PATH=/gateway # Optional sub-path prefix
# Basic authentication (management UI and API)
BASIC_AUTH_USER=admin
BASIC_AUTH_PASSWORD=changeme
# JWT Configuration
JWT_SECRET_KEY=my-test-key
JWT_ALGORITHM=HS256
TOKEN_EXPIRY=10080 # Minutes
# Authentication Control
AUTH_REQUIRED=true
AUTH_ENCRYPTION_SECRET=my-test-salt
# Federation Features
FEDERATION_ENABLED=true
FEDERATION_DISCOVERY=false
FEDERATION_PEERS=["http://peer1:4444","http://peer2:4444"]
FEDERATION_TIMEOUT=30
FEDERATION_SYNC_INTERVAL=300
docker run -d --name mcpgateway \
-p 4444:4444 \
-e HOST=0.0.0.0 \
-e JWT_SECRET_KEY=my-secret-key \
-e BASIC_AUTH_USER=admin \
-e BASIC_AUTH_PASSWORD=changeme \
-e AUTH_REQUIRED=true \
-e DATABASE_URL=sqlite:///./mcp.db \
ghcr.io/ibm/mcp-context-forge:latest
# Create a virtual environment and install dependencies
make venv install serve
# Or install manually
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
uvicorn mcpgateway.main:app --host 0.0.0.0 --port 4444
export MCPGATEWAY_BEARER_TOKEN=$(python3 -m mcpgateway.utils.create_jwt_token --username admin --exp 10080 --secret my-test-key)
curl -X POST -u admin:changeme \
-H "Content-Type: application/json" \
-d '{
"protocol_version":"2025-03-26",
"capabilities":{},
"client_info":{"name":"MyClient","version":"1.0.0"}
}' \
http://localhost:4444/protocol/initialize
curl -X POST -u admin:changeme \
-H "Content-Type: application/json" \
-d '{
"name":"clock_tool",
"url":"http://localhost:9000/rpc",
"description":"Returns current time",
"input_schema":{
"type":"object",
"properties":{"timezone":{"type":"string"}},
"required":[]
}
}' \
http://localhost:4444/tools
curl -X POST -u admin:changeme \
-H "Content-Type: application/json" \
-d '{
"name":"greet",
"template":"Hello, {{ user }}!",
"argument_schema":{
"type":"object",
"properties":{"user":{"type":"string"}},
"required":["user"]
}
}' \
http://localhost:4444/prompts
The project provides complete IBM Cloud Code Engine deployment support:
IBMCLOUD_REGION=us-south
IBMCLOUD_RESOURCE_GROUP=default
IBMCLOUD_PROJECT=my-codeengine-project
IBMCLOUD_CODE_ENGINE_APP=mcpgateway
IBMCLOUD_IMAGE_NAME=us.icr.io/myspace/mcpgateway:latest
IBMCLOUD_API_KEY=your_api_key_here
make ibmcloud-check-env # Check environment variables
make ibmcloud-cli-install # Install IBM Cloud CLI
make ibmcloud-login # Login to IBM Cloud
make ibmcloud-ce-login # Select Code Engine project
make ibmcloud-tag # Tag container image
make ibmcloud-push # Push to IBM Container Registry
make ibmcloud-deploy # Deploy to Code Engine
mcpgateway/
├── admin.py # FastAPI routes and management UI controller
├── cache/
│ └── resource_cache.py # In-memory LRU+TTL cache for resources
├── config.py # Pydantic settings loader
├── db.py # SQLAlchemy ORM models and database setup
├── federation/
│ ├── discovery.py # Peer gateway discovery
│ ├── forward.py # RPC forwarding logic
│ └── manager.py # Federation coordination and health checks
├── handlers/
│ └── sampling.py # MCP streaming sampling request handler
├── services/
│ ├── completion_service.py # Prompt and resource parameter completion logic
│ ├── gateway_service.py # Peer gateway registration and management
│ ├── prompt_service.py # Prompt template CRUD and rendering
│ ├── resource_service.py # Resource registration, retrieval, subscription
│ ├── server_service.py # Server registration and health monitoring
│ └── tool_service.py # Tool registration, invocation, metrics
├── transports/
│ ├── sse_transport.py # Server-Sent Events transport
│ ├── stdio_transport.py # stdio transport
│ └── websocket_transport.py # WebSocket transport
└── utils/
├── create_jwt_token.py # JWT generation and verification tool
└── verify_credentials.py # FastAPI authentication dependency
# Install development dependencies
make install-dev
# Run code checks
make lint
# Run tests
make test
# Run coverage tests
make coverage
The project integrates various code quality tools:
MCP Context Forge is a fully functional, production-ready Model Context Protocol gateway solution, particularly suitable for enterprise-grade LLM application tool integration and management needs. It not only implements the complete functionality of the MCP protocol but also provides rich extension features such as federation discovery, protocol conversion, and virtualization services, making it an ideal infrastructure component for building complex AI application ecosystems.