Creating Mastra Projects
Mastra provides two CLI commands for project setup:
mastra create
: Generate a new projectmastra init
: Add Mastra to an existing project
Creating a New Project
You can create a new project using either a package manager or the mastra CLI:
npm create mastra@latest
npm install -g mastra@latest
mastra create
Generated project structure:
my-project/
├── src/
│ └── mastra/
│ └── index.ts # Mastra entry point
├── package.json
└── tsconfig.json
Adding to an Existing Project
mastra init
Changes made to project:
- Creates
src/mastra
directory with entry point - Adds required dependencies
- Configures TypeScript compiler options
Command Arguments
Arguments:
--components Specify components: agents, memory, storage
--llm-provider LLM provider: openai, anthropic
--add-example Include example implementation
--llm-api-key Provider API key
Interactive Setup
Running commands without arguments starts a CLI prompt for:
- Component selection
- LLM provider configuration
- API key setup
- Example code inclusion
Project Initialization
# Install dependencies
npm install
# Start development server on port 3000
mastra dev
# Access playground at http://localhost:3000