Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Build Mastra AI agents and workflows with guidance on current API lookup, tools, memory, and RAG patterns.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
SKILL.md
1---2name: mastra3description: "Comprehensive Mastra framework guide. Teaches how to find current documentation, verify API signatures, and build agents and workflows. Covers documentation lookup strategies (embedded docs, remote docs), core concepts (agents vs workflows, tools, memory, RAG), TypeScript requirements, and common patterns. Use this skill for all Mastra development to ensure you're using current APIs from the installed version or latest documentation."4license: Apache-2.05metadata:6author: Mastra7version: "2.0.0"8repository: https://github.com/mastra-ai/skills9---1011# Mastra Framework Guide1213Build AI applications with Mastra. This skill teaches you how to find current documentation and build agents and workflows.1415## ⚠️ Critical: Do not trust internal knowledge1617Everything you know about Mastra is likely outdated or wrong. Never rely on memory. Always verify against current documentation.1819Your training data contains obsolete APIs, deprecated patterns, and incorrect usage. Mastra evolves rapidly - APIs change between versions, constructor signatures shift, and patterns get refactored.2021## Prerequisites2223Before writing any Mastra code, check if packages are installed:2425```bash26ls node_modules/@mastra/27```2829- **If packages exist:** Use embedded docs first (most reliable)30- **If no packages:** Install first or use remote docs3132## Available files3334### References3536| User Question | First Check | How To |37| ----------------------------------- | ---------------------------------------------------------------- | ---------------------------------------------- |38| "Create/install Mastra project" | [`references/create-mastra.md`](references/create-mastra.md) | Setup guide with CLI and manual steps |39| "How do I use Agent/Workflow/Tool?" | [`references/embedded-docs.md`](references/embedded-docs.md) | Look up in `node_modules/@mastra/*/dist/docs/` |40| "How do I use X?" (no packages) | [`references/remote-docs.md`](references/remote-docs.md) | Fetch from `https://mastra.ai/llms.txt` |41| "I'm getting an error..." | [`references/common-errors.md`](references/common-errors.md) | Common errors and solutions |42| "Upgrade from v0.x to v1.x" | [`references/migration-guide.md`](references/migration-guide.md) | Version upgrade workflows |4344### Scripts4546- `scripts/provider-registry.mjs`: Look up current providers and models available in the model router. Always run this before using a model to verify provider keys and model names.4748## Priority order for writing code4950⚠️ Never write code without checking current docs first.51521. **Embedded docs first** (if packages installed)5354Look up current docs in `node_modules` for a package. Example of looking up "Agent" docs in `@mastra/core`:5556```bash57grep -r "Agent" node_modules/@mastra/core/dist/docs/references58```5960- **Why:** Matches your EXACT installed version61- **Most reliable source of truth**62- **More information:** [`references/embedded-docs.md`](references/embedded-docs.md)63642. **Source code second** (if packages installed)6566If you can't find what you need in the embedded docs, look directly at the source code. This is more time consuming but can provide insights into implementation details.6768```bash69# Check what's available70cat node_modules/@mastra/core/dist/docs/assets/SOURCE_MAP.json | grep '"Agent"'7172# Read the actual type definition73cat node_modules/@mastra/core/dist/[path-from-source-map]74```7576- **Why:** Ultimate source of truth if docs are missing or unclear77- **Use when:** Embedded docs don't cover your question78- **More information:** [`references/embedded-docs.md`](references/embedded-docs.md)79803. **Remote docs third** (if packages not installed)8182You can fetch the latest docs from the Mastra website:8384```bash85https://mastra.ai/llms.txt86```8788- **Why:** Latest published docs (may be ahead of installed version)89- **Use when:** Packages not installed or exploring new features90- **More information:** [`references/remote-docs.md`](references/remote-docs.md)9192## Core concepts9394### Agents vs workflows9596**Agent**: Autonomous, makes decisions, uses tools97Use for: Open-ended tasks (support, research, analysis)9899**Workflow**: Structured sequence of steps100Use for: Defined processes (pipelines, approvals, ETL)101102### Key components103104- **Tools**: Extend agent capabilities (APIs, databases, external services)105- **Memory**: Maintain context (message history, working memory, semantic recall, observational memory)106- **RAG**: Query external knowledge (vector stores, graph relationships)107- **Storage**: Persist data (Postgres, LibSQL, MongoDB)108109### Mastra Studio110111Studio provides an interactive UI for building, testing, and managing agents, workflows, and tools. It helps with debugging and improving your applications iteratively.112113Inside a Mastra project, run:114115```bash116npm run dev117```118119Then open `http://localhost:4111` in your browser to access Mastra Studio.120121## Critical requirements122123### TypeScript config124125Mastra requires **ES2022 modules**. CommonJS will fail.126127```json128{129"compilerOptions": {130"target": "ES2022",131"module": "ES2022",132"moduleResolution": "bundler"133}134}135```136137### Model format138139Always use `"provider/model-name"` when defining models using Mastra's model router.140141Use the provider registry script to look up available providers and models:142143```bash144# List all available providers145node scripts/provider-registry.mjs --list146147# List all models for a specific provider (sorted newest first)148node scripts/provider-registry.mjs --provider openai149node scripts/provider-registry.mjs --provider anthropic150```151152When the user asks to use a model or provider, **always run the script first** to verify the provider key and model name are valid. Do not guess model names from memory as they change frequently.153154Example model strings:155156- `"openai/gpt-5.4"`157- `"anthropic/claude-sonnet-4-5"`158- `"google/gemini-2.5-pro"`159160## When you see errors161162**Type errors often mean your knowledge is outdated.**163164**Common signs of outdated knowledge:**165166- `Property X does not exist on type Y`167- `Cannot find module`168- `Type mismatch` errors169- Constructor parameter errors170171**What to do:**1721731. Check [`references/common-errors.md`](references/common-errors.md)1742. Verify current API in embedded docs1753. Don't assume the error is a user mistake - it might be your outdated knowledge176177## Development workflow178179**Always verify before writing code:**1801811. **Check packages installed**182183```bash184ls node_modules/@mastra/185```1861872. **Look up current API**188- If installed → Use embedded docs [`references/embedded-docs.md`](references/embedded-docs.md)189- If not → Use remote docs [`references/remote-docs.md`](references/remote-docs.md)1901913. **Write code based on current docs**1921934. **Test in Studio**194```bash195npm run dev # http://localhost:4111196```197198## Resources199200- **Setup**: [`references/create-mastra.md`](references/create-mastra.md)201- **Embedded docs lookup**: [`references/embedded-docs.md`](references/embedded-docs.md) - Start here if packages are installed202- **Remote docs lookup**: [`references/remote-docs.md`](references/remote-docs.md)203- **Common errors**: [`references/common-errors.md`](references/common-errors.md)204- **Migrations**: [`references/migration-guide.md`](references/migration-guide.md)205