create-mastra
创建独立的 Mastra 项目。默认情况下,create-mastra 会安装默认 starter,并针对你选择的模型 Provider 进行配置。
- npm
- pnpm
- Yarn
- Bun
npx create-mastra@latest
pnpm dlx create-mastra@latest
yarn dlx create-mastra@latest
bun x create-mastra@latest
创建模式创建模式的直接链接
默认 starter默认 starter的直接链接
默认 starter 会创建一个 Agent harness,其中包含 Workspace Tool、Memory、任务跟踪、Web 访问、定期调度、Storage 和 Observability。可以选择 OpenAI、Anthropic、Gemini 或 xAI 作为模型 Provider。
同时提供项目名称和 Provider,即可在不显示提示的情况下创建项目。以下示例使用 Anthropic;你也可以传入 openai、google 或 xai:
- npm
- pnpm
- Yarn
- Bun
npx create-mastra@latest my-mastra-project --llm anthropic
pnpm dlx create-mastra@latest my-mastra-project --llm anthropic
yarn dlx create-mastra@latest my-mastra-project --llm anthropic
bun x create-mastra@latest my-mastra-project --llm anthropic
省略 --llm 可通过交互方式选择 Provider,并可选择输入其 API key。交互式设置还会询问是否将项目连接到 Mastra 平台。启用后,该命令会打开浏览器身份验证流程,并创建一个与本地项目同名的平台项目。随后,它会将 MASTRA_PLATFORM_ACCESS_TOKEN 和 MASTRA_PROJECT_ID 写入 .env。
模板模板的直接链接
使用模板 slug 或公开的 GitHub URL:
- npm
- pnpm
- Yarn
- Bun
npx create-mastra@latest my-mastra-project --template agent-harness
pnpm dlx create-mastra@latest my-mastra-project --template agent-harness
yarn dlx create-mastra@latest my-mastra-project --template agent-harness
bun x create-mastra@latest my-mastra-project --template agent-harness
- npm
- pnpm
- Yarn
- Bun
npx create-mastra@latest my-mastra-project --template https://github.com/mastra-ai/template-agent-harness
pnpm dlx create-mastra@latest my-mastra-project --template https://github.com/mastra-ai/template-agent-harness
yarn dlx create-mastra@latest my-mastra-project --template https://github.com/mastra-ai/template-agent-harness
bun x create-mastra@latest my-mastra-project --template https://github.com/mastra-ai/template-agent-harness
将模板值留空可通过交互方式选择模板:
- npm
- pnpm
- Yarn
- Bun
npx create-mastra@latest my-mastra-project --template
pnpm dlx create-mastra@latest my-mastra-project --template
yarn dlx create-mastra@latest my-mastra-project --template
bun x create-mastra@latest my-mastra-project --template
模板作者负责其依赖项、模型、环境变量和源代码。create-mastra 不会应用 --llm 或 --llm-api-key。
空 scaffold空 scaffold的直接链接
使用 --empty 创建一个不含 Provider、Agent、示例、模型 SDK 或环境文件的项目:
- npm
- pnpm
- Yarn
- Bun
npx create-mastra@latest my-empty-project --empty
pnpm dlx create-mastra@latest my-empty-project --empty
yarn dlx create-mastra@latest my-empty-project --empty
bun x create-mastra@latest my-empty-project --empty
自动设置自动设置的直接链接
安装依赖项后,该命令会:
- 检测
PATH中受支持的编程助手并安装 Mastra Skill。如果未检测到,则安装通用 Skill。 - 当当前目录和生成的项目尚未位于 Git 仓库中时,创建初始 Git commit。
使用 --no-skills 或 --no-git 可跳过这些步骤。Skill 和 Git 设置失败会产生警告,但不会移除已成功创建的项目。
冲突与验证冲突与验证的直接链接
--empty和--template不能同时使用。--llm和--llm-api-key仅适用于默认 starter 项目。- 项目名称必须是安全的、小写的单一目录名称,且目标不能已存在。
系统会在获取模板或创建文件之前拒绝无效输入。
参数和 flag参数和 flag的直接链接
[project-name]?:
--empty?:
-l, --llm <provider>?:
-k, --llm-api-key <key>?:
--no-skills?:
--no-git?:
--no-install?:
-t, --template [template]?:
--timeout <milliseconds>?:
--version?:
--help?:
遥测遥测的直接链接
Mastra 会收集匿名的 CLI 使用信息,例如操作系统、Mastra 版本和 Node.js 版本。你可以查看分析功能源代码。
设置 MASTRA_TELEMETRY_DISABLED=1 可选择退出:
MASTRA_TELEMETRY_DISABLED=1 npx create-mastra@latest my-project --empty