Skip to main content

@leanmcp/cli

Command-line tool for creating, developing, and deploying MCP servers to LeanMCP Cloud.

Features

Quick Scaffolding

Create production-ready MCP servers in seconds

Hot Reload Development

leanmcp dev with UI component hot-reload

Cloud Deployment

Deploy to LeanMCP Cloud with custom subdomains

Project Management

List, view, and delete cloud projects

Environment Variables

Manage Lambda environment variables from CLI

Installation

npm install -g @leanmcp/cli
Or run without installing:
npx @leanmcp/cli create my-mcp-server

Commands Overview

leanmcp create <name>     # Create a new project
leanmcp add <service>     # Add a service to existing project
leanmcp dev               # Start development server with hot-reload
leanmcp build             # Build for production
leanmcp start             # Start production server

# Cloud commands
leanmcp login             # Authenticate with LeanMCP Cloud
leanmcp logout            # Remove API key
leanmcp whoami            # Show login status
leanmcp deploy <folder>   # Deploy to LeanMCP Cloud
leanmcp projects list     # List your cloud projects
leanmcp projects get <id> # Get project details
leanmcp projects delete <id>  # Delete a project

# Environment variables
leanmcp env list          # List environment variables
leanmcp env set KEY=val   # Set environment variable
leanmcp env get KEY       # Get environment variable
leanmcp env remove KEY    # Remove environment variable
leanmcp env pull          # Pull to .env file
leanmcp env push          # Push from .env file

Local Development

create

Create a new MCP server project:
leanmcp create my-sentiment-tool
Interactive prompts will guide you through:
  1. Creating the project structure
  2. Installing dependencies (optional)
  3. Starting the dev server (optional)
Generated structure:
my-mcp-server/
├── main.ts              # Entry point with HTTP server
├── package.json         # Dependencies and scripts
├── tsconfig.json        # TypeScript configuration
└── mcp/                 # Services directory
    └── example.ts       # Example service with tools

add

Add a new service to an existing project:
cd my-mcp-server
leanmcp add weather
This:
  • Creates mcp/weather.ts with example Tool, Prompt, and Resource
  • Automatically registers the service in main.ts
  • Includes @SchemaConstraint validation examples

dev

Start the development server with hot-reload:
leanmcp dev
This command:
  • Scans for @UIApp components and builds them
  • Starts the HTTP server with tsx watch
  • Watches mcp/ directory for changes
  • Automatically rebuilds UI components when modified
  • Hot-reloads when adding/removing @UIApp decorators
$ leanmcp dev

LeanMCP Development Server

 Found 2 @UIApp component(s)
 UI components built

Starting development server...

[HTTP][INFO] Server running on http://localhost:3001
[HTTP][INFO] MCP endpoint: http://localhost:3001/mcp

build

Build the project for production:
leanmcp build
Compiles TypeScript and bundles UI components.

start

Start the production server:
leanmcp start
Runs the compiled production build.

Cloud Commands

login

Authenticate with LeanMCP Cloud:
leanmcp login
Steps:
  1. Go to ship.leanmcp.com/api-keys
  2. Create an API key with “BUILD_AND_DEPLOY” scope
  3. Enter the key when prompted
$ leanmcp login

LeanMCP Login

To authenticate, you need an API key from LeanMCP.

Steps:
  1. Go to: https://ship.leanmcp.com/api-keys
  2. Create a new API key with "BUILD_AND_DEPLOY" scope
  3. Copy the API key and paste it below

? Enter your API key: airtrain_xxxxx...
 API key validated and saved

Login successful!
   Config saved to: ~/.leanmcp/config.json

logout

Remove your API key:
leanmcp logout

whoami

Check your current login status:
leanmcp whoami

deploy

Deploy your MCP server to LeanMCP Cloud:
leanmcp deploy .
# Or specify a folder
leanmcp deploy ./my-project
Deployment process:
  1. Creates project (or updates existing)
  2. Packages and uploads code
  3. Builds container image
  4. Deploys to serverless Lambda
  5. Configures custom subdomain
$ leanmcp deploy .

LeanMCP Deploy

Generated project name: swift-coral-sunset
Path: /path/to/my-project

? Subdomain for your deployment: my-api
 Subdomain 'my-api' is available

Deployment Details:
  Project: swift-coral-sunset
  Subdomain: my-api
  URL: https://my-api.leanmcp.dev

? Proceed with deployment? Yes

 Project created: 7f4a3b2c...
 Project uploaded
 Build complete (45s)
 Deployed
 Subdomain configured

============================================================
  DEPLOYMENT SUCCESSFUL!
============================================================

  Your MCP server is now live:

  URL:  https://my-api.leanmcp.dev

  Test endpoints:
    curl https://my-api.leanmcp.dev/health
    curl https://my-api.leanmcp.dev/mcp

projects

Manage your cloud projects:
# List all projects
leanmcp projects list

# Get project details
leanmcp projects get <project-id>

# Delete a project
leanmcp projects delete <project-id>
leanmcp projects delete <project-id> --force  # Skip confirmation

env

Manage environment variables on your deployed Lambda functions:
# List environment variables
leanmcp env list
leanmcp env list --reveal  # Show actual values

# Set variables
leanmcp env set API_KEY=sk-123 DEBUG=true

# Get a specific variable
leanmcp env get API_KEY --reveal

# Remove a variable
leanmcp env remove OLD_KEY

# Pull to local .env file
leanmcp env pull

# Push from local .env file
leanmcp env push
leanmcp env push --replace  # Replace all variables
Changes to environment variables are applied immediately and will take effect after a cold start. See the Environment Variables guide for detailed documentation.

NPM Scripts

Generated projects include:
npm run dev     # Start with hot reload (tsx watch)
npm run build   # Build for production
npm run start   # Run production build
npm run clean   # Remove build artifacts

Testing Your Server

# List available tools
curl http://localhost:3001/mcp \
  -X POST \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "tools/list"
  }'

# Call a tool
curl http://localhost:3001/mcp \
  -X POST \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "tools/call",
    "params": {
      "name": "calculate",
      "arguments": { "a": 10, "b": 5, "operation": "add" }
    }
  }'

Configuration

Port

PORT=4000 npm run dev
# Or in .env file
PORT=4000

LeanMCP Config

Stored in ~/.leanmcp/config.json:
{
  "apiKey": "airtrain_...",
  "apiUrl": "https://api.leanmcp.com",
  "lastUpdated": "2024-01-15T10:30:00.000Z"
}

Troubleshooting

Change the port in .env:
PORT=3002
Ensure dependencies are installed:
npm install
Ensure your tsconfig.json has:
{
  "compilerOptions": {
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true
  }
}
Run leanmcp login first to authenticate with your API key.
Choose a different subdomain when prompted.

Requirements

  • Node.js >= 18.0.0
  • npm >= 9.0.0