@mastra/mcp-docs-server 1.0.0-beta.7 → 1.0.0-beta.8
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 +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +17 -17
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +18 -18
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +17 -17
- package/.docs/organized/changelogs/%40mastra%2Fconvex.md +16 -0
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +21 -21
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +13 -13
- package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +17 -17
- package/.docs/organized/changelogs/%40mastra%2Flance.md +17 -17
- package/.docs/organized/changelogs/%40mastra%2Flibsql.md +17 -17
- package/.docs/organized/changelogs/%40mastra%2Floggers.md +29 -29
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +17 -17
- package/.docs/organized/changelogs/%40mastra%2Fmssql.md +17 -17
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +21 -21
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Freact.md +7 -0
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +17 -17
- package/.docs/raw/guides/build-your-ui/ai-sdk-ui.mdx +381 -431
- package/.docs/raw/guides/getting-started/quickstart.mdx +11 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/workflows.mdx +31 -0
- package/.docs/raw/reference/ai-sdk/chat-route.mdx +127 -0
- package/.docs/raw/reference/ai-sdk/handle-chat-stream.mdx +117 -0
- package/.docs/raw/reference/ai-sdk/handle-network-stream.mdx +64 -0
- package/.docs/raw/reference/ai-sdk/handle-workflow-stream.mdx +116 -0
- package/.docs/raw/reference/ai-sdk/network-route.mdx +99 -0
- package/.docs/raw/reference/ai-sdk/to-ai-sdk-stream.mdx +289 -0
- package/.docs/raw/reference/ai-sdk/workflow-route.mdx +110 -0
- package/.docs/raw/server-db/custom-api-routes.mdx +5 -5
- package/.docs/raw/workflows/workflow-state.mdx +4 -5
- package/CHANGELOG.md +7 -0
- package/package.json +3 -3
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: toAISdkStream() | AI SDK"
|
|
3
|
+
description: API reference for toAISdkStream(), a function to convert Mastra streams to AI SDK-compatible streams.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
import PropertiesTable from "@site/src/components/PropertiesTable";
|
|
7
|
+
|
|
8
|
+
# toAISdkStream()
|
|
9
|
+
|
|
10
|
+
Converts Mastra streams (agent, network, or workflow) to AI SDK-compatible streams. Use this function when you need to manually transform Mastra streams for use with AI SDK's `createUIMessageStream()` and `createUIMessageStreamResponse()`.
|
|
11
|
+
|
|
12
|
+
This is useful when building custom streaming endpoints outside Mastra's provided route helpers such as [`chatRoute()`](/reference/v1/ai-sdk/chat-route) or [`workflowRoute()`](/reference/v1/ai-sdk/workflow-route).
|
|
13
|
+
|
|
14
|
+
## Usage example
|
|
15
|
+
|
|
16
|
+
Next.js App Router example:
|
|
17
|
+
|
|
18
|
+
```typescript title="app/api/chat/route.ts" copy
|
|
19
|
+
import { mastra } from "../../mastra";
|
|
20
|
+
import { createUIMessageStream, createUIMessageStreamResponse } from "ai";
|
|
21
|
+
import { toAISdkStream } from "@mastra/ai-sdk";
|
|
22
|
+
|
|
23
|
+
export async function POST(req: Request) {
|
|
24
|
+
const { messages } = await req.json();
|
|
25
|
+
const myAgent = mastra.getAgent("weatherAgent");
|
|
26
|
+
const stream = await myAgent.stream(messages);
|
|
27
|
+
|
|
28
|
+
const uiMessageStream = createUIMessageStream({
|
|
29
|
+
originalMessages: messages,
|
|
30
|
+
execute: async ({ writer }) => {
|
|
31
|
+
for await (const part of toAISdkStream(stream, { from: "agent" })) {
|
|
32
|
+
await writer.write(part);
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
return createUIMessageStreamResponse({
|
|
38
|
+
stream: uiMessageStream,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
:::tip
|
|
44
|
+
|
|
45
|
+
Pass `messages` to `originalMessages` in `createUIMessageStream()` to avoid duplicated assistant messages in the UI. See [Troubleshooting: Repeated Assistant Messages](https://ai-sdk.dev/docs/troubleshooting/repeated-assistant-messages) for details.
|
|
46
|
+
|
|
47
|
+
:::
|
|
48
|
+
|
|
49
|
+
## Parameters
|
|
50
|
+
|
|
51
|
+
The first parameter is the Mastra stream to convert. It can be one of:
|
|
52
|
+
- `MastraModelOutput` - An agent stream from `agent.stream()`
|
|
53
|
+
- `MastraAgentNetworkStream` - A network stream from `agent.network()`
|
|
54
|
+
- `MastraWorkflowStream` or `WorkflowRunOutput` - A workflow stream
|
|
55
|
+
|
|
56
|
+
The second parameter is an options object:
|
|
57
|
+
|
|
58
|
+
<PropertiesTable
|
|
59
|
+
content={[
|
|
60
|
+
{
|
|
61
|
+
name: "from",
|
|
62
|
+
type: "'agent' | 'network' | 'workflow'",
|
|
63
|
+
description: "The type of Mastra stream being converted.",
|
|
64
|
+
isOptional: false,
|
|
65
|
+
defaultValue: "'agent'",
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
name: "lastMessageId",
|
|
69
|
+
type: "string",
|
|
70
|
+
description: "(Agent only) The ID of the last message in the conversation.",
|
|
71
|
+
isOptional: true,
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
name: "sendStart",
|
|
75
|
+
type: "boolean",
|
|
76
|
+
description: "(Agent only) Whether to send start events in the stream.",
|
|
77
|
+
isOptional: true,
|
|
78
|
+
defaultValue: "true",
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
name: "sendFinish",
|
|
82
|
+
type: "boolean",
|
|
83
|
+
description: "(Agent only) Whether to send finish events in the stream.",
|
|
84
|
+
isOptional: true,
|
|
85
|
+
defaultValue: "true",
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
name: "sendReasoning",
|
|
89
|
+
type: "boolean",
|
|
90
|
+
description: "(Agent only) Whether to include reasoning-delta chunks in the stream. Set to true to stream reasoning content from models that support extended thinking.",
|
|
91
|
+
isOptional: true,
|
|
92
|
+
defaultValue: "false",
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
name: "sendSources",
|
|
96
|
+
type: "boolean",
|
|
97
|
+
description: "(Agent only) Whether to include source citations in the output.",
|
|
98
|
+
isOptional: true,
|
|
99
|
+
defaultValue: "false",
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
name: "includeTextStreamParts",
|
|
103
|
+
type: "boolean",
|
|
104
|
+
description: "(Workflow only) Whether to include text stream parts in the output.",
|
|
105
|
+
isOptional: true,
|
|
106
|
+
defaultValue: "true",
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
name: "messageMetadata",
|
|
110
|
+
type: "(options: { part: UIMessageStreamPart }) => Record<string, unknown> | undefined",
|
|
111
|
+
description: "(Agent only) A function that receives the current stream part and returns metadata to attach to start and finish chunks.",
|
|
112
|
+
isOptional: true,
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
name: "onError",
|
|
116
|
+
type: "(error: unknown) => string",
|
|
117
|
+
description: "(Agent only) A function to handle errors during stream conversion. Receives the error and should return a string representation.",
|
|
118
|
+
isOptional: true,
|
|
119
|
+
},
|
|
120
|
+
]}
|
|
121
|
+
/>
|
|
122
|
+
|
|
123
|
+
## Examples
|
|
124
|
+
|
|
125
|
+
### Converting a workflow stream
|
|
126
|
+
|
|
127
|
+
```typescript title="app/api/workflow/route.ts" copy {13}
|
|
128
|
+
import { mastra } from "../../mastra";
|
|
129
|
+
import { createUIMessageStream, createUIMessageStreamResponse } from "ai";
|
|
130
|
+
import { toAISdkStream } from "@mastra/ai-sdk";
|
|
131
|
+
|
|
132
|
+
export async function POST(req: Request) {
|
|
133
|
+
const { input } = await req.json();
|
|
134
|
+
const workflow = mastra.getWorkflow("myWorkflow");
|
|
135
|
+
const run = workflow.createRun();
|
|
136
|
+
const stream = await run.stream({ inputData: input });
|
|
137
|
+
|
|
138
|
+
const uiMessageStream = createUIMessageStream({
|
|
139
|
+
execute: async ({ writer }) => {
|
|
140
|
+
for await (const part of toAISdkStream(stream, { from: "workflow" })) {
|
|
141
|
+
await writer.write(part);
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
return createUIMessageStreamResponse({
|
|
147
|
+
stream: uiMessageStream,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### Converting a network stream
|
|
153
|
+
|
|
154
|
+
```typescript title="app/api/network/route.ts" copy {12}
|
|
155
|
+
import { mastra } from "../../mastra";
|
|
156
|
+
import { createUIMessageStream, createUIMessageStreamResponse } from "ai";
|
|
157
|
+
import { toAISdkStream } from "@mastra/ai-sdk";
|
|
158
|
+
|
|
159
|
+
export async function POST(req: Request) {
|
|
160
|
+
const { messages } = await req.json();
|
|
161
|
+
const routingAgent = mastra.getAgent("routingAgent");
|
|
162
|
+
const stream = await routingAgent.network(messages);
|
|
163
|
+
|
|
164
|
+
const uiMessageStream = createUIMessageStream({
|
|
165
|
+
execute: async ({ writer }) => {
|
|
166
|
+
for await (const part of toAISdkStream(stream, { from: "network" })) {
|
|
167
|
+
await writer.write(part);
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
return createUIMessageStreamResponse({
|
|
173
|
+
stream: uiMessageStream,
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Converting an agent stream with reasoning enabled
|
|
179
|
+
|
|
180
|
+
```typescript title="app/api/reasoning/route.ts" copy {8-12,17-20}
|
|
181
|
+
import { mastra } from "../../mastra";
|
|
182
|
+
import { createUIMessageStream, createUIMessageStreamResponse } from "ai";
|
|
183
|
+
import { toAISdkStream } from "@mastra/ai-sdk";
|
|
184
|
+
|
|
185
|
+
export async function POST(req: Request) {
|
|
186
|
+
const { messages } = await req.json();
|
|
187
|
+
const reasoningAgent = mastra.getAgent("reasoningAgent");
|
|
188
|
+
const stream = await reasoningAgent.stream(messages, {
|
|
189
|
+
providerOptions: {
|
|
190
|
+
openai: { reasoningEffort: "high" },
|
|
191
|
+
},
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
const uiMessageStream = createUIMessageStream({
|
|
195
|
+
originalMessages: messages,
|
|
196
|
+
execute: async ({ writer }) => {
|
|
197
|
+
for await (const part of toAISdkStream(stream, {
|
|
198
|
+
from: "agent",
|
|
199
|
+
sendReasoning: true,
|
|
200
|
+
})) {
|
|
201
|
+
await writer.write(part);
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
return createUIMessageStreamResponse({
|
|
207
|
+
stream: uiMessageStream,
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
### Using messageMetadata
|
|
213
|
+
|
|
214
|
+
```typescript title="app/api/chat-with-metadata/route.ts" copy {13-19}
|
|
215
|
+
import { mastra } from "../../mastra";
|
|
216
|
+
import { createUIMessageStream, createUIMessageStreamResponse } from "ai";
|
|
217
|
+
import { toAISdkStream } from "@mastra/ai-sdk";
|
|
218
|
+
|
|
219
|
+
export async function POST(req: Request) {
|
|
220
|
+
const { messages } = await req.json();
|
|
221
|
+
const myAgent = mastra.getAgent("weatherAgent");
|
|
222
|
+
const stream = await myAgent.stream(messages);
|
|
223
|
+
|
|
224
|
+
const uiMessageStream = createUIMessageStream({
|
|
225
|
+
originalMessages: messages,
|
|
226
|
+
execute: async ({ writer }) => {
|
|
227
|
+
for await (const part of toAISdkStream(stream, {
|
|
228
|
+
from: "agent",
|
|
229
|
+
messageMetadata: ({ part }) => ({
|
|
230
|
+
timestamp: Date.now(),
|
|
231
|
+
partType: part.type,
|
|
232
|
+
}),
|
|
233
|
+
})) {
|
|
234
|
+
await writer.write(part);
|
|
235
|
+
}
|
|
236
|
+
},
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
return createUIMessageStreamResponse({
|
|
240
|
+
stream: uiMessageStream,
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
### Client-side stream transformation
|
|
246
|
+
|
|
247
|
+
If you're using the Mastra client SDK (`@mastra/client-js`) on the client side and want to convert streams to AI SDK format:
|
|
248
|
+
|
|
249
|
+
```typescript title="client-stream-to-ai-sdk.ts" copy {14-23,25-35}
|
|
250
|
+
import { MastraClient } from "@mastra/client-js";
|
|
251
|
+
import { createUIMessageStream } from "ai";
|
|
252
|
+
import { toAISdkStream } from "@mastra/ai-sdk";
|
|
253
|
+
import type { ChunkType, MastraModelOutput } from "@mastra/core/stream";
|
|
254
|
+
|
|
255
|
+
const client = new MastraClient({
|
|
256
|
+
baseUrl: "http://localhost:4111",
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
const agent = client.getAgent("weatherAgent");
|
|
260
|
+
const response = await agent.stream("What is the weather in Tokyo?");
|
|
261
|
+
|
|
262
|
+
// Convert the client SDK stream to a ReadableStream<ChunkType>
|
|
263
|
+
const chunkStream = new ReadableStream<ChunkType>({
|
|
264
|
+
async start(controller) {
|
|
265
|
+
await response.processDataStream({
|
|
266
|
+
onChunk: async (chunk) => {
|
|
267
|
+
controller.enqueue(chunk);
|
|
268
|
+
},
|
|
269
|
+
});
|
|
270
|
+
controller.close();
|
|
271
|
+
},
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
// Transform to AI SDK format
|
|
275
|
+
const uiMessageStream = createUIMessageStream({
|
|
276
|
+
execute: async ({ writer }) => {
|
|
277
|
+
for await (const part of toAISdkStream(
|
|
278
|
+
chunkStream as unknown as MastraModelOutput,
|
|
279
|
+
{ from: "agent" }
|
|
280
|
+
)) {
|
|
281
|
+
await writer.write(part);
|
|
282
|
+
}
|
|
283
|
+
},
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
for await (const part of uiMessageStream) {
|
|
287
|
+
console.log(part);
|
|
288
|
+
}
|
|
289
|
+
```
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: workflowRoute() | AI SDK"
|
|
3
|
+
description: API reference for workflowRoute(), a function to create workflow route handlers for streaming workflow execution in AI SDK-compatible format.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
import PropertiesTable from "@site/src/components/PropertiesTable";
|
|
7
|
+
|
|
8
|
+
# workflowRoute()
|
|
9
|
+
|
|
10
|
+
Creates a workflow route handler for streaming workflow execution using the AI SDK format. This function registers an HTTP `POST` endpoint that accepts input data, executes a workflow, and streams the response back to the client in AI SDK-compatible format. You have to use it inside a [custom API route](/docs/v1/server-db/custom-api-routes).
|
|
11
|
+
|
|
12
|
+
Use [`handleWorkflowStream()`](/reference/v1/ai-sdk/handle-workflow-stream) if you need a framework-agnostic handler.
|
|
13
|
+
|
|
14
|
+
:::tip Agent streaming in workflows
|
|
15
|
+
|
|
16
|
+
When a workflow step pipes an agent's stream to the workflow writer (e.g., `await response.fullStream.pipeTo(writer)`), the agent's text chunks and tool calls are forwarded to the UI stream in real time, even when the agent runs inside workflow steps.
|
|
17
|
+
|
|
18
|
+
See [Workflow Streaming](/docs/v1/streaming/workflow-streaming#streaming-agent-text-chunks-to-ui) for more details.
|
|
19
|
+
|
|
20
|
+
:::
|
|
21
|
+
|
|
22
|
+
## Usage example
|
|
23
|
+
|
|
24
|
+
This example shows how to set up a workflow route at the `/workflow` endpoint that uses a workflow with the ID `weatherWorkflow`.
|
|
25
|
+
|
|
26
|
+
```typescript title="src/mastra/index.ts" copy
|
|
27
|
+
import { Mastra } from "@mastra/core";
|
|
28
|
+
import { workflowRoute } from "@mastra/ai-sdk";
|
|
29
|
+
|
|
30
|
+
export const mastra = new Mastra({
|
|
31
|
+
server: {
|
|
32
|
+
apiRoutes: [
|
|
33
|
+
workflowRoute({
|
|
34
|
+
path: "/workflow",
|
|
35
|
+
workflow: "weatherWorkflow",
|
|
36
|
+
}),
|
|
37
|
+
],
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
You can also use dynamic workflow routing based on a `workflowId`. The URL `/workflow/weatherWorkflow` will resolve to the workflow with the ID `weatherWorkflow`.
|
|
43
|
+
|
|
44
|
+
```typescript title="src/mastra/index.ts" copy
|
|
45
|
+
import { Mastra } from "@mastra/core";
|
|
46
|
+
import { workflowRoute } from "@mastra/ai-sdk";
|
|
47
|
+
|
|
48
|
+
export const mastra = new Mastra({
|
|
49
|
+
server: {
|
|
50
|
+
apiRoutes: [
|
|
51
|
+
workflowRoute({
|
|
52
|
+
path: "/workflow/:workflowId",
|
|
53
|
+
}),
|
|
54
|
+
],
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Parameters
|
|
60
|
+
|
|
61
|
+
<PropertiesTable
|
|
62
|
+
content={[
|
|
63
|
+
{
|
|
64
|
+
name: "path",
|
|
65
|
+
type: "string",
|
|
66
|
+
description: "The route path (e.g., `/workflow` or `/workflow/:workflowId`). Include `:workflowId` for dynamic workflow routing.",
|
|
67
|
+
isOptional: true,
|
|
68
|
+
defaultValue: "'/api/workflows/:workflowId/stream'",
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
name: "workflow",
|
|
72
|
+
type: "string",
|
|
73
|
+
description: "Fixed workflow ID when not using dynamic routing.",
|
|
74
|
+
isOptional: true,
|
|
75
|
+
defaultValue: "undefined",
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
name: "includeTextStreamParts",
|
|
79
|
+
type: "boolean",
|
|
80
|
+
description: "Whether to include text stream parts in the output.",
|
|
81
|
+
isOptional: true,
|
|
82
|
+
defaultValue: "true",
|
|
83
|
+
},
|
|
84
|
+
]}
|
|
85
|
+
/>
|
|
86
|
+
|
|
87
|
+
## Additional configuration
|
|
88
|
+
|
|
89
|
+
You can use [`prepareSendMessagesRequest`](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat#transport.default-chat-transport.prepare-send-messages-request) to customize the request sent to the workflow route, for example to pass additional configuration to the workflow:
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
const { error, status, sendMessage, messages, regenerate, stop } = useChat({
|
|
93
|
+
transport: new DefaultChatTransport({
|
|
94
|
+
api: "http://localhost:4111/workflow",
|
|
95
|
+
prepareSendMessagesRequest({ messages }) {
|
|
96
|
+
return {
|
|
97
|
+
body: {
|
|
98
|
+
inputData: {
|
|
99
|
+
city: messages[messages.length - 1].parts[0].text,
|
|
100
|
+
},
|
|
101
|
+
// Or resumeData for resuming a suspended workflow
|
|
102
|
+
resumeData: {
|
|
103
|
+
confirmation: messages[messages.length - 1].parts[0].text
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
},
|
|
108
|
+
}),
|
|
109
|
+
});
|
|
110
|
+
```
|
|
@@ -5,11 +5,11 @@ description: "Expose additional HTTP endpoints from your Mastra server."
|
|
|
5
5
|
|
|
6
6
|
# Custom API Routes
|
|
7
7
|
|
|
8
|
-
By default Mastra automatically exposes registered agents and workflows via
|
|
8
|
+
By default, Mastra automatically exposes registered agents and workflows via its server. For additional behavior you can define your own HTTP routes.
|
|
9
9
|
|
|
10
|
-
Routes are provided with a helper `registerApiRoute` from `@mastra/core/server`. Routes can live in the same file as the `Mastra` instance but separating them helps keep configuration concise.
|
|
10
|
+
Routes are provided with a helper `registerApiRoute()` from `@mastra/core/server`. Routes can live in the same file as the `Mastra` instance but separating them helps keep configuration concise.
|
|
11
11
|
|
|
12
|
-
```typescript title="src/mastra/index.ts" copy
|
|
12
|
+
```typescript title="src/mastra/index.ts" copy
|
|
13
13
|
import { Mastra } from "@mastra/core";
|
|
14
14
|
import { registerApiRoute } from "@mastra/core/server";
|
|
15
15
|
|
|
@@ -39,9 +39,9 @@ curl http://localhost:4111/my-custom-route
|
|
|
39
39
|
|
|
40
40
|
Each route's handler receives the Hono `Context`. Within the handler you can access the `Mastra` instance to fetch or call agents and workflows.
|
|
41
41
|
|
|
42
|
-
To add route-specific middleware pass a `middleware` array when calling `registerApiRoute`.
|
|
42
|
+
To add route-specific middleware pass a `middleware` array when calling `registerApiRoute()`.
|
|
43
43
|
|
|
44
|
-
```typescript title="src/mastra/index.ts" copy
|
|
44
|
+
```typescript title="src/mastra/index.ts" copy
|
|
45
45
|
import { Mastra } from "@mastra/core";
|
|
46
46
|
import { registerApiRoute } from "@mastra/core/server";
|
|
47
47
|
|
|
@@ -28,7 +28,7 @@ const step1 = createStep({
|
|
|
28
28
|
console.log(state.sharedCounter);
|
|
29
29
|
|
|
30
30
|
// Update state for subsequent steps
|
|
31
|
-
setState({
|
|
31
|
+
await setState({ sharedCounter: state.sharedCounter + 1 });
|
|
32
32
|
|
|
33
33
|
// Return output that flows to next step's inputData
|
|
34
34
|
return { step1Output: "processed" };
|
|
@@ -50,8 +50,7 @@ const step1 = createStep({
|
|
|
50
50
|
const { message } = inputData;
|
|
51
51
|
const { processedItems } = state;
|
|
52
52
|
|
|
53
|
-
setState({
|
|
54
|
-
...state,
|
|
53
|
+
await setState({
|
|
55
54
|
processedItems: [...processedItems, "item-1", "item-2"],
|
|
56
55
|
});
|
|
57
56
|
|
|
@@ -124,7 +123,7 @@ const step1 = createStep({
|
|
|
124
123
|
execute: async ({ state, setState, suspend, resumeData }) => {
|
|
125
124
|
if (!resumeData) {
|
|
126
125
|
// First run: update state and suspend
|
|
127
|
-
setState({
|
|
126
|
+
await setState({ count: state.count + 1, items: [...state.items, "item-1"] });
|
|
128
127
|
await suspend({});
|
|
129
128
|
return {};
|
|
130
129
|
}
|
|
@@ -166,7 +165,7 @@ const parentStep = createStep({
|
|
|
166
165
|
stateSchema: z.object({ sharedValue: z.string() }),
|
|
167
166
|
execute: async ({ state, setState }) => {
|
|
168
167
|
// Modify state before nested workflow runs
|
|
169
|
-
setState({
|
|
168
|
+
await setState({ sharedValue: "modified-by-parent" });
|
|
170
169
|
return {};
|
|
171
170
|
},
|
|
172
171
|
});
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @mastra/mcp-docs-server
|
|
2
2
|
|
|
3
|
+
## 1.0.0-beta.8
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`0d41fe2`](https://github.com/mastra-ai/mastra/commit/0d41fe245355dfc66d61a0d9c85d9400aac351ff), [`6b3ba91`](https://github.com/mastra-ai/mastra/commit/6b3ba91494cc10394df96782f349a4f7b1e152cc), [`7907fd1`](https://github.com/mastra-ai/mastra/commit/7907fd1c5059813b7b870b81ca71041dc807331b)]:
|
|
8
|
+
- @mastra/core@1.0.0-beta.8
|
|
9
|
+
|
|
3
10
|
## 1.0.0-beta.7
|
|
4
11
|
|
|
5
12
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/mcp-docs-server",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.8",
|
|
4
4
|
"description": "MCP server for accessing Mastra.ai documentation, changelogs, and news.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"@modelcontextprotocol/sdk": "^1.17.5",
|
|
29
29
|
"jsdom": "^26.1.0",
|
|
30
30
|
"zod": "^3.25.76",
|
|
31
|
-
"@mastra/core": "1.0.0-beta.
|
|
31
|
+
"@mastra/core": "1.0.0-beta.8",
|
|
32
32
|
"@mastra/mcp": "^1.0.0-beta.5"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"typescript": "^5.8.3",
|
|
47
47
|
"vitest": "4.0.12",
|
|
48
48
|
"@internal/lint": "0.0.53",
|
|
49
|
-
"@mastra/core": "1.0.0-beta.
|
|
49
|
+
"@mastra/core": "1.0.0-beta.8"
|
|
50
50
|
},
|
|
51
51
|
"homepage": "https://mastra.ai",
|
|
52
52
|
"repository": {
|