@mastra/mcp-docs-server 1.2.4 → 1.2.5-alpha.3

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 (200) hide show
  1. package/.docs/docs/agent-builder/deploying.md +1 -1
  2. package/.docs/docs/agent-controller/overview.md +1 -1
  3. package/.docs/docs/agent-controller/session.md +1 -1
  4. package/.docs/docs/agents/overview.md +1 -1
  5. package/.docs/docs/agents/processors.md +1 -1
  6. package/.docs/docs/agents/supervisor-agents.md +3 -3
  7. package/.docs/docs/agents/using-tools.md +1 -1
  8. package/.docs/docs/{agents → long-running-agents}/background-tasks.md +2 -2
  9. package/.docs/docs/{agents → long-running-agents}/durable-agents.md +2 -2
  10. package/.docs/docs/{agents → long-running-agents}/goals.md +1 -1
  11. package/.docs/docs/{agents → long-running-agents}/heartbeats.md +5 -5
  12. package/.docs/docs/{agents → long-running-agents}/signal-providers.md +4 -4
  13. package/.docs/docs/memory/working-memory.md +1 -1
  14. package/.docs/docs/observability/config.md +1 -2
  15. package/.docs/docs/server/pubsub.md +2 -2
  16. package/.docs/docs/voice/overview.md +3 -3
  17. package/.docs/docs/voice/speech-to-speech.md +81 -1
  18. package/.docs/docs/voice/speech-to-text.md +19 -1
  19. package/.docs/docs/voice/text-to-speech.md +21 -1
  20. package/.docs/docs/workflows/control-flow.md +1 -1
  21. package/.docs/docs/workflows/error-handling.md +1 -1
  22. package/.docs/docs/workflows/human-in-the-loop.md +1 -1
  23. package/.docs/docs/workflows/overview.md +1 -1
  24. package/.docs/docs/workflows/snapshots.md +1 -1
  25. package/.docs/docs/workflows/suspend-and-resume.md +1 -1
  26. package/.docs/docs/workflows/time-travel.md +1 -1
  27. package/.docs/docs/workflows/workflow-state.md +1 -1
  28. package/.docs/guides/build-your-ui/copilotkit/channels.md +76 -0
  29. package/.docs/guides/build-your-ui/copilotkit/generative-ui.md +174 -0
  30. package/.docs/guides/build-your-ui/copilotkit/overview.md +411 -0
  31. package/.docs/guides/concepts/streaming.md +1 -1
  32. package/.docs/guides/deployment/vercel.md +1 -2
  33. package/.docs/guides/guide/signal-provider.md +5 -5
  34. package/.docs/models/environment-variables.md +2 -0
  35. package/.docs/models/index.md +1 -1
  36. package/.docs/models/providers/alibaba-cn.md +2 -1
  37. package/.docs/models/providers/friendli.md +1 -2
  38. package/.docs/models/providers/kenari.md +95 -0
  39. package/.docs/models/providers/nvidia.md +2 -3
  40. package/.docs/models/providers/tencent-token-plan.md +7 -7
  41. package/.docs/models/providers/tencent-tokenhub.md +5 -4
  42. package/.docs/models/providers.md +2 -0
  43. package/.docs/reference/acp/acp-agent.md +5 -5
  44. package/.docs/reference/acp/create-acp-tool.md +5 -5
  45. package/.docs/reference/agent-controller/agent-controller-class.md +27 -27
  46. package/.docs/reference/agents/agent.md +34 -34
  47. package/.docs/reference/agents/channels.md +19 -19
  48. package/.docs/reference/agents/createSkill.md +2 -2
  49. package/.docs/reference/agents/durable-agent.md +22 -22
  50. package/.docs/reference/agents/generate.md +10 -10
  51. package/.docs/reference/agents/generateLegacy.md +12 -12
  52. package/.docs/reference/agents/getMetadata.md +1 -1
  53. package/.docs/reference/agents/getVoice.md +1 -1
  54. package/.docs/reference/agents/inngest-agent.md +9 -9
  55. package/.docs/reference/agents/network.md +1 -1
  56. package/.docs/reference/ai-sdk/chat-route.md +4 -4
  57. package/.docs/reference/ai-sdk/handle-chat-stream.md +6 -6
  58. package/.docs/reference/ai-sdk/handle-network-stream.md +3 -3
  59. package/.docs/reference/ai-sdk/handle-workflow-stream.md +1 -1
  60. package/.docs/reference/ai-sdk/network-route.md +4 -4
  61. package/.docs/reference/ai-sdk/to-ai-sdk-messages.md +1 -1
  62. package/.docs/reference/ai-sdk/to-ai-sdk-stream.md +1 -1
  63. package/.docs/reference/ai-sdk/with-mastra.md +2 -2
  64. package/.docs/reference/ai-sdk/workflow-route.md +2 -2
  65. package/.docs/reference/ai-sdk/workflow-snapshot-to-stream.md +1 -1
  66. package/.docs/reference/auth/google.md +10 -10
  67. package/.docs/reference/auth/okta.md +11 -11
  68. package/.docs/reference/auth/workos.md +3 -3
  69. package/.docs/reference/channels/slack-provider.md +15 -15
  70. package/.docs/reference/cli/mastra.md +145 -0
  71. package/.docs/reference/client-js/agents.md +9 -9
  72. package/.docs/reference/client-js/mastra-client.md +5 -5
  73. package/.docs/reference/client-js/responses.md +3 -3
  74. package/.docs/reference/configuration.md +1 -1
  75. package/.docs/reference/core/getAgentById.md +3 -3
  76. package/.docs/reference/core/getWorkflow.md +1 -1
  77. package/.docs/reference/core/listWorkflows.md +1 -1
  78. package/.docs/reference/core/mastra-class.md +3 -3
  79. package/.docs/reference/core/removeWorkspace.md +2 -2
  80. package/.docs/reference/datasets/compareExperiments.md +1 -1
  81. package/.docs/reference/datasets/getItemHistory.md +1 -1
  82. package/.docs/reference/datasets/list.md +5 -5
  83. package/.docs/reference/datasets/listExperimentResults.md +4 -4
  84. package/.docs/reference/datasets/listExperiments.md +4 -4
  85. package/.docs/reference/datasets/listItems.md +5 -5
  86. package/.docs/reference/datasets/listVersions.md +3 -3
  87. package/.docs/reference/datasets/startExperiment.md +8 -8
  88. package/.docs/reference/datasets/startExperimentAsync.md +1 -1
  89. package/.docs/reference/editor/agent-builder/agent-builder-options.md +4 -4
  90. package/.docs/reference/editor/agent-builder/builder-agent-defaults.md +7 -7
  91. package/.docs/reference/editor/agent-builder/builder-models.md +4 -4
  92. package/.docs/reference/editor/blob-store-provider.md +2 -2
  93. package/.docs/reference/editor/browser-provider.md +2 -2
  94. package/.docs/reference/editor/filesystem-provider.md +2 -2
  95. package/.docs/reference/editor/mastra-editor.md +2 -2
  96. package/.docs/reference/editor/processor-provider.md +4 -4
  97. package/.docs/reference/editor/sandbox-provider.md +2 -2
  98. package/.docs/reference/editor/storage-browser-ref.md +2 -2
  99. package/.docs/reference/editor/storage-workspace-ref.md +7 -7
  100. package/.docs/reference/evals/create-scorer.md +8 -8
  101. package/.docs/reference/evals/rubric.md +1 -1
  102. package/.docs/reference/evals/run-evals.md +7 -7
  103. package/.docs/reference/evals/trajectory-accuracy.md +1 -1
  104. package/.docs/reference/index.md +2 -2
  105. package/.docs/reference/logging/pino-logger.md +4 -4
  106. package/.docs/reference/memory/cloneThread.md +35 -4
  107. package/.docs/reference/memory/memory-class.md +5 -5
  108. package/.docs/reference/memory/observational-memory.md +43 -43
  109. package/.docs/reference/memory/recall.md +4 -4
  110. package/.docs/reference/memory/serialized-memory-config.md +6 -6
  111. package/.docs/reference/observability/tracing/configuration.md +4 -4
  112. package/.docs/reference/processors/language-detector.md +1 -1
  113. package/.docs/reference/processors/moderation-processor.md +1 -1
  114. package/.docs/reference/processors/pii-detector.md +1 -1
  115. package/.docs/reference/processors/processor-interface.md +20 -20
  116. package/.docs/reference/processors/prompt-injection-detector.md +1 -1
  117. package/.docs/reference/processors/response-cache.md +6 -6
  118. package/.docs/reference/processors/unicode-normalizer.md +1 -1
  119. package/.docs/reference/pubsub/base.md +7 -7
  120. package/.docs/reference/pubsub/caching-pubsub.md +1 -1
  121. package/.docs/reference/pubsub/event-emitter.md +2 -2
  122. package/.docs/reference/pubsub/google-cloud-pubsub.md +1 -1
  123. package/.docs/reference/pubsub/lease-provider.md +3 -3
  124. package/.docs/reference/pubsub/redis-streams.md +6 -6
  125. package/.docs/reference/pubsub/unix-socket-pubsub.md +1 -1
  126. package/.docs/reference/rag/chunk.md +2 -2
  127. package/.docs/reference/server/create-route.md +3 -3
  128. package/.docs/reference/server/express-adapter.md +4 -4
  129. package/.docs/reference/server/fastify-adapter.md +4 -4
  130. package/.docs/reference/server/hono-adapter.md +4 -4
  131. package/.docs/reference/server/koa-adapter.md +4 -4
  132. package/.docs/reference/server/mastra-server.md +1 -1
  133. package/.docs/reference/server/nestjs-adapter.md +3 -3
  134. package/.docs/reference/server/register-api-route.md +3 -3
  135. package/.docs/reference/signals/create-notification-inbox-tool.md +3 -3
  136. package/.docs/reference/signals/signal-provider.md +7 -7
  137. package/.docs/reference/signals/webhook-signal-provider.md +2 -2
  138. package/.docs/reference/storage/clickhouse.md +7 -7
  139. package/.docs/reference/storage/composite.md +2 -2
  140. package/.docs/reference/storage/duckdb.md +1 -1
  141. package/.docs/reference/storage/dynamodb.md +1 -1
  142. package/.docs/reference/storage/libsql.md +1 -1
  143. package/.docs/reference/storage/postgresql.md +2 -2
  144. package/.docs/reference/storage/redis.md +2 -2
  145. package/.docs/reference/storage/retention.md +5 -5
  146. package/.docs/reference/storage/spanner.md +6 -6
  147. package/.docs/reference/streaming/ChunkType.md +3 -3
  148. package/.docs/reference/streaming/agents/stream.md +14 -14
  149. package/.docs/reference/streaming/agents/streamLegacy.md +10 -10
  150. package/.docs/reference/streaming/agents/streamUntilIdle.md +1 -1
  151. package/.docs/reference/streaming/workflows/resumeStream.md +1 -1
  152. package/.docs/reference/templates/overview.md +1 -140
  153. package/.docs/reference/tools/brightdata.md +4 -4
  154. package/.docs/reference/tools/create-code-mode.md +5 -5
  155. package/.docs/reference/tools/create-tool.md +15 -15
  156. package/.docs/reference/tools/graph-rag-tool.md +1 -1
  157. package/.docs/reference/tools/mcp-client.md +2 -2
  158. package/.docs/reference/tools/mcp-server.md +12 -12
  159. package/.docs/reference/tools/perplexity.md +3 -3
  160. package/.docs/reference/tools/tavily.md +1 -1
  161. package/.docs/reference/tools/vector-query-tool.md +1 -1
  162. package/.docs/reference/vectors/chroma.md +1 -1
  163. package/.docs/reference/vectors/mongodb.md +1 -1
  164. package/.docs/reference/vectors/pg.md +1 -1
  165. package/.docs/reference/vectors/s3vectors.md +4 -4
  166. package/.docs/reference/voice/google-gemini-live.md +3 -3
  167. package/.docs/reference/voice/inworld-realtime.md +12 -12
  168. package/.docs/reference/voice/inworld.md +2 -2
  169. package/.docs/reference/voice/voice.on.md +1 -1
  170. package/.docs/reference/workflows/run-methods/resume.md +1 -1
  171. package/.docs/reference/workflows/run-methods/timeTravel.md +1 -1
  172. package/.docs/reference/workspace/agentcore-runtime-sandbox.md +4 -4
  173. package/.docs/reference/workspace/agentfs-filesystem.md +1 -1
  174. package/.docs/reference/workspace/apple-container-sandbox.md +5 -5
  175. package/.docs/reference/workspace/archil-filesystem.md +5 -5
  176. package/.docs/reference/workspace/blaxel-sandbox.md +1 -1
  177. package/.docs/reference/workspace/daytona-sandbox.md +1 -1
  178. package/.docs/reference/workspace/docker-sandbox.md +2 -2
  179. package/.docs/reference/workspace/e2b-sandbox.md +2 -2
  180. package/.docs/reference/workspace/files-sdk-filesystem.md +1 -1
  181. package/.docs/reference/workspace/filesystem.md +1 -1
  182. package/.docs/reference/workspace/local-filesystem.md +3 -3
  183. package/.docs/reference/workspace/local-sandbox.md +1 -1
  184. package/.docs/reference/workspace/mesa-filesystem.md +3 -3
  185. package/.docs/reference/workspace/modal-sandbox.md +1 -1
  186. package/.docs/reference/workspace/railway-sandbox.md +1 -1
  187. package/.docs/reference/workspace/s3-filesystem.md +4 -4
  188. package/.docs/reference/workspace/sandbox.md +1 -1
  189. package/.docs/reference/workspace/{vercel-microvm-sandbox.md → vercel-sandbox.md} +21 -15
  190. package/.docs/reference/workspace/{vercel.md → vercel-serverless.md} +21 -14
  191. package/.docs/reference/workspace/workspace-class.md +15 -15
  192. package/CHANGELOG.md +15 -0
  193. package/package.json +5 -5
  194. package/.docs/docs/agents/adding-voice.md +0 -383
  195. package/.docs/docs/community/contributing-templates.md +0 -5
  196. package/.docs/docs/community/discord.md +0 -11
  197. package/.docs/guides/build-your-ui/copilotkit.md +0 -291
  198. package/LICENSE.md +0 -30
  199. /package/.docs/docs/{community/licensing.md → license.md} +0 -0
  200. /package/.docs/docs/{agents → long-running-agents}/signals.md +0 -0
@@ -0,0 +1,174 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
3
+ # CopilotKit generative UI
4
+
5
+ Generative UI is the family of UI paradigms enabled by agents and useful for interacting with them. CopilotKit organizes these along a single axis, the **generative UI spectrum**, which runs from author-controlled (you decide every pixel) to agent-invented (the agent owns the rendered surface). Where you sit on the axis is a trade-off between predictability and breadth.
6
+
7
+ The spectrum has three tiers:
8
+
9
+ | Tier | Who controls the surface | Primitives |
10
+ | --------------- | ------------------------------------------------------------------------------------------ | -------------------------------------------------------------------- |
11
+ | **Controlled** | You wrote the component; the agent picks which one and what data to pass. | Tool call rendering, state rendering, reasoning, components as tools |
12
+ | **Declarative** | The agent emits a structured spec; the frontend composes it from a catalog you registered. | A2UI (fixed schema and dynamic) |
13
+ | **Open-ended** | The UI is invented elsewhere (an MCP server) and you sandbox it. | MCP Apps |
14
+
15
+ Each tier is a Mastra agent exposed through `registerCopilotKit()` (see [CopilotKit overview](https://mastra.ai/guides/build-your-ui/copilotkit/overview)) plus the matching CopilotKit hook on the frontend. For the full concept, see CopilotKit's [generative UI spectrum](https://www.copilotkit.ai/generative-ui-spectrum) and [generative UI overview](https://docs.copilotkit.ai/concepts/generative-ui-overview).
16
+
17
+ > **Tip:** Mastra's [UI Dojo](https://ui-dojo.mastra.ai/) has working CopilotKit examples; browse the source under `src/pages/copilot-kit`.
18
+
19
+ ## Controlled
20
+
21
+ You ship a fixed set of components and the agent chooses which to render, with what data. This is the workhorse of the spectrum: predictable and brand-safe, the right tool for high-traffic surfaces. The Controlled primitives use CopilotKit's v2 API, imported from `@copilotkit/react-core/v2`.
22
+
23
+ ### Tool call rendering
24
+
25
+ Render an agent's tool call as a React component. Define the agent and tool on the Mastra server as usual:
26
+
27
+ ```typescript
28
+ import { Agent } from '@mastra/core/agent'
29
+ import { weatherTool } from '../tools/weather-tool'
30
+
31
+ export const weatherAgent = new Agent({
32
+ id: 'weather-agent',
33
+ name: 'Weather Agent',
34
+ instructions: 'Use the weatherTool to fetch current weather data.',
35
+ model: 'openai/gpt-5.5',
36
+ tools: { weatherTool },
37
+ })
38
+ ```
39
+
40
+ On the frontend, register a renderer for the tool by name with `useRenderTool`. It is render-only (it does not execute the tool); the `render` function receives the tool call's `status` and, once the agent returns, its `result`:
41
+
42
+ ```tsx
43
+ import { z } from 'zod'
44
+ import { CopilotChat } from '@copilotkit/react-ui'
45
+ import { CopilotKit, useRenderTool } from '@copilotkit/react-core/v2'
46
+ import { Weather } from '@/components/weather'
47
+
48
+ function Chat() {
49
+ useRenderTool(
50
+ {
51
+ name: 'weatherTool',
52
+ parameters: z.object({ location: z.string() }),
53
+ render: ({ status, result }) => {
54
+ if (status !== 'complete') {
55
+ return <div>Retrieving weather...</div>
56
+ }
57
+ return <Weather {...result} />
58
+ },
59
+ },
60
+ [],
61
+ )
62
+
63
+ return <CopilotChat labels={{ title: 'Weather Assistant' }} />
64
+ }
65
+
66
+ export default function Page() {
67
+ return (
68
+ <CopilotKit runtimeUrl="http://localhost:4111/copilotkit" agent="weatherAgent">
69
+ <Chat />
70
+ </CopilotKit>
71
+ )
72
+ }
73
+ ```
74
+
75
+ Because Mastra streams tool-call arguments incrementally, the `render` function is called repeatedly as the arguments arrive, so the UI can paint progressively while the agent works.
76
+
77
+ ### Components as tools
78
+
79
+ Register a React component and let the agent call it as a tool. CopilotKit renders it inline with typed props (defined with a Zod schema):
80
+
81
+ ```tsx
82
+ import { z } from 'zod'
83
+ import { useComponent } from '@copilotkit/react-core/v2'
84
+
85
+ const schema = z.object({ text: z.string() })
86
+
87
+ function Callout({ text }: z.infer<typeof schema>) {
88
+ return <div className="callout">{text}</div>
89
+ }
90
+
91
+ function Chat() {
92
+ useComponent({ name: 'callout', render: Callout, parameters: schema }, [])
93
+ return <CopilotChat labels={{ title: 'Assistant' }} />
94
+ }
95
+ ```
96
+
97
+ The agent invokes `callout` like any other tool, and CopilotKit renders `Callout` with the props it passed.
98
+
99
+ ### State rendering
100
+
101
+ Render UI from the agent's state and re-render as it streams. On Mastra, agent state is the agent's working memory, streamed to the client as it changes. Read it with `useAgent`; `agent.state` is reactive, so the component updates automatically:
102
+
103
+ ```tsx
104
+ import { useAgent } from '@copilotkit/react-core/v2'
105
+
106
+ function TaskBoard() {
107
+ const { agent } = useAgent()
108
+ const tasks = (agent.state.tasks as any[]) ?? []
109
+
110
+ return (
111
+ <ul>
112
+ {tasks.map((task, i) => (
113
+ <li key={i}>
114
+ {task.title}: {task.status}
115
+ </li>
116
+ ))}
117
+ </ul>
118
+ )
119
+ }
120
+ ```
121
+
122
+ ### Reasoning
123
+
124
+ Reasoning is zero-config: when your Mastra agent runs a reasoning-capable model, `CopilotChat` renders the model's thinking inline as a dedicated message type, with no extra code. To restyle it, pass your own component to the `reasoningMessage` slot on `CopilotChat`. See CopilotKit's [generative UI guides](https://docs.copilotkit.ai/) for details.
125
+
126
+ ## Declarative
127
+
128
+ Instead of a fixed component per tool, you register a catalog of typed building blocks and the agent assembles them into a UI tree per request. CopilotKit calls this **A2UI** (Agent-to-UI), available in a fixed-schema and a dynamic variant. It suits the long tail of secondary interactions where breadth matters more than pixel-perfection.
129
+
130
+ The path of least resistance is to pass your catalog to the `<CopilotKit>` provider. That single prop enables A2UI rendering and injects the A2UI tool into your agent, so no backend change is needed:
131
+
132
+ ```tsx
133
+ import { CopilotKit } from '@copilotkit/react-core/v2'
134
+ import { myCatalog } from './a2ui-catalog'
135
+
136
+ export default function Page() {
137
+ return (
138
+ <CopilotKit
139
+ runtimeUrl="http://localhost:4111/copilotkit"
140
+ agent="weatherAgent"
141
+ a2ui={{ catalog: myCatalog }}
142
+ >
143
+ {/* your app */}
144
+ </CopilotKit>
145
+ )
146
+ }
147
+ ```
148
+
149
+ The catalog defines the primitives (their schemas) and the renderers (how each primitive displays). In the fixed-schema variant the components are pre-authored and the agent's tool only supplies data; the dynamic variant lets the agent compose the tree more freely. See CopilotKit's [A2UI documentation](https://docs.copilotkit.ai/a2a/generative-ui/a2ui).
150
+
151
+ ## Open-ended
152
+
153
+ At the far end of the spectrum, the agent owns the entire surface: the UI is invented elsewhere and sandboxed in your app. CopilotKit supports this through **MCP Apps**, where an MCP server ships UI that renders inside your application. This tier trades determinism for novelty and is the most experimental point on the spectrum.
154
+
155
+ The path of least resistance keeps the frontend untouched: your existing `<CopilotKit>` provider is enough. On the backend, point `registerCopilotKit()` at one or more MCP servers with the `mcpApps` option (it is forwarded to the CopilotKit runtime):
156
+
157
+ ```typescript
158
+ registerCopilotKit({
159
+ path: '/copilotkit',
160
+ resourceId: 'weatherAgent',
161
+ mcpApps: {
162
+ servers: [{ type: 'http', url: 'http://localhost:3108/mcp', serverId: 'my-server' }],
163
+ },
164
+ })
165
+ ```
166
+
167
+ When the agent calls an MCP App tool, CopilotKit fetches and renders that tool's UI in the chat with no additional frontend code. See CopilotKit's [MCP Apps documentation](https://docs.copilotkit.ai/agno/generative-ui/mcp-apps).
168
+
169
+ ## App control and interactivity
170
+
171
+ Some capabilities sit next to the spectrum rather than on it: they control your app or gate a run instead of rendering agent output. Both are covered in [Get started](https://mastra.ai/guides/build-your-ui/copilotkit/overview):
172
+
173
+ - **Frontend tools** (`useFrontendTool`): let the agent act on your application. This is part of CopilotKit's separate [App Control](https://docs.copilotkit.ai/) concept, alongside shared state and agent context.
174
+ - **Human-in-the-loop**: pause a run and wait for user approval or edits. Backend side, see Mastra's [Agent approval](https://mastra.ai/docs/agents/agent-approval); frontend side, see CopilotKit's [`useHumanInTheLoop`](https://docs.copilotkit.ai/reference/hooks/useHumanInTheLoop).
@@ -0,0 +1,411 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
3
+ # Using CopilotKit
4
+
5
+ [CopilotKit](https://www.copilotkit.ai/) provides React components to quickly integrate customizable AI copilots into your application. Combined with Mastra, you can build sophisticated AI apps featuring bidirectional state synchronization and interactive UIs.
6
+
7
+ CopilotKit talks to Mastra through the [AG-UI protocol](https://docs.ag-ui.com/). The `@ag-ui/mastra` package exposes your Mastra agents as an AG-UI endpoint, and CopilotKit's React hooks and components consume it. This unlocks a spectrum of experiences on top of ordinary chat: [generative UI, human-in-the-loop, and frontend tools](https://mastra.ai/guides/build-your-ui/copilotkit/generative-ui), plus deploying the same agent to [messaging channels like Slack](https://mastra.ai/guides/build-your-ui/copilotkit/channels).
8
+
9
+ Visit the [CopilotKit documentation](https://docs.copilotkit.ai/) to learn more about CopilotKit concepts, components, and advanced usage patterns.
10
+
11
+ > **Info:** For a full-stack integration approach where Mastra runs directly in your Next.js API routes, see the [CopilotKit Quickstart](https://docs.copilotkit.ai/mastra/quickstart) guide.
12
+
13
+ > **Tip:** Visit Mastra's ["UI Dojo"](https://ui-dojo.mastra.ai/) to see real-world examples of CopilotKit integrated with Mastra.
14
+
15
+ ## Integration guide
16
+
17
+ Run Mastra as a standalone server and connect your Next.js frontend (with CopilotKit) to its API endpoints.
18
+
19
+ 1. Set up your directory structure. A possible directory structure could look like this:
20
+
21
+ ```bash
22
+ project-root
23
+ ├── mastra-server
24
+ │ ├── src
25
+ │ │ └── mastra
26
+ │ └── package.json
27
+ └── my-copilot-app
28
+ └── package.json
29
+ ```
30
+
31
+ Bootstrap your Mastra server:
32
+
33
+ **npm**:
34
+
35
+ ```bash
36
+ npx create-mastra@latest
37
+ ```
38
+
39
+ **pnpm**:
40
+
41
+ ```bash
42
+ pnpm dlx create-mastra@latest
43
+ ```
44
+
45
+ **Yarn**:
46
+
47
+ ```bash
48
+ yarn dlx create-mastra@latest
49
+ ```
50
+
51
+ **Bun**:
52
+
53
+ ```bash
54
+ bun x create-mastra@latest
55
+ ```
56
+
57
+ This command opens an interactive wizard that scaffolds a new Mastra project. Follow the prompts to create your server project.
58
+
59
+ Navigate to your newly created Mastra server directory:
60
+
61
+ ```bash
62
+ cd mastra-server # Replace with the actual directory name you provided
63
+ ```
64
+
65
+ You now have a basic Mastra server project ready.
66
+
67
+ > **Note:** Ensure that you have set the appropriate environment variables for your LLM provider in the `.env` file.
68
+
69
+ 2. Create a chat route for the CopilotKit frontend by using the `registerCopilotKit()` helper from `@ag-ui/mastra`. Add it to your Mastra project (and its peer dependencies):
70
+
71
+ **npm**:
72
+
73
+ ```bash
74
+ npm install @ag-ui/mastra @mastra/client-js @mastra/core @ag-ui/core @ag-ui/client @copilotkit/runtime
75
+ ```
76
+
77
+ **pnpm**:
78
+
79
+ ```bash
80
+ pnpm add @ag-ui/mastra @mastra/client-js @mastra/core @ag-ui/core @ag-ui/client @copilotkit/runtime
81
+ ```
82
+
83
+ **Yarn**:
84
+
85
+ ```bash
86
+ yarn add @ag-ui/mastra @mastra/client-js @mastra/core @ag-ui/core @ag-ui/client @copilotkit/runtime
87
+ ```
88
+
89
+ **Bun**:
90
+
91
+ ```bash
92
+ bun add @ag-ui/mastra @mastra/client-js @mastra/core @ag-ui/core @ag-ui/client @copilotkit/runtime
93
+ ```
94
+
95
+ In your `src/mastra/index.ts` file, register the chat route:
96
+
97
+ ```typescript
98
+ import { Mastra } from '@mastra/core/mastra'
99
+ import { registerCopilotKit } from '@ag-ui/mastra/copilotkit'
100
+ // Rest of the imports...
101
+
102
+ export const mastra = new Mastra({
103
+ // Rest of the configuration...
104
+ server: {
105
+ cors: {
106
+ origin: '*',
107
+ allowMethods: ['*'],
108
+ allowHeaders: ['*'],
109
+ },
110
+ apiRoutes: [
111
+ registerCopilotKit({
112
+ path: '/copilotkit',
113
+ resourceId: 'weatherAgent',
114
+ }),
115
+ ],
116
+ },
117
+ })
118
+ ```
119
+
120
+ This exposes the agents on your Mastra instance at `/copilotkit` in a CopilotKit-compatible format. The frontend selects which agent to talk to with the `agent` prop shown below. Add the CORS configuration so the CopilotKit frontend can access the Mastra server. For production deployments, restrict CORS origins to your frontend domain.
121
+
122
+ 3. Run the Mastra server using the following command:
123
+
124
+ **npm**:
125
+
126
+ ```bash
127
+ npm run dev
128
+ ```
129
+
130
+ **pnpm**:
131
+
132
+ ```bash
133
+ pnpm run dev
134
+ ```
135
+
136
+ **Yarn**:
137
+
138
+ ```bash
139
+ yarn dev
140
+ ```
141
+
142
+ **Bun**:
143
+
144
+ ```bash
145
+ bun run dev
146
+ ```
147
+
148
+ By default, the Mastra server runs on `http://localhost:4111`. Keep this server running while you set up the CopilotKit frontend.
149
+
150
+ 4. Go up one directory to your project root.
151
+
152
+ ```bash
153
+ cd ..
154
+ ```
155
+
156
+ Create a new Next.js project with the name `my-copilot-app`:
157
+
158
+ **npm**:
159
+
160
+ ```bash
161
+ npx create-next-app@latest my-copilot-app
162
+ ```
163
+
164
+ **pnpm**:
165
+
166
+ ```bash
167
+ pnpm dlx create-next-app@latest my-copilot-app
168
+ ```
169
+
170
+ **Yarn**:
171
+
172
+ ```bash
173
+ yarn dlx create-next-app@latest my-copilot-app
174
+ ```
175
+
176
+ **Bun**:
177
+
178
+ ```bash
179
+ bun x create-next-app@latest my-copilot-app
180
+ ```
181
+
182
+ Navigate to your newly created Next.js project directory:
183
+
184
+ ```bash
185
+ cd my-copilot-app
186
+ ```
187
+
188
+ 5. Install the CopilotKit UI packages which you'll use to display a chat interface:
189
+
190
+ **npm**:
191
+
192
+ ```bash
193
+ npm install @copilotkit/react-ui @copilotkit/react-core
194
+ ```
195
+
196
+ **pnpm**:
197
+
198
+ ```bash
199
+ pnpm add @copilotkit/react-ui @copilotkit/react-core
200
+ ```
201
+
202
+ **Yarn**:
203
+
204
+ ```bash
205
+ yarn add @copilotkit/react-ui @copilotkit/react-core
206
+ ```
207
+
208
+ **Bun**:
209
+
210
+ ```bash
211
+ bun add @copilotkit/react-ui @copilotkit/react-core
212
+ ```
213
+
214
+ Open the home route of the Next.js app (usually `app/page.tsx` or `src/app/page.tsx`) and replace the existing contents with the following code to set up a basic CopilotKit chat interface:
215
+
216
+ ```typescript
217
+ import { CopilotChat } from '@copilotkit/react-ui'
218
+ import { CopilotKit } from '@copilotkit/react-core'
219
+ import '@copilotkit/react-ui/styles.css'
220
+
221
+ export default function Home() {
222
+ return (
223
+ <CopilotKit runtimeUrl="http://localhost:4111/copilotkit" agent="weatherAgent">
224
+ <CopilotChat
225
+ labels={{
226
+ title: 'Weather Agent',
227
+ initial: 'Hi! 👋 Ask me about the weather, forecasts, and climate.',
228
+ }}
229
+ />
230
+ </CopilotKit>
231
+ )
232
+ }
233
+ ```
234
+
235
+ The `agent` prop names the Mastra agent to route to. It must match a key in your Mastra instance's `agents` map.
236
+
237
+ 6. Ensure both the Mastra server and the CopilotKit frontend are running. Start the Next.js development server:
238
+
239
+ **npm**:
240
+
241
+ ```bash
242
+ npm run dev
243
+ ```
244
+
245
+ **pnpm**:
246
+
247
+ ```bash
248
+ pnpm run dev
249
+ ```
250
+
251
+ **Yarn**:
252
+
253
+ ```bash
254
+ yarn dev
255
+ ```
256
+
257
+ **Bun**:
258
+
259
+ ```bash
260
+ bun run dev
261
+ ```
262
+
263
+ Open the app in your browser and chat with your agent.
264
+
265
+ Your CopilotKit frontend now communicates with a standalone Mastra agent server.
266
+
267
+ ## Chat UI options
268
+
269
+ `CopilotChat` renders an inline, full-height chat. CopilotKit ships two other drop-in surfaces that share the same props:
270
+
271
+ - `CopilotSidebar`: a collapsible panel docked to the side of your app.
272
+ - `CopilotPopup`: a floating button that opens a chat window.
273
+
274
+ Swap the component to change the surface. All three connect through the same `CopilotKit` provider:
275
+
276
+ ```typescript
277
+ import { CopilotSidebar } from '@copilotkit/react-ui'
278
+ import { CopilotKit } from '@copilotkit/react-core'
279
+ import '@copilotkit/react-ui/styles.css'
280
+
281
+ export default function Home() {
282
+ return (
283
+ <CopilotKit runtimeUrl="http://localhost:4111/copilotkit" agent="weatherAgent">
284
+ <CopilotSidebar
285
+ labels={{
286
+ title: 'Weather Agent',
287
+ initial: 'Hi! 👋 Ask me about the weather.',
288
+ }}
289
+ />
290
+ {/* your app */}
291
+ </CopilotKit>
292
+ )
293
+ }
294
+ ```
295
+
296
+ For fully custom chat UIs (bring your own components), see [CopilotKit's headless UI guide](https://docs.copilotkit.ai/).
297
+
298
+ ## App control and interactivity
299
+
300
+ Beyond rendering agent output as UI (see [generative UI](https://mastra.ai/guides/build-your-ui/copilotkit/generative-ui)), CopilotKit lets the agent act on your application and pause for the user. Both patterns run against the same Mastra setup.
301
+
302
+ ### Frontend tools
303
+
304
+ Give the agent the ability to act on your app. Register the tool on the frontend with `useFrontendTool`; the `handler` runs in the browser when the agent calls it:
305
+
306
+ ```tsx
307
+ import { CopilotChat } from '@copilotkit/react-ui'
308
+ import { CopilotKit, useFrontendTool } from '@copilotkit/react-core'
309
+
310
+ function Chat() {
311
+ useFrontendTool({
312
+ name: 'colorChangeTool',
313
+ description: 'Changes the background color',
314
+ parameters: [
315
+ { name: 'color', type: 'string', description: 'The color to change to', required: true },
316
+ ],
317
+ handler: ({ color }) => {
318
+ document.body.style.setProperty('--background', color)
319
+ },
320
+ })
321
+
322
+ return <CopilotChat labels={{ title: 'Background Color Changer' }} />
323
+ }
324
+
325
+ export default function Page() {
326
+ return (
327
+ <CopilotKit runtimeUrl="http://localhost:4111/copilotkit" agent="bgColorAgent">
328
+ <Chat />
329
+ </CopilotKit>
330
+ )
331
+ }
332
+ ```
333
+
334
+ The matching Mastra agent is a normal agent instructed to call `colorChangeTool` with the requested color.
335
+
336
+ ### Human-in-the-loop
337
+
338
+ Pause the agent mid-run and wait for the user to approve, edit, or reject before continuing. Use `useHumanInTheLoop`: its `render` function receives a `respond` callback, and the agent's run stays suspended until you call it.
339
+
340
+ ```tsx
341
+ import { CopilotChat } from '@copilotkit/react-ui'
342
+ import { CopilotKit, useHumanInTheLoop } from '@copilotkit/react-core'
343
+ import { StepsFeedback } from '@/components/steps-feedback'
344
+
345
+ function Chat() {
346
+ useHumanInTheLoop({
347
+ name: 'generate_task_steps',
348
+ description: 'Generates a list of steps for the user to perform',
349
+ parameters: [
350
+ {
351
+ name: 'steps',
352
+ type: 'object[]',
353
+ attributes: [
354
+ { name: 'description', type: 'string' },
355
+ { name: 'status', type: 'string', enum: ['enabled', 'disabled', 'executing'] },
356
+ ],
357
+ },
358
+ ],
359
+ available: 'enabled',
360
+ // `respond` resumes the agent with the user's edited selection.
361
+ render: ({ args, respond, status }) => (
362
+ <StepsFeedback args={args} respond={respond} status={status} />
363
+ ),
364
+ })
365
+
366
+ return <CopilotChat labels={{ title: 'Planning Agent' }} />
367
+ }
368
+
369
+ export default function Page() {
370
+ return (
371
+ <CopilotKit runtimeUrl="http://localhost:4111/copilotkit" agent="planningAgent">
372
+ <Chat />
373
+ </CopilotKit>
374
+ )
375
+ }
376
+ ```
377
+
378
+ Inside `StepsFeedback`, let the user toggle steps and then call `respond({ accepted: true, steps })` to resume the agent, or `respond({ accepted: false })` to reject. The agent reads the returned value and continues accordingly. See the full component in the [UI Dojo](https://ui-dojo.mastra.ai/).
379
+
380
+ The example above uses a client tool: the agent calls `generate_task_steps` and the frontend fulfills it through `respond`. Mastra can also pause on the server, suspending a tool call before it executes so a human approves or supplies input. For that path, see Mastra's [Agent approval](https://mastra.ai/docs/agents/agent-approval) guide for the backend side and CopilotKit's [`useHumanInTheLoop`](https://docs.copilotkit.ai/reference/hooks/useHumanInTheLoop) reference for the frontend.
381
+
382
+ ## Configuration options
383
+
384
+ Use these `registerCopilotKit()` options for the common integration points:
385
+
386
+ | Option | Use it to |
387
+ | ---------------- | --------------------------------------------------------------------------------------------- |
388
+ | `path` | Set the route path, such as `/copilotkit`. |
389
+ | `resourceId` | Scope Mastra memory for conversations. |
390
+ | `cors` | Configure per-route CORS in addition to `server.cors`. |
391
+ | `setContext` | Populate request context before agents run, such as auth or per-user resource IDs. |
392
+ | `agents` | Provide pre-constructed AG-UI agents instead of the agents registered on the Mastra instance. |
393
+ | `tracingOptions` | Forward Mastra tracing options to each agent run. |
394
+
395
+ By default, the endpoint exposes every agent registered on the Mastra instance, and the frontend chooses one with the `agent` prop. Other CopilotKit runtime options are forwarded to the underlying runtime. For example, see [Open-ended generative UI](https://mastra.ai/guides/build-your-ui/copilotkit/generative-ui) for `mcpApps`.
396
+
397
+ ## Deployment
398
+
399
+ When deploying your Mastra server with CopilotKit, you must exclude `@copilotkit/runtime` from the bundle. This package contains dependencies that aren't compatible with bundling and will cause 500 errors if included.
400
+
401
+ > **Note:** This issue doesn't occur during development with `mastra dev` since it doesn't require bundling. However, anyone running `mastra build` for deployment will encounter this issue.
402
+
403
+ Add the `@copilotkit/runtime` package to your bundler externals configuration:
404
+
405
+ ```typescript
406
+ export const mastra = new Mastra({
407
+ bundler: {
408
+ externals: ['@copilotkit/runtime'],
409
+ },
410
+ })
411
+ ```
@@ -31,7 +31,7 @@ for await (const chunk of stream.textStream) {
31
31
 
32
32
  > **Info:** Visit [Agent.stream()](https://mastra.ai/reference/streaming/agents/stream) for more information.
33
33
 
34
- > **Tip:** For agents that dispatch [background tasks](https://mastra.ai/docs/agents/background-tasks), use [`Agent.streamUntilIdle()`](https://mastra.ai/reference/streaming/agents/streamUntilIdle) to keep the stream open until those tasks complete and the agent has had a chance to respond to their results.
34
+ > **Tip:** For agents that dispatch [background tasks](https://mastra.ai/docs/long-running-agents/background-tasks), use [`Agent.streamUntilIdle()`](https://mastra.ai/reference/streaming/agents/streamUntilIdle) to keep the stream open until those tasks complete and the agent has had a chance to respond to their results.
35
35
 
36
36
  ### Output from `Agent.stream()`
37
37
 
@@ -105,8 +105,7 @@ export default async function handler(req: VercelRequest, res: VercelResponse) {
105
105
  const agent = mastra.getAgent('myAgent')
106
106
  const result = await agent.generate([{ role: 'user', content: message }])
107
107
 
108
- const observability = mastra.getObservability()
109
- await observability?.flush()
108
+ await mastra.observability.flush()
110
109
 
111
110
  return res.json(result)
112
111
  }
@@ -14,11 +14,11 @@ The example watches build pipelines in a fake CI service, but the pattern applie
14
14
  - An API key from a supported [Model Provider](https://mastra.ai/models)
15
15
  - An existing Mastra project. Follow the [installation guide](https://mastra.ai/guides/getting-started/quickstart) if needed.
16
16
 
17
- This guide also assumes you understand [signals](https://mastra.ai/docs/agents/signals) at a high level. For the full API surface, see the [`SignalProvider` reference](https://mastra.ai/reference/signals/signal-provider).
17
+ This guide also assumes you understand [signals](https://mastra.ai/docs/long-running-agents/signals) at a high level. For the full API surface, see the [`SignalProvider` reference](https://mastra.ai/reference/signals/signal-provider).
18
18
 
19
19
  ## Add notification storage
20
20
 
21
- A signal provider pushes [notification signals](https://mastra.ai/docs/agents/signals) into threads, and notifications require a storage adapter that supports the notifications domain. Configure storage on your Mastra instance.
21
+ A signal provider pushes [notification signals](https://mastra.ai/docs/long-running-agents/signals) into threads, and notifications require a storage adapter that supports the notifications domain. Configure storage on your Mastra instance.
22
22
 
23
23
  ```typescript
24
24
  import { Mastra } from '@mastra/core'
@@ -207,13 +207,13 @@ You can extend this signal provider to:
207
207
 
208
208
  - Replace `fetchBuildStatus()` with a real API client.
209
209
  - Persist subscriptions so they survive a restart, then rehydrate them in [`start()`](https://mastra.ai/reference/signals/signal-provider).
210
- - Add a [webhook](https://mastra.ai/docs/agents/signal-providers) entry point with [`handleWebhook()`](https://mastra.ai/reference/signals/signal-provider) for push-based sources.
210
+ - Add a [webhook](https://mastra.ai/docs/long-running-agents/signal-providers) entry point with [`handleWebhook()`](https://mastra.ai/reference/signals/signal-provider) for push-based sources.
211
211
  - Expose `subscribe` and `unsubscribe` tools with [`getTools()`](https://mastra.ai/reference/signals/signal-provider) so the agent can manage its own subscriptions.
212
212
  - Use [`dedupeKey` and `coalesceKey`](https://mastra.ai/reference/agents/agent) when notifications need deduplication or batching.
213
213
 
214
214
  Learn more:
215
215
 
216
- - [Building signal providers](https://mastra.ai/docs/agents/signal-providers)
217
- - [Signals](https://mastra.ai/docs/agents/signals)
216
+ - [Building signal providers](https://mastra.ai/docs/long-running-agents/signal-providers)
217
+ - [Signals](https://mastra.ai/docs/long-running-agents/signals)
218
218
  - [`SignalProvider` reference](https://mastra.ai/reference/signals/signal-provider)
219
219
  - [`WebhookSignalProvider` reference](https://mastra.ai/reference/signals/webhook-signal-provider)
@@ -56,6 +56,7 @@ List of required environment variables for each model provider and gateway suppo
56
56
  | [Inference](https://mastra.ai/models/providers/inference) | `inference/*` | `INFERENCE_API_KEY` |
57
57
  | [IO.NET](https://mastra.ai/models/providers/io-net) | `io-net/*` | `IOINTELLIGENCE_API_KEY` |
58
58
  | [Jiekou.AI](https://mastra.ai/models/providers/jiekou) | `jiekou/*` | `JIEKOU_API_KEY` |
59
+ | [Kenari](https://mastra.ai/models/providers/kenari) | `kenari/*` | `KENARI_API_KEY` |
59
60
  | [Kilo Gateway](https://mastra.ai/models/providers/kilo) | `kilo/*` | `KILO_API_KEY` |
60
61
  | [Kimi For Coding](https://mastra.ai/models/providers/kimi-for-coding) | `kimi-for-coding/*` | `KIMI_API_KEY` |
61
62
  | [KUAE Cloud Coding Plan](https://mastra.ai/models/providers/kuae-cloud-coding-plan) | `kuae-cloud-coding-plan/*` | `KUAE_API_KEY` |
@@ -114,6 +115,7 @@ List of required environment variables for each model provider and gateway suppo
114
115
  | [submodel](https://mastra.ai/models/providers/submodel) | `submodel/*` | `SUBMODEL_INSTAGEN_ACCESS_KEY` |
115
116
  | [Synthetic](https://mastra.ai/models/providers/synthetic) | `synthetic/*` | `SYNTHETIC_API_KEY` |
116
117
  | [Tencent Coding Plan (China)](https://mastra.ai/models/providers/tencent-coding-plan) | `tencent-coding-plan/*` | `TENCENT_CODING_PLAN_API_KEY` |
118
+ | [Tencent Token Plan](https://mastra.ai/models/providers/tencent-token-plan) | `tencent-token-plan/*` | `TENCENT_TOKEN_PLAN_API_KEY` |
117
119
  | [Tencent TokenHub](https://mastra.ai/models/providers/tencent-tokenhub) | `tencent-tokenhub/*` | `TENCENT_TOKENHUB_API_KEY` |
118
120
  | [The Grid AI](https://mastra.ai/models/providers/the-grid-ai) | `the-grid-ai/*` | `THEGRIDAI_API_KEY` |
119
121
  | [Tinfoil](https://mastra.ai/models/providers/tinfoil) | `tinfoil/*` | `TINFOIL_API_KEY` |
@@ -2,7 +2,7 @@
2
2
 
3
3
  # Model Providers
4
4
 
5
- Mastra provides a unified interface for working with LLMs across multiple providers, giving you access to 4520 models from 137 providers through a single API.
5
+ Mastra provides a unified interface for working with LLMs across multiple providers, giving you access to 4544 models from 139 providers through a single API.
6
6
 
7
7
  ## Features
8
8