---
title: "Generate Sandboxed MCP Servers with OpenAPI2MCP | Cosmonic"
description: "Generate sandboxed MCP servers from any OpenAPI spec using OpenAPI2MCP and wash."
canonical: "https://cosmonic.com/blog/generate-sandboxed-mcp-servers-with-wasm-shell-and-openapi2mcp/"
---

[Bailey Hayes](https://cosmonic.com/blog/team/bailey-hayes/)

| Oct 14, 2025| 7 min read

# Generate Sandboxed MCP Servers with OpenAPI2MCP

![Generate Sandboxed MCP Servers with OpenAPI2MCP](https://cosmonic.com/blog/assets/images/generate-blog-header-afb7da28e7cfefe021867ab2500f574d.webp)

Servers using the [**Model Context Protocol (MCP)**](https://github.com/modelcontextprotocol/) from Anthropic have become the industry standard approach for extending the capabilities of Large Language Models (LLMs) and creating agentic workflows. WebAssembly (Wasm) components are quickly emerging as the ideal unit of deployment, [providing a secure-by-default sandbox for MCP servers](https://cosmonic.com/blog/remote-hosting-sandboxed-mcp-servers-with-wasm-and-cosmonic-control/).

In this blog, we'll explain how you can use the open source [Wasm Shell (`wash`) CLI](https://github.com/wasmcloud/wash) and **OpenAPI2MCP** to quickly and easily develop MCP servers that enable models to use APIs defined in the [OpenAPI specification](https://www.openapis.org/what-is-openapi)—and then compile those MCP servers to Wasm component binaries that can be deployed to Kubernetes with Cosmonic Control.

## Requirements

We'll need a handful of tools for this tutorial:

- [`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/wash) **v2.0.0-rc.7** for developing and building Wasm components

- [TypeScript](https://www.typescriptlang.org/) (`npm install -g typescript`)

### Install Wasm Shell (`wash`)

On macOS and Linux, you can install `wash` with a quick `curl` of the install script:

```bash
curl -fsSL https://raw.githubusercontent.com/wasmcloud/wash/refs/heads/main/install.sh | bash
```

For installations on other systems, see the [Wasm Shell Installation](https://wasmcloud.com/docs/next/wash/get-started/) documentation.

### Install OpenAPI2MCP

The OpenAPI2MCP `npm` module generates a TypeScript-based MCP server from 3.0.+ OpenAPI specifications.

Download OpenAPI2MCP:

```bash
npm install -g @cosmonic-labs/openapi2mcp
```

### Generate MCP server

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

```shell
git clone https://github.com/cosmonic-labs/mcp-server-template-ts.git 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
openapi2mcp input.json --project-path petstore
```

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

## Developing the MCP Server

Now we can use the `wash dev` command to start a development loop and run the MCP server:

```shell
wash dev
```

The MCP server will run at `http://127.0.0.1:8000/v1/mcp`. When you start the development loop, `wash` will automatically launch the MCP Model Inspector.

### 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 `wash dev`, `wash` automatically launches the model inspector in your browser, 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`

## 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/blog/generate-sandboxed-mcp-servers-with-wasm-shell-and-openapi2mcp/#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/blog/generate-sandboxed-mcp-servers-with-wasm-shell-and-openapi2mcp/#ngrok-configuration-and-usage) to a public HTTPS address so that MCP Hosts that require a signed certificate like Claude can connect.

### 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).

#### Configure MCP Server as Extension

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`

![Configuration for new Goose extension](https://cosmonic.com/blog/assets/images/goose-mcp-5013c37310a3ac1a7df253a3d34cca1f.webp)

Using the Goose CLI, start a new LLM session:

```shell
goose session
```

### ngrok: Configuration and usage

*Goose does not require a HTTPS address, so if you are using Goose, **you may skip this step**.*

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

### Test the MCP Server

Give your LLM 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 MCP server should 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.

![Tools tab of MCP Inspector](https://cosmonic.com/blog/assets/images/petstore-inspector-952064ae8002c2e63ce3f9c8a41d2c2a.webp)

## Build the Wasm binary

From here, you have everything you need for a complete MCP server development workflow.

When you're ready to compile your MCP server to a Wasm binary, you can simply run:

```shell
wash build
```

You can also use `wash` to push your Wasm binary to an OCI registry:

```shell
wash oci push ghcr.io/<your-namespace>/components/petstore-mcp:0.1.0 ./dist/component.wasm
```

## Next Steps

For information on deploying MCP servers like the one we built here, check out our blog, [Remote-hosting Sandboxed MCP Servers with Wasm](https://cosmonic.com/blog/remote-hosting-sandboxed-mcp-servers-with-wasm-and-cosmonic-control/). To run one locally in a few minutes, see [How to Sandbox an MCP Server](https://cosmonic.com/mcp-security/sandbox-an-mcp-server/).

Have questions about sandboxed MCP server development, Wasm, or using open source platforms like wasmCloud to deploy server-side Wasm workloads? You can find the Cosmonic team on the [wasmCloud Slack](https://slack.wasmcloud.com/) or at [weekly wasmCloud community meetings](https://wasmcloud.com/community/). Hope to see you there!

*Updated January 28, 2026*

> About the author
>
> ### [Bailey Hayes](https://cosmonic.com/blog/team/bailey-hayes/)
>
> Chief Technology Officer, Co-Founder
>
> Bailey Hayes is the CTO at Cosmonic. She believes the future is in distributed systems and WebAssembly (Wasm). She wears many hats in the open source ecosystem, from standards to implementations as the W3C WebAssembly WASI Subgroup co-chair, Bytecode Alliance TSC Director, and maintainer of CNCF wasmCloud.
>
> [More from Bailey](https://cosmonic.com/blog/team/bailey-hayes/)
