Skip to Content

VercelDeployer

The VercelDeployer deploys Mastra applications to Vercel, handling configuration, environment variable synchronization, and deployment processes. It extends the abstract Deployer class to provide Vercel-specific deployment functionality.

Usage Example

import { Mastra } from '@mastra/core'; import { VercelDeployer } from '@mastra/deployer-vercel'; const mastra = new Mastra({ deployer: new VercelDeployer({ teamSlug: 'your-team-slug', projectName: 'your-project-name', token: 'your-vercel-token' }), // ... other Mastra configuration options });

Parameters

Constructor Parameters

teamSlug:

string
Your Vercel team slug

projectName:

string
Name of your Vercel project (will be created if it doesn't exist).

token:

string
Your Vercel authentication token.

Environment Variables

The VercelDeployer handles environment variables from multiple sources:

  1. Environment Files: Variables from .env.production and .env files.
  2. Configuration: Variables passed through the Mastra configuration.
  3. Vercel Dashboard: Variables can also be managed through Vercel’s web interface.

The deployer automatically synchronizes environment variables between your local development environment and Vercel’s environment variable system, ensuring consistency across all deployment environments (production, preview, and development).

Build Mastra Project

To build your Mastra project for Vercel deployment:

npx mastra build

The build process generates the following output structure in the .mastra/output directory:

.mastra/output/ ├── vercel.json # Vercel configuration └── index.mjs # Application entry point

Vercel Configuration

The VercelDeployer automatically generates a vercel.json configuration file in .mastra/output with the following settings:

{ "version": 2, "installCommand": "npm install --omit=dev", "builds": [ { "src": "index.mjs", "use": "@vercel/node", "config": { "includeFiles": ["**"] } } ], "routes": [ { "src": "/(.*)", "dest": "index.mjs" } ] }

Deployment Options

After building, you can deploy your Mastra application .mastra/output to Vercel using any of these methods:

  1. Vercel CLI: Deploy directly using Vercel’s official CLI tool

  2. Vercel Dashboard: Connect your Git repository or drag-and-drop the build output through the Vercel dashboard

Platform Documentation