Serverless Deployment
This guide covers deploying Mastra to Cloudflare Workers, Vercel, and Netlify using platform-specific deployers
For self-hosted Node.js server deployment, see the Creating A Mastra Server guide.
Prerequisites
Before you begin, ensure you have:
- Node.js installed (version 18 or higher is recommended)
- If using a platform-specific deployer:
- An account with your chosen platform
- Required API keys or credentials
Serverless Platform Deployers
Platform-specific deployers handle configuration and deployment for:
- Cloudflare Workers
- Vercel
- Netlify
- Mastra Cloud (beta). You can join the cloud waitlist  for early access.
Installing Deployers
# For Cloudflare
npm install @mastra/deployer-cloudflare@latest
# For Vercel
npm install @mastra/deployer-vercel@latest
# For Netlify
npm install @mastra/deployer-netlify@latest
Configuring Deployers
Configure the deployer in your entry file:
import { Mastra, createLogger } from "@mastra/core";
import { CloudflareDeployer } from "@mastra/deployer-cloudflare";
export const mastra = new Mastra({
agents: {
/* your agents here */
},
logger: createLogger({ name: "MyApp", level: "debug" }),
deployer: new CloudflareDeployer({
scope: "your-cloudflare-scope",
projectName: "your-project-name",
// See complete configuration options in the reference docs
}),
});
Deployer Configuration
Each deployer has specific configuration options. Below are basic examples, but refer to the reference documentation for complete details.
Cloudflare Deployer
new CloudflareDeployer({
scope: "your-cloudflare-account-id",
projectName: "your-project-name",
// For complete configuration options, see the reference documentation
});
View Cloudflare Deployer Reference →
Vercel Deployer
new VercelDeployer({
teamSlug: "your-vercel-team-slug",
projectName: "your-project-name",
token: "your-vercel-token",
// For complete configuration options, see the reference documentation
});
View Vercel Deployer Reference →
Netlify Deployer
new NetlifyDeployer({
scope: "your-netlify-team-slug",
projectName: "your-project-name",
token: "your-netlify-token",
});
View Netlify Deployer Reference →
Environment Variables
Required variables:
- Platform deployer variables (if using platform deployers):
- Platform credentials
- Agent API keys:
OPENAI_API_KEY
ANTHROPIC_API_KEY
- Server configuration (for universal deployment):
PORT
: HTTP server port (default: 3000)HOST
: Server host (default: 0.0.0.0)
Build Mastra Project
To build your Mastra project for your target platform run:
npx mastra build
When a Deployer is used, the build output is automatically prepared for the target platform.
You can then deploy the build output .mastra/output
via your platform’s (Vercel, netlify, cloudfare e.t.c)
CLI/UI.