メインコンテンツへ移動

VercelDeployer

VercelDeployer は Mastra サーバーをバンドルし、Vercel の Build Output API に準拠した出力を生成します。Vercel はこの出力をサーバーレス関数として直接デプロイします。

インストール
インストールへの直接リンク

VercelDeployer を使用するには、@mastra/deployer-vercel パッケージをインストールします。

npm install @mastra/deployer-vercel@latest

使用例
使用例への直接リンク

VercelDeployer をインポートし、Mastra 設定で deployer に指定します。

src/mastra/index.ts
import { Mastra } from '@mastra/core'
import { VercelDeployer } from '@mastra/deployer-vercel'

export const mastra = new Mastra({
deployer: new VercelDeployer(),
})

コンストラクターオプション
コンストラクターオプションへの直接リンク

deployer は次のオプションを受け取ります。

  • studio?: boolean:API とともに Studio を、Vercel の Edge CDN から配信される静的アセットとしてデプロイします。デフォルトは false です。
  • maxDuration?: number:関数の実行タイムアウト(秒)
  • memory?: number:関数のメモリ(MB)
  • regions?: string[]:関数をデプロイするリージョン(例:['sfo1','iad1']

maxDurationmemoryregions オプションは、デフォルトフィールド(handlerlauncherTyperuntimeshouldAddHelpers)を保持したまま .vercel/output/functions/index.func/.vc-config.json にマージされます。

オーバーライドの例
オーバーライドの例への直接リンク

src/mastra/index.ts
import { Mastra } from '@mastra/core'
import { VercelDeployer } from '@mastra/deployer-vercel'

export const mastra = new Mastra({
deployer: new VercelDeployer({
studio: true,
maxDuration: 600,
memory: 1536,
regions: ['sfo1', 'iad1'],
}),
})

ビルド出力
ビルド出力への直接リンク

mastra build を実行すると、deployer は Vercel の Build Output API (v3) に準拠した .vercel/output ディレクトリを生成します。このディレクトリには、Vercel がフレームワーク検出を介さずに直接デプロイするルーティング設定とサーバーレス関数バンドルが含まれます。

出力には次のものが含まれます。

  • config.json:リクエストを適切なハンドラーへ振り分けるルーティング設定
  • functions/:サーバーレス関数としてバンドルされた Mastra サーバー
  • static/:Studio SPA のアセット(studio: true の場合のみ)

Studio を含めない場合:

.vercel/
└── output/
├── config.json
└── functions/
└── index.func/
├── .vc-config.json
├── index.mjs
└── node_modules/

studio: true の場合:

.vercel/
└── output/
├── config.json
├── static/
│ ├── index.html
│ └── assets/
│ ├── *.js
│ └── *.css
└── functions/
└── index.func/
├── .vc-config.json
├── index.mjs
└── node_modules/

Studio が有効な場合、/api/* リクエストはサーバーレス関数によって処理され、静的アセット(JS、CSS)は関数を呼び出さずに Vercel の Edge CDN から配信されます。それ以外のすべてのパスは、クライアント側ルーティングのために index.html へフォールバックするよう設定されます。

このフォルダーはビルド時に生成されるため、バージョン管理にコミットしないでください。