Back to Mastra

Reference: NetlifyDeployer | Deployer

docs/src/content/en/reference/deployer/netlify.mdx

2025-12-181.7 KB
Original Source

NetlifyDeployer

The NetlifyDeployer class handles packaging, configuration, and deployment by adapting Mastra's output to create an optimized version of your server. It extends the base Deployer class with Netlify specific functionality. It enables you to run Mastra within Netlify functions.

Installation

In order to use NetlifyDeployer, you need to install the @mastra/deployer-netlify package:

bash
npm install @mastra/deployer-netlify@latest

Usage example

Import NetlifyDeployer and set it as the deployer in your Mastra configuration:

typescript
import { Mastra } from '@mastra/core'
// highlight-next-line
import { NetlifyDeployer } from '@mastra/deployer-netlify'

export const mastra = new Mastra({
  // highlight-next-line
  deployer: new NetlifyDeployer(),
})

Output

After running mastra build, the deployer generates a .netlify folder. The build output includes all agents, tools, and workflows of your project, alongside a special config.json file. The config.json file configures the behavior of Netlify functions.

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

The config.json file contains:

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