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

# Self-host MCP Gateway

> Run MCP Gateway on your machine so Cursor, Codex, and Claude Code can call a live API or the API on your current branch

You can run MCP Gateway locally instead of using the hosted product. The open-source CLI compiles an OpenAPI document and serves MCP tools over Streamable HTTP or stdio.

Use it two ways, both first-class:

* **Live API** — compile a public OpenAPI document and point the editor at the gateway.
* **WIP / branch API** — your server is already on this machine (`localhost`, a Docker network). Point the gateway at that origin so Cursor, Codex, or Claude Code can exercise the branch you are editing.

## How do I install it? <a href="#install" id="install" />

The project lives on GitHub: [Fetch-Hive/openapi-mcp](https://github.com/Fetch-Hive/openapi-mcp). Install with Homebrew, Docker, `npx`, the curl installer, or `cargo install` — the README lists the current commands.

## How do I connect a local or branch API? <a href="#local-api" id="local-api" />

1. Run `mcp-gateway init --allow-private-networks` so loopback and private networks are allowed.
2. Add the spec from a file in the repo: `mcp-gateway add-spec --name demo --file ./openapi.yaml --base-url http://127.0.0.1:3000 --insecure-http`. `--base-url` is this checkout, not production.
3. Start `mcp-gateway serve demo` (default `http://127.0.0.1:8787/mcp`).
4. Paste `mcp-gateway inspect demo --client cursor` (or `codex`, `claude-code`, `vscode`) into the editor. The token from `init` goes in `MCP_GATEWAY_TOKEN`.

`--allow-private-networks` is required for localhost. `--insecure-http` is required when the API speaks HTTP.

## How do I connect a live API? <a href="#live-api" id="live-api" />

1. Run `mcp-gateway init` (no private-network flag).
2. `mcp-gateway add-spec --name demo --url https://…` (or `--file` plus `--base-url https://api.example.com`).
3. `mcp-gateway serve demo`, then the same `inspect --client` snippets.

`mcp-gateway doctor` checks config, secrets, the local IR cache, and the SSRF policy.

## Can I deploy on Render, Heroku, DigitalOcean, or Hetzner?

Yes. The GitHub repo has platform guides and one-click buttons for Render, Heroku, and DigitalOcean App Platform, plus Compose/cloud-init for a Hetzner VPS: [openapi-mcp deploy docs](https://github.com/Fetch-Hive/openapi-mcp/blob/main/docs/deploy/README.md). After deploy, point the editor at `https://<host>/mcp` with the same bearer token.

Vercel cannot run this server (it is serverless, not a long-lived process). If you do not want to operate a VPS, use [hosted MCP Gateway](overview) for a **live** API. Hosted MCP Gateway does not proxy `localhost` — use the CLI on your machine for a branch API.

Set `MCP_GATEWAY_TOKEN` and `MCP_GATEWAY_SPEC_URL` (an HTTPS OpenAPI document). The container reads `PORT` itself.

## How is this different from hosted MCP Gateway?

Hosted MCP Gateway on Fetch Hive gives you a dashboard, client tokens, plan quotas, and a public `/g/{slug}` URL for live APIs. Self-hosting keeps the process and secrets on your machine and is how you attach an editor to a local checkout. Binding all interfaces requires `--expose`. TLS is your reverse proxy's job.

## Related

* [MCP Gateway overview](overview)
* [Create a hosted MCP server from OpenAPI](create-from-openapi)
* [Use a hosted MCP Gateway with an agent](use-with-agents)
