---
title: "Mastra：功能、版本和快速入门 · DotsAgent"
description: "Mastra 维护的 Mastra：许可证、最新版本、MCP 支持、持久化运行、人工审批、追踪和评测，并附有可复制的快速入门。"
url: https://dotsagent.io/zh/frameworks/mastra
---

框架 · Mastra

# 快速了解 Mastra

一个 TypeScript framework，将 agents、支持暂停和恢复的 workflows、memory、evals 和 Studio UI 整合在同一个包中。可集成到 Next.js、Express 或 Hono 应用中；核心部分采用 Apache-2.0 许可证，ee/ 目录则采用企业许可证。

**适用于：**  希望用一套技术栈构建 agents、workflows、memory 和 evals 的 TypeScript 团队。

## 关键信息

- **维护者**: Mastra
- **语言**: TypeScript
- **许可证**: Apache-2.0 (core)
- **最新版本**: `@mastra/core 1.73.0` · 2026年10月1日
- **代码仓库**: [mastra-ai/mastra](https://github.com/mastra-ai/mastra) · 28,467 个 stars
- **托管选项**: [Mastra Cloud / Mastra Platform](https://mastra.ai/docs)mastra deploy 会构建并部署 Docker 镜像。

## 快速入门

安装软件包、设置凭据，然后运行官方文档中的最简 agent。这里使用的模型 ID 与文档一致，但你的账户可能尚未启用这些模型。

`安装`

```
npm install @mastra/core@latest zod@latest typescript@latest @types/node@latest mastra@latest  (or scaffold: npm create mastra@latest)
```

需要 OPENAI_API_KEY

`TypeScript`

```
// src/mastra/agents/weather-agent.ts
import { Agent } from '@mastra/core/agent'
import { weatherTool } from '../tools/weather-tool.ts'

export const weatherAgent = new Agent({
  id: 'weather-agent',
  name: 'Weather Agent',
  instructions: `
      You are a helpful weather assistant that provides accurate weather information.

      Your primary function is to help users get weather details for specific locations. When responding:
      - Include relevant details like humidity, wind conditions, and precipitation
      - Keep responses concise but informative

      Use the weatherTool to fetch current weather data.
`,
  // Use a string in provider/model format, not provider:model or a provider object.
  model: 'openai/gpt-5.6-sol',
  tools: { weatherTool },
})

// run.mjs (after registering the agent in src/mastra/index.ts)
import { mastra } from './src/mastra/index.ts'

const agent = mastra.getAgentById('weather-agent')
const response = await agent.generate('Weather in SF')
console.log(response.text)
```

[快速入门来源](https://mastra.ai/docs)

## 功能

| 支持任意模型 | — | 模型路由使用 provider/model 格式的字符串 |
| --- | --- | --- |
| MCP 客户端 | — | — |
| MCP 服务器 | — | MCPServer 可公开 agents、tools、workflows、prompts 和 resources |
| 多 agent | — | agent 可以作为其他 agent 的工具 |
| 持久化运行 | — | 通过 libSQL、Postgres 等存储快照，实现暂停和恢复 |
| 人工审批 | — | suspend() 和 resume() 用于收集人工输入 |
| 追踪 | — | 通过 OTel exporter 对接 Langfuse、Braintrust、Datadog 和 LangSmith |
| 评测 | — | Scorer 可通过采样在线运行，也可在 CI 中离线运行 |

## 近期更新

- npm create mastra 现在可搭建通用 harness，包含 workspace、shell 工具、memory 和定时任务。
- Mastra Factory 面向由 coding agents 构建的软件工厂。

## 同一语言的替代方案

- [OpenAI Agents SDK (JS)](https://dotsagent.io/zh/frameworks/openai-agents-js)

- [Claude Agent SDK](https://dotsagent.io/zh/frameworks/claude-agent-sdk)

- [Google ADK](https://dotsagent.io/zh/frameworks/google-adk)

- [LangGraph](https://dotsagent.io/zh/frameworks/langgraph)

- [LlamaIndex](https://dotsagent.io/zh/frameworks/llamaindex)

- [Vercel AI SDK](https://dotsagent.io/zh/frameworks/vercel-ai-sdk)

## 来源

1. [mastra.ai](https://mastra.ai/docs)/docs
2. [mastra.ai](https://mastra.ai/docs/connections/mcp)/docs/connections/mcp
3. [mastra.ai](https://mastra.ai/reference/tools/mcp-server)/reference/tools/mcp-server
4. [mastra.ai](https://mastra.ai/docs/workflows/suspend-and-resume)/docs/workflows/suspend-and-resume
5. [mastra.ai](https://mastra.ai/docs/workflows/snapshots)/docs/workflows/snapshots
6. [mastra.ai](https://mastra.ai/ai-agent-observability)/ai-agent-observability
7. [github.com](https://github.com/mastra-ai/mastra/blob/main/LICENSE.md)/mastra-ai/mastra/blob/main/LICENSE.md
8. [registry.npmjs.org](https://registry.npmjs.org/@mastra%2fcore)/@mastra%2fcore

为 AI agent 开发者提供的独立参考资料。与此处提及的任何厂商均无关联。

© 2026 DotsAgent · 事实核查日期：2026年10月1日
