---
title: "Securely Deploy MCP on Kubernetes | Cosmonic"
description: "Deploy MCP servers as sandboxed WebAssembly components on Kubernetes with Cosmonic Control for secure agentic AI."
canonical: "https://cosmonic.com/docs/securely-deploy-mcp-on-kubernetes/"
---

# Securely Deploy MCP on Kubernetes

The [**Model Context Protocol (MCP)**](https://github.com/modelcontextprotocol/) is an open protocol introduced by Anthropic that has emerged as the standard for integrations between Large Language Models (LLMs) and external tools and resources. Unfortunately, MCP servers introduce [novel security risks](https://cosmonic.com/mcp-security/) including LLM prompt injection, data exfiltration, and execution environment exploits, among others.

**WebAssembly (Wasm) components** mitigate agentic AI security risks by providing a secure-by-default unit of deployment. Since Wasm component binaries are portable sandboxes that interact with the outside world via explicitly enabled, language-agnostic interfaces, MCP servers can be deployed as components with the confidence that agents can only interact with approved tools and resources in approved ways. This default-deny posture is an application of the [Principle of Least Authority](https://cosmonic.com/ai-sandbox/least-privilege-ai-agents/) to the MCP threat model, with [capability-based security](https://cosmonic.com/ai-sandbox/capabilities/) as the mechanism that enforces it. See [Security and Non-Deterministic I/O](https://cosmonic.com/docs/agent-sdk/capabilities/) for the structural argument that this matters specifically when an LLM is in the loop.

To run sandboxed MCP servers locally without a Kubernetes cluster, see [Sandbox MCP Servers](https://cosmonic.com/docs/desktop/sandbox-mcp-servers/) in the Cosmonic Desktop docs; the same Workload manifest and security model apply.

![architecture with components image](https://cosmonic.com/docs/assets/images/mcp-architecture-control-2a24d42f0d6fcaab7712b825010ac4c7.webp)

## Sandbox MCP and deploy on Kubernetes

Requirements:

- [`node` - NodeJS runtime](https://nodejs.org)
- [`npm` - Node Package Manager (NPM)](https://github.com/npm/cli) manages packages for the NodeJS ecosystem
- [`wash` - Wasm Shell](https://github.com/wasmCloud/wasmcloud) **v2.2.0** for developing and building Wasm components

> **Note**
>
> `wash` **v2.2.0** or higher is required for compatibility with the MCP server template.

### Generate MCP server

Create a new project based on the [MCP server template](https://github.com/cosmonic-labs/mcp-server-template-ts):

```shell
wash new https://github.com/cosmonic-labs/mcp-server-template-ts --name petstore
```

When `wash` prompts you to `Execute template setup command 'npm install'?`, type `y` to select **yes**. This will run `npm install` automatically upon project creation. (If you'd rather run `npm install` manually after navigating to the directory, you can do that, too.)

Navigate to the project directory:

```shell
cd petstore
```

Use `curl` to download the PetStore API to your project directory:

```shell
curl -fLO https://raw.githubusercontent.com/cosmonic-labs/openapi2mcp/refs/heads/main/tests/petstore/input.json
```

Generate MCP tools into the server project from an OpenAPI specification:

```shell
npm run openapi2mcp input.json
```

When the process is complete, your MCP server will be ready.

### Developing the MCP server

Start a development loop:

```shell
npm run dev
```

The MCP server will run at `http://127.0.0.1:8000/v1/mcp`.

When you start the development loop, `npm` will automatically launch the MCP Model Inspector in your browser on [`http://localhost:6274/`](http://localhost:6274/).

### Use the MCP Model Inspector

The [official MCP model inspector](https://github.com/modelcontextprotocol/inspector) is a useful tool for developing and debugging components. Using the model inspector, you can connect to the local MCP server via HTTP, manipulate resources, run tools, and more.

When you run `npm run dev`, `npm` automatically launches the model inspector in your browser on [`http://localhost:6274/`](http://localhost:6274/)., pre-populated with the configuration you need to connect to your server.

Simply click **Connect** to connect the inspector to your server. The options should be configured as below:

- Transport Type: **Streamable HTTP**
- URL: `http://127.0.0.1:8000/v1/mcp`

Once connected to the MCP server you can interact with the MCP server; for example:

- On the top menu bar select `Tools`
- then in the center Tool list click `get_pet_find_by_tags`
- then on the right you can add a query tag, for example cat\`
- then select `Run Tool`

And the local MCP server should query the remote pets database, returning a list of currently configured cats:

![SandboxMCP Petstore Demonstration, Querying for Cats](https://cosmonic.com/docs/assets/images/sandboxmcp-petstore-demo-mcp-inspector-cats-example-ecdc6e21a1eeef0d9274957645f2cb5c.webp)

### Connect to a model

Testing the MCP server requires access to a model that acts as an MCP host. There are many ways to connect a model with your server—below we've outlined two approaches:

- [Use Goose as a client](https://cosmonic.com/docs/securely-deploy-mcp-on-kubernetes/#goose-configuration-and-usage) for models in MCP development workflows. You can configure Goose to connect to [a variety of models](https://block.github.io/goose/docs/getting-started/providers#available-providers) including Claude, ChatGPT, Gemini, locally-hosted open source LLMs, and more. (You can follow this approach for free and without creating accounts for other services.)
- [Use ngrok to forward your local MCP server](https://cosmonic.com/docs/securely-deploy-mcp-on-kubernetes/#ngrok-configuration-and-usage) to a public HTTPS address so that MCP Hosts that require a signed certificate like Claude can connect.

Goose will connect to an MCP server running in **http**, while other models like Claude require **https**.

#### Goose: Configuration and usage

[Goose](https://block.github.io/goose/) is an open source AI agent with the ability to connect to MCP Servers for development workflows. Follow the [instructions in the Goose documentation to install Goose](https://block.github.io/goose/docs/getting-started/installation).

You'll need a MCP Host (like Goose, VS Code, etc) with tool-calling capabilities to test a MCP server. Otherwise, you can use the LLM model of your choice. Some AI assistants such as Google Gemini offer a free tier. In this example, we used Google Gemini (`gemini-2.5-flash-lite-preview-06-17`).

Follow the instructions in the Goose documentation to [configure your LLM of choice](https://block.github.io/goose/docs/getting-started/providers#configure-provider).

Goose refers to connected MCP servers as **extensions**. To add a new extension (i.e., configure Goose to act as an MCP client and connect to your MCP server), first run:

```shell
goose configure
```

Next...

- Select **Add Extension**
- Select **Remote Extension (Streaming HTTP)**
- Call the extension `petstore`
- Set the **Streaming HTTP endpoint URI** to `http://127.0.0.1:8000/v1/mcp`
- You can set the timeout to the default `300`

Using the Goose CLI, start a new LLM session:

```shell
goose session
```

Give the Goose CLI a prompt like:

```text
What pets are available for adoption?
```

Different models will produce different results—you may have to adjust the prompt to something like, `Which pets have the status available in the petstore?` The Goose CLI should use your MCP server to return results from [Swagger's Petstore V3](https://petstore3.swagger.io/api/v3):

```text
( O)> What pets are available for adoption?
─── get_pet_find_by_status | petstore ──────────────────────────
status: available
Here are the pets currently available in the petstore:
* Dog 1 (ID: 4)
* Lion 1 (ID: 7)
* Lion 2 (ID: 8)
* Dog (ID: 123)
* MyPet (ID: 99999999)
...
```

In your MCP Inspector, you can compare the returned results with the JSON results for a direct tool call in the **Tools** tab.

![MCP Inspector Tools tab](https://cosmonic.com/docs/assets/images/mcp-tools-tab-24807c216858343e61ed236de19080bb.webp)

#### ngrok: Configuration and usage

[ngrok](https://ngrok.com/) is an API gateway that can be used to forward your local MCP server to a public HTTPS address. Note that you will need to sign up for an ngrok account.

Follow the [instructions in the ngrok documentation](https://ngrok.com/docs/getting-started) to install the ngrok CLI and connect your account.

Once the CLI is installed and connected, forward your local server:

```shell
ngrok http http://localhost:8000
```

Visit the site ngrok serves to enable the route, and copy the forwarding URL for future use. Note that adding the connection to Claude requires an endpoint of `$FORWARDING_URL/v1/mcp`.

Once connected, you can give your model a prompt like:

```text
What pets are available for adoption?
```

Different models will produce different results—you may have to adjust the prompt to something like, `Which pets have the status available in the petstore?` The Goose CLI should use your MCP server to return results from [Swagger's Petstore V3](https://petstore3.swagger.io/api/v3):

```text
( O)> What pets are available for adoption?
─── get_pet_find_by_status | petstore ──────────────────────────
status: available
Here are the pets currently available in the petstore:
* Dog 1 (ID: 4)
* Lion 1 (ID: 7)
* Lion 2 (ID: 8)
* Dog (ID: 123)
* MyPet (ID: 99999999)
...
```

In your MCP Inspector, you can compare the returned results with the JSON results for a direct tool call in the **Tools** tab.

### Build and publish

Compile the component:

```shell
wash build
```

The `.wasm` binary will output to `./dist`.

#### Push the image to a registry

Push your Wasm binary to a registry as an OCI artifact. (For more information on pushing to registries with `wash`, see the [wasmCloud Developer Guide](https://wasmcloud.com/docs/wash/developer-guide/).)

```shell
wash oci push ghcr.io/<your-namespace>/<your project name>:0.1.0 ./dist/component.wasm
```

If you used our [MCP server template](https://github.com/cosmonic-labs/mcp-server-template-ts), GitHub workflows for publishing on a release is an included workflow. To trigger a push to to the repository's packages, create a new release.

1. Go to "Releases" from your project's GitHub repo page
2. Click "Draft a new release"

![Draft a new release](https://cosmonic.com/docs/assets/images/petstore-020-094114ae59ff2d11b5706ed602effe06.webp)

3. Create a new tag with the next version (e.g. `v0.3.0`)

![Tag next version](https://cosmonic.com/docs/assets/images/petstore-new-release-030-1a1725273fa3bbd42b6ca84441272eb6.webp)

4. Fill in the release details, for example name the release v0.3.0
5. Click "Publish release" A successful publish workflow will look like the following:

![Publish workflow](https://cosmonic.com/docs/assets/images/petstore-publish-37e93910a416374019405d6d0695acb7.webp)

Whether using the GitHub workflows included in the template or pushing manually, if you're using GHCR, the uploaded OCI artifact's **Visibility** will default to **Private**. [Make the artifact **Public**](https://docs.github.com/en/packages/learn-github-packages/configuring-a-packages-access-control-and-visibility).

### Deploy to Kubernetes

> **Cosmonic Control required**
>
> You will need a Kubernetes cluster with Cosmonic Control installed to deploy the component. Follow the [Get Started](https://cosmonic.com/docs/install-cosmonic-control/) instructions to set up Cosmonic Control.

Requirements:

- [`kubectl`](https://kubernetes.io/releases/download/)
- [Helm](https://helm.sh/docs) v3.8.0+

#### Install Local Kubernetes Environment

For the best local Kubernetes development experience, we recommend [`k3d`](https://k3d.io/), which runs a lightweight [k3s](https://k3s.io/) cluster inside Docker. **Requirements:** [Docker](https://docs.docker.com/get-started/get-docker/) and [k3d](https://k3d.io/#installation)

Create a cluster with port 80 mapped for [Envoy ingress](https://cosmonic.com/docs/operations/ingress-and-workloads/#how-ingress-works):

```shell
k3d cluster create cosmonic \
  --port "80:80@loadbalancer" \
  --k3s-arg "--disable=traefik@server:0"
```

#### Install Cosmonic Control

Deploy Cosmonic Control to Kubernetes with Helm:

```shell
helm install cosmonic-control oci://ghcr.io/cosmonic/cosmonic-control\
  --version 0.15.0\
  --namespace cosmonic-system\
  --create-namespace\
  --set ingress.enabled=false\
  --set envoy.service.type=LoadBalancer
```

Deploy a HostGroup:

```shell
helm install hostgroup oci://ghcr.io/cosmonic/cosmonic-control-hostgroup --version 0.15.0 --namespace cosmonic-system
```

Use the HTTPTrigger chart to quickly and easily deploy your MCP server:

```shell
helm install petstore-mcp --version 0.2.0 oci://ghcr.io/cosmonic-labs/charts/http-trigger -f https://raw.githubusercontent.com/cosmonic-labs/control-demos/refs/heads/main/petstore-mcp/values.http-trigger.yaml
```

#### Connect to the deployed MCP server

If you'd like to debug your MCP server, you can start [the official MCP model inspector](https://github.com/modelcontextprotocol/inspector) via the following command:

```console
npx @modelcontextprotocol/inspector
```

Configure the MCP model inspector's connection:

- Transport Type: **Streamable HTTP**
- URL: `http://petstore-mcp.localhost.cosmonic.sh/v1/mcp`
- Connection Type: **Via Proxy**

You can explore the MCP Server's available tools in the **Tools** tab and list available resources in the **Resources** tab.

Last updated on **Nov 10, 2026** by **Liam Randall**
