create-mastra
建立獨立的 Mastra 專案。create-mastra 預設會安裝預設起始專案,並為你選擇的模型 Provider 完成設定。
- npm
- pnpm
- Yarn
- Bun
npx create-mastra@latest
pnpm dlx create-mastra@latest
yarn dlx create-mastra@latest
bun x create-mastra@latest
建立模式「建立模式」的直接連結
預設起始專案「預設起始專案」的直接連結
預設起始專案會建立包含 Workspace Tool、記憶體、任務追蹤、網路存取、週期性排程、儲存空間與可觀測性的 Agent harness。選擇 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 金鑰。互動式設定也會詢問是否要將專案連接至 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。
空白骨架「空白骨架」的直接連結
使用 --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只適用於預設起始專案。- 專案名稱必須是安全、全小寫的單一目錄名稱,且目標不得已存在。
系統會在擷取模板或建立檔案前拒絕無效輸入。
引數與旗標「引數與旗標」的直接連結
[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