Skip to main content

HAPI CLI

The HAPI CLI is a command-line tool for managing and serving API projects using the HAPI server for Model Context Protocol (MCP). It enables you to bootstrap, configure, and run API-first services with ease.

Installation

To install HAPI CLI, you can download the latest release from the HAPI GitHub repository.

Another option is to use the install script accessible via curl:

Linux users

curl -fsSL https://get.mcp.com.ai/hapi.sh | bash

Windows users

irm https://get.mcp.com.ai/hapi.ps1 | iex

Or download the binary directly from the releases page

Other installation methods, including Docker, Fly.io, and Cloudflare Workers, can be found in the HAPI Server Deployment.

Commands Overview

  • serve: Start a HAPI MCP server from a local project name or a remote OpenAPI URL.
  • list: Show available specs discovered under ~/.hapi/specs (or your configured HAPI_HOME).
  • deploy: Publish a HAPI MCP server to Cloudflare Workers (uses Wrangler under the hood).
  • login: Authenticate the CLI for deploy targets.
  • --help: Display the full command and flag reference.

Basic Usage (serve)

To start a HAPI server for your API project, use the serve command:

# local file
hapi serve <projectname> [options]
# remote URL
hapi serve https://petstore3.swagger.io/api/v3/openapi.json [options]

Example

hapi serve petstore --headless

This will start the Headless API (HAPI) MCP server for the "petstore" project on port 3000 (default).

Common Options (serve)

OptionDescriptionDefault
-p, --portPort to listen on3000
--devEnable developer/debug mode
-m, --mcpEnable MCP mode (Greenfield)false
--headlessRun in headless mode (no REST API, only MCP - Brownfield)false
-u, --urlBase URL for backend API (used in headless mode) - default: Swagger's servershttp://localhost:3000
--certPath to SSL certificate file (.pem) for HTTPS
--keyPath to SSL key file (.pem) for HTTPS
-c, --corsComma-separated list of allowed origins for CORS* (all origins)

Environment variables

VariablePurpose
HAPI_HOMEDirectory for specs, configs, and logs (matches --home).
HAPI_OPENAPIOverride the OpenAPI source URL/path when using deploy flows.
HAPI_URLBackend base URL for headless mode.
HAPI_LOG_LEVEL_DEVLog level when NODE_ENV=development.
HAPI_LOG_LEVEL_PRODLog level when NODE_ENV=production.
HAPI_DISABLE_FILE_LOGSSet to true to disable file logging.

Tip: Flags take precedence over environment variables when both are provided.

Running with TLS (HTTPS)

To enable HTTPS, provide both a certificate and key file:

hapi serve linkedin --port 443 --cert ./certs/cert.pem --key ./certs/key.pem

Tip: You can generate a self-signed certificate for development using OpenSSL:

openssl req -x509 -newkey rsa:2048 -nodes -keyout key.pem -out cert.pem -days 365 -subj "/CN=localhost"

Headless Mode

Headless mode disables the REST API and only enables MCP server functionality:

hapi serve myproject --headless

CORS Configuration

Allow specific origins for CORS:

hapi serve myproject --cors "https://example.com,https://another.com"

Debugging

Enable debug mode to see detailed logs and registered routes:

hapi serve myproject --dev

Listing available specs

List all OpenAPI specs discovered in your HAPI home:

hapi list

Deploying to Cloudflare Workers

Use hapi deploy to publish a worker (Wrangler required):

hapi deploy --openapi https://petstore3.swagger.io/api/v3/openapi.json \
--url https://petstore3.swagger.io/api/v3 \
--name petstore-hapi

Notable flags:

  • --openapi <url>: (required) OpenAPI spec URL or file.
  • --url <url>: Backend base URL for headless mode.
  • --name <name>: Worker name (RFC 1123 compliant). Autogenerated if omitted.
  • --project <project>: Optional project grouping name.
  • --var KEY=VALUE: Repeatable extra vars passed to the worker.
  • --dry-run: Show what would be deployed without executing.
  • --keep-config: Keep generated temporary config files for inspection.

Using Docker

You can run the CLI inside a container for local or air-gapped environments:

docker run --name hapi-petstore -d --rm \
-p 3030:3030 \
-v ~/.hapi:/app/.hapi \
hapimcp/hapi-cli:latest serve petstore --port 3030 --headless

For more deployment patterns (Fly.io, Cloudflare, air-gapped), see the Docker deployment guide in the deployment section.

Help

To see all available commands and options:

hapi --help

Further Reading