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
Option | Description | Default |
---|---|---|
-p, --port | Port to listen on | 3000 |
-d, --debug | Enable debug mode | |
-m, --mcp | Enable MCP mode (Greenfield) | false |
--headless | Run in headless mode (no REST API, only MCP - Brownfield) | false |
-u, --url | Base URL for backend API (used in headless mode) - default: Swagger's servers | http://localhost:3000 |
--cert | Path to SSL certificate file (.pem) for HTTPS | |
--key | Path to SSL key file (.pem) for HTTPS | |
-c, --cors | Comma-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