What Is Mastra? Building AI Agents in TypeScript, Setup, MCP, License and Pricing
Mastra is an open-source framework, written in TypeScript, for adding an AI agent to your site or app. You start a project with `npm create mastra@latest`, write a tool with `createTool` (for example a function that looks up an order's status) and an agent that uses it with `new Agent`; when a customer asks "where is order 1042?", the agent calls the tool and writes the answer. `mastra dev` opens Studio, where you try the agent in the browser. The framework is free (Apache-2.0); the model provider's API fees are separate, and the Mastra platform has free and paid plans for deployment and observability. It isn't a no-code tool.
What is Mastra and what does it do?
An open-source framework for building AI agents that call tools, plus workflows, memory and RAG, in TypeScript. It is used to add an agent that answers customer questions and looks up orders to a site or app.
Is Mastra free and open source?
Most of the framework is Apache-2.0-licensed and free; the enterprise features in the ee/ folders are source-available, not open source, and need a license in production. The Mastra platform, which offers deployment and observability, has a Free plan at $0, Starter at $25 and Team at $250 (per month, per workspace). Model API fees are separate.
- What it does
- Builds AI agents that call tools, and workflows, in TypeScript
- Type
- TypeScript library + command line (mastra)
- Maker
- Mastra (Kepler Software, Inc.)
- Requirements
- Node.js 22.13+ and a model API key
- Watch out
- Enterprise features need a license in production
- Latest release
- @mastra/core 1.87.0 (December 2, 2026)
- Price
- Framework free; platform $0, $25, $250/month
What is Mastra and what does it do?
No. Mastra is a software library: you write agents and tools in TypeScript. The Studio screen is for trying out an agent, not for building one. If you want to build agents or automations without code, visual tools such as n8n, Dify or Langflow fit better.
An agent is an AI program that decides on its own which tool to call and when, for the goal it is given: it reads a customer question, checks the order system and writes an answer. Mastra gives you the parts to build this in TypeScript in one package: agents, tools, workflows with defined steps, conversation memory, answers from documents (RAG), evaluation (evals) and observability. The README says its model routing connects to more than 40 providers through one interface.
Who it's for: JavaScript/TypeScript developers and web agencies that want to add an agent to a website or app that answers customer questions and looks up orders or bookings. Who it's not for: business owners who don't write code, and teams that only use Python: Mastra is written in TypeScript.
Sources: Mastra README, docs "Agents" and "Workflows", December 3, 2026. The repository was created on August 6, 2024; the first npm release came on October 2, 2024, and version 1.0.0 on January 20, 2026.
How does Mastra work?
The agent decides which tool to call; you decide in code what the tool can access. For jobs whose steps are known in advance, you use a workflow instead of an agent.
.then(), .branch(), .parallel().Sources: README (Why Mastra), docs "Agents" (When to use agents) and "Workflows", December 3, 2026.
How do you install Mastra?
No account needed. You need Node.js 22.13 or later (the version the @mastra/core package requires) and an API key from a model provider. The README recommends the project starter command as the easiest route; you can also add it to an existing project by hand.
› npm create mastra@latestOther package managers: pnpm create mastra@latest, yarn create mastra, bunx create-mastra. The command sets up a project by asking questions; according to the docs, the starter brings an agent scaffold with a local workspace, shell tools, memory, task tracking, web access and scheduled jobs. The command also installs Mastra skills for the coding agent on your computer.
› npm install @mastra/core@latest zod@latest typescript@latest @types/node@latest mastra@latestThe docs have separate integration guides for Next.js, React + Vite, Astro, Express, SvelteKit and Hono.
- Add the key: Put the provider's key in the project's
.envfile:OPENAI_API_KEY,ANTHROPIC_API_KEYorGOOGLE_API_KEY. For Claude models the route is an Anthropic API key; a Claude.ai subscription doesn't replace that key. - Open Studio: Type
npm run dev(ormastra dev) and go tohttp://localhost:4111in your browser; you chat with the agent and see its tool calls. You try the REST API atlocalhost:4111/swagger-ui.
Sources: README (Get started), docs "Studio", npm @mastra/core 1.87.0 (engines: node >=22.13.0), December 3, 2026.
How do you use Mastra? Write your first tool and agent
The code below follows the pattern of the weather example in the docs; the order data is made up, and you connect the body of execute to your own order system. You write the model ID in provider/model form, as in the Models section.
› import { createTool } from '@mastra/core/tools'
import { z } from 'zod'
export const orderTool = createTool({
id: 'order-status',
description: 'Returns the shipping status of an order by its number',
inputSchema: z.object({ orderId: z.string() }),
outputSchema: z.object({ orderId: z.string(), status: z.string() }),
execute: async ({ orderId }) => {
return { orderId, status: 'shipped' }
},
})› import { Agent } from '@mastra/core/agent'
import { orderTool } from '../tools/order-tool'
export const supportAgent = new Agent({
id: 'support-agent',
name: 'Support Agent',
instructions: 'You answer customer questions. Use orderTool to look up order status.',
model: 'openai/<model-id>',
tools: { orderTool },
})What you get: after you register the agent in src/mastra/index.ts with new Mastra({ agents: { supportAgent } }), calling agent.generate('Where is order 1042?') returns the agent's final answer in response.text; response.toolCalls shows which tools were called. Write the tool description (description) clearly: the agent uses it to decide which tool to pick.
order-status tool with orderId: "1042", reads the returned status and writes the answer. If you ask for something the tool doesn't return (such as a delivery date), the agent may guess; so add a rule like "say when you don't know" to the instructions.!The default storage is in memory: when the server restarts, memory and workflow state are wiped; add a persistent storage adapter.
Sources: docs "Agents" (Creating an agent, Using agents) and "Tools", December 3, 2026.
What's in Mastra? Workflows, memory, RAG, observability
Building agents
- Writing an agent with instructions, a model and tools using new AgentRequires separate setupAvailable on the free planAn agent that answers via agent.generate() · Free; needs a model API key
- Defining a tool with a zod schema (for example an order lookup) using createToolRequires separate setupAvailable on the free planA tool the agent calls, with validated input · Free
- Picking a model from more than 40 providers with a provider/model stringRequires a connectionLimited on the free planA model you switch in one line · The framework is free; the model API is billed by the provider
- Adding conversation memory and answering from documents (RAG)Requires separate setupAvailable on the free planAn agent that remembers earlier conversation · Free; persistent memory needs storage
Workflows
- Building a workflow that chains steps with .then, .branch and .parallel and pauses for human approvalRequires separate setupAvailable on the free planA workflow that can pause and resume · Free
Connecting
- Connecting MCP servers' tools to an agent (MCPClient) and exposing the agent as an MCP server (MCPServer)Requires separate setupAvailable on the free planAn agent that uses external MCP tools · Free; the @mastra/mcp package
Testing and deploying
- Chatting with the agent and watching tool calls in Studio with mastra devRequires separate setupAvailable on the free planA test screen at localhost:4111 · Free
- Deploying the agent to the Mastra platform with mastra deploy and monitoring itRequires a connectionLimited on the free planA live agent and observability records · Limited on the Free plan; Starter $25/month
Labels: "Requires a connection" means linking another account or app; "Requires separate setup" means installing a separate program. Pricing is listed per feature; a product having a free plan doesn't mean every feature is free. Compiled from official sources on December 3, 2026.
› import { createWorkflow, createStep } from '@mastra/core/workflows'
const step1 = createStep({ /* id, inputSchema, outputSchema, execute */ })
export const testWorkflow = createWorkflow({ /* id, inputSchema, outputSchema */ })
.then(step1)
.commit()What you get: a workflow whose steps run in order, with each step's input and output checked against a schema. Human approval: an agent or workflow can be suspended to wait for the user's approval, then resume where it left off; the docs say this state is kept in storage. There is also conversation history, fetching information from your sources (RAG), and built-in evals and observability.
Sources: README (Workflows, Human-in-the-loop, Context management, Production essentials), docs "Workflows", December 3, 2026.
How does Mastra connect to MCP servers?
MCP (Model Context Protocol) is an open standard that connects AI agents to external tools and data. Mastra works in both directions: with MCPClient you connect existing MCP servers' tools to your agent, and with MCPServer you expose your own agents, tools and workflows to other MCP-compatible systems.
› npm install @mastra/mcp@latest› import { MCPClient } from '@mastra/mcp'
export const mcpClient = new MCPClient({
id: 'my-mcp-client',
servers: {
wikipedia: { command: 'npx', args: ['-y', 'wikipedia-mcp'] },
weather: { url: new URL('https://weather.example.com/mcp') },
},
})What you get: when you give the agent's tools field await mcpClient.listTools(), the tools on these servers become the agent's tools. For hosted servers that require OAuth, Connect on the Mastra platform can handle the sign-in flow.
Source: docs "MCP" (Connect to MCP servers, MCPServer), December 3, 2026.
Which models does Mastra work with?
Mastra has no model of its own. You write a string in provider/model form in the agent's model field; the README says model routing connects to more than 40 providers, including OpenAI, Anthropic and Gemini, through one interface. The docs' examples use openai/gpt-6.2-sol; the examples write the provider/model string with a slash.
| Provider | Environment variable |
|---|---|
| OpenAI | OPENAI_API_KEY |
| Anthropic (Claude) | ANTHROPIC_API_KEY |
| Google (Gemini) | GOOGLE_API_KEY |
To switch models you only change the string and the key; the rest of the agent stays the same. The provider you choose charges for the model.
Sources: README (Model routing), docs "Agents", December 3, 2026.
Is Mastra free? Mastra platform pricing
The framework itself is free (Apache-2.0): you can run it on your own server, on Vercel, Netlify, Cloudflare or another Node.js environment; server costs and updates are on you. The model provider's API fees are always separate. What costs money is the Mastra platform, which offers deployment, hosted Studio and observability; prices are per workspace, each month.
- Unlimited agents, users and deployments
- 100K observability events
- 10 GB egress, 5 connections
- Dedicated project
- 1 small dedicated project
- 250K observability events
- 25 GB egress, 10 connections
- Usage alerts
- 1 small + 2 medium projects
- 10M observability events
- 50 GB egress, 50 connections
- SOC 2 report
- RBAC, SSO, audit logs
Memory $0.25/GB-hour, vCPU $0.25/vCPU-hour, connections $0.50 each, egress $0.10/GB, observability events $10 per 100K. Each plan includes some memory and vCPU hours.
Gateway runs on prepaid credit; the 3% processing fee is waived through December 31, 2026. According to the Gateway docs, prompts and completions aren't stored.
Sources: mastra.ai/pricing, Gateway docs "Overview" and "Usage, pricing, and limits", December 3, 2026. The product used to be called Mastra Cloud; the docs now say Mastra platform (Observability, Studio, Server). There is no price for Enterprise; you contact the company.
Mastra's license: which part is open source, which needs a license?
GitHub shows the license as "NOASSERTION" because the repository has two licenses. According to LICENSE.md, everything outside folders named ee/ is Apache-2.0; the enterprise features in the ee/ folders are under the Mastra Enterprise Edition License 2.0: the source is visible, but it isn't open source. According to the license page, whether you need it depends on the features you turn on, not on the packages you install; in development and testing everything works without a license.
| Feature | EE license in production |
|---|---|
Authentication on API routes (server.auth), with any provider | Not needed |
| Studio with Simple Auth, JWT or Mastra platform auth | Not needed |
| Studio sign-in screen with a third-party provider (an SSO button or an email and password form) | Needed |
| Role-based access control (RBAC) | Needed |
| Fine-grained authorization (FGA) | Needed |
| Agent Builder | Needed |
- Using, modifying and distributing the Apache-2.0 part in a commercial product
- Trying the enterprise features without a license in development and testing
- Using the enterprise features in production without a written agreement and a license key (
MASTRA_LICENSE_KEY) - Redistributing the enterprise features or offering them as a managed service
Without a key in production, the server doesn't start when RBAC, FGA or Agent Builder is on; in Studio with third-party sign-in, the sign-in screen is hidden. The @mastra/connect package in the repository is Apache-2.0; only its ready-made provider actions (src/providers/), adapted from third-party templates, carry the Elastic License 2.0.
Sources: LICENSE.md, ee/LICENSE (Mastra Enterprise Edition License 2.0, effective September 22, 2026), docs "License", packages/connect package.json, NOTICE.md and LICENSE-ELv2.txt, December 3, 2026. This is not legal advice.
Does Mastra work in Turkish?
| Docs and StudioNo | The docs, commands and the Studio screen are in English. |
|---|---|
| An agent that answers in TurkishYes | The agent's language depends on the model and the instructions you choose; you can write the instructions in Turkish and say "answer in Turkish". If you write tool descriptions in Turkish, check on the first try that it picks the right tool. |
| Use from TurkeyYes | A publicly available package on npm; no account needed. Platform payments are in dollars. |
Is Mastra safe? Data and permissions
Questions to the agent and tool results go to the model provider you choose and are subject to its data terms. In tools that return personal data, return only the fields that are needed.
Tool code runs with the server's permissions; the agent has as much access as the tools you give it. The starter project includes shell tools and web access: remove them if you don't need them.
Don't write API keys into the code; keep them in the .env file and don't commit it to the repository.
Sources: docs "Agents", "Tools", "MCP" (credentials and permission boundaries), December 3, 2026. This is not a security audit.
Common problems and fixes
| What happens | What to do |
|---|---|
| Memory is lost when the server restarts | The default storage is in memory; add a persistent storage adapter. |
| The server won't start in production, and the error names a feature | RBAC, FGA or Agent Builder needs a license: add MASTRA_LICENSE_KEY or turn the feature off. |
| A model call fails with an auth error | Pass the provider's key in .env under the right name (OPENAI_API_KEY, ANTHROPIC_API_KEY, GOOGLE_API_KEY). |
| A Node version error during install | @mastra/core needs Node.js 22.13 or later. |
| The model string isn't recognized | The examples in the docs use a string in provider/model form (for example openai/...); a slash, not a colon. |
How do you uninstall Mastra?
› npm uninstall @mastra/core mastraAdd the other @mastra/* packages you installed (for example @mastra/mcp) to the same command; if you won't use a project you created with npm create mastra, deleting the folder is enough. If you deployed to the Mastra platform, you delete the project separately in the platform dashboard.
Mastra, n8n or Langflow?
The Mastra row comes from its official docs; the other rows summarize those tools' own guides. This is not a ranking.
Frequently asked questions
Can I use it without code?
No. Mastra is a library written in TypeScript; the Studio screen is for trying out an agent. For building agents or automations without code, visual tools such as n8n, Dify or Langflow fit better.
Mastra, LangChain or LangGraph?
Mastra was written for TypeScript from the start; agents, tools, workflows, memory, MCP and Studio come in one package, and you switch models with a provider/model string. If your team uses Python, Python-based frameworks may feel more natural. When choosing, compare the language, the integrations you need and the license terms.
How do you write an agent with Mastra?
You start a project with npm create mastra@latest, write a tool with createTool and an agent with instructions, a model and tools using new Agent, and register the agent in new Mastra. You open Studio with npm run dev and try the agent at localhost:4111.
What is Mastra Studio?
A test screen that opens locally with the mastra dev command: you chat with agents, run workflows and see tool calls and traces. Its default address is localhost:4111. There is also a hosted Studio on the Mastra platform.
What is Mastra Agent Builder, and is it paid?
Agent Builder is one of Mastra's enterprise (ee) features. According to the license page, it works without a license in development and testing, but using it in production needs a Mastra Enterprise license and MASTRA_LICENSE_KEY; without the key the server doesn't start.
Does Mastra work with Claude?
Yes. You write a model string starting with anthropic in the agent's model field and add ANTHROPIC_API_KEY to the .env file. This is an Anthropic API key and usage is billed separately; a Claude.ai subscription doesn't replace it.
Related guides
Sources
- Mastra README
- Documentation
- Agents
- Tools
- Workflows
- MCP
- Studio
- Deployment
- Mastra platform
- Pricing
- Gateway overview
- Gateway usage, pricing and limits
- License page
- LICENSE.md
- ee/LICENSE
- npm: @mastra/core
Not clear in the official sources: The price of the Enterprise plan and the enterprise license (you contact the company). Covered in the relevant section along with what you can do.





