> ## 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 Validate the MCP to Kubernetes Connection

> Guide to validate a local Managed Control Plane connected to Kubernetes via Supergateway, including health check, JSON-RPC initialize handshake, and running a kubectl_get tool to list namespaces

Welcome back.

This guide walks you through validating that your local MCP (Managed Control Plane) service is connected to a Kubernetes cluster. We start the MCP wrapped by Supergateway and then run a few checks: a health probe, a JSON-RPC initialization handshake, and a tool invocation (kubectl\_get) to list namespaces.

The MCP Streamable HTTP endpoint will be available at `http://localhost:8000/mcp` after launching the Supergateway command below.

## 1) Start the Supergateway-backed MCP

Run the following command to start Supergateway which launches the MCP container and exposes the Streamable HTTP endpoint:

```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
```

Trimmed example startup output:

```text 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/you/.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
```

Keep this process running in its terminal. If you stop it, subsequent curl checks will fail.

Keep the Supergateway process running in its terminal while you run the curl checks below from another terminal.

## 2) Health check

Open a new terminal and verify the health endpoint:

```bash theme={null}
curl -s http://localhost:8000/healthz
```

Expected output:

```text theme={null}
ok
```

A successful response confirms the Supergateway process is alive and responding on the configured health endpoint.

## 3) Initialize (JSON-RPC handshake)

Next, perform a JSON-RPC `initialize` handshake to learn the MCP's protocol version and capabilities. The MCP supports Server-Sent Events (SSE), so include `Accept: application/json, text/event-stream` to receive SSE-style responses.

Example request (single-line JSON payload for brevity):

```bash theme={null}
curl -s -N -X POST http://localhost:8000/mcp \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json, text/event-stream' \
  -d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"curl-test","version":"1.0"}}}'
```

Example SSE-style response (one `event: message` entry):

```text theme={null}
event: message
data: {"result":{"protocolVersion":"2024-11-05","capabilities":{"prompts":{},"resources":{},"tools":{}},"serverInfo":{"name":"kubernetes","version":"3.9.3"}},"jsonrpc":"2.0","id":1}
```

Key fields to inspect:

* `protocolVersion` — MCP protocol version.
* `capabilities` — features the server exposes. Typical groups:
  * `prompts` — LLM prompt/response integration
  * `resources` — managed resource types
  * `tools` — tooling endpoints (e.g., kubectl-like commands)
* `serverInfo` — server name and version.

Note: Even if `prompts` (LLM features) are not configured yet, `tools` may already be available for direct calls.

## 4) Invoke a tool — run kubectl\_get to list namespaces

With `tools` available, you can invoke tool methods exposed by the MCP. The example below calls the `kubectl_get` tool to list namespaces across the cluster and format output as `name`.

Request:

```bash theme={null}
curl -s -N -X POST http://localhost:8000/mcp \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json, text/event-stream' \
  -d '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"kubectl_get","arguments":{"resourceType":"namespaces","allNamespaces":true,"output":"name"}}}'
```

Example SSE-style response containing the tool output (note `\n` newline escapes inside the `text` field):

```text theme={null}
event: message
data: {"result":{"content":[{"type":"text","text":"namespace/airline\nnamespace/booking-api\nnamespace/flight-search\nnamespace/inventory\nnamespace/kube-node-lease\nnamespace/kube-public\nnamespace/kube-system\nnamespace/local-path-storage\nnamespace/payment\n"}]},"jsonrpc":"2.0","id":2}
```

The `text` string is plain command output; `\n` denotes newline characters. In this example you can see the namespaces returned by the Kubernetes API.

## Quick reference — commands and expected responses

| Step | Command (run from a separate terminal) | Expected response |
| - | - | - |
| Start Supergateway (run in its own terminal) | See the start command above | Logs showing `Listening on port 8000` and `StreamableHttp endpoint: http://localhost:8000/mcp` |
| Health check | `curl -s http://localhost:8000/healthz` | `ok` |
| Initialize (JSON-RPC) | `curl -s -N -X POST http://localhost:8000/mcp -H 'Content-Type: application/json' -H 'Accept: application/json, text/event-stream' -d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"curl-test","version":"1.0"}}}'` | SSE `event: message` with `protocolVersion` and `capabilities` |
| Tool call (kubectl\_get) | `curl -s -N -X POST http://localhost:8000/mcp -H 'Content-Type: application/json' -H 'Accept: application/json, text/event-stream' -d '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"kubectl_get","arguments":{"resourceType":"namespaces","allNamespaces":true,"output":"name"}}}'` | SSE `event: message` containing namespace list in `text` |

## Summary

* You started the MCP via Supergateway and exposed a Streamable HTTP endpoint at `http://localhost:8000/mcp`.
* You confirmed the service health at `/healthz`.
* You completed a JSON-RPC `initialize` handshake to discover MCP protocol version and capabilities.
* You invoked a `tools/call` for `kubectl_get` and retrieved Kubernetes namespaces from the cluster.

## What's next?

The next step is to integrate an LLM so you can issue natural-language requests that the system will translate into tool calls (for example, asking an LLM to "list all Kubernetes namespaces" which would trigger a `kubectl_get` call). That integration and architecture will be covered in a subsequent lesson.

Links and references

* [Kubernetes Basics](https://kubernetes.io/docs/concepts/overview/what-is-kubernetes/)
* [Kubernetes API reference](https://kubernetes.io/docs/reference/)
* Supergateway & Supermachine: [https://supermachine.ai](https://supermachine.ai)

> **[Watch Video](https://learn.kodekloud.com/user/courses/building-kubernetes-finops-ai-agent/module/195615db-9bd2-4d1d-b899-9bd378d97521/lesson/084f2158-de78-4ec5-8155-23e993a75d88)**

> **[Practice Lab](https://learn.kodekloud.com/user/courses/building-kubernetes-finops-ai-agent/module/195615db-9bd2-4d1d-b899-9bd378d97521/lesson/170b7a0d-db32-4b50-b15e-efe571e584a8)**


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