Skip to main content

create-mastra

create-mastra 命令创建一个新的独立 Mastra 项目。使用此命令可以在专用目录中搭建完整的 Mastra 环境。你可以添加额外的参数来定制搭建过程。

🌐 The create-mastra command creates a new standalone Mastra project. Use this command to scaffold a complete Mastra setup in a dedicated directory. You can run it with additional flags to customize the setup process.

用法
Direct link to 用法

🌐 Usage

npx create-mastra@latest

create-mastra 会自动以 交互式 模式运行,但你也可以通过命令行参数指定你的项目名称和模板。

npx create-mastra@latest my-mastra-project -- --template coding-agent

查看完整列表的模板,并使用 slug 作为 --template CLI 标志的输入。

🌐 Check out the full list of templates and use the slug as input to the --template CLI flag.

你也可以使用任何 GitHub 仓库作为模板(它必须是一个有效的 Mastra 项目):

🌐 You can also use any GitHub repo as a template (it has to be a valid Mastra project):

npx create-mastra@latest my-mastra-project -- --template mastra-ai/template-coding-agent

命令行标志
Direct link to 命令行标志

🌐 CLI flags

你也可以定义这些命令行参数而不是使用交互式提示。

🌐 Instead of an interactive prompt you can also define these CLI flags.

--version?:

boolean
Output the version number

--project-name?:

string
Project name that will be used in package.json and as the project directory name

--default?:

boolean
Quick start with defaults (src, OpenAI, no examples)

--components?:

string
Comma-separated list of components (agents, tools, workflows, scorers)

--llm?:

string
Default model provider (openai, anthropic, groq, google, or cerebras)

--llm-api-key?:

string
API key for the model provider

--example?:

boolean
Include example code

--no-example?:

boolean
Do not include example code

--template?:

string
Create project from a template (use template name, public GitHub URL, or leave blank to select from list)

--timeout?:

number
Configurable timeout for package installation, defaults to 60000 ms

--dir?:

string
Target directory for Mastra source code (default: src/)

--mcp?:

string
MCP Server for code editor (cursor, cursor-global, windsurf, vscode)

--help?:

boolean
Display help for command

遥测
Direct link to 遥测

🌐 Telemetry

默认情况下,Mastra 会收集有关你的项目的匿名信息,如你的操作系统、Mastra 版本或 Node.js 版本。你可以查看 源代码 来了解收集了哪些信息。

🌐 By default, Mastra collects anonymous information about your project like your OS, Mastra version or Node.js version. You can read the source code to check what's collected.

你可以通过设置环境变量来选择退出 CLI 分析:

🌐 You can opt out of the CLI analytics by setting an environment variable:

MASTRA_TELEMETRY_DISABLED=1

你也可以在使用其他 mastra 命令时设置这个:

🌐 You can also set this while using other mastra commands:

MASTRA_TELEMETRY_DISABLED=1 npx create-mastra@latest