Enable the Cloudflare Tunnel publisher
By default the MCP tunnel listens on loopback only. This guide publishes it through Cloudflare Tunnel, the proposed default transport.
Prerequisites
Section titled “Prerequisites”- A Cloudflare account and a zone you control
- A running sandbox stack
-
Create a tunnel in the Cloudflare Zero Trust dashboard under Networks, then Tunnels. Choose the cloudflared connector and copy the tunnel token.
-
Point the tunnel’s public hostname at the MCP tunnel service. Set the ingress origin to
http://mcp-tunnel:8787, which is the service name on the compose network. -
Add the token to your
.env.Terminal window CLOUDFLARE_TUNNEL_TOKEN=YOUR-TUNNEL-TOKEN -
Start the stack with the cloudflared profile.
Terminal window just up-cloudflared -
Verify from outside. Replace the hostname with the one you configured.
Terminal window curl https://mcp.example.com/healthz# {"ok":true,"routes":["example"]}
Protect the endpoint
Section titled “Protect the endpoint”MCP servers behind the tunnel trust their callers, so put Cloudflare Access in front of the public hostname before sharing it. An Access policy that requires your identity provider costs nothing extra and turns the endpoint from public to authenticated.