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
建立模式建立模式 的直接連結
預設起始項目預設起始項目 的直接連結
預設起始項目會建立 Agent harness,當中包含 Workspace Tool、記憶、任務追蹤、網絡存取、週期排程、儲存及可觀測性功能。你可以選擇 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