DocumentationCli

CLI Reference for Coding Agents

Every nitrostack-cli command on one page, written for AI coding agents

Comprehensive CLI reference for AI agents working with NitroStack

Installation

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

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

Commands Overview

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

Initialize Project

# 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

cd my-project

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

Development Mode

# 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

Build Project

nitrostack-cli build

Build Process

The nitrostack-cli build command:

  1. Builds Widgets First (if present)

    • Input: src/widgets/
    • Output: src/widgets/out/ (one HTML file per widget)
    • 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/out/           # Built widgets

Run Production Build

# 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

Generate Code

Generate Module

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

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

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

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

Generate Guard

nitrostack-cli generate guard admin

Creates src/guards/admin.guard.ts:

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

Usage:

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

Generate Middleware

nitrostack-cli generate middleware logging

Creates src/middleware/logging.middleware.ts:

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

Generate Interceptor

nitrostack-cli generate interceptor transform

Creates src/interceptors/transform.interceptor.ts:

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

Generate Pipe

nitrostack-cli generate pipe validation

Creates src/pipes/validation.pipe.ts:

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

Generate Types

# 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):

@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):

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

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

Usage in Widgets:

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

Cursor IDE Integration (nitrostack-cli cursor)

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

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

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

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

# Global configuration with overwrite
nitrostack-cli 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

Project Packaging (nitrostack-cli pack)

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

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

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

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

# Custom output zip name
nitrostack-cli 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.

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)

# 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

Troubleshooting

CLI Not Found

# Install globally
npm install -g @nitrostack/cli

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

Port Already in Use

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

# Or terminate process on port gracefully
lsof -ti:3000 | xargs kill -15
lsof -ti:3001 | xargs kill -15

Build Errors

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

# Check TypeScript errors
npx tsc --noEmit

Module Not Found: nitrostack

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

Widgets Not Loading

# 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

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

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

Development Flow

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

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

Studio

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

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.

On this page