NitroStack Logo
/ai agents
/cli reference

NitroStack CLI Reference - For AI Code Editors

Comprehensive CLI reference for AI agents working with NitroStack v3.0


Installation

Bash
# Global install (recommended)
npm install -g @nitrostack/cli

# Or run on-demand with npx
npx @nitrostack/cli <command>

Commands Overview

Bash
nitrostack init <project-name> [options]         # Create new project
nitrostack dev [--port <number>]                 # Start development mode
nitrostack build [--output <path>]               # Build for production
nitrostack start [--port <number>]               # Start production MCP server
nitrostack generate <type> [name] [options]      # Generate code boilerplate
nitrostack upgrade [--dry-run] [--latest]        # Upgrade packages & skills
nitrostack install [--skip-widgets]              # Install root and widget deps
nitrostack cursor [options]                      # Configure Cursor IDE MCP integration
nitrostack pack [options]                        # Package production zip bundle
nitrostack --version                             # Show version
nitrostack --help                                # Show help

1. Initialize Project

Bash
# Basic initialization (uses typescript-starter)
npx @nitrostack/cli init my-project

# Using preset shorthand:
npx @nitrostack/cli init my-project --preset starter
npx @nitrostack/cli init my-enterprise --preset enterprise-search
npx @nitrostack/cli init my-codemode --preset code-mode
npx @nitrostack/cli init my-pizzaz --preset pizzaz
npx @nitrostack/cli init my-flights --preset oauth

# Or with full template name:
npx @nitrostack/cli init my-enterprise --template typescript-enterprise-search

Available Templates & Presets

  1. typescript-starter (Preset: starter, Default)

    • Calculator tool, resource, and prompt examples
    • Interactive UI widget
    • Health checks and DI configuration
    • Perfect for quick starts and learning basics
  2. typescript-enterprise-search (Preset: enterprise-search)

    • Progressive tool discovery with BM25SearchTransform
    • @Controller domain namespacing (finance, inventory, support)
    • Reduces model prompt token consumption by up to 98%
    • alwaysVisible bypass for bootstrap tools
  3. typescript-code-mode (Preset: code-mode)

    • Sandboxed QuickJS WebAssembly script execution
    • Dedicated worker thread pool with memory and timeout caps
    • Exposes search, get_schema, and execute meta-tools
    • Batch data pipeline scripts in a single round-trip
  4. typescript-pizzaz (Preset: pizzaz, Rich UI & Widgets)

    • Pizza shop finder with interactive Mapbox map
    • Multi-widget dashboard integration
    • State and theme synchronization
    • Next.js and Tailwind widget architecture
  5. typescript-oauth (Preset: oauth, Production Authentication)

    • OAuth 2.1 authentication flow with PKCE
    • Duffel API flight booking tools
    • Token introspection and scope guards
    • Enterprise security architecture

What init Does

  1. Copies selected template files
  2. Installs npm dependencies (MCP server)
  3. Installs widget dependencies (src/widgets/)
  4. Creates .env from .env.example
  5. Copies agent skills (SKILL.md) to .cursor/skills, .claude/skills, .gemini/skills, etc.

After Init

Bash
cd my-project

# Start development (MCP server + widget dev server)
npm run dev

2. Development Mode

Bash
# Start development (MCP server + widget dev server)
nitrostack-cli dev

# Custom port for widget development server (default: 3001)
nitrostack-cli dev --port 3005

What It Starts

  1. MCP Server (stdio mode)

    • Communicates via stdin/stdout
    • Follows MCP protocol spec
    • Hot reload on code changes
  2. Studio (port 3000, or custom)

    • Visual development interface
    • Test tools manually
    • AI chat (OpenAI/Gemini)
    • Widget preview
    • Resources browser
    • Prompts testing
    • Health checks dashboard
    • OAuth 2.1 config
    • Connection monitoring
  3. Widget Dev Server (port 3001)

    • Next.js dev server
    • Hot module replacement
    • Serves UI widgets
    • Fast refresh

Studio Features

TabPurpose
ToolsExecute tools, see widget previews, examples
AI ChatChat with LLM using your tools
ResourcesBrowse resources, view UI widgets
PromptsTest prompt templates
HealthMonitor health checks
OAuth 2.1Configure OAuth endpoints
PingTest MCP connection

URLs

  • Studio UI: http://localhost:3000
  • Widget Dev: http://localhost:3001
  • MCP Server: stdio (no HTTP)

Hot Reload

Changes auto-reload:

  • TypeScript files (src/**/*.ts)
  • Widget files (src/widgets/app/**/*)
  • No manual restart needed

3. Build Project

Bash
nitrostack-cli build

Build Process

The nitrostack-cli build command:

  1. Builds Widgets First (if present)

    • Input: src/widgets/
    • Output: src/widgets/.next/
    • Production optimized
    • Static assets bundled
  2. Compiles TypeScript

    • Input: src/**/*.ts
    • Output: dist/**/*.js
    • ES modules format
    • Source maps included
  3. Auto-Detects Project Structure

    • Checks for src/widgets/package.json
    • Installs widget dependencies if needed
    • Handles everything automatically

Output Structure

dist/
├── index.js               # Entry point
├── app.module.js
├── modules/
│   ├── auth/
│   ├── products/
│   └── ...
└── ... (all compiled code)

src/widgets/.next/         # Built widgets

Run Production Build

Bash
# After build - use npm script (recommended)
npm start

# Or run directly
node dist/index.js

# Or use CLI
nitrostack-cli start

The nitrostack-cli start command:

  • Runs the compiled dist/index.js
  • Starts widget production server (if built)
  • Sets NODE_ENV=production
  • Handles all process orchestration

4. Generate Code

Generate Module

Bash
nitrostack-cli generate module payments

Creates:

src/modules/payments/
├── payments.module.ts       # @Module definition
├── payments.tools.ts        # @Tool definitions
├── payments.resources.ts    # @Resource definitions
├── payments.prompts.ts      # @Prompt definitions
└── payments.service.ts      # @Injectable service

Generated module includes:

  • Boilerplate decorator setup
  • Example tool with Zod schema
  • Example resource
  • Example prompt
  • Injectable service with DI
  • Ready to import in app.module.ts

Generate Tools

Bash
nitrostack-cli generate tools process-payment --module payments
  • Adds tool to src/modules/payments/payments.tools.ts
  • Includes:
    • @Tool decorator
    • Zod input schema
    • Example request/response
    • @Widget placeholder
    • Execution context

Generate Resources

Bash
nitrostack-cli generate resources payment-schema --module payments
  • Adds resource to src/modules/payments/payments.resources.ts
  • Includes URI pattern, mime type, examples

Generate Prompts

Bash
nitrostack-cli generate prompts payment-help --module payments
  • Adds prompt to src/modules/payments/payments.prompts.ts
  • Includes arguments, message template

Generate Guard

Bash
nitrostack-cli generate guard admin

Creates src/guards/admin.guard.ts:

Typescript
@Injectable()
export class AdminGuard implements Guard {
  async canActivate(context: ExecutionContext): Promise<boolean> {
    // Your authorization logic
  }
}

Usage:

Typescript
@Tool({ name: 'admin_tool' })
@UseGuards(AdminGuard)
async adminTool(input: any, ctx: ExecutionContext) {}

Generate Middleware

Bash
nitrostack-cli generate middleware logging

Creates src/middleware/logging.middleware.ts:

Typescript
@Middleware()
export class LoggingMiddleware implements MiddlewareInterface {
  async use(context: ExecutionContext, next: () => Promise<any>) {
    // Before
    const result = await next();
    // After
    return result;
  }
}

Generate Interceptor

Bash
nitrostack-cli generate interceptor transform

Creates src/interceptors/transform.interceptor.ts:

Typescript
@Interceptor()
export class TransformInterceptor implements InterceptorInterface {
  async intercept(context: ExecutionContext, next: () => Promise<any>) {
    const result = await next();
    return { success: true, data: result };
  }
}

Generate Pipe

Bash
nitrostack-cli generate pipe validation

Creates src/pipes/validation.pipe.ts:

Typescript
@Pipe()
export class ValidationPipe implements PipeInterface {
  async transform(value: any, metadata: any): Promise<any> {
    // Transform/validate value
    return value;
  }
}

Generate Types

Bash
# Generate TypeScript types from tool schemas
nitrostack-cli generate types

# Custom output path
nitrostack-cli generate types --output src/widgets/types/generated.ts

What It Does:

  1. Scans all *.tools.ts files
  2. Extracts Zod schemas from @Tool decorators
  3. Converts to TypeScript interfaces
  4. Outputs to src/widgets/types/tool-data.ts (default)

Example Input (tool):

Typescript
@Tool({
  name: 'get_product',
  inputSchema: z.object({
    product_id: z.string()
  })
})
async getProduct(input: any) {
  return { id: input.product_id, name: 'Product', price: 99 };
}

Example Output (generated types):

Typescript
// Auto-generated by NitroStack CLI
export interface GetProductInput {
  product_id: string;
}

export interface GetProductOutput {
  id: string;
  name: string;
  price: number;
}

Usage in Widgets:

Typescript
import { GetProductOutput } from '../../types/tool-data';

export default function ProductCard({ data }: { data: GetProductOutput }) {
  return <div>{data.name} - ${data.price}</div>;
}

When to Run:

  • After adding new tools
  • After modifying tool schemas
  • Before building widgets
  • As part of CI/CD pipeline

5. Cursor IDE Integration (nitrostack cursor)

Integrate your MCP server directly into Cursor IDE (.cursor/mcp.json or ~/.cursor/mcp.json):

Bash
# Configure local .cursor/mcp.json (default: command mode)
nitrostack cursor

# Configure with legacy SSE endpoint
nitrostack cursor --type legacy-sse --port 3000

# Configure with modern MCP 2026-07-28 Streamable HTTP endpoint
nitrostack cursor --type streamable-http --url http://localhost:3000/mcp

# Global configuration with overwrite
nitrostack cursor --global --force

Options:

  • -g, --global: Write to user home ~/.cursor/mcp.json
  • -l, --local: Write to .cursor/mcp.json (default)
  • -t, --type <type>: command, legacy-sse, or streamable-http
  • -u, --url <url>: Explicit server URL
  • -p, --port <port>: Port for HTTP URL generation (default: 3000)
  • --force: Overwrite existing configuration key

6. Project Packaging (nitrostack pack)

Create a clean, production-ready .zip deployment archive excluding build artifacts, local caches, and secret .env files:

Bash
# Create deployment bundle (e.g. my-project.zip in root)
nitrostack pack

# Preview files that would be included/excluded
nitrostack pack --dry-run

# Include environment variables if deploying to secure cloud workers
nitrostack pack --include-env

# Custom output zip name
nitrostack pack --output deploy-v1.0.0.zip

Default Exclusions:

  • node_modules/, .git/, .next/, dist/
  • .env, .env.local, .env.*.local (unless --include-env is passed)
  • Canonical .gitignore rules automatically synchronized

Configuration

Application Configuration (ConfigModule & .env)

NitroStack applications configure server settings, DI parameters, and runtime variables using @nitrostack/core's ConfigModule and environment variables (.env). NitroStack does not use a nitrostack.config.ts configuration file.

Typescript
import { McpApp, Module, ConfigModule } from '@nitrostack/core';

@McpApp({
  name: 'my-server',
  version: '1.0.0',
  description: 'My MCP server',
  module: AppModule
})
@Module({
  imports: [
    ConfigModule.forRoot({
      isGlobal: true,
      envFilePath: '.env',
    }),
  ]
})
export class AppModule {}

Environment Variables (.env)

Env
# Node Environment
NODE_ENV=development

# Server Configuration
PORT=3000
MCP_SERVER_PORT=3000
WIDGET_PORT=3001
LOG_LEVEL=info

# OAuth 2.1 (if using typescript-oauth template)
OAUTH_CLIENT_ID=your-client-id
OAUTH_CLIENT_SECRET=your-client-secret
OAUTH_REDIRECT_URI=http://localhost:3000/callback

# Gemini API (for Studio chat)
GEMINI_API_KEY=your-gemini-key

Common Workflows

1. Create New Project (Starter Template)

Bash
# Install CLI
npm install -g @nitrostack/cli

# Initialize project
npx @nitrostack/cli init my-calculator --template typescript-starter
cd my-calculator

# Start development
npm run dev

# Open Studio
# http://localhost:3000

2. Create New Project (OAuth 2.1 Template)

Bash
# Initialize flight booking template
npx @nitrostack/cli init flight-booking --preset oauth
cd flight-booking

# Start development
npm run dev

3. Create Enterprise Search Project (BM25 Progressive Discovery)

Bash
# Initialize enterprise search template
npx @nitrostack/cli init enterprise-portal --preset enterprise-search
cd enterprise-portal

# Start development
npm run dev

4. Create Sandboxed Execution Project (Code Mode)

Bash
# Initialize QuickJS code mode template
npx @nitrostack/cli init data-engine --preset code-mode
cd data-engine

# Start development
npm run dev

5. Add New Feature Module

Bash
# Generate module
nitrostack-cli generate module payments

# Add to app.module.ts imports
# imports: [ConfigModule.forRoot(), PaymentsModule]

# Generate tools
nitrostack-cli generate tools create-payment --module payments
nitrostack-cli generate tools get-payment --module payments

# Generate types for widgets
nitrostack-cli generate types

# Create widget
mkdir -p src/widgets/app/payment-success
# Create page.tsx in that directory

# Test in Studio
npm run dev

4. Development Cycle

Bash
# Start dev server (auto-detects and builds everything)
npm run dev

# The CLI automatically:
# - Installs dependencies (if needed)
# - Builds widgets (on first run)
# - Starts TypeScript watch mode
# - Starts Studio
# - Starts widget dev server
# - Hot reloads everything

# Edit code (auto-reloads)
# - Edit src/modules/**/*.ts (MCP server hot reloads)
# - Edit src/widgets/app/**/* (Widget dev server hot reloads)

# Test in Studio
# - Execute tools manually
# - Test with AI chat
# - Preview widgets

# Add widget dependencies
npm run widget add <package-name>

# Generate types for widgets
nitrostack-cli generate types

# Build for production
npm run build

# Test production build
npm start

5. Deploy to Production

Bash
# Build project
nitrostack-cli build

# Copy to server
scp -r dist/ user@server:/app/
scp -r src/widgets/.next/ user@server:/app/widgets/
scp package.json user@server:/app/
scp .env.production user@server:/app/.env

# On server
cd /app
npm install --production
node dist/index.js

Troubleshooting

CLI Not Found

Bash
# Install globally
npm install -g nitrostack

# Or use npx
npx nitrostack-cli init my-project

Port Already in Use

Bash
# Use custom port
nitrostack-cli dev --port 3002

# Or kill process on port
lsof -ti:3000 | xargs kill -9
lsof -ti:3001 | xargs kill -9

Build Errors

Bash
# Clean and rebuild
rm -rf dist
rm -rf src/widgets/.next
npm run build

# Check TypeScript errors
npx tsc --noEmit

Module Not Found: nitrostack

Bash
# Reinstall dependencies
rm -rf node_modules package-lock.json
npm install

Widgets Not Loading

Bash
# The CLI handles widgets automatically, but if you need to debug:

# Install widget dependencies
npm run widget install

# Check widget dev server
curl http://localhost:3001

# Or restart dev mode (rebuilds everything)
npm run dev

Studio Not Connecting

Bash
# Check MCP server is running
ps aux | grep node

# Check logs
tail -f logs/server.log

# Restart
npm run dev

Quick Reference Card

Commands

CommandDescription
nitrostack init <name>Create new project
nitrostack init <name> --preset <p>Create with preset (starter, enterprise-search, code-mode, pizzaz, oauth)
nitrostack init <name> --template <t>Create with template directory name
nitrostack devStart dev mode (MCP server + widget dev server)
nitrostack dev --port <n>Start with custom widget port (default: 3001)
nitrostack buildBuild MCP server + widgets for production
nitrostack startStart production server (default: 3000)
nitrostack generate <type> <name>Generate code (module, tools, resources, prompts, guard, middleware, pipe, health, etc.)
nitrostack upgradeUpgrade @nitrostack/core and refresh agent skills
nitrostack installInstall root and widget dependencies
nitrostack cursorConfigure Cursor IDE MCP integration (command, legacy-sse, streamable-http)
nitrostack packBundle production .zip deployment archive
nitrostack --versionShow version
nitrostack --helpShow help

Project Scripts

ScriptDescription
npm run devStart development (MCP server + widgets, auto-reload)
npm run buildBuild MCP server + widgets for production
npm startRun production server
npm run widget <cmd>Run npm command in widgets directory

Studio URLs

URLPurpose
http://localhost:3000Studio UI
http://localhost:3000/chatAI Chat
http://localhost:3001Widget dev server

Key Concepts for AI Agents

1. Templates & Presets

  • typescript-starter (starter): Simple calculator, Next.js widget, health checks
  • typescript-enterprise-search (enterprise-search): Progressive BM25 tool search, @Controller namespacing
  • typescript-code-mode (code-mode): QuickJS WebAssembly sandboxing, worker pool script orchestration
  • typescript-pizzaz (pizzaz): Rich interactive map, multi-widget dashboard
  • typescript-oauth (oauth): OAuth 2.1 PKCE, Duffel flight booking tools

2. Development Flow

  • init → dev → test in Studio → build → start (or pack for deployment)

3. Code Generation

  • Generate module first (generate module <name>)
  • Then generate tools/resources/prompts (generate tools <name> --module <name>)
  • Always run generate types after schema changes

4. Studio

  • Test tools interactively
  • Use chat to verify model integrations
  • Preview widgets with live simulated tool data

5. Widget Development

  • Widgets live in src/widgets/app/
  • Link with @Widget('widget-name')
  • Generate types for type safety
  • Hot reload enabled

That's the complete NitroStack CLI reference!

Use nitrostack --help for more details or check /docs for SDK documentation.