CLI Introduction
Overview
The NitroStack CLI is a powerful command-line tool for creating, developing, and building MCP servers with v3.0's decorator-based architecture.
Features
- 🚀 Quick Initialization - Create new projects in seconds
- 🔥 Hot Reload - Development mode with automatic reloading
- 🎨 Studio Integration - Visual testing environment
- 🔨 Code Generation - Generate modules, tools, types, and more
- 📦 Production Builds - Optimize for deployment
- 🎯 Templates - Pre-built templates (basic, typescript-auth)
Commands
| Command | Description |
|---|---|
init | Create a new NitroStack project |
dev | Start development server with Studio |
build | Build project for production |
generate | Generate code (types, modules, tools, etc.) |
Installation
Global Installation
Bash
npm install -g @nitrostack/cli
Verify installation:
Bash
nitrostack-cli --version
Using npx
No installation required:
Bash
npx @nitrostack/cli init my-project
Quick Start
Bash
# Create a new project
nitrostack-cli init my-server --template typescript-auth
# Navigate to project
cd my-server
# Install dependencies
npm install
# Start development
nitrostack-cli dev
Studio opens at http://localhost:3000 automatically!
Command Reference
nitrostack-cli init
Create a new NitroStack project.
Bash
nitrostack-cli init <project-name> [options]
Options:
--template <name>- Template to use (typescript, typescript-auth)
Example:
Bash
nitrostack-cli init ecommerce --template typescript-auth
nitrostack-cli dev
Start development server with hot reload and Studio.
Bash
nitrostack-cli dev [options]
Options:
--port <number>- Studio port (default: 3000)
Example:
Bash
nitrostack-cli dev --port 8080
nitrostack-cli build
Build project for production.
Bash
nitrostack-cli build
Outputs to dist/ directory.
nitrostack-cli generate
Generate code from templates.
Bash
nitrostack-cli generate <type> [name] [options]
Types:
types- Generate TypeScript types from toolsmodule- Generate a new moduletool- Generate a tool definitionresource- Generate a resource definitionprompt- Generate a prompt definitionguard- Generate an authentication guardmiddleware- Generate middlewareinterceptor- Generate an interceptorpipe- Generate a pipefilter- Generate an exception filterservice- Generate a service
Examples:
Bash
# Generate types
nitrostack-cli generate types
# Generate module
nitrostack-cli generate module payments
# Generate tool
nitrostack-cli generate tool create-payment --module payments
# Generate guard
nitrostack-cli generate guard admin
Configuration
CLI behavior can be configured via:
- Command-line flags - Highest priority
- Environment variables - Medium priority
- Config file - Lowest priority
Environment Variables
Bash
# .env
NITROSTACK_PORT=3000
NITROSTACK_WIDGET_PORT=3001
Config File
Create nitrostack.config.js:
Javascript
export default {
dev: {
port: 3000,
widgetPort: 3001,
openBrowser: true
},
build: {
outDir: 'dist',
sourcemap: true
}
};
Development Workflow
- Initialize - Create project with
init - Develop - Use
devfor hot reload + Studio - Generate - Add features with
generate - Test - Test in Studio with AI chat
- Build - Production build with
build - Deploy - Deploy
dist/to server
Best Practices
1. Use Templates
Start with a template for best practices:
Bash
nitrostack-cli init my-project --template typescript-auth
2. Generate Code
Use generators instead of manual coding:
Bash
nitrostack-cli generate module users
nitrostack-cli generate tool get-user --module users
3. Type Generation
Regenerate types after tool changes:
Bash
nitrostack-cli generate types
4. Test in Studio
Always test in Studio before deployment:
Bash
nitrostack-cli dev
# Test with AI chat
# Test manual execution
Troubleshooting
Command Not Found
Bash
# If installed globally
npm install -g nitrostack
# Or use npx
npx nitrostack --version
Port Already in Use
Bash
# Use different port
nitrostack-cli dev --port 8080
Permission Errors
Bash
# Fix npm permissions
sudo chown -R $USER /usr/local/lib/node_modules
Next Steps
CLI Version: 3.0.0