mastra-deployment
Skill2 starsChanged 29 days agoApache-2.0View on GitHub
Deploy a Mastra application to production: the standalone server from mastra build, deployers for Vercel, Netlify, and Cloudflare, Docker and VMs, Kubernetes, AWS Lambda, Bedrock AgentCore, Azure, DigitalOcean, Render, Neon, sandbox previews, split worker processes, and workflow runners such as Inngest and Temporal. Use this skill whenever the user wants to ship, host, containerize, or scale a Mastra project, pick a hosting target, fix a build or deploy failure, or run workflows on managed infrastructure. Triggers on mastra build, mastra start, .mastra/output, VercelDeployer, NetlifyDeployer, CloudflareDeployer, SandboxDeployer, @mastra/deployer-vercel, @mastra/deployer-netlify, @mastra/deployer-cloudflare, @mastra/deployer-sandbox, bundler externals, transpilePackages, drainTimeout, MASTRA_WORKERS, mastra worker build, @mastra/inngest, @mastra/temporal, Dockerfile, Helm. Also triggers when a deployed app loses data because LibSQLStore points at a local file, or when requests time out on serverless.
- Reads credentials
In this repository46 other files it gives its agents.
- mastra-a2a-acpSkill
- mastra-agent-approval-hitlSkill
- mastra-agentic-uiSkill
- mastra-agent-skillsSkill
- mastra-agentsSkill
- mastra-authSkill
- mastra-browserSkill
- mastra-build-playbookSkill
- mastra-channelsSkill
- mastra-classifierSkill
- mastra-cli-apiSkill
- mastra-client-sdkSkill
- mastra-datasets-experimentsSkill
- mastra-evalsSkill
- mastra-file-based-agentsSkill
- mastra-framework-integrationSkill
- mastra-guideSkill
- mastra-harnessSkill
- mastra-knowledgeSkill
- mastra-mcpSkill
- mastra-memorySkill
- mastra-migrationsSkill
- mastra-modelsSkill
- mastra-multi-agentSkill
- mastra-observabilitySkill
- mastra-observational-memorySkill
- mastra-platformSkill
- mastra-processors-guardrailsSkill
- mastra-project-setupSkill
- mastra-ragSkill
- mastra-schedulesSkill
- mastra-semantic-recallSkill
- mastra-serverSkill
- mastra-signalsSkill
- mastra-storageSkill
- mastra-streamingSkill
- mastra-structured-outputSkill
- mastra-studio-editorSkill
- mastra-tool-integrationsSkill
- mastra-toolsSkill
- mastra-troubleshootingSkill
- mastra-vector-storesSkill
- mastra-voiceSkill
- mastra-workflowsSkill
- mastra-workflow-suspend-resumeSkill
- mastra-workspace-sandboxSkill
The file
We split this skill into the rules it gives an agent
9 rules. About 0 are common, 1 is distinctive, and 8 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
8
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 51
Ask for the target and storage first.
- Very specific: line 95
Do not hide them behind a factory call (new Mastra(createMastraOptions())) or a spread (new Mastra({ ...options })).
- Very specific: line 97
Every built-in route lives under /api.
- Very specific: line 103
Verify the API: If node_modules/@mastra/ exists, read node_modules/@mastra/core/dist/docs/ and the installed deployer package docs.
- Very specific: line 104
Pick the target: Use references/targets.md.
- Very specific: line 109
Build: Run mastra build (add --studio to bundle Studio).
- Very specific: line 141
Always pass --output-dir to mastra worker build.
- Very specific: line 150
JavaScript heap out of memoryduring build: Run NODE_OPTIONS="--max-old-space-size=4096" mastra build. - Very specific: line 151
Package fails to bundle: Add it to bundler.externals.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Mastra Deployment
Choose a hosting target for a Mastra application, build it correctly, and run it in production with persistent storage, sane timeouts, and authentication.
When to use
- Picking where to host a Mastra app (VM, container, serverless, edge, Kubernetes)
- Running
mastra buildand serving.mastra/outputwithmastra startor Node - Configuring
VercelDeployer,NetlifyDeployer,CloudflareDeployer, orSandboxDeployer - Writing a Dockerfile, Kubernetes manifests, or Helm values for Mastra
- Splitting orchestration, scheduler, and background-task workers into their own processes
- Running workflows on Inngest or Temporal
- Fixing build failures (heap size, bundling, monorepo packages) or serverless timeouts
When NOT to use
- Deploying to the hosted Mastra Platform with
mastra deploy(usemastra-platform) - CLI flags and
mastra apicalls against a deployed server (usemastra-cli-api) - Server routes, middleware, CORS, server adapters for Express or Hono (use
mastra-server) - Next.js, Astro, or other framework integration code (use
mastra-framework-integration) - Choosing and configuring a database adapter (use
mastra-storage) - Securing endpoints and Studio (use
mastra-auth) - Durable agents, crash recovery, background tasks semantics (use
mastra-harness) - Cron schedules on workflows (use
mastra-schedules) - Tracing exporters and flushing (use
mastra-observability)
Required inputs
- Hosting target, or the constraints that pick one (long-running streams, WebSockets, scale to zero, existing cloud)
- Storage in use and whether it is reachable from the target (remote URL, not
file:on ephemeral disks) - Expected request duration (agent streams and workflow runs often exceed default serverless limits)
- Package manager and repo layout (single package or monorepo path such as
apps/api) - Whether Studio should ship with the API, and how it will be protected
- Provider env vars the app needs at runtime (model keys, database URLs)
Ask for the target and storage first. Everything else follows from them.
The framework: build once, pick an output shape
mastra build bundles src/mastra/index.ts into a self-contained Hono server. A deployer changes the output shape for a specific platform.
| Option | Output | Use when |
| Mastra server (no deployer) | .mastra/output/index.mjs | VMs, containers, PaaS, Kubernetes, long-running streams |
VercelDeployer | .vercel/output (Build Output API) | Vercel serverless functions |
NetlifyDeployer | .netlify/v1 | Netlify Functions or Edge Functions |
CloudflareDeployer | wrangler.jsonc pointing at .mastra/output | Cloudflare Workers |
SandboxDeployer | Live sandbox URL | Previews, CI checks, agent-built apps |
| Server adapter or web framework | Your app's normal build | Mastra inside Express, Hono, Next.js, Astro |
| Mastra Platform | mastra deploy | Managed hosting (see mastra-platform) |
Runtimes: Node.js v22.13.0 or later, Bun, Deno, Cloudflare.
Minimal build and run:
mastra build
mastra start
# or
node .mastra/output/index.mjsBuild-time options (bundler, deployer, server) must be direct properties of the object passed to new Mastra():
import { Mastra } from '@mastra/core/mastra'
export const mastra = new Mastra({
bundler: {
externals: ['sharp'],
},
server: {
port: 4111,
},
})Do not hide them behind a factory call (new Mastra(createMastraOptions())) or a spread (new Mastra({ ...options })). The build cannot extract them and silently falls back to defaults.
Every built-in route lives under /api. Verify any deployment with GET /api/agents (JSON list of agents) or GET /health.
Workflow
- Verify the API. If
node_modules/@mastra/exists, readnode_modules/@mastra/core/dist/docs/and the installed deployer package docs. Otherwise fetchhttps://mastra.ai/docs/deployment/overview.mdand the target page fromreferences/targets.mdwith.mdappended. Trust these over memory. - Pick the target. Use
references/targets.md. Prefer a long-running server for streaming agents and long workflows. Use serverless only when request duration fits. - Fix storage first. Ephemeral filesystems (Vercel, Netlify, Cloudflare, Lambda, DigitalOcean App Platform, some Azure tiers) lose
file:databases. Point storage at a remote database. Keep database files out ofsrc/mastra/public. - Add a deployer if the target needs one. Install
@mastra/deployer-<target>@latestand setdeployer:onnew Mastra(). - Set timeouts. Raise
server.timeout(ms, default180000) alongside any platform limit such as VercelmaxDuration(seconds). - Set graceful shutdown. Size
server.drainTimeout(default 5 s) to the platform's termination grace period. Use durable agents when turns must survive restarts. - Build. Run
mastra build(add--studioto bundle Studio). For monorepos run the package'sbuildscript from the workspace tool. - Configure env vars on the platform.
mastra startloads.env.productionand.env. Most platforms need variables set in their dashboard. Cloudflare secrets go throughnpx wrangler secret bulk .env. - Deploy and verify. Hit
<url>/api/agentsand<url>/health. Then exercise one agent withmastra api --url <url> agent list(seemastra-cli-api). - Secure it. Enable server auth before exposing endpoints or Studio publicly (see
mastra-auth).
Deep dive: scaling and workers
One process runs everything by default: API, workflow orchestration, cron scheduler, and background tool calls. Scale out only when needed.
Multiple API replicas need shared infrastructure, or work started on one pod is invisible to the others:
- A distributed PubSub (
RedisStreamsPubSub,ValkeyStreamsPubSub, orGoogleCloudPubSub) - Shared storage (for example
PostgresStore) - A shared cache (
RedisServerCache) for resumable streams - Durable agents (
createDurableAgent) for streams and approvals that cross pods
Split workers run the same build with different MASTRA_WORKERS values:
mastra build
mastra worker build --output-dir .mastra/worker| Process | MASTRA_WORKERS | Replicas |
| API | false | Any |
| Orchestration | orchestration | Scale out; needs MASTRA_STEP_EXECUTION_URL=http://api:4111/api |
| Scheduler | scheduler | Exactly one |
| Background tasks | backgroundTasks | Scale out |
Always pass --output-dir to mastra worker build. Its default is .mastra/output, which overwrites the server bundle. Workers are beta. See references/examples.md for the Docker Compose layout.
Failure patterns
- Data vanishes after a deploy or cold start.
LibSQLStoreusesfile:./mastra.dbon an ephemeral disk. Point it at a remote database (Turso, Postgres). 504 Gateway Timeoutafter 180 s on Vercel despite a highmaxDuration.server.timeoutstill applies. Raise both.- Build options ignored.
bundler,deployer, orserverhidden in a spread or factory. Make them direct properties ofnew Mastra({...}). JavaScript heap out of memoryduring build. RunNODE_OPTIONS="--max-old-space-size=4096" mastra build.- Package fails to bundle. Add it to
bundler.externals. For uncompiled workspace packages, add tobundler.transpilePackages. - Monorepo deploy builds the wrong thing. The platform root points at the repo root. Set it to the app directory (
apps/api). Keep.envin that directory. Cannot find module '@libsql/linux-x64-gnu'in a container. Host-builtnode_moduleswas copied. Install dependencies inside the image and ignore.mastra/output/node_modules./apireturns Not Found on a healthy server./apiis only a prefix. Call/api/agents.- Sandbox deploy fails with an auth error.
mastra builddoes not load.env. Load it into the shell (dotenv -e .env -- mastra build) or export CI secrets. - Cloudflare binding is
undefined. It was read outsidenew Mastra({...}). Keepenv.Xusage inline in the constructor call. - Inngest route throws at startup. A custom route under
/api. Use/inngest/api, or move built-ins withserver.apiPrefix. - Duplicate cron fires. More than one scheduler, or the API also runs workers. Run one scheduler and set
MASTRA_WORKERS=falseon the API. - Traces missing on serverless. The function exits before export.
await mastra.observability.flush()before returning. - Temporal worker on Lambda or Vercel. The worker must be long-lived. Use a container or VM.
Output format
A finished deployment delivery contains:
- The
src/mastra/index.tschange (deployer,bundler,server.timeout,server.drainTimeout) if needed - A
buildscript ("build": "mastra build") and platform config (netlify.toml,Dockerfile, manifests, values file) - Remote storage configured through env vars, with no
file:URLs on ephemeral targets - An
.env.examplelisting every runtime variable (never commit.env) - The verification result:
GET <url>/api/agentsreturns JSON,GET <url>/healthreturns 200 - A note on how endpoints and Studio are protected
Reference files
references/api.md- Deployer constructors, bundler and server options, env vars, worker and runner APIs.references/targets.md- Every deploy target with package, entry shape, env vars, and caveats.references/examples.md- Docker server, Vercel with Studio, split workers with Compose, Inngest workflows, sandbox preview.references/checklist.md- Pre-production deployment checklist.
Live docs
- https://mastra.ai/docs/deployment/overview
- https://mastra.ai/docs/deployment/mastra-server
- https://mastra.ai/docs/deployment/monorepo
- https://mastra.ai/docs/deployment/cloud-providers
- https://mastra.ai/docs/deployment/web-framework
- https://mastra.ai/docs/deployment/sandbox
- https://mastra.ai/docs/deployment/workers
- https://mastra.ai/docs/deployment/workflow-runners
- https://mastra.ai/reference/deployer
- https://mastra.ai/reference/configuration
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

