@mastra/mcp-docs-server 1.0.0-beta.10 → 1.0.0-beta.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.docs/organized/changelogs/%40mastra%2Fagent-builder.md +12 -12
- package/.docs/organized/changelogs/%40mastra%2Fai-sdk.md +50 -50
- package/.docs/organized/changelogs/%40mastra%2Fchroma.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +45 -45
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +109 -109
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +39 -39
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +39 -39
- package/.docs/organized/changelogs/%40mastra%2Fconvex.md +38 -0
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +264 -264
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +25 -25
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +37 -37
- package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +39 -39
- package/.docs/organized/changelogs/%40mastra%2Ffastembed.md +6 -0
- package/.docs/organized/changelogs/%40mastra%2Flance.md +39 -39
- package/.docs/organized/changelogs/%40mastra%2Flibsql.md +45 -45
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +22 -22
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +13 -13
- package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +39 -39
- package/.docs/organized/changelogs/%40mastra%2Fmssql.md +39 -39
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +45 -45
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +104 -104
- package/.docs/organized/changelogs/%40mastra%2Freact.md +66 -0
- package/.docs/organized/changelogs/%40mastra%2Fschema-compat.md +6 -0
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +59 -59
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +39 -39
- package/.docs/organized/changelogs/create-mastra.md +31 -31
- package/.docs/organized/changelogs/mastra.md +49 -49
- package/.docs/organized/code-examples/quick-start.md +0 -4
- package/.docs/organized/code-examples/stock-price-tool.md +21 -2
- package/.docs/raw/agents/agent-approval.mdx +136 -2
- package/.docs/raw/agents/agent-memory.mdx +4 -4
- package/.docs/raw/agents/guardrails.mdx +44 -7
- package/.docs/raw/agents/networks.mdx +1 -1
- package/.docs/raw/agents/overview.mdx +2 -2
- package/.docs/raw/agents/processors.mdx +151 -0
- package/.docs/raw/agents/using-tools.mdx +1 -1
- package/.docs/raw/course/01-first-agent/07-creating-your-agent.md +1 -2
- package/.docs/raw/course/01-first-agent/12-connecting-tool-to-agent.md +1 -1
- package/.docs/raw/course/01-first-agent/16-adding-memory-to-agent.md +1 -2
- package/.docs/raw/course/02-agent-tools-mcp/05-updating-your-agent.md +1 -1
- package/.docs/raw/course/02-agent-tools-mcp/10-updating-agent-instructions-zapier.md +1 -1
- package/.docs/raw/course/02-agent-tools-mcp/16-updating-agent-instructions-github.md +1 -1
- package/.docs/raw/course/02-agent-tools-mcp/21-updating-agent-instructions-hackernews.md +1 -1
- package/.docs/raw/course/02-agent-tools-mcp/27-updating-agent-instructions-filesystem.md +1 -1
- package/.docs/raw/course/02-agent-tools-mcp/31-enhancing-memory-configuration.md +2 -2
- package/.docs/raw/course/03-agent-memory/04-creating-basic-memory-agent.md +1 -2
- package/.docs/raw/course/03-agent-memory/08-configuring-conversation-history.md +1 -2
- package/.docs/raw/course/03-agent-memory/16-configuring-semantic-recall.md +3 -4
- package/.docs/raw/course/03-agent-memory/21-configuring-working-memory.md +2 -3
- package/.docs/raw/course/03-agent-memory/22-custom-working-memory-templates.md +2 -3
- package/.docs/raw/course/03-agent-memory/25-combining-memory-features.md +1 -2
- package/.docs/raw/course/03-agent-memory/27-creating-learning-assistant.md +2 -3
- package/.docs/raw/course/04-workflows/11-creating-an-ai-agent.md +2 -3
- package/.docs/raw/deployment/cloud-providers.mdx +20 -0
- package/.docs/raw/deployment/{building-mastra.mdx → mastra-server.mdx} +2 -2
- package/.docs/raw/deployment/monorepo.mdx +23 -44
- package/.docs/raw/deployment/overview.mdx +28 -53
- package/.docs/raw/deployment/web-framework.mdx +12 -14
- package/.docs/raw/getting-started/mcp-docs-server.mdx +57 -0
- package/.docs/raw/getting-started/start.mdx +10 -1
- package/.docs/raw/getting-started/studio.mdx +25 -2
- package/.docs/raw/guides/build-your-ui/ai-sdk-ui.mdx +1021 -67
- package/.docs/raw/{deployment/cloud-providers → guides/deployment}/aws-lambda.mdx +3 -6
- package/.docs/raw/{deployment/cloud-providers → guides/deployment}/azure-app-services.mdx +4 -6
- package/.docs/raw/{deployment/cloud-providers → guides/deployment}/cloudflare-deployer.mdx +4 -0
- package/.docs/raw/{deployment/cloud-providers → guides/deployment}/digital-ocean.mdx +3 -6
- package/.docs/raw/guides/deployment/index.mdx +32 -0
- package/.docs/raw/{deployment/cloud-providers → guides/deployment}/netlify-deployer.mdx +4 -0
- package/.docs/raw/{deployment/cloud-providers → guides/deployment}/vercel-deployer.mdx +4 -0
- package/.docs/raw/guides/getting-started/express.mdx +71 -152
- package/.docs/raw/guides/getting-started/hono.mdx +227 -0
- package/.docs/raw/guides/getting-started/next-js.mdx +173 -63
- package/.docs/raw/guides/getting-started/vite-react.mdx +307 -137
- package/.docs/raw/guides/guide/research-assistant.mdx +4 -4
- package/.docs/raw/guides/migrations/upgrade-to-v1/agent.mdx +70 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/client.mdx +17 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/overview.mdx +6 -0
- package/.docs/raw/index.mdx +1 -1
- package/.docs/raw/{deployment/mastra-cloud → mastra-cloud}/dashboard.mdx +2 -6
- package/.docs/raw/{deployment/mastra-cloud → mastra-cloud}/observability.mdx +1 -5
- package/.docs/raw/{deployment/mastra-cloud → mastra-cloud}/overview.mdx +2 -6
- package/.docs/raw/{deployment/mastra-cloud → mastra-cloud}/setting-up.mdx +3 -6
- package/.docs/raw/memory/overview.mdx +1 -1
- package/.docs/raw/memory/storage/memory-with-libsql.mdx +1 -1
- package/.docs/raw/memory/storage/memory-with-mongodb.mdx +1 -1
- package/.docs/raw/memory/storage/memory-with-pg.mdx +1 -1
- package/.docs/raw/memory/storage/memory-with-upstash.mdx +1 -1
- package/.docs/raw/{server-db/storage.mdx → memory/storage/overview.mdx} +2 -2
- package/.docs/raw/observability/logging.mdx +1 -1
- package/.docs/raw/observability/tracing/exporters/cloud.mdx +1 -1
- package/.docs/raw/observability/tracing/exporters/default.mdx +1 -1
- package/.docs/raw/rag/chunking-and-embedding.mdx +12 -25
- package/.docs/raw/rag/graph-rag.mdx +220 -0
- package/.docs/raw/rag/overview.mdx +1 -2
- package/.docs/raw/rag/retrieval.mdx +13 -29
- package/.docs/raw/rag/vector-databases.mdx +7 -3
- package/.docs/raw/reference/agents/agent.mdx +11 -4
- package/.docs/raw/reference/agents/getDefaultGenerateOptions.mdx +1 -1
- package/.docs/raw/reference/agents/getDefaultOptions.mdx +1 -1
- package/.docs/raw/reference/agents/getDefaultStreamOptions.mdx +1 -1
- package/.docs/raw/reference/agents/getInstructions.mdx +1 -1
- package/.docs/raw/reference/agents/getLLM.mdx +1 -1
- package/.docs/raw/reference/agents/getMemory.mdx +1 -1
- package/.docs/raw/reference/agents/getModel.mdx +1 -1
- package/.docs/raw/reference/agents/listScorers.mdx +1 -1
- package/.docs/raw/reference/ai-sdk/chat-route.mdx +1 -1
- package/.docs/raw/reference/ai-sdk/handle-chat-stream.mdx +1 -1
- package/.docs/raw/reference/ai-sdk/handle-network-stream.mdx +1 -1
- package/.docs/raw/reference/ai-sdk/handle-workflow-stream.mdx +1 -1
- package/.docs/raw/reference/ai-sdk/network-route.mdx +1 -1
- package/.docs/raw/reference/ai-sdk/to-ai-sdk-v4-messages.mdx +127 -0
- package/.docs/raw/reference/ai-sdk/to-ai-sdk-v5-messages.mdx +107 -0
- package/.docs/raw/reference/ai-sdk/workflow-route.mdx +1 -1
- package/.docs/raw/reference/auth/auth0.mdx +1 -1
- package/.docs/raw/reference/auth/clerk.mdx +1 -1
- package/.docs/raw/reference/auth/firebase.mdx +1 -1
- package/.docs/raw/reference/auth/jwt.mdx +1 -1
- package/.docs/raw/reference/auth/supabase.mdx +1 -1
- package/.docs/raw/reference/auth/workos.mdx +1 -1
- package/.docs/raw/reference/cli/mastra.mdx +1 -1
- package/.docs/raw/reference/client-js/mastra-client.mdx +1 -1
- package/.docs/raw/reference/client-js/workflows.mdx +20 -0
- package/.docs/raw/reference/core/getServer.mdx +3 -3
- package/.docs/raw/reference/core/getStorage.mdx +1 -1
- package/.docs/raw/reference/core/getStoredAgentById.mdx +1 -1
- package/.docs/raw/reference/core/listStoredAgents.mdx +1 -1
- package/.docs/raw/reference/core/setStorage.mdx +1 -1
- package/.docs/raw/reference/logging/pino-logger.mdx +1 -1
- package/.docs/raw/reference/processors/processor-interface.mdx +314 -13
- package/.docs/raw/reference/rag/database-config.mdx +1 -1
- package/.docs/raw/reference/server/create-route.mdx +1 -1
- package/.docs/raw/reference/server/express-adapter.mdx +4 -4
- package/.docs/raw/reference/server/hono-adapter.mdx +4 -4
- package/.docs/raw/reference/server/mastra-server.mdx +2 -2
- package/.docs/raw/reference/server/routes.mdx +28 -1
- package/.docs/raw/reference/streaming/ChunkType.mdx +23 -2
- package/.docs/raw/reference/streaming/agents/stream.mdx +38 -29
- package/.docs/raw/reference/streaming/workflows/stream.mdx +33 -20
- package/.docs/raw/reference/tools/create-tool.mdx +23 -1
- package/.docs/raw/reference/tools/graph-rag-tool.mdx +3 -3
- package/.docs/raw/reference/tools/vector-query-tool.mdx +3 -3
- package/.docs/raw/reference/workflows/run-methods/startAsync.mdx +143 -0
- package/.docs/raw/reference/workflows/workflow-methods/create-run.mdx +35 -0
- package/.docs/raw/reference/workflows/workflow-methods/foreach.mdx +68 -3
- package/.docs/raw/reference/workflows/workflow.mdx +37 -0
- package/.docs/raw/{auth → server/auth}/auth0.mdx +1 -1
- package/.docs/raw/{auth → server/auth}/clerk.mdx +1 -1
- package/.docs/raw/{auth → server/auth}/firebase.mdx +1 -1
- package/.docs/raw/{auth → server/auth}/index.mdx +6 -6
- package/.docs/raw/{auth → server/auth}/jwt.mdx +1 -1
- package/.docs/raw/{auth → server/auth}/supabase.mdx +1 -1
- package/.docs/raw/{auth → server/auth}/workos.mdx +1 -1
- package/.docs/raw/{server-db → server}/custom-adapters.mdx +3 -3
- package/.docs/raw/{server-db → server}/custom-api-routes.mdx +1 -1
- package/.docs/raw/{server-db → server}/mastra-client.mdx +2 -2
- package/.docs/raw/{server-db → server}/mastra-server.mdx +12 -10
- package/.docs/raw/{server-db → server}/middleware.mdx +2 -2
- package/.docs/raw/{server-db → server}/request-context.mdx +3 -3
- package/.docs/raw/{server-db → server}/server-adapters.mdx +6 -6
- package/.docs/raw/tools-mcp/overview.mdx +2 -2
- package/.docs/raw/workflows/control-flow.mdx +348 -2
- package/.docs/raw/workflows/error-handling.mdx +162 -1
- package/.docs/raw/workflows/overview.mdx +2 -2
- package/CHANGELOG.md +21 -0
- package/package.json +5 -5
- package/.docs/organized/changelogs/%40internal%2Fai-sdk-v4.md +0 -1
- package/.docs/raw/deployment/cloud-providers/index.mdx +0 -55
- /package/.docs/raw/{deployment/cloud-providers → guides/deployment}/amazon-ec2.mdx +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: "
|
|
2
|
+
title: "React + Vite | Frameworks"
|
|
3
3
|
description: A step-by-step guide to integrating Mastra with React and Vite.
|
|
4
4
|
---
|
|
5
5
|
|
|
@@ -8,248 +8,418 @@ import TabItem from "@theme/TabItem";
|
|
|
8
8
|
|
|
9
9
|
# Integrate Mastra in your React + Vite project
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
In this guide, you'll build a tool-calling AI agent using Mastra, then connect it to React by calling the agent directly from Mastra's standalone server.
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
- Simplify deployment with a unified codebase for frontend and backend
|
|
15
|
-
- Take advantage of Mastra's Client SDK
|
|
13
|
+
You'll use [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui/overview) and [AI Elements](https://ai-sdk.dev/elements) to create a beautiful, interactive chat experience.
|
|
16
14
|
|
|
17
|
-
|
|
15
|
+
## Before you begin
|
|
18
16
|
|
|
19
|
-
|
|
17
|
+
- You'll need an API key from a supported [model provider](/models/v1). If you don't have a preference, use [OpenAI](/models/v1/providers/openai).
|
|
18
|
+
- Install Node.js `v22.13.0` or later
|
|
20
19
|
|
|
21
|
-
|
|
20
|
+
## Create a new React + Vite app (optional)
|
|
22
21
|
|
|
23
|
-
|
|
22
|
+
If you already have a React + Vite app using Tailwind, skip to the next step.
|
|
24
23
|
|
|
25
|
-
|
|
24
|
+
### Project scaffold
|
|
26
25
|
|
|
27
|
-
|
|
26
|
+
Run the following command to [create a new React + Vite app](https://vite.dev/guide/#scaffolding-your-first-vite-project):
|
|
28
27
|
|
|
29
|
-
<Tabs>
|
|
28
|
+
<Tabs groupId="pm">
|
|
30
29
|
<TabItem value="npm" label="npm">
|
|
31
|
-
|
|
32
30
|
```bash copy
|
|
33
|
-
npm
|
|
31
|
+
npm create vite@latest mastra-react -- --template react-ts
|
|
32
|
+
cd mastra-react
|
|
34
33
|
```
|
|
35
|
-
|
|
36
34
|
</TabItem>
|
|
37
|
-
<TabItem value="
|
|
38
|
-
|
|
35
|
+
<TabItem value="pnpm" label="pnpm">
|
|
39
36
|
```bash copy
|
|
40
|
-
|
|
37
|
+
pnpm create vite mastra-react --template react-ts
|
|
38
|
+
cd mastra-react
|
|
41
39
|
```
|
|
42
|
-
|
|
43
40
|
</TabItem>
|
|
44
|
-
<TabItem value="
|
|
45
|
-
|
|
41
|
+
<TabItem value="yarn" label="yarn">
|
|
46
42
|
```bash copy
|
|
47
|
-
|
|
43
|
+
yarn create vite mastra-react --template react-ts
|
|
44
|
+
cd mastra-react
|
|
48
45
|
```
|
|
49
|
-
|
|
50
46
|
</TabItem>
|
|
51
47
|
<TabItem value="bun" label="bun">
|
|
52
|
-
|
|
53
48
|
```bash copy
|
|
54
|
-
bun
|
|
49
|
+
bun create vite mastra-react --template react-ts
|
|
50
|
+
cd mastra-react
|
|
55
51
|
```
|
|
56
|
-
|
|
57
52
|
</TabItem>
|
|
58
53
|
</Tabs>
|
|
59
54
|
|
|
60
|
-
|
|
55
|
+
This creates a project called `mastra-react`, but you can replace it with any name you want.
|
|
61
56
|
|
|
62
|
-
|
|
57
|
+
### Tailwind
|
|
63
58
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
Run the following command to quickly scaffold the default Weather agent with sensible defaults:
|
|
59
|
+
Next, install Tailwind:
|
|
67
60
|
|
|
61
|
+
<Tabs groupId="pm">
|
|
62
|
+
<TabItem value="npm" label="npm">
|
|
68
63
|
```bash copy
|
|
69
|
-
|
|
64
|
+
npm install tailwindcss @tailwindcss/vite
|
|
70
65
|
```
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
### 2. Use the Interactive CLI
|
|
75
|
-
|
|
76
|
-
If you prefer to customize the setup, run the `init` command and choose from the options when prompted:
|
|
77
|
-
|
|
66
|
+
</TabItem>
|
|
67
|
+
<TabItem value="pnpm" label="pnpm">
|
|
78
68
|
```bash copy
|
|
79
|
-
|
|
69
|
+
pnpm add tailwindcss @tailwindcss/vite
|
|
80
70
|
```
|
|
71
|
+
</TabItem>
|
|
72
|
+
<TabItem value="yarn" label="yarn">
|
|
73
|
+
```bash copy
|
|
74
|
+
yarn add tailwindcss @tailwindcss/vite
|
|
75
|
+
```
|
|
76
|
+
</TabItem>
|
|
77
|
+
<TabItem value="bun" label="bun">
|
|
78
|
+
```bash copy
|
|
79
|
+
bun add tailwindcss @tailwindcss/vite
|
|
80
|
+
```
|
|
81
|
+
</TabItem>
|
|
82
|
+
</Tabs>
|
|
81
83
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
84
|
+
Configure the Vite plugins:
|
|
85
|
+
|
|
86
|
+
```typescript title="vite.config.ts" {3-4,7-12}
|
|
87
|
+
import { defineConfig } from 'vite'
|
|
88
|
+
import react from '@vitejs/plugin-react'
|
|
89
|
+
import path from "path"
|
|
90
|
+
import tailwindcss from '@tailwindcss/vite'
|
|
91
|
+
|
|
92
|
+
export default defineConfig({
|
|
93
|
+
plugins: [react(), tailwindcss()],
|
|
94
|
+
resolve: {
|
|
95
|
+
alias: {
|
|
96
|
+
"@": path.resolve(__dirname, "./src"),
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
})
|
|
100
|
+
```
|
|
85
101
|
|
|
86
|
-
|
|
102
|
+
Replace everything in `src/index.css` with the following:
|
|
87
103
|
|
|
88
|
-
|
|
104
|
+
```css title="src/index.css"
|
|
105
|
+
@import "tailwindcss";
|
|
106
|
+
```
|
|
89
107
|
|
|
90
|
-
|
|
91
|
-
<TabItem value="app" label="app">
|
|
108
|
+
Add these `compilerOptions` to `tsconfig.json`:
|
|
92
109
|
|
|
93
|
-
```
|
|
110
|
+
```ts title="tsconfig.json"
|
|
94
111
|
{
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
"
|
|
98
|
-
"
|
|
112
|
+
// ...
|
|
113
|
+
"compilerOptions": {
|
|
114
|
+
"baseUrl": ".",
|
|
115
|
+
"paths": {
|
|
116
|
+
"@/*": ["./src/*"]
|
|
117
|
+
}
|
|
99
118
|
}
|
|
100
119
|
}
|
|
101
120
|
```
|
|
102
121
|
|
|
103
|
-
|
|
104
|
-
<TabItem value="src-app" label="src/app">
|
|
122
|
+
Edit `tsconfig.app.json` to resolve paths:
|
|
105
123
|
|
|
106
|
-
```
|
|
124
|
+
```ts title="tsconfig.app.json"
|
|
107
125
|
{
|
|
108
|
-
"
|
|
109
|
-
...
|
|
110
|
-
"
|
|
111
|
-
"
|
|
126
|
+
"compilerOptions": {
|
|
127
|
+
// ...
|
|
128
|
+
"baseUrl": ".",
|
|
129
|
+
"paths": {
|
|
130
|
+
"@/*": [
|
|
131
|
+
"./src/*"
|
|
132
|
+
]
|
|
133
|
+
}
|
|
134
|
+
// ...
|
|
112
135
|
}
|
|
113
136
|
}
|
|
114
137
|
```
|
|
115
138
|
|
|
116
|
-
|
|
117
|
-
</Tabs>
|
|
139
|
+
## Initialize Mastra
|
|
118
140
|
|
|
119
|
-
|
|
141
|
+
Run [`mastra init`](/reference/v1/cli/create-mastra). When prompted, choose a provider (e.g. OpenAI) and enter your key:
|
|
120
142
|
|
|
121
|
-
|
|
143
|
+
<Tabs groupId="pm">
|
|
144
|
+
<TabItem value="npm" label="npm">
|
|
122
145
|
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
"exclude": ["dist", ".mastra"]
|
|
127
|
-
}
|
|
146
|
+
```bash copy
|
|
147
|
+
cd mastra-react
|
|
148
|
+
npx mastra@beta init
|
|
128
149
|
```
|
|
129
150
|
|
|
130
|
-
|
|
151
|
+
</TabItem>
|
|
152
|
+
<TabItem value="pnpm" label="pnpm">
|
|
131
153
|
|
|
132
|
-
```bash
|
|
133
|
-
|
|
154
|
+
```bash copy
|
|
155
|
+
cd mastra-react
|
|
156
|
+
pnpm dlx mastra@beta init
|
|
134
157
|
```
|
|
135
158
|
|
|
136
|
-
>
|
|
159
|
+
</TabItem>
|
|
160
|
+
<TabItem value="yarn" label="yarn">
|
|
137
161
|
|
|
138
|
-
|
|
162
|
+
```bash copy
|
|
163
|
+
cd mastra-react
|
|
164
|
+
yarn dlx mastra@beta init
|
|
165
|
+
```
|
|
139
166
|
|
|
140
|
-
|
|
167
|
+
</TabItem>
|
|
168
|
+
<TabItem value="bun" label="bun">
|
|
141
169
|
|
|
142
|
-
```bash
|
|
143
|
-
|
|
170
|
+
```bash copy
|
|
171
|
+
cd mastra-react
|
|
172
|
+
bunx mastra@beta init
|
|
144
173
|
```
|
|
145
174
|
|
|
146
|
-
|
|
175
|
+
</TabItem>
|
|
176
|
+
</Tabs>
|
|
177
|
+
|
|
178
|
+
This creates a `src/mastra` folder with an example weather agent and the following files:
|
|
179
|
+
|
|
180
|
+
- `index.ts` - Mastra config, including memory
|
|
181
|
+
- `tools/weather-tool.ts` - a tool to fetch weather for a given location
|
|
182
|
+
- `agents/weather-agent.ts`- a weather agent with a prompt that uses the tool
|
|
147
183
|
|
|
148
|
-
|
|
184
|
+
You'll call `weather-agent.ts` from your chat UI in the next steps.
|
|
149
185
|
|
|
150
|
-
|
|
186
|
+
## Install AI SDK UI & AI Elements
|
|
187
|
+
|
|
188
|
+
Install AI SDK UI along with the Mastra adapter:
|
|
189
|
+
|
|
190
|
+
<Tabs groupId="pm">
|
|
151
191
|
<TabItem value="npm" label="npm">
|
|
152
192
|
|
|
153
193
|
```bash copy
|
|
154
|
-
npm
|
|
194
|
+
npm install @mastra/ai-sdk@beta @ai-sdk/react ai
|
|
155
195
|
```
|
|
156
196
|
|
|
157
197
|
</TabItem>
|
|
158
|
-
<TabItem value="
|
|
198
|
+
<TabItem value="pnpm" label="pnpm">
|
|
159
199
|
|
|
160
200
|
```bash copy
|
|
161
|
-
mastra
|
|
201
|
+
pnpm add @mastra/ai-sdk@beta @ai-sdk/react ai
|
|
162
202
|
```
|
|
163
203
|
|
|
164
204
|
</TabItem>
|
|
165
|
-
|
|
205
|
+
<TabItem value="yarn" label="yarn">
|
|
206
|
+
|
|
207
|
+
```bash copy
|
|
208
|
+
yarn add @mastra/ai-sdk@beta @ai-sdk/react ai
|
|
209
|
+
```
|
|
166
210
|
|
|
167
|
-
>
|
|
211
|
+
</TabItem>
|
|
212
|
+
<TabItem value="bun" label="bun">
|
|
168
213
|
|
|
169
|
-
|
|
214
|
+
```bash copy
|
|
215
|
+
bun add @mastra/ai-sdk@beta @ai-sdk/react ai
|
|
216
|
+
```
|
|
170
217
|
|
|
171
|
-
|
|
218
|
+
</TabItem>
|
|
219
|
+
</Tabs>
|
|
172
220
|
|
|
173
|
-
|
|
221
|
+
Next, initialize AI Elements. When prompted, choose the default options:
|
|
174
222
|
|
|
175
|
-
|
|
223
|
+
<Tabs groupId="pm">
|
|
224
|
+
<TabItem value="npm" label="npm">
|
|
176
225
|
|
|
177
226
|
```bash copy
|
|
178
|
-
|
|
179
|
-
touch lib/mastra.ts
|
|
227
|
+
npx ai-elements@latest
|
|
180
228
|
```
|
|
181
229
|
|
|
182
|
-
|
|
183
|
-
|
|
230
|
+
</TabItem>
|
|
231
|
+
<TabItem value="pnpm" label="pnpm">
|
|
184
232
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
});
|
|
233
|
+
```bash copy
|
|
234
|
+
pnpm dlx ai-elements@latest
|
|
188
235
|
```
|
|
189
236
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
Add new `route` to the config:
|
|
193
|
-
|
|
194
|
-
```typescript title="app/routes.ts" showLineNumbers copy
|
|
195
|
-
import { type RouteConfig, index, route } from "@react-router/dev/routes";
|
|
237
|
+
</TabItem>
|
|
238
|
+
<TabItem value="yarn" label="yarn">
|
|
196
239
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
route("test", "routes/test.tsx"),
|
|
200
|
-
] satisfies RouteConfig;
|
|
240
|
+
```bash copy
|
|
241
|
+
yarn dlx ai-elements@latest
|
|
201
242
|
```
|
|
202
243
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
Create a new Route, and add the example code:
|
|
244
|
+
</TabItem>
|
|
245
|
+
<TabItem value="bun" label="bun">
|
|
206
246
|
|
|
207
247
|
```bash copy
|
|
208
|
-
|
|
248
|
+
bunx ai-elements@latest
|
|
209
249
|
```
|
|
210
250
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
import { mastraClient } from "../../lib/mastra";
|
|
251
|
+
</TabItem>
|
|
252
|
+
</Tabs>
|
|
214
253
|
|
|
215
|
-
|
|
216
|
-
const [result, setResult] = useState<string | null>(null);
|
|
254
|
+
This downloads the entire AI Elements UI component library into a `@/components/ai-elements` folder.
|
|
217
255
|
|
|
218
|
-
|
|
219
|
-
event.preventDefault();
|
|
256
|
+
## Create a chat route
|
|
220
257
|
|
|
221
|
-
|
|
222
|
-
const city = formData.get("city")?.toString();
|
|
223
|
-
const agent = mastraClient.getAgent("weatherAgent");
|
|
258
|
+
Open `src/mastra/index.ts` and add a [chatRoute()](https://github.com/reference/v1/ai-sdk/chat-route) to your config. This creates an API route your React frontend can call for AI SDK-compatible chat responses, which you’ll use with useChat() next.
|
|
224
259
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
260
|
+
```ts title="src/mastra/index.ts"
|
|
261
|
+
import { Mastra } from '@mastra/core/mastra';
|
|
262
|
+
// Existing imports...
|
|
263
|
+
import { chatRoute } from "@mastra/ai-sdk"
|
|
228
264
|
|
|
229
|
-
|
|
265
|
+
export const mastra = new Mastra({
|
|
266
|
+
// Existing config...
|
|
267
|
+
server: {
|
|
268
|
+
apiRoutes: [
|
|
269
|
+
chatRoute({
|
|
270
|
+
path: '/chat/:agentId'
|
|
271
|
+
})
|
|
272
|
+
]
|
|
230
273
|
}
|
|
274
|
+
});
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
## Add the chat UI
|
|
278
|
+
|
|
279
|
+
Replace the `src/App.tsx` file to create a chat interface:
|
|
280
|
+
|
|
281
|
+
```tsx title="src/App.tsx"
|
|
282
|
+
import * as React from 'react';
|
|
283
|
+
import { DefaultChatTransport, type ToolUIPart } from 'ai';
|
|
284
|
+
import { useChat } from '@ai-sdk/react';
|
|
285
|
+
|
|
286
|
+
import {
|
|
287
|
+
PromptInput,
|
|
288
|
+
PromptInputBody,
|
|
289
|
+
PromptInputTextarea,
|
|
290
|
+
} from '@/components/ai-elements/prompt-input';
|
|
291
|
+
|
|
292
|
+
import {
|
|
293
|
+
Conversation,
|
|
294
|
+
ConversationContent,
|
|
295
|
+
ConversationScrollButton,
|
|
296
|
+
} from '@/components/ai-elements/conversation';
|
|
297
|
+
|
|
298
|
+
import {
|
|
299
|
+
Message,
|
|
300
|
+
MessageContent,
|
|
301
|
+
MessageResponse
|
|
302
|
+
} from '@/components/ai-elements/message';
|
|
303
|
+
|
|
304
|
+
import {
|
|
305
|
+
Tool,
|
|
306
|
+
ToolHeader,
|
|
307
|
+
ToolContent,
|
|
308
|
+
ToolInput,
|
|
309
|
+
ToolOutput,
|
|
310
|
+
} from '@/components/ai-elements/tool';
|
|
311
|
+
|
|
312
|
+
export default function App() {
|
|
313
|
+
const [input, setInput] = React.useState<string>('');
|
|
314
|
+
|
|
315
|
+
const { messages, sendMessage, status } = useChat({
|
|
316
|
+
transport: new DefaultChatTransport({
|
|
317
|
+
api: 'http://localhost:4111/chat/weather-agent',
|
|
318
|
+
}),
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
const handleSubmit = async () => {
|
|
322
|
+
if (!input.trim()) return;
|
|
323
|
+
|
|
324
|
+
sendMessage({ text: input });
|
|
325
|
+
setInput('');
|
|
326
|
+
};
|
|
231
327
|
|
|
232
328
|
return (
|
|
233
|
-
|
|
234
|
-
<
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
329
|
+
<div className="max-w-4xl mx-auto p-6 relative size-full h-screen">
|
|
330
|
+
<div className="flex flex-col h-full">
|
|
331
|
+
<Conversation className="h-full">
|
|
332
|
+
<ConversationContent>
|
|
333
|
+
{messages.map((message) => (
|
|
334
|
+
<div key={message.id}>
|
|
335
|
+
{message.parts?.map((part, i) => {
|
|
336
|
+
if (part.type === 'text') {
|
|
337
|
+
return (
|
|
338
|
+
<Message
|
|
339
|
+
key={`${message.id}-${i}`}
|
|
340
|
+
from={message.role}>
|
|
341
|
+
<MessageContent>
|
|
342
|
+
<MessageResponse>{part.text}</MessageResponse>
|
|
343
|
+
</MessageContent>
|
|
344
|
+
</Message>
|
|
345
|
+
);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
if (part.type?.startsWith('tool-')) {
|
|
349
|
+
return (
|
|
350
|
+
<Tool key={`${message.id}-${i}`}>
|
|
351
|
+
<ToolHeader
|
|
352
|
+
type={(part as ToolUIPart).type}
|
|
353
|
+
state={(part as ToolUIPart).state || 'output-available'}
|
|
354
|
+
className="cursor-pointer"
|
|
355
|
+
/>
|
|
356
|
+
<ToolContent>
|
|
357
|
+
<ToolInput input={(part as ToolUIPart).input || {}} />
|
|
358
|
+
<ToolOutput
|
|
359
|
+
output={(part as ToolUIPart).output}
|
|
360
|
+
errorText={(part as ToolUIPart).errorText}
|
|
361
|
+
/>
|
|
362
|
+
</ToolContent>
|
|
363
|
+
</Tool>
|
|
364
|
+
);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
return null;
|
|
368
|
+
})}
|
|
369
|
+
</div>
|
|
370
|
+
))}
|
|
371
|
+
<ConversationScrollButton />
|
|
372
|
+
</ConversationContent>
|
|
373
|
+
</Conversation>
|
|
374
|
+
<PromptInput onSubmit={handleSubmit} className="mt-20">
|
|
375
|
+
<PromptInputBody>
|
|
376
|
+
<PromptInputTextarea
|
|
377
|
+
onChange={(e) => setInput(e.target.value)}
|
|
378
|
+
className="md:leading-10"
|
|
379
|
+
value={input}
|
|
380
|
+
placeholder="Ask about the weather..."
|
|
381
|
+
disabled={status !== 'ready'}
|
|
382
|
+
/>
|
|
383
|
+
</PromptInputBody>
|
|
384
|
+
</PromptInput>
|
|
385
|
+
</div>
|
|
386
|
+
</div>
|
|
241
387
|
);
|
|
242
388
|
}
|
|
243
389
|
```
|
|
244
390
|
|
|
245
|
-
|
|
391
|
+
This component connects [`useChat()`](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat) to the `chat/weather-agent` endpoint, sending prompts there and streaming the response back in chunks.
|
|
246
392
|
|
|
247
|
-
|
|
393
|
+
It renders the response text using the [`<MessageResponse>`](https://ai-sdk.dev/elements/components/message#messageresponse-) component, and shows any tool invocations with the [`<Tool>`](https://ai-sdk.dev/elements/components/tool) component.
|
|
248
394
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
395
|
+
## Test your agent
|
|
396
|
+
|
|
397
|
+
In order to test your agent with the chat interface, you need to run both the Mastra server and the Vite development server.
|
|
398
|
+
|
|
399
|
+
1. Start the Mastra development server:
|
|
400
|
+
|
|
401
|
+
```bash copy
|
|
402
|
+
npx mastra dev
|
|
403
|
+
```
|
|
404
|
+
1. In a separate terminal window, start the Vite development server:
|
|
405
|
+
|
|
406
|
+
```bash copy
|
|
407
|
+
npm run dev
|
|
408
|
+
```
|
|
409
|
+
1. Open your application at http://localhost:5173
|
|
410
|
+
1. Try asking about the weather. If your API key is set up correctly, you'll get a response
|
|
252
411
|
|
|
253
412
|
## Next steps
|
|
254
413
|
|
|
255
|
-
|
|
414
|
+
Congratulations on building your Mastra agent with React! 🎉
|
|
415
|
+
|
|
416
|
+
From here, you can extend the project with your own tools and logic:
|
|
417
|
+
|
|
418
|
+
- Learn more about [agents](/docs/v1/agents/overview)
|
|
419
|
+
- Give your agent its own [tools](/docs/v1/agents/using-tools)
|
|
420
|
+
- Add human-like [memory](/docs/v1/agents/agent-memory) to your agent
|
|
421
|
+
|
|
422
|
+
When you're ready, read more about how Mastra integrates with AI SDK UI and React, and how to deploy your agent anywhere:
|
|
423
|
+
|
|
424
|
+
- Integrate Mastra with [AI SDK UI](/guides/v1/build-your-ui/ai-sdk-ui)
|
|
425
|
+
- Deploy your agent [anywhere](/docs/v1/deployment/overview)
|
|
@@ -373,7 +373,7 @@ curl -X POST http://localhost:4111/api/agents/researchAgent/generate \
|
|
|
373
373
|
|
|
374
374
|
Explore these examples for more advanced RAG techniques:
|
|
375
375
|
|
|
376
|
-
- [Filter RAG](/examples/
|
|
377
|
-
- [Cleanup RAG](/examples/
|
|
378
|
-
- [Chain of Thought RAG](/examples/
|
|
379
|
-
- [Rerank RAG](/examples/
|
|
376
|
+
- [Filter RAG](https://github.com/mastra-ai/mastra/tree/main/examples/basics/rag/filter-rag) for filtering results using metadata
|
|
377
|
+
- [Cleanup RAG](https://github.com/mastra-ai/mastra/tree/main/examples/basics/rag/cleanup-rag) for optimizing information density
|
|
378
|
+
- [Chain of Thought RAG](https://github.com/mastra-ai/mastra/tree/main/examples/basics/rag/cot-rag) for complex reasoning queries using workflows
|
|
379
|
+
- [Rerank RAG](https://github.com/mastra-ai/mastra/tree/main/examples/basics/rag/rerank-rag) for improved result relevance
|
|
@@ -313,3 +313,73 @@ To migrate, remove the `TMetrics` generic parameter and configure scorers using
|
|
|
313
313
|
// ...
|
|
314
314
|
});
|
|
315
315
|
```
|
|
316
|
+
|
|
317
|
+
### Tripwire response format changed
|
|
318
|
+
|
|
319
|
+
The tripwire response format has changed from separate `tripwire` and `tripwireReason` fields to a single `tripwire` object containing all related data.
|
|
320
|
+
|
|
321
|
+
To migrate, update your code to access tripwire data from the new object structure.
|
|
322
|
+
|
|
323
|
+
```diff
|
|
324
|
+
const result = await agent.generate('Hello');
|
|
325
|
+
|
|
326
|
+
- if (result.tripwire) {
|
|
327
|
+
- console.log(result.tripwireReason);
|
|
328
|
+
- }
|
|
329
|
+
+ if (result.tripwire) {
|
|
330
|
+
+ console.log(result.tripwire.reason);
|
|
331
|
+
+ // New fields available:
|
|
332
|
+
+ // result.tripwire.retry - whether this step should be retried
|
|
333
|
+
+ // result.tripwire.metadata - additional metadata from the processor
|
|
334
|
+
+ // result.tripwire.processorId - which processor triggered the tripwire
|
|
335
|
+
+ }
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
For streaming responses:
|
|
339
|
+
|
|
340
|
+
```diff
|
|
341
|
+
for await (const chunk of stream.fullStream) {
|
|
342
|
+
if (chunk.type === 'tripwire') {
|
|
343
|
+
- console.log(chunk.payload.tripwireReason);
|
|
344
|
+
+ console.log(chunk.payload.reason);
|
|
345
|
+
+ // New fields available:
|
|
346
|
+
+ // chunk.payload.retry
|
|
347
|
+
+ // chunk.payload.metadata
|
|
348
|
+
+ // chunk.payload.processorId
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
The step results now also include tripwire information:
|
|
354
|
+
|
|
355
|
+
```diff
|
|
356
|
+
const result = await agent.generate('Hello');
|
|
357
|
+
|
|
358
|
+
for (const step of result.steps) {
|
|
359
|
+
- // No tripwire info on steps
|
|
360
|
+
+ if (step.tripwire) {
|
|
361
|
+
+ console.log('Step was blocked:', step.tripwire.reason);
|
|
362
|
+
+ }
|
|
363
|
+
}
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
### `prepareStep` messages format
|
|
367
|
+
|
|
368
|
+
The `prepareStep` callback now receives messages in `MastraDBMessage` format instead of AI SDK v5 model message format. This change unifies `prepareStep` with the new `processInputStep` processor method, which runs at each step of the agentic loop.
|
|
369
|
+
|
|
370
|
+
If you need the old AI SDK v5 format, use `messageList.get.all.aiV5.model()`:
|
|
371
|
+
|
|
372
|
+
```diff
|
|
373
|
+
agent.generate({
|
|
374
|
+
prompt: 'Hello',
|
|
375
|
+
prepareStep: async ({ messages, messageList }) => {
|
|
376
|
+
- // messages was AI SDK v5 ModelMessage format
|
|
377
|
+
- console.log(messages[0].content);
|
|
378
|
+
+ // messages is now MastraDBMessage format
|
|
379
|
+
+ // Use messageList to get AI SDK v5 format if needed:
|
|
380
|
+
+ const aiSdkMessages = messageList.get.all.aiV5.model();
|
|
381
|
+
|
|
382
|
+
return { toolChoice: 'auto' };
|
|
383
|
+
},
|
|
384
|
+
});
|
|
385
|
+
```
|
|
@@ -155,6 +155,23 @@ To migrate, use workflow streaming APIs instead of watch.
|
|
|
155
155
|
+ }
|
|
156
156
|
```
|
|
157
157
|
|
|
158
|
+
### Run-related methods cannot be called directly on workflow instance
|
|
159
|
+
|
|
160
|
+
Run-related methods cannot be called directly on workflow instance. You need to create a run instance first using `createRun()` method.
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
```diff
|
|
164
|
+
- const result = await workflow.start({ runId: '123', inputData: { ... } });
|
|
165
|
+
+ const run = await workflow.createRun({ runId: '123' });
|
|
166
|
+
+ const result = await run.start({ inputData: { ... } });
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
```diff
|
|
170
|
+
- const result = await workflow.stream({ runId: '123', inputData: { ... } });
|
|
171
|
+
+ const run = await workflow.createRun({ runId: '123' });
|
|
172
|
+
+ const stream = await run.stream({ inputData: { ... } });
|
|
173
|
+
```
|
|
174
|
+
|
|
158
175
|
### Deprecated stream endpoints
|
|
159
176
|
|
|
160
177
|
Some stream endpoints are deprecated and will be removed. The `/api/agents/:agentId/stream/vnext` endpoint returns 410 Gone, and `/api/agents/:agentId/stream/ui` is deprecated. This change consolidates on standard streaming endpoints.
|