Deploying HAPI MCP Server on Fly.io
This guide explains how to deploy the HAPI MCP Server on Fly.io using the official pre-built image (hapimcp/hapi-cli). You do not need to build or customize a Dockerfileβjust use the official image for a fast, reliable deployment.
Prerequisitesβ
- A Fly.io account
- The flyctl CLI installed on your machine
Quick Start: Run a HAPI MCP Server Instantlyβ
For rapid prototyping or testing, you can use fly machine run to launch a HAPI MCP Server instance immediately, bypassing the need for manual app creation or configuration files.
fly machine run hapimcp/hapi-cli:latest --command \
"hapi serve --specs https://petstore3.swagger.io/api/v3/openapi.json --url https://petstore3.swagger.io/api/v3 --headless"
- Replace
latestwith a specific version tag if needed. - Pass
hapi serve's own flags (--specs,--url,--headless, etc.) directly in--commandβ this is the same invocation you'd run locally, just wrapped for Fly's machine runner. - Use
-eto set additional environment variables the server should see at runtime (e.g.HAPI_PUBLIC_HOST, secrets), not the document source itself.
Possible Combinations
-
Custom Port: Add
-p 8080to expose a specific port. -
Additional Environment Variables: Add more
-e VAR=valueflags as needed. -
Custom Command: Run a different command if you need to override the default entrypoint.
Ephemeral Machines:β
Add --ephemeral to create a machine that is automatically destroyed when stopped.
Recommended: Launch and Deploy for Production
If you plan to run a production MCP server, follow the full deployment steps below to create a persistent app with proper configuration that can be managed and scaled.
Stepsβ
1. Authenticate with Fly.ioβ
Log in to your Fly.io account:
fly auth login
If you don't have an account, sign up with:
fly auth signup
2. Create and Configure Your App/MCP Serverβ
Create a new Fly.io app and generate a configuration file:
fly launch --no-deploy --image hapimcp/hapi-cli:latest
- When prompted, choose a unique app name and region.
- This creates a
fly.tomlfile in your directory. Add a[processes]entry telling Fly whichhapi servecommand to run β see thefly.tomlexample at the end of this guide, which passes--specs/--url/--headlessdirectly rather than through environment variables.
3. Edit fly.toml for the Pre-Built Imageβ
Open the generated fly.toml and ensure it does not reference a build section. You will deploy using the pre-built image, so the build section can be removed or ignored.
4. Deploy the Pre-Built HAPI MCP Imageβ
Deploy your app using the official image:
fly deploy -- serve
# Or specify the image explicitly:
fly deploy --image hapimcp/hapi-cli:latest
- Replace
latestwith a specific version tag if needed. - This command will push the pre-built image to Fly.io and start your HAPI MCP Server.
5. (Optional) Set Environment Variablesβ
If your HAPI MCP Server requires environment variables, set them with:
fly secrets set VAR_NAME=value
Or add them to your fly.toml under the [env] section.
Use secrets for sensitive data like API keys.
6. Monitor and Access Your App/MCP Serverβ
After deployment, Fly.io will provide a public URL for your app. You can monitor logs with:
fly logs
Notesβ
- No Dockerfile or local build is required.
- You can redeploy at any time with the same
fly deploy --image ...command. - For advanced configuration (volumes, scaling, etc.), refer to the Fly.io documentation.
fly.toml example for HAPI MCP Serverβ
app = 'my-mcp-server'
primary_region = 'dfw'
[build]
image = 'hapimcp/hapi-cli:latest'
[processes]
app = 'hapi serve --specs https://petstore3.swagger.io/api/v3/openapi.json --url https://petstore3.swagger.io/api/v3 --headless'
[http_service]
internal_port = 3000
force_https = true
auto_stop_machines = 'stop'
auto_start_machines = true
min_machines_running = 0
processes = ['app']
[[vm]]
memory = '256mb'
cpus = 1
memory_mb = 256
internal_port matches hapi serve's default port (3000). If you pass
--port explicitly, update internal_port to match.