{"type":"mcp_server","name":"mcp-context-forge","description":"MCP Gateway & Registry: Manages LLM tool/prompt access via MCP. Converts APIs, composes servers, & bridges protocols (REST, stdio, SSE).","category":"AI","language":"Python","stars":4145,"forks":109,"owner":"IBM","github_url":"https://github.com/IBM/mcp-context-forge","homepage":"https://ibm.github.io/mcp-context-forge/","setup":"## Setup\n\n### Prerequisites\n\n*   **Python ≥ 3.10** (3.11 recommended)\n*   **GNU Make** (optional, but all common workflows are available as Make targets)\n*   Optional: **Docker / Podman** for containerised runs\n*   **curl + jq** - only for the last smoke-test step\n\n### Installation\n\nYou can install MCP Gateway using one of the following methods:\n\n#### 1. Via PyPI (Recommended)\n\n```bash\n# 1️⃣  Isolated env + install from pypi\nmkdir mcpgateway && cd mcpgateway\npython3 -m venv .venv && source .venv/bin/activate\npip install --upgrade pip\npip install mcp-contextforge-gateway\n```\n\n#### 2. Via Make\n\n```bash\nmake venv install          # create .venv + install deps\n```\n\n#### 3. UV (alternative)\n\n```bash\nuv venv && source .venv/bin/activate\nuv pip install -e '.[dev]' # IMPORTANT: in zsh, quote to disable glob expansion!\n```\n\n#### 4. pip (alternative)\n\n```bash\npython3 -m venv .venv && source .venv/bin/activate\npip install -e \".[dev]\"\n```\n\n#### 5. Optional (PostgreSQL adapter)\n\nYou can configure the gateway with SQLite, PostgreSQL (or any other compatible database) in .env.\n\nWhen using PostgreSQL, you need to install `psycopg2` driver.\n\n```bash\nuv pip install psycopg2-binary   # dev convenience\n# or\nuv pip install psycopg2          # production build\n```\n\n##### Quick Postgres container\n\n```bash\ndocker run --name mcp-postgres \\\n  -e POSTGRES_USER=postgres \\\n  -e POSTGRES_PASSWORD=mysecretpassword \\\n  -e POSTGRES_DB=mcp \\\n  -p 5432:5432 -d postgres\n```\n\nA `make compose-up` target is provided along with a [docker-compose.yml](docker-compose.yml) file to make this process simpler.\n\n### Configuration\n\nMCP Gateway is configured using environment variables. You can set these variables directly in your shell or by creating a `.env` file in the project root directory.\n\n1.  Copy the provided `.env.example` to `.env`:\n\n    ```bash\n    cp .env.example .env\n    ```\n\n2.  Edit the `.env` file to configure the gateway according to your needs.\n\n### Environment Variables\n\nThe following environment variables are available for configuring MCP Gateway:\n\n#### Basic\n\n| Setting         | Description                              | Default                | Options                |\n| --------------- | ---------------------------------------- | ---------------------- | ---------------------- |\n| `APP_NAME`      | Gateway / OpenAPI title                  | `MCP Gateway`          | string                 |\n| `HOST`          | Bind address for the app                 | `0.0.0.0`              | IPv4/IPv6              |\n| `PORT`          | Port the server listens on               | `4444`                 | 1-65535                |\n| `DATABASE_URL`  | SQLAlchemy connection URL                | `sqlite:///./mcp.db`   | any SQLAlchemy dialect |\n| `APP_ROOT_PATH` | Subpath prefix for app (e.g. `/gateway`) | (empty)                | string                 |\n| `TEMPLATES_DIR` | Path to Jinja2 templates                 | `mcpgateway/templates` | path                   |\n| `STATIC_DIR`    | Path to static files                     | `mcpgateway/static`    | path                   |\n\n> 💡 Use `APP_ROOT_PATH=/foo` if reverse-proxying under a subpath like `https://host.com/foo/`.\n\n#### Authentication\n\n| Setting               | Description                                                      | Default       | Options    |\n| --------------------- | ---------------------------------------------------------------- | ------------- | ---------- |\n| `BASIC_AUTH_USER`     | Username for Admin UI login and HTTP Basic authentication        | `admin`       | string     |\n| `BASIC_AUTH_PASSWORD` | Password for Admin UI login and HTTP Basic authentication        | `changeme`    | string     |\n| `AUTH_REQUIRED`       | Require authentication for all API routes                        | `true`        | bool       |\n| `JWT_SECRET_KEY`      | Secret key used to **sign JWT tokens** for API access            | `my-test-key` | string     |\n| `JWT_ALGORITHM`       | Algorithm used to sign the JWTs (`HS256` is default, HMAC-based) | `HS256`       | PyJWT algs |\n| `TOKEN_EXPIRY`        | Expiry of generated JWTs in minutes                              | `10080`       | int > 0    |\n| `AUTH_ENCRYPTION_SECRET` | Passphrase used to derive AES key for encrypting tool auth headers | `my-test-salt` | string |\n\n> 🔐 `BASIC_AUTH_USER`/`PASSWORD` are used for:\n>\n> *   Logging into the web-based Admin UI\n> *   Accessing APIs via Basic Auth (`curl -H \"Authorization: Bearer $MCPGATEWAY_BEARER_TOKEN\"`)\n>\n> 🔑 `JWT_SECRET_KEY` is used to:\n>\n> *   Sign JSON Web Tokens (`Authorization: Bearer <token>`)\n> *   Generate tokens via:\n>\n>     ```bash\n>     export MCPGATEWAY_BEARER_TOKEN=$(python3 -m mcpgateway.utils.create_jwt_token --username admin --exp 0 --secret my-test-key)\n>     echo $MCPGATEWAY_BEARER_TOKEN\n>     ```\n> *   Tokens allow non-interactive API clients to authenticate securely.\n>\n> 🧪 Set `AUTH_REQUIRED=false` during development if you want to disable all authentication (e.g. for local testing or open APIs) or clients that don't support SSE authentication.\n> In production, you should use the SSE to stdio `mcpgateway-wrapper` for such tools that don't support authenticated SSE, while still ensuring the gateway uses authentication.\n>\n> 🔐 `AUTH_ENCRYPTION_SECRET` is used to encrypt and decrypt tool authentication credentials (`auth_value`).\n> You must set the same value across environments to decode previously stored encrypted auth values.\n> Recommended: use a long, random string.\n\n#### UI Features\n\n| Setting                        | Description                            | Default | Options |\n| ------------------------------ | -------------------------------------- | ------- | ------- |\n| `MCPGATEWAY_UI_ENABLED`        | Enable the interactive Admin dashboard | `true`  | bool    |\n| `MCPGATEWAY_ADMIN_API_ENABLED` | Enable API endpoints for admin ops     | `true`  | bool    |\n\n> 🖥️ Set both to `false` to disable management UI and APIs in production.\n\n#### Security\n\n| Setting           | Description                    | Default                                        | Options    |\n| ----------------- | ------------------------------ | ---------------------------------------------- | ---------- |\n| `SKIP_SSL_VERIFY` | Skip upstream TLS verification | `false`                                        | bool       |\n| `ALLOWED_ORIGINS` | CORS allow-list                | `[\"http://localhost\",\"http://localhost:4444\"]` | JSON array |\n| `CORS_ENABLED`    | Enable CORS                    | `true`                                         | bool       |\n\n> Note: do not quote the ALLOWED_ORIGINS values, this needs to be valid JSON, such as: `ALLOWED_ORIGINS=[\"http://localhost\", \"http://localhost:4444\"]`\n\n#### Logging\n\n| Setting      | Description       | Default | Options            |\n| ------------ | ----------------- | ------- | ------------------ |\n| `LOG_LEVEL`  | Minimum log level | `INFO`  | `DEBUG`...`CRITICAL` |\n| `LOG_FORMAT` | Log format        | `json`  | `json`, `text`     |\n| `LOG_FILE`   | Log output file   | (none)  | path or empty      |\n\n#### Transport\n\n| Setting                   | Description                        | Default | Options                         |\n| ------------------------- | ---------------------------------- | ------- | ------------------------------- |\n| `TRANSPORT_TYPE`          | Enabled transports                 | `all`   | `http`,`ws`,`sse`,`stdio`,`all` |\n| `WEBSOCKET_PING_INTERVAL` | WebSocket ping (secs)              | `30`    | int > 0                         |\n| `SSE_RETRY_TIMEOUT`       | SSE retry timeout (ms)             | `5000`  | int > 0                         |\n| `USE_STATEFUL_SESSIONS`   | streamable http config             | `false` | bool                            |\n| `JSON_RESPONSE_ENABLED`   | json/sse streams (streamable http) | `true`  | bool                            |\n\n#### Federation\n\n| Setting                    | Description            | Default | Options    |\n| -------------------------- | ---------------------- | ------- | ---------- |\n| `FEDERATION_ENABLED","tools":"## Available Tools\n\nContextForge MCP Gateway offers a comprehensive suite of tools and features designed to streamline the integration and management of Model Context Protocol (MCP) and REST services. These tools can be accessed via the Admin UI, API endpoints, or through the `mcpgateway.wrapper` for stdio-based clients.\n\n**Core Features:**\n\n*   **Federation:**\n    *   **What it does:** Enables the gateway to discover and aggregate tools and services from multiple MCP and REST endpoints, presenting a unified view to clients.\n    *   **Usage:** Configure `FEDERATION_ENABLED`, `FEDERATION_DISCOVERY`, and `FEDERATION_PEERS` in the `.env` file.\n*   **Virtualization:**\n    *   **What it does:** Allows wrapping existing REST/gRPC services as virtual MCP servers, making them accessible through the MCP protocol.\n    *   **Usage:** Register REST APIs as tools using the `/tools` endpoint, specifying the URL and input schema.\n*   **Transport Flexibility:**\n    *   **What it does:** Supports multiple transport protocols, including HTTP, JSON-RPC, WebSocket, SSE, and stdio, allowing clients to connect using their preferred method.\n    *   **Usage:** Configure `TRANSPORT_TYPE` in the `.env` file to enable specific transports. The `mcpgateway.wrapper` facilitates stdio connections.\n*   **Admin UI:**\n    *   **What it does:** Provides a web-based interface for managing gateways, tools, resources, prompts, and servers.\n    *   **Usage:** Enable with `MCPGATEWAY_UI_ENABLED=true` and access at `/admin`. Login with `BASIC_AUTH_USER` and `BASIC_AUTH_PASSWORD`.\n*   **Authentication & Authorization:**\n    *   **What it does:** Secures access to the gateway and its resources using Basic Auth and JWT tokens.\n    *   **Usage:** Configure `AUTH_REQUIRED`, `JWT_SECRET_KEY`, `BASIC_AUTH_USER`, and `BASIC_AUTH_PASSWORD` in the `.env` file. Generate tokens using `python3 -m mcpgateway.utils.create_jwt_token`.\n*   **Observability:**\n    *   **What it does:** Provides structured logs, health endpoints, and metrics for monitoring the gateway's performance and health.\n    *   **Usage:** Access health endpoint at `/health` and metrics at `/metrics`. Configure logging with `LOG_LEVEL` and `LOG_FORMAT`.\n*   **Unified Registries:**\n    *   **What it does:** Manages prompts, resources, and tools in a central repository, enabling easy access and reuse.\n    *   **Usage:** Use the `/prompts`, `/resources`, and `/tools` API endpoints to create, read, update, and delete these entities.\n\n**Specific Tool Management Features:**\n\n*   **Tool Registration:**\n    *   **What it does:** Allows registering new tools with the gateway, specifying their name, URL, description, and input schema.\n    *   **Usage:**\n        ```bash\n        curl -X POST -H \"Authorization: Bearer $MCPGATEWAY_BEARER_TOKEN\" \\\n             -H \"Content-Type: application/json\" \\\n             -d '{\n                   \"name\":\"clock_tool\",\n                   \"url\":\"http://localhost:9000/rpc\",\n                   \"description\":\"Returns current time\",\n                   \"input_schema\":{\n                     \"type\":\"object\",\n                     \"properties\":{\"timezone\":{\"type\":\"string\"}},\n                     \"required\":[]\n                   }\n                 }' \\\n             http://localhost:4444/tools\n        ```\n*   **Tool Listing:**\n    *   **What it does:** Retrieves a list of all registered tools.\n    *   **Usage:**\n        ```bash\n        curl -H \"Authorization: Bearer $MCPGATEWAY_BEARER_TOKEN\" http://localhost:4444/tools\n        ```\n*   **Tool Retrieval:**\n    *   **What it does:** Retrieves a specific tool by its ID.\n    *   **Usage:**\n        ```bash\n        curl -H \"Authorization: Bearer $MCPGATEWAY_BEARER_TOKEN\" http://localhost:4444/tools/1\n        ```\n*   **Tool Update:**\n    *   **What it does:** Updates the properties of an existing tool.\n    *   **Usage:**\n        ```bash\n        curl -X PUT -H \"Authorization: Bearer $MCPGATEWAY_BEARER_TOKEN\" \\\n             -H \"Content-Type: application/json\" \\\n             -d '{ \"description\":\"Updated desc\" }' \\\n             http://localhost:4444/tools/1\n        ```\n*   **Tool Activation/Deactivation:**\n    *   **What it does:** Toggles the active status of a tool, enabling or disabling it.\n    *   **Usage:**\n        ```bash\n        curl -X POST -H \"Authorization: Bearer $MCPGATEWAY_BEARER_TOKEN\" \\\n             http://localhost:4444/tools/1/toggle?activate=false\n        curl -X POST -H \"Authorization: Bearer $MCPGATEWAY_BEARER_TOKEN\" \\\n             http://localhost:4444/tools/1/toggle?activate=true\n        ```\n*   **Tool Deletion:**\n    *   **What it does:** Deletes a registered tool.\n    *   **Usage:**\n        ```bash\n        curl -X DELETE -H \"Authorization: Bearer $MCPGATEWAY_BEARER_TOKEN\" http://localhost:4444/tools/1\n        ```\n*   **Tool Invocation:**\n    *   **What it does:** Calls a registered tool with specified arguments.  This can be done via the `/rpc` endpoint.\n    *   **Usage:**\n        ```bash\n        curl -X POST -H \"Authorization: Bearer $MCPGATEWAY_BEARER_TOKEN\" \\\n             -H \"Content-Type: application/json\" \\\n             -d '{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"clock_tool\",\"params\":{\"timezone\":\"UTC\"}}' \\\n             http://localhost:4444/rpc\n        ```\n*   **Tool Configuration:**\n    *   **What it does:** Allows setting timeouts, retry policies, rate limits, and concurrency limits for tool invocations.\n    *   **Usage:** Configure `TOOL_TIMEOUT`, `MAX_TOOL_RETRIES`, `TOOL_RATE_LIMIT`, and `TOOL_CONCURRENT_LIMIT` in the `.env` file.\n\n**Other Notable Features:**\n\n*   **Resource Management:** Create, read, update, delete, and subscribe to resources via the `/resources` endpoint.\n*   **Prompt Management:** Create, read, update, delete, and render prompts via the `/prompts` endpoint.\n*   **Server Management:** Create, read, update, and manage virtual servers via the `/servers` endpoint.  Virtual servers bundle tools together.\n*   **Root Management:** Manage file system roots via the `/roots` endpoint.\n*   **Metrics:** Access aggregated metrics via the `/metrics` endpoint.\n*   **Events:** Subscribe to events via the `/events` SSE endpoint or the `/ws` WebSocket endpoint.\n*   **Health Checks:** Monitor the gateway's health via the `/health` endpoint.\n\nThese tools and features provide a robust and flexible platform for managing and integrating MCP and REST services, enabling developers to build powerful AI applications.","faq":null,"created_at":"2025-05-08T08:16:59+00:00","updated_at":"2025-07-07T16:48:36+00:00","source_url":"https://model-context-protocol.com/servers/mcp-context-forge","related_articles":[]}