0
Fork 0
mirror of https://github.com/mastra-ai/mastra.git synced 2026-11-17 08:44:46 +00:00
mastra/server-adapters/nestjs
History 2026-11-12 21:12:29 +00:00
..
src feat(server): memory, observability and agent builder MCP toolsets (#29931) 2026-11-12 10:25:19 -08:00
.gitignore feat(server): add NestJS server adapter (#12751) 2026-04-30 19:34:31 -07:00
CHANGELOG.md chore: version - exit prerelease mode 2026-11-12 21:12:29 +00:00
lint-staged.config.js refactor(lint): replace ESLint with type-aware oxlint (#27476) 2026-10-18 10:38:35 -07:00
package.json chore: version - exit prerelease mode 2026-11-12 21:12:29 +00:00
README.md feat(server-adapters): publish shared adapter test suite (#24254) 2026-09-17 14:39:24 +02:00
tsconfig.build.json feat(server): add NestJS server adapter (#12751) 2026-04-30 19:34:31 -07:00
tsconfig.json chore: migrate package builds to tsdown (#19829) 2026-07-28 12:32:21 +02:00
tsdown.config.ts fix(server-adapters): make tsc -p pass for every server adapter (#28219) 2026-10-22 21:38:49 -04:00
vitest.config.ts chore(deps): update dependencies across the monorepo (#28417) 2026-10-26 16:59:30 +01:00

@mastra/nestjs

NestJS server adapter for Mastra. Use it to expose agents, workflows, tools, MCP, memory, voice, and streaming endpoints through NestJS with native dependency injection, guards, interceptors, and exception handling.

The adapter supports NestJS running on the Express platform. If an application uses the Fastify platform, MastraModule fails during bootstrap instead of partially initializing.

Installation

npm install @mastra/nestjs

Usage

Register MastraModule in the application module. Import it after modules with application routes so its catch-all controller does not intercept them first.

import { Module } from '@nestjs/common';
import { MastraModule } from '@mastra/nestjs';
import { mastra } from './mastra';

@Module({
  imports: [
    MastraModule.register({
      mastra,
      prefix: '/api/mastra',
    }),
  ],
})
export class AppModule {}
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.create(AppModule, { bodyParser: false });
  await app.listen(3000);
}

bootstrap();

Documentation

MastraModule.register() accepts the Mastra instance and optional settings for the route prefix, rate limits, graceful shutdown, request body limits, stream heartbeat and redaction, tracing, request context parsing, tools, MCP transport, authentication, and per-route auth overrides.

The module registers Mastra routes under /api by default. Because it uses a catch-all NestJS controller, either import MastraModule last or assign a dedicated prefix such as /api/mastra.

Disable NestJS's default body parser when creating the application. MastraModule installs its own JSON parser so body limits, DELETE request bodies, scalar JSON, and route schema validation use the same adapter behavior.

Changelog

See the package changelog for version history and release notes.

Support

We have an open community Discord. Come and say hello and let us know if you have any questions or need any help getting things running.