0
Fork 0
mirror of https://github.com/mastra-ai/mastra.git synced 2026-11-17 08:44:46 +00:00
mastra/server-adapters/next
History 2026-11-12 21:12:29 +00:00
..
src fix(server-adapters): abort in-flight MCP tool calls when the client disconnects on Hono, Elysia and Next (#28217) 2026-10-22 20:47:02 -04:00
CHANGELOG.md chore: version - exit prerelease mode 2026-11-12 21:12:29 +00:00
lint-staged.config.js chore: run lint-staged for root files and the 16 packages without a config (#29898) 2026-11-10 14:08:55 +01:00
package.json chore: version - exit prerelease mode 2026-11-12 21:12:29 +00:00
README.md docs: add Next.js and TanStack Start server adapter guides (#22964) 2026-09-03 10:55:07 +02:00
tsconfig.build.json feat: add @mastra/next server adapter for Next.js App Router (#18230) 2026-06-20 18:39:02 +02:00
tsconfig.json chore: migrate package builds to tsdown (#19829) 2026-07-28 12:32:21 +02:00
tsdown.config.ts chore: migrate package builds to tsdown (#19829) 2026-07-28 12:32:21 +02:00
vitest.config.ts feat: add @mastra/next server adapter for Next.js App Router (#18230) 2026-06-20 18:39:02 +02:00

@mastra/next

@mastra/next exposes a Mastra instance through Next.js App Router route handlers. Use it to serve Mastra's REST, streaming, custom API, MCP, and A2A endpoints from the same serverless deployment as a Next.js application.

Installation

npm install @mastra/next

Usage

Create a catch-all App Router route at app/api/[...mastra]/route.ts:

import { createNextRouteHandler } from '@mastra/next';
import { mastra } from '../../../src/mastra';

export const { GET, POST, PUT, DELETE, PATCH, OPTIONS, HEAD } = createNextRouteHandler({
  mastra,
});

The route prefix and catch-all location must match. For a route mounted below /api/mastra, pass the same prefix:

createNextRouteHandler({
  mastra,
  prefix: '/api/mastra',
  tools: { customTool },
});

Documentation

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.