Skip to main content

NetlifyDeployer

The NetlifyDeployer class handles deployment of standalone Mastra applications to Netlify. It manages configuration, deployment, and extends the base Deployer class with Netlify specific functionality.

Installation
Direct link to Installation

npm install @mastra/deployer-netlify@beta

Usage example
Direct link to Usage example

src/mastra/index.ts
import { Mastra } from "@mastra/core";
import { NetlifyDeployer } from "@mastra/deployer-netlify";

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

See the NetlifyDeployer API reference for all available configuration options.

Continuous integration
Direct link to Continuous integration

After connecting your Mastra project’s Git repository to Netlify, update the project settings. In the Netlify dashboard, go to Project configuration > Build & deploy > Continuous deployment, and under Build settings, set the following:

  • Build command: npm run build (optional)

Environment variables
Direct link to Environment variables

Before your first deployment, make sure to add any environment variables used by your application. For example, if you're using OpenAI as the LLM, you'll need to set OPENAI_API_KEY in your Netlify project settings.

See Environment variables overview for more details.

Your project is now configured with automatic deployments which occur whenever you push to the configured branch of your GitHub repository.

Manual deployment
Direct link to Manual deployment

Manual deployments are also possible using the Netlify CLI. With the Netlify CLI installed run the following from your project root to deploy your application. You can also run netlify dev from your project root to test your Mastra application locally.

netlify deploy --prod
warning

When using netlify deploy instead of continuous deployment, you need to create a netlify.toml file with these contents:

[build]
command = "npm run build"
publish = ".netlify/v1/functions"

[functions]
directory = ".netlify/v1/functions"
node_bundler = "none"
included_files = [".netlify/v1/functions/**"]

[[redirects]]
from = "/*"
to = "/.netlify/functions/api/:splat"
status = 200

[build.environment]
NODE_VERSION = "22.13.0"

Adjust the build.command to your project.

Build output
Direct link to Build output

The build output for Mastra applications using the NetlifyDeployer includes all agents, tools, and workflows in your project, along with Mastra-specific files required to run your application on Netlify.

your-project/
└── .netlify/
└── v1/
├── config.json
└── functions/
└── api/
├── index.js
├── package.json
└── node_modules/

The NetlifyDeployer automatically generates a config.json configuration file in .netlify/v1 with the following settings:

{
"functions": {
"directory": ".netlify/v1/functions",
"node_bundler": "none",
"included_files": [".netlify/v1/functions/**"]
},
"redirects": [
{
"force": true,
"from": "/*",
"to": "/.netlify/functions/api/:splat",
"status": 200
}
]
}

Next steps
Direct link to Next steps