Skip to Content
DocsLocal DevAdd to an Existing Project

Adding to an Existing Project

You can add Mastra to an existing project using the CLI:

npm install -g mastra@latest mastra init

Changes made to project:

  1. Creates src/mastra directory with entry point
  2. Adds required dependencies
  3. Configures TypeScript compiler options

Interactive Setup

Running commands without arguments starts a CLI prompt for:

  1. Component selection
  2. LLM provider configuration
  3. API key setup
  4. Example code inclusion

Non-Interactive Setup

To initialize mastra in non-interactive mode use the following command arguments:

Arguments: --components Specify components: agents, tools, workflows --llm LLM provider: openai, anthropic, groq, google or cerebras --llm-api-key Provider API key --example Include example implementation --dir Directory for Mastra files (defaults to src/)

For more details, refer to the mastra init CLI documentation.