> ## Documentation Index
> Fetch the complete documentation index at: https://docs.leanmcp.com/llms.txt
> Use this file to discover all available pages before exploring further.

# @leanmcp/cli

> Command-line tool for creating, developing, and deploying LeanMCP projects

# @leanmcp/cli

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

## Features

<CardGroup cols={2}>
  <Card title="Quick Scaffolding" icon="bolt">
    Create production-ready MCP servers in seconds
  </Card>

  <Card title="Hot Reload Development" icon="rotate">
    `leanmcp dev` with UI component hot-reload
  </Card>

  <Card title="Cloud Deployment" icon="cloud-arrow-up">
    Deploy to LeanMCP Cloud with custom subdomains
  </Card>

  <Card title="Project Management" icon="folder">
    List, view, and delete cloud projects
  </Card>

  <Card title="Environment Variables" icon="key">
    Manage Lambda environment variables from CLI
  </Card>
</CardGroup>

## Installation

```bash theme={null}
npm install -g @leanmcp/cli
```

Or run without installing:

```bash theme={null}
npx @leanmcp/cli create my-mcp-server
```

## Commands Overview

```bash theme={null}
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:

```bash theme={null}
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:

```bash theme={null}
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:

```bash theme={null}
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

```bash theme={null}
$ 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:

```bash theme={null}
leanmcp build
```

Compiles TypeScript and bundles UI components.

### start

Start the production server:

```bash theme={null}
leanmcp start
```

Runs the compiled production build.

***

## Cloud Commands

### login

Authenticate with LeanMCP Cloud:

```bash theme={null}
leanmcp login
```

Steps:

1. Go to [leanmcp.com/api-keys](https://leanmcp.com/api-keys)
2. Create an API key with "BUILD\_AND\_DEPLOY" scope
3. Enter the key when prompted

```bash theme={null}
$ leanmcp login

LeanMCP Login

To authenticate, you need an API key from LeanMCP.

Steps:
  1. Go to: https://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:

```bash theme={null}
leanmcp logout
```

### whoami

Check your current login status:

```bash theme={null}
leanmcp whoami
```

### deploy

Deploy your MCP server to LeanMCP Cloud:

```bash theme={null}
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

```bash theme={null}
$ 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:

```bash theme={null}
# 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:

```bash theme={null}
# 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
```

<Info>
  Changes to environment variables are applied immediately and will take effect after a cold start. See the [Environment Variables](/cli/env-vars) guide for detailed documentation.
</Info>

***

## NPM Scripts

Generated projects include:

```bash theme={null}
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

```bash theme={null}
# 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

```bash theme={null}
PORT=4000 npm run dev
# Or in .env file
PORT=4000
```

### LeanMCP Config

Stored in `~/.leanmcp/config.json`:

```json theme={null}
{
  "apiKey": "airtrain_...",
  "apiUrl": "https://api.leanmcp.com",
  "lastUpdated": "2024-01-15T10:30:00.000Z"
}
```

## Troubleshooting

<AccordionGroup>
  <Accordion title="Port Already in Use">
    Change the port in `.env`:

    ```bash theme={null}
    PORT=3002
    ```
  </Accordion>

  <Accordion title="Module Not Found Errors">
    Ensure dependencies are installed:

    ```bash theme={null}
    npm install
    ```
  </Accordion>

  <Accordion title="TypeScript Decorator Errors">
    Ensure your `tsconfig.json` has:

    ```json theme={null}
    {
      "compilerOptions": {
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true
      }
    }
    ```
  </Accordion>

  <Accordion title="Deploy: Not Logged In">
    Run `leanmcp login` first to authenticate with your API key.
  </Accordion>

  <Accordion title="Deploy: Subdomain Taken">
    Choose a different subdomain when prompted.
  </Accordion>
</AccordionGroup>

## Requirements

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

## Related Packages

* [@leanmcp/core](/sdk/core) - Core MCP server functionality
* [@leanmcp/auth](/sdk/auth) - Authentication decorators
* [@leanmcp/ui](/sdk/ui) - MCP App UI components

## Links

* [GitHub Repository](https://github.com/LeanMCP/leanmcp-sdk)
* [NPM Package](https://www.npmjs.com/package/@leanmcp/cli)
* [LeanMCP Dashboard](https://leanmcp.com)
