@mastra/mcp-docs-server 1.0.0-beta.7 → 1.0.0-beta.9

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.
Files changed (63) hide show
  1. package/.docs/organized/changelogs/%40internal%2Fchangeset-cli.md +1 -15
  2. package/.docs/organized/changelogs/%40internal%2Fexternal-types.md +1 -7
  3. package/.docs/organized/changelogs/%40internal%2Ftypes-builder.md +1 -55
  4. package/.docs/organized/changelogs/%40mastra%2Fagent-builder.md +12 -12
  5. package/.docs/organized/changelogs/%40mastra%2Fai-sdk.md +48 -48
  6. package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +17 -17
  7. package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +17 -17
  8. package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +18 -18
  9. package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +17 -17
  10. package/.docs/organized/changelogs/%40mastra%2Fcodemod.md +6 -0
  11. package/.docs/organized/changelogs/%40mastra%2Fconvex.md +16 -0
  12. package/.docs/organized/changelogs/%40mastra%2Fcore.md +78 -78
  13. package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +18 -18
  14. package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +23 -23
  15. package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +17 -17
  16. package/.docs/organized/changelogs/%40mastra%2Flance.md +17 -17
  17. package/.docs/organized/changelogs/%40mastra%2Flibsql.md +65 -65
  18. package/.docs/organized/changelogs/%40mastra%2Floggers.md +29 -29
  19. package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +16 -16
  20. package/.docs/organized/changelogs/%40mastra%2Fmcp.md +12 -12
  21. package/.docs/organized/changelogs/%40mastra%2Fmemory.md +10 -10
  22. package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +17 -17
  23. package/.docs/organized/changelogs/%40mastra%2Fmssql.md +17 -17
  24. package/.docs/organized/changelogs/%40mastra%2Fpg.md +69 -69
  25. package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +31 -31
  26. package/.docs/organized/changelogs/%40mastra%2Freact.md +14 -0
  27. package/.docs/organized/changelogs/%40mastra%2Fserver.md +56 -56
  28. package/.docs/organized/changelogs/%40mastra%2Fupstash.md +17 -17
  29. package/.docs/organized/changelogs/create-mastra.md +13 -13
  30. package/.docs/organized/changelogs/mastra.md +21 -21
  31. package/.docs/organized/code-examples/mcp-server-adapters.md +1 -2
  32. package/.docs/organized/code-examples/processors-with-ai-sdk.md +14 -0
  33. package/.docs/organized/code-examples/server-app-access.md +1 -1
  34. package/.docs/organized/code-examples/server-hono-adapter.md +1 -1
  35. package/.docs/raw/getting-started/studio.mdx +4 -2
  36. package/.docs/raw/guides/agent-frameworks/ai-sdk.mdx +161 -0
  37. package/.docs/raw/guides/build-your-ui/ai-sdk-ui.mdx +381 -431
  38. package/.docs/raw/guides/getting-started/quickstart.mdx +11 -0
  39. package/.docs/raw/guides/migrations/upgrade-to-v1/tools.mdx +3 -3
  40. package/.docs/raw/guides/migrations/upgrade-to-v1/workflows.mdx +31 -0
  41. package/.docs/raw/reference/ai-sdk/chat-route.mdx +127 -0
  42. package/.docs/raw/reference/ai-sdk/handle-chat-stream.mdx +117 -0
  43. package/.docs/raw/reference/ai-sdk/handle-network-stream.mdx +64 -0
  44. package/.docs/raw/reference/ai-sdk/handle-workflow-stream.mdx +116 -0
  45. package/.docs/raw/reference/ai-sdk/network-route.mdx +99 -0
  46. package/.docs/raw/reference/ai-sdk/to-ai-sdk-stream.mdx +289 -0
  47. package/.docs/raw/reference/ai-sdk/workflow-route.mdx +110 -0
  48. package/.docs/raw/reference/client-js/agents.mdx +251 -67
  49. package/.docs/raw/reference/client-js/mastra-client.mdx +2 -2
  50. package/.docs/raw/reference/client-js/memory.mdx +4 -1
  51. package/.docs/raw/reference/core/getMemory.mdx +73 -0
  52. package/.docs/raw/reference/core/getStoredAgentById.mdx +183 -0
  53. package/.docs/raw/reference/core/listMemory.mdx +70 -0
  54. package/.docs/raw/reference/core/listStoredAgents.mdx +151 -0
  55. package/.docs/raw/reference/core/mastra-class.mdx +8 -0
  56. package/.docs/raw/reference/server/express-adapter.mdx +52 -0
  57. package/.docs/raw/reference/server/hono-adapter.mdx +54 -0
  58. package/.docs/raw/server-db/custom-api-routes.mdx +5 -5
  59. package/.docs/raw/server-db/server-adapters.mdx +94 -91
  60. package/.docs/raw/streaming/tool-streaming.mdx +10 -14
  61. package/.docs/raw/workflows/workflow-state.mdx +4 -5
  62. package/CHANGELOG.md +15 -0
  63. package/package.json +4 -4
@@ -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
+ ```