@assistant-ui/mcp-docs-server 0.1.30 → 0.1.31

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 (208) hide show
  1. package/.docs/organized/code-examples/waterfall.md +1 -1
  2. package/.docs/organized/code-examples/with-a2a.md +2 -2
  3. package/.docs/organized/code-examples/with-ag-ui.md +3 -3
  4. package/.docs/organized/code-examples/with-ai-sdk-v6.md +5 -5
  5. package/.docs/organized/code-examples/with-artifacts.md +5 -5
  6. package/.docs/organized/code-examples/with-assistant-transport.md +3 -3
  7. package/.docs/organized/code-examples/with-chain-of-thought.md +79 -50
  8. package/.docs/organized/code-examples/with-cloud-standalone.md +4 -4
  9. package/.docs/organized/code-examples/with-cloud.md +4 -4
  10. package/.docs/organized/code-examples/with-custom-thread-list.md +56 -11
  11. package/.docs/organized/code-examples/with-elevenlabs-conversational.md +7 -7
  12. package/.docs/organized/code-examples/with-elevenlabs-scribe.md +7 -7
  13. package/.docs/organized/code-examples/with-expo.md +16 -16
  14. package/.docs/organized/code-examples/with-external-store.md +2 -2
  15. package/.docs/organized/code-examples/with-ffmpeg.md +5 -5
  16. package/.docs/organized/code-examples/with-generative-ui.md +5 -5
  17. package/.docs/organized/code-examples/with-google-adk.md +4 -4
  18. package/.docs/organized/code-examples/with-heat-graph.md +1 -1
  19. package/.docs/organized/code-examples/with-interactables.md +5 -5
  20. package/.docs/organized/code-examples/with-langchain.md +3 -3
  21. package/.docs/organized/code-examples/with-langgraph.md +3 -3
  22. package/.docs/organized/code-examples/with-livekit.md +8 -8
  23. package/.docs/organized/code-examples/with-opencode.md +99 -54
  24. package/.docs/organized/code-examples/with-parent-id-grouping.md +4 -4
  25. package/.docs/organized/code-examples/with-react-hook-form.md +5 -5
  26. package/.docs/organized/code-examples/with-react-ink.md +1 -1
  27. package/.docs/organized/code-examples/with-react-router.md +8 -8
  28. package/.docs/organized/code-examples/with-store.md +1 -1
  29. package/.docs/organized/code-examples/with-tanstack.md +5 -5
  30. package/.docs/organized/code-examples/with-tap-runtime.md +2 -2
  31. package/.docs/raw/docs/(docs)/cli.mdx +2 -1
  32. package/.docs/raw/docs/(docs)/copilots/assistant-frame.mdx +1 -0
  33. package/.docs/raw/docs/(docs)/copilots/make-assistant-tool-ui.mdx +10 -3
  34. package/.docs/raw/docs/(docs)/copilots/make-assistant-tool.mdx +8 -3
  35. package/.docs/raw/docs/(docs)/copilots/make-assistant-visible.mdx +1 -0
  36. package/.docs/raw/docs/(docs)/copilots/model-context.mdx +1 -0
  37. package/.docs/raw/docs/(docs)/copilots/motivation.mdx +1 -0
  38. package/.docs/raw/docs/(docs)/copilots/use-assistant-instructions.mdx +1 -0
  39. package/.docs/raw/docs/(docs)/devtools.mdx +1 -0
  40. package/.docs/raw/docs/(docs)/index.mdx +1 -0
  41. package/.docs/raw/docs/(docs)/installation.mdx +1 -0
  42. package/.docs/raw/docs/(docs)/rtl.mdx +1 -0
  43. package/.docs/raw/docs/(reference)/api-reference/adapters/attachments.mdx +34 -0
  44. package/.docs/raw/docs/(reference)/api-reference/adapters/feedback-speech.mdx +41 -0
  45. package/.docs/raw/docs/(reference)/api-reference/adapters/index.mdx +26 -0
  46. package/.docs/raw/docs/(reference)/api-reference/adapters/persistence.mdx +34 -0
  47. package/.docs/raw/docs/(reference)/api-reference/adapters/runtime.mdx +31 -0
  48. package/.docs/raw/docs/(reference)/api-reference/context-providers/index.mdx +20 -0
  49. package/.docs/raw/docs/(reference)/api-reference/hooks/index.mdx +26 -0
  50. package/.docs/raw/docs/(reference)/api-reference/hooks/model-context.mdx +72 -0
  51. package/.docs/raw/docs/(reference)/api-reference/hooks/runtimes.mdx +41 -0
  52. package/.docs/raw/docs/(reference)/api-reference/hooks/state.mdx +48 -0
  53. package/.docs/raw/docs/(reference)/api-reference/hooks/utilities.mdx +30 -0
  54. package/.docs/raw/docs/(reference)/api-reference/integrations/index.mdx +23 -0
  55. package/.docs/raw/docs/(reference)/api-reference/overview.mdx +21 -0
  56. package/.docs/raw/docs/(reference)/api-reference/primitives/assistant-if.mdx +7 -0
  57. package/.docs/raw/docs/(reference)/api-reference/primitives/index.mdx +65 -0
  58. package/.docs/raw/docs/(reference)/api-reference/primitives/message.mdx +50 -6
  59. package/.docs/raw/docs/(reference)/api-reference/primitives/thread-list.mdx +15 -0
  60. package/.docs/raw/docs/(reference)/api-reference/primitives/thread.mdx +36 -1
  61. package/.docs/raw/docs/(reference)/api-reference/runtimes/index.mdx +38 -0
  62. package/.docs/raw/docs/(reference)/api-reference/runtimes/thread-list-runtime.mdx +5 -0
  63. package/.docs/raw/docs/(reference)/migrations/v0-14.mdx +144 -6
  64. package/.docs/raw/docs/cloud/ai-sdk-assistant-ui.mdx +230 -2
  65. package/.docs/raw/docs/cloud/ai-sdk.mdx +221 -3
  66. package/.docs/raw/docs/cloud/langgraph.mdx +274 -2
  67. package/.docs/raw/docs/{(docs)/guides → guides}/attachments.mdx +41 -36
  68. package/.docs/raw/docs/guides/branching.mdx +76 -0
  69. package/.docs/raw/docs/guides/chain-of-thought.mdx +166 -0
  70. package/.docs/raw/docs/{(docs)/guides → guides}/context-api.mdx +50 -22
  71. package/.docs/raw/docs/{(docs)/guides → guides}/dictation.mdx +2 -0
  72. package/.docs/raw/docs/guides/editing.mdx +102 -0
  73. package/.docs/raw/docs/guides/index.mdx +103 -0
  74. package/.docs/raw/docs/{(docs)/guides → guides}/interactables.mdx +49 -0
  75. package/.docs/raw/docs/{(docs)/guides → guides}/latex.mdx +51 -8
  76. package/.docs/raw/docs/{(docs)/guides → guides}/mentions.mdx +61 -86
  77. package/.docs/raw/docs/{(docs)/guides → guides}/message-timing.mdx +8 -2
  78. package/.docs/raw/docs/{(docs)/guides → guides}/multi-agent.mdx +64 -4
  79. package/.docs/raw/docs/{(docs)/guides → guides}/quoting.mdx +10 -17
  80. package/.docs/raw/docs/{(docs)/guides → guides}/slash-commands.mdx +103 -37
  81. package/.docs/raw/docs/guides/speech.mdx +156 -0
  82. package/.docs/raw/docs/{(docs)/guides → guides}/suggestions.mdx +21 -83
  83. package/.docs/raw/docs/{(docs)/guides → guides}/tool-ui.mdx +108 -36
  84. package/.docs/raw/docs/{(docs)/guides → guides}/tools.mdx +131 -35
  85. package/.docs/raw/docs/{(docs)/guides → guides}/voice.mdx +39 -0
  86. package/.docs/raw/docs/ink/index.mdx +1 -3
  87. package/.docs/raw/docs/ink/migration.mdx +1 -3
  88. package/.docs/raw/docs/ink/primitives.mdx +37 -1
  89. package/.docs/raw/docs/integrations/attachments/custom-adapter.mdx +520 -0
  90. package/.docs/raw/docs/integrations/auth/better-auth.mdx +191 -0
  91. package/.docs/raw/docs/integrations/auth/clerk.mdx +172 -0
  92. package/.docs/raw/docs/integrations/auth/next-auth.mdx +196 -0
  93. package/.docs/raw/docs/integrations/frameworks/ai-sdk.mdx +79 -0
  94. package/.docs/raw/docs/integrations/frameworks/mastra/full-stack.mdx +188 -0
  95. package/.docs/raw/docs/integrations/frameworks/mastra/overview.mdx +57 -0
  96. package/.docs/raw/docs/integrations/frameworks/mastra/separate-server.mdx +201 -0
  97. package/.docs/raw/docs/integrations/gateways/index.mdx +157 -0
  98. package/.docs/raw/docs/integrations/index.mdx +173 -0
  99. package/.docs/raw/docs/integrations/observability/helicone.mdx +130 -0
  100. package/.docs/raw/docs/integrations/observability/langfuse.mdx +156 -0
  101. package/.docs/raw/docs/integrations/observability/langsmith.mdx +146 -0
  102. package/.docs/raw/docs/integrations/persistence/custom-adapter.mdx +712 -0
  103. package/.docs/raw/docs/integrations/tools/mcp.mdx +267 -0
  104. package/.docs/raw/docs/primitives/action-bar.mdx +1 -0
  105. package/.docs/raw/docs/primitives/assistant-modal.mdx +1 -0
  106. package/.docs/raw/docs/primitives/attachment.mdx +1 -0
  107. package/.docs/raw/docs/primitives/branch-picker.mdx +1 -0
  108. package/.docs/raw/docs/primitives/chain-of-thought.mdx +90 -85
  109. package/.docs/raw/docs/primitives/composer.mdx +2 -1
  110. package/.docs/raw/docs/primitives/error.mdx +1 -0
  111. package/.docs/raw/docs/primitives/index.mdx +2 -1
  112. package/.docs/raw/docs/primitives/message.mdx +68 -5
  113. package/.docs/raw/docs/primitives/selection-toolbar.mdx +1 -0
  114. package/.docs/raw/docs/primitives/suggestion.mdx +1 -0
  115. package/.docs/raw/docs/primitives/thread-list.mdx +39 -0
  116. package/.docs/raw/docs/primitives/thread.mdx +16 -13
  117. package/.docs/raw/docs/react-native/index.mdx +1 -3
  118. package/.docs/raw/docs/react-native/migration.mdx +1 -3
  119. package/.docs/raw/docs/runtimes/a2a/client-and-hooks.mdx +396 -0
  120. package/.docs/raw/docs/runtimes/a2a/overview.mdx +60 -0
  121. package/.docs/raw/docs/runtimes/a2a/quickstart.mdx +216 -0
  122. package/.docs/raw/docs/runtimes/ag-ui/overview.mdx +70 -0
  123. package/.docs/raw/docs/runtimes/ag-ui/quickstart.mdx +243 -0
  124. package/.docs/raw/docs/runtimes/ag-ui/runtime-options.mdx +123 -0
  125. package/.docs/raw/docs/runtimes/ai-sdk/overview.mdx +52 -0
  126. package/.docs/raw/docs/runtimes/ai-sdk/v4-legacy.mdx +71 -131
  127. package/.docs/raw/docs/runtimes/ai-sdk/v5-legacy.mdx +69 -63
  128. package/.docs/raw/docs/runtimes/ai-sdk/v6.mdx +330 -123
  129. package/.docs/raw/docs/runtimes/concepts/adapters.mdx +265 -0
  130. package/.docs/raw/docs/runtimes/concepts/architecture.mdx +125 -0
  131. package/.docs/raw/docs/runtimes/concepts/stability.mdx +67 -0
  132. package/.docs/raw/docs/runtimes/concepts/threads.mdx +428 -0
  133. package/.docs/raw/docs/runtimes/custom/assistant-transport.mdx +703 -0
  134. package/.docs/raw/docs/runtimes/custom/data-stream.mdx +323 -0
  135. package/.docs/raw/docs/runtimes/custom/external-store.mdx +253 -1236
  136. package/.docs/raw/docs/runtimes/custom/local-runtime.mdx +746 -0
  137. package/.docs/raw/docs/runtimes/custom/overview.mdx +71 -0
  138. package/.docs/raw/docs/runtimes/google-adk/api.mdx +256 -0
  139. package/.docs/raw/docs/runtimes/google-adk/hooks.mdx +717 -0
  140. package/.docs/raw/docs/runtimes/google-adk/overview.mdx +69 -0
  141. package/.docs/raw/docs/runtimes/google-adk/quickstart.mdx +229 -0
  142. package/.docs/raw/docs/runtimes/langchain.mdx +533 -0
  143. package/.docs/raw/docs/runtimes/langgraph/generative-ui.mdx +305 -0
  144. package/.docs/raw/docs/runtimes/langgraph/interrupts.mdx +104 -0
  145. package/.docs/raw/docs/runtimes/langgraph/overview.mdx +84 -0
  146. package/.docs/raw/docs/runtimes/langgraph/quickstart.mdx +496 -0
  147. package/.docs/raw/docs/runtimes/langgraph/streaming.mdx +127 -0
  148. package/.docs/raw/docs/runtimes/langgraph/threads.mdx +113 -0
  149. package/.docs/raw/docs/runtimes/langgraph/tutorial/introduction.mdx +3 -3
  150. package/.docs/raw/docs/runtimes/langgraph/tutorial/part-1.mdx +0 -23
  151. package/.docs/raw/docs/runtimes/langgraph/tutorial/part-2.mdx +1 -1
  152. package/.docs/raw/docs/runtimes/opencode/hooks.mdx +191 -0
  153. package/.docs/raw/docs/runtimes/opencode/overview.mdx +48 -0
  154. package/.docs/raw/docs/runtimes/opencode/quickstart.mdx +119 -0
  155. package/.docs/raw/docs/runtimes/pick-a-runtime.mdx +71 -203
  156. package/.docs/raw/docs/ui/accordion.mdx +1 -0
  157. package/.docs/raw/docs/ui/assistant-modal.mdx +1 -0
  158. package/.docs/raw/docs/ui/assistant-sidebar.mdx +1 -0
  159. package/.docs/raw/docs/ui/attachment.mdx +1 -0
  160. package/.docs/raw/docs/ui/badge.mdx +1 -0
  161. package/.docs/raw/docs/ui/composer-trigger-popover.mdx +1 -0
  162. package/.docs/raw/docs/ui/context-display.mdx +1 -0
  163. package/.docs/raw/docs/ui/diff-viewer.mdx +1 -0
  164. package/.docs/raw/docs/ui/directive-text.mdx +1 -0
  165. package/.docs/raw/docs/ui/file.mdx +1 -0
  166. package/.docs/raw/docs/ui/image.mdx +1 -0
  167. package/.docs/raw/docs/ui/markdown.mdx +2 -14
  168. package/.docs/raw/docs/ui/mermaid.mdx +1 -0
  169. package/.docs/raw/docs/ui/message-timing.mdx +3 -2
  170. package/.docs/raw/docs/ui/model-selector.mdx +1 -0
  171. package/.docs/raw/docs/ui/part-grouping.mdx +325 -313
  172. package/.docs/raw/docs/ui/quote.mdx +1 -0
  173. package/.docs/raw/docs/ui/reasoning.mdx +66 -33
  174. package/.docs/raw/docs/ui/scrollbar.mdx +1 -0
  175. package/.docs/raw/docs/ui/select.mdx +1 -0
  176. package/.docs/raw/docs/ui/sources.mdx +1 -0
  177. package/.docs/raw/docs/ui/streamdown.mdx +1 -0
  178. package/.docs/raw/docs/ui/syntax-highlighting.mdx +1 -0
  179. package/.docs/raw/docs/ui/tabs.mdx +1 -0
  180. package/.docs/raw/docs/ui/thread-list.mdx +17 -0
  181. package/.docs/raw/docs/ui/thread.mdx +56 -1
  182. package/.docs/raw/docs/ui/tool-fallback.mdx +1 -0
  183. package/.docs/raw/docs/ui/tool-group.mdx +39 -11
  184. package/.docs/raw/docs/ui/voice.mdx +1 -0
  185. package/.docs/raw/docs/utilities/heat-graph.mdx +1 -0
  186. package/.docs/raw/docs/utilities/react-o11y.mdx +278 -0
  187. package/.docs/raw/docs/utilities/tw-shimmer.mdx +1 -0
  188. package/package.json +3 -3
  189. package/src/tools/tests/path-traversal.test.ts +1 -1
  190. package/.docs/raw/docs/(docs)/guides/branching.mdx +0 -65
  191. package/.docs/raw/docs/(docs)/guides/chain-of-thought.mdx +0 -164
  192. package/.docs/raw/docs/(docs)/guides/editing.mdx +0 -66
  193. package/.docs/raw/docs/(docs)/guides/speech.mdx +0 -38
  194. package/.docs/raw/docs/runtimes/a2a/index.mdx +0 -298
  195. package/.docs/raw/docs/runtimes/assistant-transport.mdx +0 -1033
  196. package/.docs/raw/docs/runtimes/custom/custom-thread-list.mdx +0 -314
  197. package/.docs/raw/docs/runtimes/custom/local.mdx +0 -1464
  198. package/.docs/raw/docs/runtimes/data-stream.mdx +0 -422
  199. package/.docs/raw/docs/runtimes/google-adk/index.mdx +0 -686
  200. package/.docs/raw/docs/runtimes/helicone.mdx +0 -61
  201. package/.docs/raw/docs/runtimes/langchain/comparison.mdx +0 -60
  202. package/.docs/raw/docs/runtimes/langchain/index.mdx +0 -210
  203. package/.docs/raw/docs/runtimes/langgraph/index.mdx +0 -699
  204. package/.docs/raw/docs/runtimes/langgraph/tutorial/index.mdx +0 -12
  205. package/.docs/raw/docs/runtimes/langserve.mdx +0 -116
  206. package/.docs/raw/docs/runtimes/mastra/full-stack-integration.mdx +0 -218
  207. package/.docs/raw/docs/runtimes/mastra/overview.mdx +0 -18
  208. package/.docs/raw/docs/runtimes/mastra/separate-server-integration.mdx +0 -217
@@ -0,0 +1,188 @@
1
+ ---
2
+ title: Full-stack integration
3
+ description: Run Mastra agents inside your Next.js API routes.
4
+ platforms: ["react"]
5
+ ---
6
+
7
+ import { MastraIcon } from "@/components/icons/mastra";
8
+ import { VercelIcon } from "@/components/icons/vercel";
9
+
10
+ Run Mastra in-process inside your Next.js application. The agent code, the API route, and the assistant-ui frontend all live in one project. This is the lowest-friction path: one deploy target, one set of env vars, no cross-origin plumbing.
11
+
12
+ For independent scaling, see [separate server](/docs/integrations/frameworks/mastra/separate-server) instead.
13
+
14
+ ## Setup
15
+
16
+ <Steps>
17
+ <Step>
18
+
19
+ ### Initialize assistant-ui
20
+
21
+ Set up assistant-ui in your project:
22
+
23
+ ```sh title="New project"
24
+ npx assistant-ui@latest create
25
+ ```
26
+
27
+ ```sh title="Existing project"
28
+ npx assistant-ui@latest init
29
+ ```
30
+
31
+ This installs dependencies and creates a default chat API route at `app/api/chat/route.ts`. For manual setup, see the [getting started guide](/docs).
32
+
33
+ </Step>
34
+ <Step>
35
+
36
+ ### Install Mastra packages
37
+
38
+ `@mastra/core` provides the agent runtime; `@mastra/ai-sdk` converts Mastra's stream format to AI SDK's UI message stream; `zod` is required for tool schemas.
39
+
40
+ <InstallCommand npm={["@mastra/core@latest", "@mastra/ai-sdk@latest", "zod@latest"]} />
41
+
42
+ </Step>
43
+ <Step>
44
+
45
+ ### Configure Next.js
46
+
47
+ Mastra's runtime depends on Node-only modules. Tell Next.js to bundle Mastra packages externally on the server so they aren't traced into the edge runtime.
48
+
49
+ ```js title="next.config.mjs"
50
+ /** @type {import('next').NextConfig} */
51
+ const nextConfig = {
52
+ serverExternalPackages: ["@mastra/*"],
53
+ };
54
+
55
+ export default nextConfig;
56
+ ```
57
+
58
+ If you skip this step you'll see opaque bundling errors at request time, not at build time.
59
+
60
+ </Step>
61
+ <Step>
62
+
63
+ ### Define an agent
64
+
65
+ Create a `mastra/` folder at the project root with two files:
66
+
67
+ ```txt title="Project layout"
68
+ mastra/
69
+ ├── agents/
70
+ │ └── chefAgent.ts
71
+ └── index.ts
72
+ ```
73
+
74
+ Define the agent in `chefAgent.ts`:
75
+
76
+ ```ts title="mastra/agents/chefAgent.ts"
77
+ import { Agent } from "@mastra/core/agent";
78
+
79
+ export const chefAgent = new Agent({
80
+ name: "chef-agent",
81
+ instructions:
82
+ "You are Michel, a practical and experienced home chef. " +
83
+ "You help people cook with whatever ingredients they have available.",
84
+ model: "openai/gpt-5.4-mini",
85
+ });
86
+ ```
87
+
88
+ `model: "openai/gpt-5.4-mini"` uses Mastra's model router. Set the provider key in `.env.local` so Next.js auto-loads it:
89
+
90
+ ```sh title=".env.local"
91
+ OPENAI_API_KEY=sk-...
92
+ ```
93
+
94
+ </Step>
95
+ <Step>
96
+
97
+ ### Register the agent
98
+
99
+ Initialize Mastra with the agent so it can be looked up by name:
100
+
101
+ ```ts title="mastra/index.ts"
102
+ import { Mastra } from "@mastra/core";
103
+ import { chefAgent } from "./agents/chefAgent";
104
+
105
+ export const mastra = new Mastra({
106
+ agents: { chefAgent },
107
+ });
108
+ ```
109
+
110
+ </Step>
111
+ <Step>
112
+
113
+ ### Wire the API route
114
+
115
+ Replace the default route with one that streams from the Mastra agent:
116
+
117
+ ```ts title="app/api/chat/route.ts"
118
+ import { createUIMessageStream, createUIMessageStreamResponse } from "ai";
119
+ import { toAISdkStream } from "@mastra/ai-sdk";
120
+ import { mastra } from "@/mastra";
121
+
122
+ export const maxDuration = 30;
123
+
124
+ export async function POST(req: Request) {
125
+ const { messages } = await req.json();
126
+
127
+ const agent = mastra.getAgent("chefAgent");
128
+ const stream = await agent.stream(messages);
129
+
130
+ const uiMessageStream = createUIMessageStream({
131
+ originalMessages: messages,
132
+ execute: async ({ writer }) => {
133
+ for await (const part of toAISdkStream(stream, { from: "agent" })) {
134
+ await writer.write(part);
135
+ }
136
+ },
137
+ });
138
+
139
+ return createUIMessageStreamResponse({ stream: uiMessageStream });
140
+ }
141
+ ```
142
+
143
+ `agent.stream()` returns a Mastra-native stream. `toAISdkStream` (from `@mastra/ai-sdk`) adapts each part to the AI SDK shape; `createUIMessageStream` wraps the part loop into the UI message stream that `useChatRuntime` consumes; `createUIMessageStreamResponse` returns it as an HTTP response.
144
+
145
+ The `@/mastra` import assumes the `@/*` path alias is configured in `tsconfig.json` (the assistant-ui starter sets this up). If your project uses a different alias, adjust the import path.
146
+
147
+ </Step>
148
+ <Step>
149
+
150
+ ### Run and verify
151
+
152
+ Start the dev server:
153
+
154
+ ```bash npm2yarn
155
+ npm run dev
156
+ ```
157
+
158
+ Open `http://localhost:3000`, send a message like *"What can I make with eggs and rice?"*, and confirm:
159
+
160
+ - The response streams in token by token.
161
+ - The browser's network tab shows a single `POST /api/chat` returning `text/event-stream`.
162
+ - No console errors about missing modules; if you see `Cannot find module '@mastra/...'`, revisit the `serverExternalPackages` step.
163
+
164
+ </Step>
165
+ </Steps>
166
+
167
+ ## Notes
168
+
169
+ - **Errors in the route bubble to the client as a stream error.** Wrap `agent.stream()` in `try/catch` if you need to log structured errors before they reach the client.
170
+ - **Pin compatible versions.** `@mastra/ai-sdk` tracks the AI SDK v6 contract. If you upgrade `ai` to a future major, verify the `toAISdkStream` shape against Mastra's release notes.
171
+ - **Advanced Mastra features** (memory, tools, workflows, evals) live entirely in the agent definition. assistant-ui sees only the resulting stream, so anything Mastra supports works without further frontend changes. See the [Mastra docs](https://mastra.ai/docs).
172
+
173
+ ## Related
174
+
175
+ <Cards>
176
+ <Card
177
+ icon={<MastraIcon width={20} height={20} />}
178
+ title="Separate server integration"
179
+ description="Run Mastra as a standalone server, connect via API."
180
+ href="/docs/integrations/frameworks/mastra/separate-server"
181
+ />
182
+ <Card
183
+ icon={<VercelIcon width={20} height={20} />}
184
+ title="AI SDK runtime"
185
+ description="The runtime that handles the client side of this integration."
186
+ href="/docs/runtimes/ai-sdk/v6"
187
+ />
188
+ </Cards>
@@ -0,0 +1,57 @@
1
+ ---
2
+ title: Overview
3
+ description: Wire up the Mastra TypeScript agent framework with assistant-ui.
4
+ ---
5
+
6
+ import { MastraIcon } from "@/components/icons/mastra";
7
+ import { VercelIcon } from "@/components/icons/vercel";
8
+
9
+ [Mastra](https://mastra.ai/) is an open-source TypeScript agent framework. It provides primitives for AI applications: agents with memory and tool calling, deterministic LLM workflows, RAG, model routing, workflow graphs, and automated evals.
10
+
11
+ <Callout type="info">
12
+ This is an integration guide, not a runtime adapter. assistant-ui does not ship a `@assistant-ui/react-mastra` package. You wire up Mastra through the standard [AI SDK runtime](/docs/runtimes/ai-sdk/v6) by routing your API endpoint through Mastra's agent stream.
13
+ </Callout>
14
+
15
+ ## Pick a pattern
16
+
17
+ | Pattern | When to pick |
18
+ | --- | --- |
19
+ | [Full-stack](/docs/integrations/frameworks/mastra/full-stack) | One Next.js app: API routes call Mastra in-process. Simpler deployment, single repo. |
20
+ | [Separate server](/docs/integrations/frameworks/mastra/separate-server) | Mastra runs as its own service; the Next.js frontend hits its API. Independent scaling, clearer separation of concerns. |
21
+
22
+ Both use the same client-side `useChatRuntime` from [`@assistant-ui/react-ai-sdk`](/docs/runtimes/ai-sdk/v6). The only difference is where the Mastra agent lives.
23
+
24
+ ## Architecture
25
+
26
+ Mastra integrates at the LLM-client layer on the server. assistant-ui talks to your API route via the AI SDK runtime; the route calls `agent.stream(messages)` and returns the result wrapped in a UI message stream. The client side is built on [`ExternalStoreRuntime`](/docs/runtimes/custom/external-store) through the AI SDK adapter.
27
+
28
+ Shared adapters (attachments, speech, feedback, history) work the same way described in [adapters](/docs/runtimes/concepts/adapters). Multi-thread support uses [AssistantCloud](/docs/cloud) or a [custom thread list](/docs/runtimes/concepts/threads).
29
+
30
+ ## Requirements
31
+
32
+ - A Next.js project, or another framework that can run AI SDK route handlers.
33
+ - Model API keys (OpenAI, Anthropic, etc.) configured in your environment.
34
+ - Node 18 or newer.
35
+
36
+ ## Next
37
+
38
+ <Cards>
39
+ <Card
40
+ icon={<MastraIcon width={20} height={20} />}
41
+ title="Full-stack integration"
42
+ description="Run Mastra inside your Next.js API routes."
43
+ href="/docs/integrations/frameworks/mastra/full-stack"
44
+ />
45
+ <Card
46
+ icon={<MastraIcon width={20} height={20} />}
47
+ title="Separate server integration"
48
+ description="Run Mastra as a standalone server, frontend connects via API."
49
+ href="/docs/integrations/frameworks/mastra/separate-server"
50
+ />
51
+ <Card
52
+ icon={<VercelIcon width={20} height={20} />}
53
+ title="AI SDK runtime"
54
+ description="The runtime that handles the client side of this integration."
55
+ href="/docs/runtimes/ai-sdk/v6"
56
+ />
57
+ </Cards>
@@ -0,0 +1,201 @@
1
+ ---
2
+ title: Separate server integration
3
+ description: Run Mastra as a standalone server with assistant-ui as a separate frontend.
4
+ ---
5
+
6
+ import { MastraIcon } from "@/components/icons/mastra";
7
+ import { VercelIcon } from "@/components/icons/vercel";
8
+
9
+ Run Mastra as its own service and have the assistant-ui frontend hit it over HTTP. The two halves can deploy, scale, and version independently. The tradeoff is one extra hop and CORS to configure.
10
+
11
+ For the simpler in-process variant, see [full-stack](/docs/integrations/frameworks/mastra/full-stack) instead.
12
+
13
+ ## Setup
14
+
15
+ The setup has two halves. Steps 1 to 4 happen in the **Mastra server** project; steps 5 to 7 happen in a **separate assistant-ui frontend** project. You'll have two terminals open by the end: one for each dev server.
16
+
17
+ <Steps>
18
+
19
+ <Step>
20
+
21
+ ### Create the Mastra server project
22
+
23
+ In a directory separate from your frontend, scaffold a Mastra project:
24
+
25
+ ```sh
26
+ npx create-mastra@latest
27
+ ```
28
+
29
+ Follow the wizard's prompts. When it finishes, change into the new directory and add the AI SDK adapter:
30
+
31
+ ```sh
32
+ cd your-mastra-server
33
+ ```
34
+
35
+ <InstallCommand npm={["@mastra/ai-sdk@latest"]} />
36
+
37
+ Set the model provider keys (`OPENAI_API_KEY`, etc.) in `.env.development`. The `create-mastra` wizard prompts for some keys, but verify all the providers you plan to call are present.
38
+
39
+ </Step>
40
+
41
+ <Step>
42
+
43
+ ### Define an agent
44
+
45
+ ```ts title="src/mastra/agents/chefAgent.ts"
46
+ import { Agent } from "@mastra/core/agent";
47
+
48
+ export const chefAgent = new Agent({
49
+ name: "chef-agent",
50
+ instructions:
51
+ "You are Michel, a practical and experienced home chef. " +
52
+ "You help people cook with whatever ingredients they have available.",
53
+ model: "openai/gpt-4o-mini",
54
+ });
55
+ ```
56
+
57
+ </Step>
58
+
59
+ <Step>
60
+
61
+ ### Register the agent, chat route, and CORS
62
+
63
+ Open the Mastra entry point. You will set three things in the same `Mastra` constructor: the agent, a chat route, and CORS for the frontend's origin.
64
+
65
+ ```ts title="src/mastra/index.ts"
66
+ import { Mastra } from "@mastra/core";
67
+ import { chefAgent } from "./agents/chefAgent";
68
+ import { chatRoute } from "@mastra/ai-sdk";
69
+
70
+ export const mastra = new Mastra({
71
+ agents: { chefAgent },
72
+ server: {
73
+ cors: {
74
+ origin: process.env.FRONTEND_ORIGIN ?? "http://localhost:3000",
75
+ credentials: true,
76
+ },
77
+ apiRoutes: [
78
+ chatRoute({ path: "/chat/:agentId" }),
79
+ ],
80
+ },
81
+ });
82
+ ```
83
+
84
+ A few things to note:
85
+
86
+ - `:agentId` matches the **JavaScript key** in the `agents` object, not the agent's `name` field. So `chefAgent` is reachable at `/chat/chefAgent` (camelCase), not `/chat/chef-agent`.
87
+ - Add more agents to the `agents` object and they all become callable through this single route.
88
+ - `FRONTEND_ORIGIN` should be set to your deployed frontend's URL in production. Without CORS configured, the browser blocks the request and the chat silently fails.
89
+
90
+ </Step>
91
+
92
+ <Step>
93
+
94
+ ### Run the Mastra server
95
+
96
+ ```bash npm2yarn
97
+ npm run dev
98
+ ```
99
+
100
+ The server starts on `http://localhost:4111` by default. Leave it running for the rest of the steps.
101
+
102
+ </Step>
103
+
104
+ <Step>
105
+
106
+ ### Initialize the assistant-ui frontend
107
+
108
+ In a **different directory** from the Mastra server, scaffold the frontend:
109
+
110
+ ```sh title="New project"
111
+ npx assistant-ui@latest create
112
+ ```
113
+
114
+ ```sh title="Existing project"
115
+ npx assistant-ui@latest init
116
+ ```
117
+
118
+ This creates a default chat page and a local API route at `app/api/chat/route.ts`. You won't use the local route, since the agent runs on the separate Mastra server; delete it once the next step is wired.
119
+
120
+ </Step>
121
+
122
+ <Step>
123
+
124
+ ### Point the runtime at the Mastra server
125
+
126
+ Open the file containing `useChatRuntime` (typically `app/assistant.tsx`) and pass an explicit `api` URL:
127
+
128
+ ```tsx title="app/assistant.tsx" {8}
129
+ "use client";
130
+
131
+ import { AssistantRuntimeProvider } from "@assistant-ui/react";
132
+ import { AssistantChatTransport, useChatRuntime } from "@assistant-ui/react-ai-sdk";
133
+ import { Thread } from "@/components/assistant-ui/thread";
134
+
135
+ export const Assistant = () => {
136
+ const runtime = useChatRuntime({
137
+ transport: new AssistantChatTransport({
138
+ api: process.env.NEXT_PUBLIC_MASTRA_URL!,
139
+ }),
140
+ });
141
+
142
+ return (
143
+ <AssistantRuntimeProvider runtime={runtime}>
144
+ <Thread />
145
+ </AssistantRuntimeProvider>
146
+ );
147
+ };
148
+ ```
149
+
150
+ Set the URL in your frontend's environment:
151
+
152
+ ```sh title=".env.local"
153
+ NEXT_PUBLIC_MASTRA_URL=http://localhost:4111/chat/chefAgent
154
+ ```
155
+
156
+ `NEXT_PUBLIC_*` makes the URL available in the browser. In production, point this at your deployed Mastra server. Mastra itself uses `.env.development` for its server keys; the two projects keep separate environment files.
157
+
158
+ </Step>
159
+
160
+ <Step>
161
+
162
+ ### Run and verify
163
+
164
+ Make sure the Mastra server (step 4) is still running in its own terminal, then start the frontend in a new terminal:
165
+
166
+ ```bash npm2yarn
167
+ npm run dev
168
+ ```
169
+
170
+ Open `http://localhost:3000`, send a message, and confirm:
171
+
172
+ - The response streams in token by token.
173
+ - The network tab shows the `POST` going to `http://localhost:4111/chat/chefAgent`, not the local `/api/chat`.
174
+ - No CORS errors in the console; if you see `blocked by CORS policy`, revisit step 3.
175
+
176
+ </Step>
177
+
178
+ </Steps>
179
+
180
+ ## Notes
181
+
182
+ - **Auth between frontend and Mastra**: the example above is open. In production, gate the Mastra route with a header or cookie check and forward credentials from the frontend (`AssistantChatTransport` accepts `headers` and `credentials` options).
183
+ - **Single agent vs router**: `chatRoute({ path: "/chat/:agentId" })` works for any agent registered on the `Mastra` instance. Switching agents from the frontend is a matter of pointing `NEXT_PUBLIC_MASTRA_URL` at a different agent ID.
184
+ - **Advanced Mastra features** (memory, tools, workflows, evals) live in the agent definition. The frontend sees only the resulting stream. See the [Mastra docs](https://mastra.ai/docs).
185
+
186
+ ## Related
187
+
188
+ <Cards>
189
+ <Card
190
+ icon={<MastraIcon width={20} height={20} />}
191
+ title="Full-stack integration"
192
+ description="Run Mastra inside your Next.js API routes for a single deploy target."
193
+ href="/docs/integrations/frameworks/mastra/full-stack"
194
+ />
195
+ <Card
196
+ icon={<VercelIcon width={20} height={20} />}
197
+ title="AI SDK runtime"
198
+ description="The runtime that handles the client side of this integration."
199
+ href="/docs/runtimes/ai-sdk/v6"
200
+ />
201
+ </Cards>
@@ -0,0 +1,157 @@
1
+ ---
2
+ title: LLM gateways
3
+ description: Route assistant-ui traffic through OpenAI-compatible gateways for cost, fallback, and BYOK.
4
+ ---
5
+
6
+ LLM gateways sit between your route handler and the upstream provider. They give you a single endpoint that fronts many providers, plus features like multi-provider fallback, prompt caching, and BYOK (bring-your-own-key) flows. Most are OpenAI API-compatible, so the integration is a `baseURL` swap on `createOpenAI` from `@ai-sdk/openai`.
7
+
8
+ For pure observability (proxy that logs every call) see [Helicone](/docs/integrations/observability/helicone). The gateways here overlap in spirit but are positioned around routing rather than logging.
9
+
10
+ ## Compare
11
+
12
+ | Gateway | Base URL | Auth header | Distinguishing feature |
13
+ | --- | --- | --- | --- |
14
+ | [OpenRouter](#openrouter) | `https://openrouter.ai/api/v1` | `Authorization: Bearer <key>` | Catalog of 100+ models with `vendor/model` IDs |
15
+ | [Portkey](#portkey) | `https://api.portkey.ai/v1` | `x-portkey-api-key` | Config-driven multi-provider fallback |
16
+ | [LiteLLM Proxy](#litellm-proxy) | Self-hosted | `Authorization: Bearer <virtual key>` | OSS, self-host, virtual keys per tenant |
17
+
18
+ If your need is only request logging, Helicone fits the same shape and is documented separately.
19
+
20
+ ## Common pattern
21
+
22
+ All three gateways below speak OpenAI's API. Wire them with `createOpenAI`:
23
+
24
+ ```ts title="app/api/chat/route.ts"
25
+ import { createOpenAI } from "@ai-sdk/openai";
26
+ import { streamText, convertToModelMessages } from "ai";
27
+ import type { UIMessage } from "ai";
28
+
29
+ const openai = createOpenAI({
30
+ baseURL: "<gateway base url>",
31
+ headers: { /* gateway-specific auth */ },
32
+ });
33
+
34
+ export async function POST(req: Request) {
35
+ const { messages }: { messages: UIMessage[] } = await req.json();
36
+ const result = streamText({
37
+ model: openai("<model id>"),
38
+ messages: await convertToModelMessages(messages),
39
+ });
40
+ return result.toUIMessageStreamResponse();
41
+ }
42
+ ```
43
+
44
+ The rest of this page is what to put in `baseURL`, `headers`, and `model(...)` for each gateway.
45
+
46
+ ## OpenRouter
47
+
48
+ [OpenRouter](https://openrouter.ai/) aggregates 100+ models behind one OpenAI-compatible endpoint. The model ID is `provider/model` (e.g., `anthropic/claude-sonnet-4`, `openai/gpt-5.4-mini`, `meta-llama/llama-3.3-70b-instruct`).
49
+
50
+ ```sh title=".env.local"
51
+ OPENROUTER_API_KEY=sk-or-...
52
+ SITE_URL=https://your-app.example
53
+ ```
54
+
55
+ ```ts title="app/api/chat/route.ts"
56
+ import { createOpenAI } from "@ai-sdk/openai";
57
+ import { streamText, convertToModelMessages } from "ai";
58
+ import type { UIMessage } from "ai";
59
+
60
+ const openrouter = createOpenAI({
61
+ baseURL: "https://openrouter.ai/api/v1",
62
+ apiKey: process.env.OPENROUTER_API_KEY,
63
+ headers: {
64
+ "HTTP-Referer": process.env.SITE_URL ?? "http://localhost:3000",
65
+ "X-Title": "My App",
66
+ },
67
+ });
68
+
69
+ export async function POST(req: Request) {
70
+ const { messages }: { messages: UIMessage[] } = await req.json();
71
+ const result = streamText({
72
+ model: openrouter("anthropic/claude-sonnet-4"),
73
+ messages: await convertToModelMessages(messages),
74
+ });
75
+ return result.toUIMessageStreamResponse();
76
+ }
77
+ ```
78
+
79
+ `HTTP-Referer` and `X-Title` are optional attribution headers; OpenRouter shows them in your usage dashboard.
80
+
81
+ When to pick: you want a single bill across many models, or you let users pick the model from a long list, or you need to run open-weights models without managing the inference yourself.
82
+
83
+ ## Portkey
84
+
85
+ [Portkey](https://portkey.ai/) is a gateway plus observability with a config-driven router. The differentiating feature is the *config*: a server-defined object that describes routing rules (try Anthropic first, fall back to OpenAI, fall back to a local model), retries, and caching.
86
+
87
+ ```sh title=".env.local"
88
+ PORTKEY_API_KEY=...
89
+ PORTKEY_VIRTUAL_KEY=...
90
+ ```
91
+
92
+ ```ts title="app/api/chat/route.ts"
93
+ import { createOpenAI } from "@ai-sdk/openai";
94
+
95
+ const portkey = createOpenAI({
96
+ baseURL: "https://api.portkey.ai/v1",
97
+ apiKey: "no-auth-here",
98
+ headers: {
99
+ "x-portkey-api-key": process.env.PORTKEY_API_KEY!,
100
+ "x-portkey-virtual-key": process.env.PORTKEY_VIRTUAL_KEY!,
101
+ },
102
+ });
103
+ ```
104
+
105
+ Configs live in the Portkey dashboard; reference them with `x-portkey-config: <config-id>` in the headers when you want a specific routing strategy.
106
+
107
+ When to pick: you need cross-provider fallback or prompt-cache hit rates that the AI SDK doesn't give you out of the box.
108
+
109
+ ## LiteLLM Proxy
110
+
111
+ [LiteLLM Proxy](https://docs.litellm.ai/docs/simple_proxy) is OSS and self-hostable. You run it, you configure provider keys server-side, and you hand virtual keys (per-tenant, per-user) to clients. It's the only viable path for BYOK SaaS or air-gapped deployments.
112
+
113
+ Run the proxy first (Docker, k8s, or a single Node process). Then point the AI SDK at your instance:
114
+
115
+ ```sh title=".env.local"
116
+ LITELLM_BASE_URL=https://litellm.example.com
117
+ LITELLM_VIRTUAL_KEY=sk-...
118
+ ```
119
+
120
+ ```ts title="app/api/chat/route.ts"
121
+ import { createOpenAI } from "@ai-sdk/openai";
122
+
123
+ const litellm = createOpenAI({
124
+ baseURL: process.env.LITELLM_BASE_URL!,
125
+ apiKey: process.env.LITELLM_VIRTUAL_KEY!,
126
+ });
127
+
128
+ const result = streamText({
129
+ model: litellm("gpt-5.4-mini"),
130
+ messages: await convertToModelMessages(messages),
131
+ });
132
+ ```
133
+
134
+ Model IDs depend on how you configured the proxy. LiteLLM rewrites them to upstream providers based on your config.
135
+
136
+ When to pick: self-host requirement, BYOK metering for end-users, or unified billing across providers managed by your platform team.
137
+
138
+ ## Notes
139
+
140
+ - **Server-side only.** A gateway key is a write capability against your billing account. Never set it in client code; the route handler is the right boundary.
141
+ - **Streaming, tools, attachments.** All three gateways are transparent to the AI SDK; everything that works against OpenAI directly works through them.
142
+ - **Combining with observability.** A gateway and an observability tool are not mutually exclusive. Helicone in front of OpenRouter is a common stack: OpenRouter does the routing, Helicone logs the calls.
143
+
144
+ ## Related
145
+
146
+ <Cards>
147
+ <Card
148
+ title="Helicone"
149
+ description="The observability-first proxy. Same shape, different goal."
150
+ href="/docs/integrations/observability/helicone"
151
+ />
152
+ <Card
153
+ title="AI SDK runtime"
154
+ description="The runtime that ferries gateway responses to the chat UI."
155
+ href="/docs/runtimes/ai-sdk/v6"
156
+ />
157
+ </Cards>