Mastra

Framework · Last verified 2026-09-30 · Install verified 2026-09-30

TL;DR

Mastra is a TypeScript framework from Kepler Software, which trades as Mastra, for building agents, supervisor-style multi-agent setups and step-based workflows with memory, evals and tracing. Most code is Apache-2.0, while ee/ directories use a source-available enterprise license. It suits Node.js and Next.js teams adding agents to an existing app.

Key facts

Mastra key facts. Data as of 2026-10-01.
Type Framework
Languages / SDKs TypeScript
License unknown
Pricing model Open core
Orchestration pattern Supervisor
GitHub stars 28,460 (as of 2026-10-01)
GitHub forks 2,895
Last push 2026-10-01
Latest release @mastra/core@1.72.0
Repository mastra-ai/mastra
Website mastra.ai
Documentation mastra.ai
Last verified 2026-09-30

Key features

  • Agents that combine a model, createTool() tools, structured output and memory, addressed through a provider/model string router. (source)
  • Supervisor agents: subagents listed in a parent's agents property, with onDelegationStart / onDelegationComplete hooks and a messageFilter for what context each subagent sees. (source)
  • Workflows built from typed createStep() steps and composed with .then(), .parallel(), .branch(), .dountil() and .foreach(). (source)
  • Workflow suspend() / resume() backed by snapshots in the configured storage provider, so paused runs survive restarts. (source)
  • Memory layers: message history, observational memory, working memory and semantic recall, persisted through storage providers. (source)
  • Tool-call approval (requireApproval, requireToolApproval) with approveToolCall() / declineToolCall() and in-tool suspend(). (source)
  • @mastra/mcp provides MCPClient for consuming MCP servers and MCPServer for exposing agents, tools and workflows. (source)
  • @mastra/acp runs ACP-speaking coding agents (for example OpenCode or Cline) as a Mastra tool or subagent. (source)

Architecture and orchestration pattern

Pattern: Supervisor

Mastra has two execution primitives. An Agent runs a model-and-tool loop until the model stops or maxSteps is reached. A workflow is an explicit graph of typed steps chained with .then(), run side by side with .parallel(), routed with .branch() or looped with .dountil() / .foreach(). Workflows run on a built-in engine by default, and the docs list workflow runners such as Inngest for managed execution.

Multi-agent work is centred on supervisor agents. Subagents go in the parent's agents property and the parent decides, from each subagent's description, when to delegate; delegation hooks can rewrite or reject a call. The older .network() routing API is deprecated in favour of this pattern. The multi-agent guide also describes handoffs and councils, but builds them from agents plus workflows; there is no dedicated council primitive.

State lives in storage providers (for example LibSQL or PostgreSQL). Workflow and approval snapshots are saved there so a suspended run can resume later. Agent memory combines message history with optional observational memory, working memory and semantic recall. During delegation a subagent sees the parent's conversation, but only the delegation prompt and its own reply are written to the subagent's memory.

Human in the loop

For agents, a tool marked requireApproval: true, or every tool when requireToolApproval: true is passed to stream() / generate(), pauses before execute runs. The stream emits a tool-call-approval chunk and the caller answers with approveToolCall() or declineToolCall() using the run ID; a decline can carry a reason that is returned to the model. With generate(), the result comes back with finishReason: 'suspended' instead. A tool can also call suspend() mid-execution and wait for resumeStream() with data matching its resumeSchema.

Workflows pause with suspend() inside a step and continue with run.resume() from any part of the application, such as an HTTP handler. Both mechanisms rely on snapshots, so a storage provider must be configured or resuming fails with a "snapshot not found" error. For supervisors, onDelegationStart can block or rewrite a delegation before the subagent runs.

Harnesses it can drive

Protocols

MCP, A2A and AG-UI support for Mastra. See the full matrix.
ProtocolSupportNote
MCP Yes evidence
checked 2026-09-30
Client and server: MCPClient connects to MCP servers over stdio or Streamable HTTP, and MCPServer exposes Mastra agents, tools, workflows, prompts and resources (@mastra/mcp).
A2A Yes evidence
checked 2026-09-30
Both directions: Mastra Server publishes an agent card and JSON-RPC endpoint per agent, and A2AAgent wraps a remote A2A agent as a subagent; v0.3 is the default and v1.0 is selected with the A2A-Version header.
AG-UI Partial evidence
checked 2026-09-30
Adapter maintained in the AG-UI repository: Mastra's CopilotKit guide serves Mastra agents over AG-UI with @ag-ui/mastra, which npm lists as published from ag-ui-protocol/ag-ui (integrations/mastra), not from Mastra's own packages; the AG-UI README labels Mastra 1st party.

Best for

  • TypeScript teams adding agents to an existing React, Next.js or Node.js application (shortlist)
  • Research-and-write flows where a supervisor delegates to specialised subagents (shortlist)
  • Delegating repository work to external coding agents such as OpenCode over ACP (shortlist)
  • Tool calls that must wait for a person to approve or decline them

Not for

  • Python-only teams; Mastra is a TypeScript framework
  • Production use of ee/ features without a written agreement and license key from Mastra
  • Runtimes older than Node.js 22.13, the minimum declared by @mastra/core

Quickstart

npm create mastra@latest

Install verified 2026-09-30 (temp dir, Node v22.22.3, macOS arm64: local npm i @mastra/core (no -g) ok, node -e "import('@mastra/core/agent').then(m=>console.log(typeof m.Agent))" ok, @mastra/core 1.72.0. This is the core package from the documented manual install; the interactive npm create mastra@latest scaffolder was not run. Packages came from the registry.npmmirror.com mirror, so the version is the one that mirror served on this date. Install and import check only; not a functional test.). What this means

import { Agent } from '@mastra/core/agent'
import { createTool } from '@mastra/core/tools'
import { z } from 'zod'

const lookup = createTool({
  id: 'lookup-order',
  description: 'Look up an order status by ID',
  inputSchema: z.object({ orderId: z.string() }),
  execute: async ({ orderId }) => ({ orderId, status: 'shipped' }),
})
const orders = new Agent({ id: 'orders', name: 'Orders', description: 'Answers order status questions.',
  instructions: 'Use lookup-order.', model: 'openai/gpt-5-mini', tools: { lookup } })
const lead = new Agent({ id: 'lead', name: 'Lead', instructions: 'Send order questions to orders.',
  model: 'openai/gpt-5-mini', agents: { orders } })

const res = await lead.generate('Where is order A-17?', { maxSteps: 5 })
console.log(res.text)

Common pitfalls

  • @mastra/core declares node >=22.13.0 and is an ES module; the manual setup uses { "type": "module" } in package.json.
  • A provider/model string reads the provider key from the environment, for example OPENAI_API_KEY for openai/... models.
  • The docs warn that tools passed as plain objects do not execute; define them with createTool().
  • Tool approval and workflow suspend/resume need a storage provider on the Mastra instance, otherwise resuming fails with "snapshot not found".
  • .network() is deprecated; new multi-agent code should use supervisor agents via generate() / stream(). @mastra/mcp 1.x users have a separate v2 migration guide.

Official quickstart

Pros

  • One package covers MCP in both directions: consume external MCP servers and publish Mastra agents and tools as an MCP server. (source)
  • A2A works as server and client, and one endpoint accepts both v0.3 and v1.0 requests. (source)
  • Delegation hooks can reject or rewrite a subagent call, and a message filter limits what context a subagent receives. (source)
  • Approval flows cover pre-execution approval, declines with a reason, and tools that suspend themselves mid-run. (source)
  • Existing agents built with the Claude Agent SDK, Cursor Agent SDK or OpenAI Agents SDK can be registered inside a Mastra project. (source)

Cons

  • Code under any ee/ directory is source-available only; production use requires a written agreement and a license key, which is why GitHub reports no single license. (source)
  • The .network() multi-agent API is deprecated and slated for removal, so older examples need migrating to supervisor agents. (source)
  • Approvals and suspended workflows depend on a configured storage provider; without one, resume fails. (source)
  • Coding agents started through @mastra/acp run in the configured directory without sandboxing and can reach files through their own tools. (source)
  • Minor releases of @mastra/core arrive every few days (1.64.0 to 1.71.0 in September 2026), so pinning versions matters. (source)

Alternatives

FAQ

Does Mastra support MCP?

Yes. The @mastra/mcp package includes MCPClient for connecting agents to MCP servers over stdio or Streamable HTTP and MCPServer for exposing Mastra agents, tools and workflows to MCP clients.

Is Mastra free?

Most of the repository is Apache-2.0 and free to use. Code in ee/ directories needs a commercial agreement for production use, and the hosted Mastra Platform has a free Starter tier plus paid Teams and Enterprise tiers.

Why is Mastra's license listed as unknown?

GitHub cannot assign one SPDX id because LICENSE.md combines Apache-2.0 for most code with the Mastra Enterprise License for everything under ee/ directories.

Does Mastra work with A2A and AG-UI?

A2A is built in: Mastra Server exposes agents over A2A and A2AAgent consumes remote A2A agents. AG-UI works through @ag-ui/mastra, an adapter maintained in the AG-UI repository that Mastra's docs use for CopilotKit frontends.

How does Mastra coordinate several agents?

The recommended pattern is a supervisor agent that lists subagents in its agents property and delegates to them. The older .network() API is deprecated.

Sources

Unknown fields: license: GitHub reports NOASSERTION. LICENSE.md states that everything outside ee/ directories is Apache-2.0 (Copyright Kepler Software, Inc.) and that code in any ee/ directory is under the Mastra Enterprise Edition License v2.0, a source-available license that allows development and testing but requires a written agreement and license key for production use (https://github.com/mastra-ai/mastra/blob/main/LICENSE.md, https://github.com/mastra-ai/mastra/blob/main/ee/LICENSE).

Something wrong or out of date, or do you maintain Mastra and want this page removed? Report a correction or request removal.