Skip to main content

HAPI CLI

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

Installation

You can install the HAPI CLI globally using Bun or npm:

# Linux
curl -fsSL https://get.mcp.com.ai/install | bash
# Windows
irm https://get.mcp.com.ai/install.ps1 | iex

Basic Usage

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

hapi serve <projectname> [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

OptionDescriptionDefault
-p, --portPort to listen on3000
-d, --debugEnable 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)

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 --debug

Help

To see all available commands and options:

hapi --help

Further Reading