All posts

Blog

How to Host an MCP Server on Your Own VPS (with HTTPS and a Key)

By · · 9 min read

If you want to host an MCP server on your own VPS, the short answer is: run it in Docker, give it a domain with HTTPS, and put a key in front of it. Most MCP servers you find on GitHub only speak stdio, which means they expect to run on your laptop next to your AI app. To reach one over the internet, you wrap it in a small gateway that speaks HTTP. With Dokploy that's one Compose file and a few clicks, no nginx and no certbot.

I'll walk through it for someone who has never self-hosted anything, with a real server you can copy. Then I'll show the easier way, where I asked Claude to check the setup on my Dokploy for me.

Local vs remote MCP servers

An MCP server gives an AI app (Claude, Cursor, ChatGPT and others) new tools. There are two ways an app can talk to one:

  • stdio (local). The app starts the server as a program on your machine and talks to it through standard input and output. Most servers in READMEs are set up this way, with a command like npx -y some-mcp-server.
  • Streamable HTTP (remote). The server runs somewhere else and the app sends requests to a URL like https://mcp.yourdomain.com/mcp. This is what you need for a server on a VPS, and what Claude's custom connectors use.

So hosting an MCP server comes down to two cases. If the server already speaks HTTP (its README mentions a URL, a port or "remote"), you just deploy it. If it only speaks stdio, you run it behind Supergateway, an open source tool that starts the stdio server inside the container and exposes it as Streamable HTTP.

What you need

  • A VPS. Dokploy needs at least 2 GB of RAM and 30 GB of disk. One small MCP server uses very little on top of that. Hetzner, DigitalOcean, Hostinger and others all work. Choose Ubuntu or Debian.
  • A domain you can add DNS records to. Claude only connects to remote MCP servers over HTTPS on port 443, so a bare IP and port won't do.
  • The MCP server you want to host. In this guide I use the official memory server (@modelcontextprotocol/server-memory), which gives your AI a small knowledge graph it can write to and read back. It's a good first server because it's harmless and you can see it working.

Step 1: Install Dokploy

SSH into your server and run Dokploy's install script:

curl -sSL https://dokploy.com/install.sh | sh

Ports 80, 443 and 3000 must be free. When it finishes, open http://your-server-ip:3000 and create your admin account.

Step 2: Check for a template first

Dokploy has a template library, and some MCP servers are already in it. When I listed the templates on my Dokploy there were 602, and a handful are MCP servers or ship one: Wise MCP (an unofficial Wise connector), Obscura Browser (a headless browser for agents), Dexio (a shared wiki agents read and write over MCP) and Orbit (task management with an OAuth MCP endpoint), among others.

If the server you want is there: create a project, click Create Service, choose Template, search for it, and create it. The template fills in the domain and generates secrets. Skip to Step 5 to check the domain and deploy.

The memory server isn't a template, and neither are most servers you'll find on GitHub. So the rest of this guide is the route that works for any of them: a Docker Compose file.

Step 3: Create the Compose service

  1. Create a project in Dokploy (call it "mcp").
  2. Inside it, click Create Service, choose Compose, and name it memory-mcp.
  3. Under Provider, choose Raw and paste this:
services:
  memory-mcp:
    image: supercorp/supergateway:4.3.0
    restart: unless-stopped
    command:
      - --stdio
      - npx -y @modelcontextprotocol/[email protected]
      - --outputTransport
      - streamableHttp
    environment:
      - SUPERGATEWAY_API_KEY=${MCP_API_KEY}
      - MEMORY_FILE_PATH=/data/memory.jsonl
    volumes:
      - memory-data:/data
    expose:
      - 8000

volumes:
  memory-data: {}
  1. Click Save.

What each part does:

  • supercorp/supergateway is the gateway image. It runs the command after --stdio as the real MCP server and serves it on port 8000 at /mcp.
  • --outputTransport streamableHttp matters. Supergateway's default output with --stdio is the older SSE transport, so leave this line in.
  • SUPERGATEWAY_API_KEY makes the gateway refuse any request that doesn't send the key, as Authorization: Bearer <key> or X-API-Key: <key>. Without it, anyone who finds the URL can use your server. Supergateway even prints a warning at startup if no key is set.
  • MEMORY_FILE_PATH and the volume keep the memory file on a Docker volume, so it survives redeploys. The memory server's own README says to set an absolute path, because the default sits inside node_modules and can be wiped.
  • expose instead of ports keeps port 8000 off the public internet. Dokploy's Traefik reaches it inside Docker's network and serves it on your domain.

To host a different stdio server, change the line after --stdio to its command from the README, and add whatever environment variables it needs. Supergateway also publishes a -uvx image tag for Python servers started with uvx.

Step 4: Set the key

Open the service's Environment tab and add:

MCP_API_KEY=

Set it to a long random string. You can generate one on any machine:

openssl rand -hex 32

Keep a copy somewhere safe. Your AI app will send it on every request.

Step 5: Add your domain with HTTPS

  1. At your DNS provider, add an A record for mcp.yourdomain.com pointing to your server's IP. On Cloudflare, set it to DNS only (grey cloud) so Let's Encrypt can reach your server.
  2. In Dokploy, open the service's Domains tab and add a domain: host mcp.yourdomain.com, service memory-mcp, port 8000, path /, turn on HTTPS and choose Let's Encrypt.
  3. Click Deploy. The first start takes a minute, because the container downloads the memory server with npx.

You can check it from your own machine. A request without the key should be refused with a 401:

curl -i -X POST https://mcp.yourdomain.com/mcp \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"test","version":"1"}}}'

Add -H "Authorization: Bearer YOUR_KEY" and the same request should answer with the server's name and capabilities. If something's off, the service's Logs tab shows Supergateway's output.

Step 6: Connect your AI app

Claude Code takes the key as a header:

claude mcp add --transport http memory https://mcp.yourdomain.com/mcp \
  --header "Authorization: Bearer YOUR_KEY"

Cursor takes the same thing in mcp.json:

{
  "mcpServers": {
    "memory": {
      "url": "https://mcp.yourdomain.com/mcp",
      "headers": { "Authorization": "Bearer YOUR_KEY" }
    }
  }
}

Then ask it to remember something ("remember that my staging server runs Debian 12"), open a new chat, and ask what it knows.

Claude on the web and desktop is different. Custom connectors there support OAuth sign-in or no sign-in at all. Sending a fixed key as a request header is, per Anthropic's connector docs, a beta for a limited set of organizations. So a key-protected server like this one is for Claude Code, Cursor and other apps that let you set headers. For claude.ai, either pick a server that ships its own OAuth sign-in (several of the Dokploy templates above do), or check whether your organization has the header option. I wouldn't run a server with no sign-in on a public URL.

Two more things from those docs: Claude connects from Anthropic's IP ranges, so the server must be reachable from the public internet, and the URL can't carry a port like :8443. Dokploy's Traefik on 443 covers both.

Lock down the server

Same advice as any VPS, from Dokploy's security recommendations:

  • Use your VPS provider's firewall and allow only SSH, 80 and 443. Docker writes its own iptables rules and walks past UFW.
  • Use SSH keys and turn off password login.
  • Give Dokploy its own HTTPS domain, then close port 3000.
  • Think about what the server can reach. An MCP server does what its tools do. A memory server writes one file. A filesystem or shell server on a VPS can touch everything on that VPS, so give those containers only the volumes they need.
  • Pin versions, as in the Compose file above, so a new release of a server doesn't change your tools under you. Bump them on purpose.

The easier way: just ask Claude

All of that is clicking through Dokploy. You can skip learning Dokploy by connecting it to Claude (or any AI that speaks MCP) through Zeqqat. You add your Dokploy URL and an API key to Zeqqat once, then paste Zeqqat's MCP URL into Claude as a connector. After that you say what you want.

Here's what I asked:

I want to host an MCP server on my Dokploy. Check whether Dokploy has a template for it, and if not, show me exactly what my Compose file would create. Don't create anything.

Here's what happened, call by call:

  1. Claude searched Zeqqat for "template" and found Dokploy's template tools: list, preview and deploy.
  2. It listed the templates. My Dokploy has 602. It picked out the ones that are MCP servers or ship one, the list in Step 2, and noted the memory server isn't among them.
  3. It packed the Compose file from Step 3 with a small template config (the domain on port 8000 and a generated MCP_API_KEY) and ran Dokploy's template preview, which is read only. Dokploy worked out what it would create without saving anything:
domains: memory-mcp, port 8000, <generated>.sslip.io
envs:
  MCP_API_KEY={{zq_secret_9bn6aal15oe3d1qj}}
mounts: []

The generated key never reached Claude. Zeqqat swapped it for a {{zq_secret_...}} handle before the answer came back, and Claude can pass that handle back in later calls without ever seeing the value. That matters here, because this key is the one thing standing between the internet and your MCP server. Claude also pointed out that the generated sslip.io domain is HTTP only, so the real domain with Let's Encrypt from Step 5 is still needed before Claude can connect.

I stopped there. Deploying is one more call to Dokploy's deploy-template tool, and my Zeqqat connection allows it because it creates something new. Delete is switched off on that connection, so Claude can set things up but can't remove anything. Every call carried the same one-line reason, so Zeqqat's activity log shows the whole thing as one request.

What I took from it

Hosting an MCP server is the same job as hosting any small web service: a container, a domain, HTTPS and a key. The only MCP-specific part is that most servers speak stdio, and Supergateway turns them into a URL. Dokploy makes the rest a Compose file and a domain form. The one thing I'd never skip is the key.

Zeqqat is a free and open source MCP gateway for Dokploy. Self-host it or use zeqqat.com. The code is on GitHub.

FAQ

Can I host an MCP server for free?

The software is free: Dokploy, Supergateway and most MCP servers are open source. You pay for the VPS, which is a few dollars a month at most providers, and a domain if you don't have one. One VPS can host many MCP servers side by side, each with its own subdomain.

What is the difference between a local and a remote MCP server?

A local MCP server runs on your own computer and your AI app talks to it over stdio. A remote MCP server runs on a server and your AI app talks to it over HTTP at a URL. The tools are the same; remote means it's always on, works from any device, and can be shared, which is also why it needs HTTPS and authentication.

Can Claude connect to an MCP server on my VPS?

Yes, if it's on a public HTTPS URL on port 443. Claude Code and Cursor can send an API key in a header, so a key-protected server works with them. Claude on the web and desktop supports servers with OAuth sign-in or no sign-in, and fixed header keys only as a beta for some organizations, so check that before you pick how to protect the server.