Mastra CLI
The `mastra` package provides the command-line interface (CLI) for the Mastra AI platform, enabling development, deployment, and management of AI agents, LLMs, and related services. It is currently at version 1.6.0. While the CLI itself might have a slower release pace, its core library (`@mastra/core`), which it depends on, is under active and rapid development, seeing multiple releases per month, indicating a quickly evolving ecosystem of features.
Common errors
-
mastra: command not found
cause The `mastra` package's executable is not in your system's PATH, or the package was not installed globally/linked correctly.fixIf installed locally, run `npx mastra <command>`. If you intended a global install, run `npm install -g mastra` and ensure your global `node_modules` bin directory is in your PATH. -
Error: Peer dependency "@mastra/core" is not installed or incompatible. Expected ">=1.1.0-0 <2.0.0-0".
cause The `@mastra/core` package, a required peer dependency for `mastra`, is either missing or its installed version does not meet the compatibility requirements.fixRun `npm install @mastra/core@'>=1.1.0-0 <2.0.0-0'` in your project to install a compatible version. -
Error: Zod peer dependency not found. Please install zod@^3.25.0 || ^4.0.0.
cause The `zod` validation library, a peer dependency, is not installed or its version is outside the supported range.fixRun `npm install zod@'^3.25.0 || ^4.0.0'` in your project. -
Error: RAG tracing requires an 'observabilityContext'. Please configure one.
cause You are attempting to use RAG tracing features without providing the necessary `observabilityContext` for instrumentation.fixEnsure you initialize and pass an `observabilityContext` to the relevant RAG ingestion or query operations where tracing is desired. -
Error: Workspace path '/absolute/path/to/file.txt' is no longer treated as workspace-relative. Use relative paths or verify the absolute path's intent.
cause Your workspace configuration or a tool within the workspace is using an absolute path (`/absolute/path/to/file.txt`) which is no longer interpreted relative to the workspace root after a breaking change in `@mastra/core` v1.12.0.fixUpdate your workspace configuration to use paths relative to the workspace root for internal files, or explicitly manage absolute paths if they refer to external locations.
Warnings
- gotcha The `mastra` CLI has a peer dependency on `zod` and `@mastra/core`. Ensure these are installed and compatible with your project.
- breaking Workspace filesystem path resolution now aligns with standard filesystem semantics. Absolute paths like `/file.txt` are no longer treated as workspace-relative but resolve to actual file system locations.
- gotcha End-to-end RAG tracing and new RAG/Graph span types (e.g., `RAG_INGESTION`) are opt-in and require an `observabilityContext` to be explicitly configured.
- gotcha Workspace tool output is now token-limited and ANSI-stripped for model context. This might affect applications that relied on full, unstripped terminal output from sandbox commands.
- deprecated The peer dependency `@mastra/core` is constrained to versions `>=1.1.0-0 <2.0.0-0`. Major version 2 of `@mastra/core` will likely introduce breaking changes and require an update to the `mastra` CLI.
Install
-
npm install mastra -
yarn add mastra -
pnpm add mastra
Imports
- run
import { run } from 'mastra'
Quickstart
import { Agent } from '@mastra/core';
const agent = new Agent({ name: 'MyFirstAgent', model: 'gpt-4o' });
// To run a command via the CLI (most common usage):
// npx mastra deploy MyFirstAgent --env production