tessl install tessl/npm-mastra@1.0.5Command-line tool for creating, developing, and deploying AI-powered applications with the Mastra framework
Best practices for day-to-day development with Mastra CLI.
mastra devFeatures:
DEBUG=1 MASTRA_DEBUG=1 mastra dev --debugDebug Outputs:
mastra dev --httpsBehavior:
.mastra/certs/# Start with inspector
mastra dev --inspect
# Start and break at beginning
mastra dev --inspect-brk
# Custom port
mastra dev --inspect 0.0.0.0:9229Debug in:
chrome://inspectCreate new agent in src/mastra/agents/:
// src/mastra/agents/my-agent.ts
import { Agent } from '@mastra/core';
export const myAgent = new Agent({
name: 'my-agent',
description: 'Custom agent for specific task',
llm: {
provider: 'openai',
model: 'gpt-4o'
},
tools: [/* your tools */]
});Auto-reload: Dev server detects change and restarts.
Create workflow in src/mastra/workflows/:
// src/mastra/workflows/my-workflow.ts
import { Workflow } from '@mastra/core';
export const myWorkflow = new Workflow({
name: 'my-workflow',
steps: [
// Define workflow steps
]
});Create tool in src/mastra/tools/ or external directory:
// src/tools/custom-tool.ts
import { Tool } from '@mastra/core';
export const customTool = new Tool({
name: 'custom-tool',
description: 'Performs specific operation',
schema: {
/* input schema */
},
execute: async (input) => {
// Tool logic
}
});Include external tools:
mastra dev --tools src/tools# List available scorers
mastra scorers list
# Add scorer
mastra scorers add answer-relevancy
# Creates: src/mastra/scorers/answer-relevancy.ts# Terminal 1: Dev server
mastra dev
# Terminal 2: Studio UI
mastra studioStudio Features:
# Test agent endpoint
curl http://localhost:4111/api/agents/my-agent \
-H "Content-Type: application/json" \
-d '{"input": "test input"}'
# Test workflow
curl http://localhost:4111/api/workflows/my-workflow \
-H "Content-Type: application/json" \
-d '{"data": {}}'Use different env files for different contexts:
# Development
mastra dev --env .env.development
# Local testing
mastra dev --env .env.local
# Staging
mastra dev --env .env.staging# .env.development
DATABASE_URL=postgresql://localhost:5432/mastra_dev
OPENAI_API_KEY=sk-...
DEBUG=1
MASTRA_DEBUG=1
# .env.local
DATABASE_URL=postgresql://localhost:5432/mastra_local
OPENAI_API_KEY=sk-test-...
MASTRA_TELEMETRY_DISABLED=1mastra dev \
--dir src/mastra \
--root . \
--tools src/tools,lib/toolsmastra lintChecks:
# .husky/pre-commit
#!/bin/sh
mastra lint || exit 1# .github/workflows/validate.yml
- name: Lint
run: npx mastra lint# Check pending migrations
mastra migrate
# Apply without confirmation
mastra migrate --yes
# With debug
mastra migrate --debugmastra migrate.ts file changes in Mastra directory--tools specified)package.json changes.env file changes (restart manually)node_modules/ changes.mastra/ build cache// Typical reload times:
// - Simple change: < 500ms
// - Complex change: 1-2 seconds
// - Full rebuild: 3-5 seconds# Project A
cd project-a
mastra dev --dir src/mastra --port 4111
# Project B (different terminal)
cd project-b
mastra dev --dir lib/mastra --port 4112# Project-specific
mastra create project-a --mcp cursor
# Global (affects all projects)
mastra create project-b --mcp cursor-global// Add logging to agents/workflows/tools
console.log('[DEBUG]', 'Agent input:', input);
console.error('[ERROR]', 'Tool failed:', error);View logs: Watch dev server terminal.
Start with inspector:
mastra dev --inspect-brkOpen Chrome DevTools (chrome://inspect)
Set breakpoints in source
Step through execution
# Monitor all requests
curl -v http://localhost:4111/api/agents/my-agent \
-H "Content-Type: application/json" \
-d '{"input": "test"}'# Profile build time
time mastra build --debug# Check output size
du -sh .mastra/output
ls -lh .mastra/output/index.js# Include only necessary tools
mastra dev --tools src/tools/essential.ts# Check if port is in use
lsof -i :4111
# Try different port
PORT=8080 mastra dev
# Enable debug to see issue
DEBUG=1 mastra dev --debug# Run lint to see specific errors
mastra lint
# Check with debug
mastra build --debug# Ensure dependencies installed
npm install
# Check TypeScript version
npx tsc --version
# Run lint
mastra lint# .gitignore
node_modules/
.env
.env.*
.mastra/
dist/.env.development.env.test.env.production# Before commits
mastra lint
# Before pushes
mastra lint && npm testsrc/mastra/
├── agents/
│ ├── customer-support.ts
│ └── data-analysis.ts
├── workflows/
│ ├── onboarding.ts
│ └── processing.ts
├── tools/
│ ├── api-tools.ts
│ └── data-tools.ts
└── scorers/
├── quality-scorers.ts
└── accuracy-scorers.ts