@mastra/mcp-docs-server 1.0.0-beta.6 → 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.
Files changed (88) hide show
  1. package/.docs/organized/changelogs/%40mastra%2Fagent-builder.md +12 -12
  2. package/.docs/organized/changelogs/%40mastra%2Fai-sdk.md +10 -10
  3. package/.docs/organized/changelogs/%40mastra%2Fastra.md +10 -10
  4. package/.docs/organized/changelogs/%40mastra%2Fchroma.md +12 -12
  5. package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +48 -48
  6. package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +65 -65
  7. package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +48 -48
  8. package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +48 -48
  9. package/.docs/organized/changelogs/%40mastra%2Fcodemod.md +6 -0
  10. package/.docs/organized/changelogs/%40mastra%2Fconvex.md +47 -0
  11. package/.docs/organized/changelogs/%40mastra%2Fcore.md +196 -196
  12. package/.docs/organized/changelogs/%40mastra%2Fcouchbase.md +11 -11
  13. package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +19 -19
  14. package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +27 -27
  15. package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +48 -48
  16. package/.docs/organized/changelogs/%40mastra%2Felasticsearch.md +9 -0
  17. package/.docs/organized/changelogs/%40mastra%2Flance.md +48 -48
  18. package/.docs/organized/changelogs/%40mastra%2Flibsql.md +48 -48
  19. package/.docs/organized/changelogs/%40mastra%2Floggers.md +40 -40
  20. package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +16 -16
  21. package/.docs/organized/changelogs/%40mastra%2Fmcp.md +43 -43
  22. package/.docs/organized/changelogs/%40mastra%2Fmemory.md +10 -10
  23. package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +48 -48
  24. package/.docs/organized/changelogs/%40mastra%2Fmssql.md +48 -48
  25. package/.docs/organized/changelogs/%40mastra%2Fopensearch.md +10 -10
  26. package/.docs/organized/changelogs/%40mastra%2Fpg.md +52 -52
  27. package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +10 -10
  28. package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +41 -41
  29. package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +10 -10
  30. package/.docs/organized/changelogs/%40mastra%2Freact.md +14 -0
  31. package/.docs/organized/changelogs/%40mastra%2Fs3vectors.md +9 -0
  32. package/.docs/organized/changelogs/%40mastra%2Fserver.md +65 -65
  33. package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +10 -10
  34. package/.docs/organized/changelogs/%40mastra%2Fupstash.md +48 -48
  35. package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +10 -10
  36. package/.docs/organized/changelogs/create-mastra.md +7 -7
  37. package/.docs/organized/changelogs/mastra.md +14 -14
  38. package/.docs/organized/code-examples/ai-elements.md +1 -1
  39. package/.docs/organized/code-examples/ai-sdk-useChat.md +1 -1
  40. package/.docs/organized/code-examples/ai-sdk-v5.md +1 -1
  41. package/.docs/organized/code-examples/assistant-ui.md +1 -1
  42. package/.docs/organized/code-examples/bird-checker-with-nextjs-and-eval.md +1 -1
  43. package/.docs/organized/code-examples/bird-checker-with-nextjs.md +1 -1
  44. package/.docs/organized/code-examples/crypto-chatbot.md +1 -1
  45. package/.docs/organized/code-examples/mcp-server-adapters.md +2 -2
  46. package/.docs/organized/code-examples/server-app-access.md +2 -2
  47. package/.docs/organized/code-examples/server-express-adapter.md +87 -0
  48. package/.docs/organized/code-examples/server-hono-adapter.md +85 -0
  49. package/.docs/raw/agents/overview.mdx +2 -111
  50. package/.docs/raw/agents/processors.mdx +1 -1
  51. package/.docs/raw/agents/structured-output.mdx +224 -0
  52. package/.docs/raw/guides/build-your-ui/ai-sdk-ui.mdx +381 -431
  53. package/.docs/raw/guides/getting-started/quickstart.mdx +11 -0
  54. package/.docs/raw/guides/migrations/upgrade-to-v1/workflows.mdx +40 -1
  55. package/.docs/raw/memory/working-memory.mdx +1 -0
  56. package/.docs/raw/observability/tracing/bridges/otel.mdx +25 -1
  57. package/.docs/raw/observability/tracing/exporters/arize.mdx +19 -0
  58. package/.docs/raw/observability/tracing/exporters/langfuse.mdx +63 -0
  59. package/.docs/raw/observability/tracing/exporters/otel.mdx +30 -19
  60. package/.docs/raw/observability/tracing/exporters/posthog.mdx +20 -0
  61. package/.docs/raw/observability/tracing/overview.mdx +6 -1
  62. package/.docs/raw/reference/ai-sdk/chat-route.mdx +127 -0
  63. package/.docs/raw/reference/ai-sdk/handle-chat-stream.mdx +117 -0
  64. package/.docs/raw/reference/ai-sdk/handle-network-stream.mdx +64 -0
  65. package/.docs/raw/reference/ai-sdk/handle-workflow-stream.mdx +116 -0
  66. package/.docs/raw/reference/ai-sdk/network-route.mdx +99 -0
  67. package/.docs/raw/reference/ai-sdk/to-ai-sdk-stream.mdx +289 -0
  68. package/.docs/raw/reference/ai-sdk/workflow-route.mdx +110 -0
  69. package/.docs/raw/reference/observability/tracing/bridges/otel.mdx +27 -0
  70. package/.docs/raw/reference/observability/tracing/exporters/arize.mdx +25 -0
  71. package/.docs/raw/reference/observability/tracing/exporters/langfuse.mdx +43 -0
  72. package/.docs/raw/reference/observability/tracing/exporters/otel.mdx +27 -43
  73. package/.docs/raw/reference/server/create-route.mdx +314 -0
  74. package/.docs/raw/reference/server/express-adapter.mdx +193 -0
  75. package/.docs/raw/reference/server/hono-adapter.mdx +174 -0
  76. package/.docs/raw/reference/server/mastra-server.mdx +316 -0
  77. package/.docs/raw/reference/server/routes.mdx +250 -0
  78. package/.docs/raw/reference/streaming/workflows/timeTravelStream.mdx +170 -0
  79. package/.docs/raw/reference/tools/mcp-client.mdx +54 -1
  80. package/.docs/raw/reference/workflows/run-methods/timeTravel.mdx +310 -0
  81. package/.docs/raw/reference/workflows/run.mdx +14 -0
  82. package/.docs/raw/server-db/custom-adapters.mdx +380 -0
  83. package/.docs/raw/server-db/custom-api-routes.mdx +5 -5
  84. package/.docs/raw/server-db/mastra-server.mdx +11 -32
  85. package/.docs/raw/server-db/server-adapters.mdx +286 -0
  86. package/.docs/raw/workflows/workflow-state.mdx +4 -5
  87. package/CHANGELOG.md +15 -0
  88. package/package.json +4 -4
@@ -0,0 +1,116 @@
1
+ ---
2
+ title: "Reference: handleWorkflowStream() | AI SDK"
3
+ description: API reference for handleWorkflowStream(), a framework-agnostic handler for streaming workflow execution in AI SDK-compatible format.
4
+ ---
5
+
6
+ import PropertiesTable from "@site/src/components/PropertiesTable";
7
+
8
+ # handleWorkflowStream()
9
+
10
+ Framework-agnostic handler for streaming workflow execution in AI SDK-compatible format. Use this function directly when you need to handle workflow streaming outside Hono or Mastra's own [apiRoutes](/docs/v1/server-db/custom-api-routes) feature.
11
+
12
+ `handleWorkflowStream()` returns a `ReadableStream` that you can wrap with [`createUIMessageStreamResponse()`](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream-response).
13
+
14
+ Use [`workflowRoute()`](/reference/v1/ai-sdk/workflow-route) if you want to create a workflow route inside a Mastra server.
15
+
16
+ :::tip Agent streaming in workflows
17
+
18
+ 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.
19
+
20
+ See [Workflow Streaming](/docs/v1/streaming/workflow-streaming#streaming-agent-text-chunks-to-ui) for more details.
21
+
22
+ :::
23
+
24
+ ## Usage example
25
+
26
+ Next.js App Router example:
27
+
28
+ ```typescript title="app/api/workflow/route.ts" copy
29
+ import { handleWorkflowStream } from '@mastra/ai-sdk';
30
+ import { createUIMessageStreamResponse } from 'ai';
31
+ import { mastra } from '@/src/mastra';
32
+
33
+ export async function POST(req: Request) {
34
+ const params = await req.json();
35
+ const stream = await handleWorkflowStream({
36
+ mastra,
37
+ workflowId: 'weatherWorkflow',
38
+ params,
39
+ });
40
+ return createUIMessageStreamResponse({ stream });
41
+ }
42
+ ```
43
+
44
+ ## Parameters
45
+
46
+ <PropertiesTable
47
+ content={[
48
+ {
49
+ name: "mastra",
50
+ type: "Mastra",
51
+ description: "The Mastra instance containing registered workflows.",
52
+ isOptional: false,
53
+ },
54
+ {
55
+ name: "workflowId",
56
+ type: "string",
57
+ description: "The ID of the workflow to execute.",
58
+ isOptional: false,
59
+ },
60
+ {
61
+ name: "params",
62
+ type: "WorkflowStreamHandlerParams",
63
+ description: "Parameters for the workflow stream.",
64
+ isOptional: false,
65
+ },
66
+ {
67
+ name: "params.runId",
68
+ type: "string",
69
+ description: "Optional run ID for the workflow execution.",
70
+ isOptional: true,
71
+ },
72
+ {
73
+ name: "params.resourceId",
74
+ type: "string",
75
+ description: "Optional resource ID for the workflow run.",
76
+ isOptional: true,
77
+ },
78
+ {
79
+ name: "params.inputData",
80
+ type: "Record<string, any>",
81
+ description: "Input data for starting a new workflow execution.",
82
+ isOptional: true,
83
+ },
84
+ {
85
+ name: "params.resumeData",
86
+ type: "Record<string, any>",
87
+ description: "Data for resuming a suspended workflow execution.",
88
+ isOptional: true,
89
+ },
90
+ {
91
+ name: "params.requestContext",
92
+ type: "RequestContext",
93
+ description: "Request context to pass to the workflow execution.",
94
+ isOptional: true,
95
+ },
96
+ {
97
+ name: "params.tracingOptions",
98
+ type: "TracingOptions",
99
+ description: "Options for tracing and observability.",
100
+ isOptional: true,
101
+ },
102
+ {
103
+ name: "params.step",
104
+ type: "string",
105
+ description: "Specific step to target in the workflow.",
106
+ isOptional: true,
107
+ },
108
+ {
109
+ name: "includeTextStreamParts",
110
+ type: "boolean",
111
+ description: "Whether to include text stream parts in the output.",
112
+ isOptional: true,
113
+ defaultValue: "true",
114
+ },
115
+ ]}
116
+ />
@@ -0,0 +1,99 @@
1
+ ---
2
+ title: "Reference: networkRoute() | AI SDK"
3
+ description: API reference for networkRoute(), a function to create network route handlers for streaming network execution in AI SDK-compatible format.
4
+ ---
5
+
6
+ import PropertiesTable from "@site/src/components/PropertiesTable";
7
+
8
+ # networkRoute()
9
+
10
+ Creates a network route handler for streaming network execution using the AI SDK format. This function registers an HTTP `POST` endpoint that accepts messages, executes an agent network, and streams the response back to the client in AI SDK-compatible format. Agent networks allow a routing agent to delegate tasks to other agents. You have to use it inside a [custom API route](/docs/v1/server-db/custom-api-routes).
11
+
12
+ Use [`handleNetworkStream()`](/reference/v1/ai-sdk/handle-network-stream) if you need a framework-agnostic handler.
13
+
14
+ ## Usage example
15
+
16
+ This example shows how to set up a network route at the `/network` endpoint that uses an agent with the ID `weatherAgent`.
17
+
18
+ ```typescript title="src/mastra/index.ts" copy
19
+ import { Mastra } from "@mastra/core";
20
+ import { networkRoute } from "@mastra/ai-sdk";
21
+
22
+ export const mastra = new Mastra({
23
+ server: {
24
+ apiRoutes: [
25
+ networkRoute({
26
+ path: "/network",
27
+ agent: "weatherAgent",
28
+ }),
29
+ ],
30
+ },
31
+ });
32
+ ```
33
+
34
+ You can also use dynamic agent routing based on an `agentId`. The URL `/network/weatherAgent` will resolve to the agent with the ID `weatherAgent`.
35
+
36
+ ```typescript title="src/mastra/index.ts" copy
37
+ import { Mastra } from "@mastra/core";
38
+ import { networkRoute } from "@mastra/ai-sdk";
39
+
40
+ export const mastra = new Mastra({
41
+ server: {
42
+ apiRoutes: [
43
+ networkRoute({
44
+ path: "/network/:agentId",
45
+ }),
46
+ ],
47
+ },
48
+ });
49
+ ```
50
+
51
+ ## Parameters
52
+
53
+ <PropertiesTable
54
+ content={[
55
+ {
56
+ name: "path",
57
+ type: "string",
58
+ description: "The route path (e.g., `/network` or `/network/:agentId`). Include `:agentId` for dynamic agent routing.",
59
+ isOptional: false,
60
+ defaultValue: "'/network/:agentId'",
61
+ },
62
+ {
63
+ name: "agent",
64
+ type: "string",
65
+ description: "The ID of the routing agent to use for this network route. Required if the path doesn't include `:agentId`.",
66
+ isOptional: true,
67
+ },
68
+ {
69
+ name: "defaultOptions",
70
+ type: "AgentExecutionOptions",
71
+ description: "Default options passed to agent execution. These can include instructions, memory configuration, maxSteps, and other execution settings.",
72
+ isOptional: true,
73
+ },
74
+ ]}
75
+ />
76
+
77
+ ## Additional configuration
78
+
79
+ 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 network route, for example to pass additional configuration to the agent:
80
+
81
+ ```typescript
82
+ const { error, status, sendMessage, messages, regenerate, stop } = useChat({
83
+ transport: new DefaultChatTransport({
84
+ api: "http://localhost:4111/network",
85
+ prepareSendMessagesRequest({ messages }) {
86
+ return {
87
+ body: {
88
+ messages,
89
+ // Pass memory config
90
+ memory: {
91
+ thread: "user-1",
92
+ resource: "user-1",
93
+ },
94
+ },
95
+ };
96
+ },
97
+ }),
98
+ });
99
+ ```
@@ -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
+ ```
@@ -143,6 +143,33 @@ The OtelBridge requires an active OpenTelemetry SDK to function. The bridge read
143
143
 
144
144
  See the [OtelBridge Guide](/docs/v1/observability/tracing/bridges/otel#configuration) for complete setup instructions, including how to configure OTEL instrumentation and run your application.
145
145
 
146
+ ## Tags Support
147
+
148
+ The OtelBridge supports trace tagging for categorization and filtering. Tags are only applied to root spans and are included as the `mastra.tags` attribute on native OTEL spans.
149
+
150
+ ### Usage
151
+
152
+ ```typescript
153
+ const result = await agent.generate({
154
+ messages: [{ role: "user", content: "Hello" }],
155
+ tracingOptions: {
156
+ tags: ["production", "experiment-v2", "user-request"],
157
+ },
158
+ });
159
+ ```
160
+
161
+ ### How Tags Are Stored
162
+
163
+ Tags are stored as a JSON-stringified array in the `mastra.tags` span attribute:
164
+
165
+ ```json
166
+ {
167
+ "mastra.tags": "[\"production\",\"experiment-v2\",\"user-request\"]"
168
+ }
169
+ ```
170
+
171
+ This format ensures compatibility with all OTEL-compatible backends and collectors.
172
+
146
173
  ## Related
147
174
 
148
175
  - [OtelBridge Guide](/docs/v1/observability/tracing/bridges/otel) - Setup guide with examples
@@ -161,6 +161,31 @@ const exporter = new ArizeExporter({
161
161
 
162
162
  The ArizeExporter implements [OpenInference Semantic Conventions](https://github.com/Arize-ai/openinference/tree/main/spec) for generative AI applications, providing standardized trace structure across different observability platforms.
163
163
 
164
+ ## Tags Support
165
+
166
+ The ArizeExporter supports trace tagging for categorization and filtering. Tags are only applied to root spans and are mapped to the native OpenInference `tag.tags` semantic convention.
167
+
168
+ ### Usage
169
+
170
+ ```typescript
171
+ const result = await agent.generate({
172
+ messages: [{ role: "user", content: "Hello" }],
173
+ tracingOptions: {
174
+ tags: ["production", "experiment-v2", "user-request"],
175
+ },
176
+ });
177
+ ```
178
+
179
+ ### How Tags Are Stored
180
+
181
+ Tags are stored using the OpenInference `tag.tags` attribute:
182
+
183
+ ```json
184
+ {
185
+ "tag.tags": ["production", "experiment-v2", "user-request"]
186
+ }
187
+ ```
188
+
164
189
  ## Related
165
190
 
166
191
  - [ArizeExporter Documentation](/docs/v1/observability/tracing/exporters/arize)