> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Demo Start the MCP Gateway

> Guide to start a local MCP gateway that runs an MCP server in Docker and exposes a streamable HTTP endpoint using npx supergateway, with kubeconfig and health checks.

Welcome back. In this lesson you'll start a local MCP (Machine Control Plane) gateway that exposes an MCP server as a streamable HTTP endpoint. This guide walks through the prerequisites, verifying your kubeconfig, exporting the environment variable, and running the gateway using `npx supergateway` to wrap the MCP Docker image.

## Prerequisites

* A valid kubeconfig and a kubectl context pointing to the intended cluster.
* `docker` installed and running (used to run the `mcp/kubernetes:latest` image).
* `npx` (comes with Node.js / npm) to run `supergateway`.
* Export an environment variable pointing to the kubeconfig file so the MCP container can access cluster metadata and credentials.

Helpful references:

* [Kubernetes Concepts](https://kubernetes.io/docs/concepts/overview/what-is-kubernetes/)
* [Docker Documentation](https://docs.docker.com/get-started/)
* [npm / npx](https://docs.npmjs.com/cli/v9/commands/npx)

## Verify kubectl context

Confirm your kubectl context is set to the cluster you want to use and list namespaces to ensure connectivity:

```bash theme={null}
➜  ~ kubectl config current-context
kind-finops-cluster

➜  ~ kubectl get ns
NAME                 STATUS   AGE
airline              Active   32h
booking-api          Active   32h
default              Active   32h
flight-search        Active   32h
inventory            Active   32h
kube-node-lease      Active   32h
kube-public          Active   32h
kube-system          Active   32h
local-path-storage   Active   32h
payment              Active   32h
```

## Export the kubeconfig file location

Most environments use the default kubeconfig path at `$HOME/.kube/config`. Export an environment variable that points to the kubeconfig file so it can be mounted into the MCP container:

```bash theme={null}
➜  ~ export KUBECONFIG_FILE="${KUBECONFIG:-$HOME/.kube/config}"
```

Quickly verify the file exists and the variable is set:

```bash theme={null}
➜  ~ test -f "$KUBECONFIG_FILE" && echo "Using $KUBECONFIG_FILE"
Using /Users/raghunandanask/.kube/config
```

## Start the MCP gateway

We use the npm package `supergateway` (via `npx`) to run a gateway process that:

* launches the MCP server inside Docker (`mcp/kubernetes:latest`),
* connects the server’s STDIN/STDOUT to the gateway,
* exposes a streamable HTTP endpoint for MCP requests.

Run the following command to start the gateway:

```bash theme={null}
npx -y supergateway \
  --stdio "docker run --rm -i --network host --user 0:0 \
  -v ${KUBECONFIG_FILE}:/kubeconfig:ro -e KUBECONFIG=/kubeconfig \
  mcp/kubernetes:latest" \
  --outputTransport streamableHttp \
  --port 8000 \
  --healthEndpoint /healthz
```

Key options explained:

* `npx -y supergateway --stdio "<command>"` — runs the MCP process and tunnels its STDIN/STDOUT to the gateway.
* Docker run:
  * `-v ${KUBECONFIG_FILE}:/kubeconfig:ro` mounts your kubeconfig into the container at `/kubeconfig` (read-only).
  * `-e KUBECONFIG=/kubeconfig` sets the environment variable inside the container so the MCP server uses the mounted kubeconfig.
  * `mcp/kubernetes:latest` is the MCP server image.
* `--outputTransport streamableHttp` instructs the gateway to use a single HTTP connection that can stream JSON chunks in the response.
* `--healthEndpoint /healthz` enables the gateway health check endpoint.
* `--port 8000` chooses the gateway listening port.

Streamable HTTP uses a single HTTP request/response where the response can be streamed incrementally (JSON chunks). This is a convenient transport for local MCP experimentation. An alternative transport is Server-Sent Events (SSE).

## Expected output

When the gateway starts successfully you should see output similar to:

```bash theme={null}
[supergateway] Starting...
[supergateway] Supergateway is supported by Supermachine (hosted MCPs) - https://supermachine.ai
[supergateway]  - outputTransport: streamableHttp
[supergateway] Running stateless server
[supergateway]  - Headers: (none)
[supergateway]  - port: 8000
[supergateway]  - stdio: docker run --rm -i --network host --user 0:0  -v /Users/raghunandanask/.kube/config:/kubeconfig:ro -e KUBECONFIG=/kubeconfig     mcp/kubernetes:latest
[supergateway]  - streamableHttpPath: /mcp
[supergateway]  - protocolVersion: 2024-11-05
[supergateway]  - CORS: disabled
[supergateway]  - Health endpoints: /healthz
[supergateway] Listening on port 8000
[supergateway] StreamableHttp endpoint: http://localhost:8000/mcp
```

## Exposed endpoints

| Endpoint | Purpose | Example |
| - | - | - |
| `/healthz` | Health check for the gateway | `curl http://localhost:8000/healthz` |
| `/mcp` | Streamable HTTP MCP endpoint (accepts streamed MCP requests and returns JSON) | `http://localhost:8000/mcp` |

## Next steps

The MCP gateway is now running and ready to accept MCP-formatted requests over the streamable HTTP endpoint. Interacting with the MCP (for example, sending MCP requests with `curl` or a client) will be covered in later lessons.

Additional references:

* [Kubernetes Documentation](https://kubernetes.io/docs/)
* [Docker CLI Reference](https://docs.docker.com/engine/reference/commandline/cli/)
* [npm / npx Documentation](https://docs.npmjs.com/cli/v9/commands/npx)

> **[Watch Video](https://learn.kodekloud.com/user/courses/building-kubernetes-finops-ai-agent/module/195615db-9bd2-4d1d-b899-9bd378d97521/lesson/1ea9d77f-79c4-4897-8f85-9f8c088de253)**


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.