@mastra/mcp-docs-server 0.13.5 → 0.13.6

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 (80) hide show
  1. package/.docs/organized/changelogs/%40internal%2Fstorage-test-utils.md +76 -76
  2. package/.docs/organized/changelogs/%40mastra%2Fagui.md +61 -61
  3. package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +54 -54
  4. package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +194 -194
  5. package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +75 -75
  6. package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +91 -91
  7. package/.docs/organized/changelogs/%40mastra%2Fcore.md +171 -171
  8. package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +237 -237
  9. package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +143 -143
  10. package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +143 -143
  11. package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +233 -233
  12. package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +84 -84
  13. package/.docs/organized/changelogs/%40mastra%2Fevals.md +56 -56
  14. package/.docs/organized/changelogs/%40mastra%2Ffastembed.md +7 -0
  15. package/.docs/organized/changelogs/%40mastra%2Ffirecrawl.md +62 -62
  16. package/.docs/organized/changelogs/%40mastra%2Flance.md +55 -0
  17. package/.docs/organized/changelogs/%40mastra%2Flibsql.md +56 -56
  18. package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +25 -25
  19. package/.docs/organized/changelogs/%40mastra%2Fmcp.md +25 -25
  20. package/.docs/organized/changelogs/%40mastra%2Fmemory.md +119 -119
  21. package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +58 -58
  22. package/.docs/organized/changelogs/%40mastra%2Fmssql.md +69 -0
  23. package/.docs/organized/changelogs/%40mastra%2Fpg.md +119 -119
  24. package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +244 -244
  25. package/.docs/organized/changelogs/%40mastra%2Frag.md +61 -61
  26. package/.docs/organized/changelogs/%40mastra%2Fschema-compat.md +18 -0
  27. package/.docs/organized/changelogs/%40mastra%2Fserver.md +195 -195
  28. package/.docs/organized/changelogs/%40mastra%2Fupstash.md +76 -76
  29. package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +44 -44
  30. package/.docs/organized/changelogs/create-mastra.md +119 -119
  31. package/.docs/organized/changelogs/mastra.md +256 -256
  32. package/.docs/organized/code-examples/agent.md +6 -0
  33. package/.docs/organized/code-examples/agui.md +3 -3
  34. package/.docs/organized/code-examples/ai-sdk-useChat.md +2 -2
  35. package/.docs/organized/code-examples/ai-sdk-v5.md +201 -0
  36. package/.docs/organized/code-examples/assistant-ui.md +2 -2
  37. package/.docs/organized/code-examples/bird-checker-with-nextjs-and-eval.md +2 -2
  38. package/.docs/organized/code-examples/bird-checker-with-nextjs.md +2 -2
  39. package/.docs/organized/code-examples/client-side-tools.md +1 -1
  40. package/.docs/organized/code-examples/crypto-chatbot.md +5 -5
  41. package/.docs/organized/code-examples/openapi-spec-writer.md +2 -2
  42. package/.docs/organized/code-examples/workflow-with-suspend-resume.md +181 -0
  43. package/.docs/raw/agents/agent-memory.mdx +126 -0
  44. package/.docs/raw/agents/dynamic-agents.mdx +34 -2
  45. package/.docs/raw/agents/overview.mdx +5 -0
  46. package/.docs/raw/deployment/cloud-providers/amazon-ec2.mdx +60 -26
  47. package/.docs/raw/deployment/cloud-providers/index.mdx +44 -9
  48. package/.docs/raw/deployment/serverless-platforms/cloudflare-deployer.mdx +9 -30
  49. package/.docs/raw/deployment/serverless-platforms/index.mdx +13 -13
  50. package/.docs/raw/frameworks/agentic-uis/ai-sdk.mdx +291 -216
  51. package/.docs/raw/frameworks/agentic-uis/assistant-ui.mdx +0 -34
  52. package/.docs/raw/frameworks/agentic-uis/copilotkit.mdx +162 -181
  53. package/.docs/raw/frameworks/servers/express.mdx +1 -1
  54. package/.docs/raw/frameworks/web-frameworks/astro.mdx +2 -2
  55. package/.docs/raw/frameworks/web-frameworks/next-js.mdx +1 -1
  56. package/.docs/raw/frameworks/web-frameworks/sveltekit.mdx +4 -4
  57. package/.docs/raw/frameworks/web-frameworks/vite-react.mdx +1 -1
  58. package/.docs/raw/getting-started/installation.mdx +10 -7
  59. package/.docs/raw/getting-started/model-capability.mdx +1 -1
  60. package/.docs/raw/memory/overview.mdx +8 -0
  61. package/.docs/raw/memory/semantic-recall.mdx +6 -0
  62. package/.docs/raw/observability/tracing.mdx +30 -0
  63. package/.docs/raw/reference/agents/agent.mdx +2 -2
  64. package/.docs/raw/reference/cli/create-mastra.mdx +7 -0
  65. package/.docs/raw/reference/cli/dev.mdx +4 -3
  66. package/.docs/raw/reference/client-js/agents.mdx +8 -0
  67. package/.docs/raw/reference/memory/query.mdx +35 -14
  68. package/.docs/raw/reference/observability/providers/keywordsai.mdx +73 -0
  69. package/.docs/raw/reference/storage/mssql.mdx +108 -0
  70. package/.docs/raw/server-db/custom-api-routes.mdx +38 -26
  71. package/.docs/raw/tools-mcp/mcp-overview.mdx +24 -1
  72. package/.docs/raw/workflows/control-flow.mdx +85 -87
  73. package/.docs/raw/workflows/input-data-mapping.mdx +31 -43
  74. package/.docs/raw/workflows/overview.mdx +22 -12
  75. package/.docs/raw/workflows/pausing-execution.mdx +49 -4
  76. package/.docs/raw/workflows/suspend-and-resume.mdx +17 -16
  77. package/.docs/raw/workflows/using-with-agents-and-tools.mdx +16 -13
  78. package/.docs/raw/workflows-legacy/overview.mdx +11 -0
  79. package/package.json +6 -8
  80. package/.docs/raw/frameworks/ai-sdk-v5.mdx +0 -91
@@ -69,40 +69,6 @@ You now have a basic Mastra server project ready. You should have the following
69
69
  Ensure that you have set the appropriate environment variables for your LLM provider in the `.env` file.
70
70
  </Callout>
71
71
 
72
- ### Compatibility Fix
73
-
74
- Currently, to ensure proper compatibility between Mastra and Assistant UI, you need to setup server middleware. Update your `/mastra/index.ts` file with the following configuration:
75
-
76
- ```typescript showLineNumbers copy filename="src/mastra/index.ts"
77
- export const mastra = new Mastra({
78
- //mastra server middleware
79
- server:{
80
- middleware: [{
81
- path: '/api/agents/*/stream',
82
- handler: async (c,next)=>{
83
-
84
- const body = await c.req.json();
85
-
86
- if ('state' in body && body.state == null) {
87
- delete body.state;
88
- delete body.tools;
89
- }
90
-
91
- c.req.json = async() => body;
92
-
93
- return next()
94
- }
95
- }]
96
- },
97
- });
98
- ```
99
-
100
- This middleware ensures that when Assistant UI sends a request with `state: null` and `tools: {}` in the request body, we remove those properties to make the request work properly with Mastra.
101
-
102
- <Callout type="info">
103
- The `state: null` property can cause errors like `Cannot use 'in' operator to search for 'input' in null` in Mastra. Additionally, passing `tools: {}` overrides Mastra's built-in tools. Mastra only supports `clientTools` via the Mastra client SDK from the client side. For more information about client tools, see the [Client Tools documentation](/reference/client-js/agents#client-tools).
104
- </Callout>
105
-
106
72
  ### Run the Mastra Server
107
73
 
108
74
  Run the Mastra server using the following command:
@@ -3,147 +3,124 @@ title: "Using with CopilotKit"
3
3
  description: "Learn how Mastra leverages the CopilotKit's AGUI library and how you can leverage it to build user experiences"
4
4
  ---
5
5
 
6
- import { Tabs } from "nextra/components";
6
+ import { Tabs, Steps } from "nextra/components";
7
7
  import Image from "next/image";
8
8
 
9
- # Using with CopilotKit in React
9
+ # Integrate CopilotKit with Mastra
10
10
 
11
- CopilotKit provides React components to quickly integrate customizable AI copilots into your application.
12
- Combined with Mastra, you can build sophisticated AI apps featuring bidirectional state synchronization and interactive UIs.
11
+ CopilotKit 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.
13
12
 
14
- ## Create a Mastra Project
15
- {/*
16
- LLM CONTEXT:
17
- This Tabs component shows commands for creating a new Mastra project using different package managers.
18
- Each tab displays the command for that specific package manager to create a Mastra project.
19
- This is the first step in setting up Mastra with CopilotKit for building AI copilot applications.
20
- All commands create the same Mastra project but use different package manager syntax.
21
- */}
22
-
23
- <Tabs items={["npx", "npm", "yarn", "pnpm"]}>
24
- <Tabs.Tab>
25
- ```bash copy
26
- npx create-mastra@latest
27
- ```
28
- </Tabs.Tab>
29
- <Tabs.Tab>
30
- ```bash copy
31
- npm create mastra
32
- ```
33
- </Tabs.Tab>
34
- <Tabs.Tab>
35
- ```bash copy
36
- yarn create mastra
37
- ```
38
- </Tabs.Tab>
39
- <Tabs.Tab>
40
- ```bash copy
41
- pnpm create mastra
42
- ```
43
- </Tabs.Tab>
44
- </Tabs>
13
+ Visit the [CopilotKit documentation](https://docs.copilotkit.ai/) to learn more about CopilotKit concepts, components, and advanced usage patterns.
45
14
 
15
+ This guide shows two distinct integration approaches:
46
16
 
47
- Select the agent example when scaffolding your project. This will give you a weather agent.
17
+ 1. Integrate CopilotKit in your Mastra server with a separate React frontend.
18
+ 2. Integrate CopilotKit in your Next.js app
48
19
 
49
- For detailed setup instructions, see the [installation guide](/docs/getting-started/installation).
20
+ <Tabs items={["Mastra Server", "Next.js" ]}>
21
+ <Tabs.Tab>
50
22
 
51
- ## Basic Setup
23
+ <Steps>
24
+ ## Install React Dependencies
52
25
 
53
- Integrating Mastra with CopilotKit involves two main steps: setting up the backend runtime and configuring your frontend components.
54
- {/*
55
- LLM CONTEXT: This Tabs component shows installation commands for the CopilotKit runtime package.
56
- Each tab displays the installation command for that specific package manager.
57
- This installs the core CopilotKit runtime needed for backend integration with Mastra.
58
- All commands install the same @copilotkit/runtime package but use different package manager syntax.
59
- */}
26
+ In your React frontend, install the required CopilotKit packages:
60
27
 
61
28
  <Tabs items={["npm", "yarn", "pnpm"]}>
62
29
  <Tabs.Tab>
63
30
  ```bash copy
64
- npm install @copilotkit/runtime
31
+ npm install @copilotkit/react-core @copilotkit/react-ui
65
32
  ```
66
33
  </Tabs.Tab>
67
34
  <Tabs.Tab>
68
35
  ```bash copy
69
- yarn add @copilotkit/runtime
36
+ yarn add @copilotkit/react-core @copilotkit/react-ui
70
37
  ```
71
38
  </Tabs.Tab>
72
39
  <Tabs.Tab>
73
40
  ```bash copy
74
- pnpm add @copilotkit/runtime
41
+ pnpm add @copilotkit/react-core @copilotkit/react-ui
75
42
  ```
76
43
  </Tabs.Tab>
77
44
  </Tabs>
78
45
 
79
- ## Set up the runtime
46
+ ## Create CopilotKit Component
80
47
 
81
- You can leverage Mastra's custom API routes to add CopilotKit's runtime to your Mastra server.
48
+ Create a CopilotKit component in your React frontend:
82
49
 
83
- The current version of the integration leverages `MastraClient` to format Mastra agents into the AGUI format of CopilotKit.
50
+ ```tsx filename="components/copilotkit-component.tsx" showLineNumbers copy
51
+ import { CopilotChat } from "@copilotkit/react-ui";
52
+ import { CopilotKit } from "@copilotkit/react-core";
53
+ import "@copilotkit/react-ui/styles.css";
84
54
 
85
- {/*
86
- LLM CONTEXT: This Tabs component shows installation commands for the Mastra AGUI package.
87
- Each tab displays the installation command for that specific package manager.
88
- This installs the alpha version of @ag-ui/mastra which provides CopilotKit integration capabilities.
89
- All commands install the same @ag-ui/mastra package but use different package manager syntax.
90
- */}
55
+ export function CopilotKitComponent({ runtimeUrl }: { runtimeUrl: string}) {
56
+ return (
57
+ <CopilotKit
58
+ runtimeUrl={runtimeUrl}
59
+ agent="weatherAgent"
60
+ >
61
+ <CopilotChat
62
+ labels={{
63
+ title: "Your Assistant",
64
+ initial: "Hi! 👋 How can I assist you today?",
65
+ }}
66
+ />
67
+ </CopilotKit>
68
+ );
69
+ }
70
+ ```
71
+
72
+ ## Install Dependencies
73
+
74
+ If you have not yet set up your Mastra server, follow the [getting started guide](/docs/getting-started/installation) to set up a new Mastra project.
75
+
76
+ In your Mastra server, install additional packages for CopilotKit integration:
91
77
 
92
78
  <Tabs items={["npm", "yarn", "pnpm"]}>
93
79
  <Tabs.Tab>
94
80
  ```bash copy
95
- npm install @ag-ui/mastra
81
+ npm install @copilotkit/runtime @ag-ui/mastra
96
82
  ```
97
83
  </Tabs.Tab>
98
84
  <Tabs.Tab>
99
85
  ```bash copy
100
- yarn add @ag-ui/mastra
86
+ yarn add @copilotkit/runtime @ag-ui/mastra
101
87
  ```
102
88
  </Tabs.Tab>
103
89
  <Tabs.Tab>
104
90
  ```bash copy
105
- pnpm add @ag-ui/mastra
91
+ pnpm add @copilotkit/runtime @ag-ui/mastra
106
92
  ```
107
93
  </Tabs.Tab>
108
94
  </Tabs>
109
95
 
110
- Next, let's update the Mastra instance with a custom API route for CopilotKit.
96
+ ## Configure Mastra Server
111
97
 
112
- ```typescript filename="src/mastra/index.ts" showLineNumbers copy
98
+ Configure your Mastra instance to include CopilotKit's runtime endpoint:
99
+
100
+ ```typescript filename="src/mastra/index.ts" showLineNumbers copy {5-8,12-28}
113
101
  import { Mastra } from "@mastra/core/mastra";
114
- import { PinoLogger } from "@mastra/loggers";
115
- import { LibSQLStore } from "@mastra/libsql";
116
- import { CopilotRuntime, copilotRuntimeNodeHttpEndpoint, ExperimentalEmptyAdapter } from "@copilotkit/runtime";
117
102
  import { registerCopilotKit } from "@ag-ui/mastra";
118
103
  import { weatherAgent } from "./agents/weather-agent";
119
104
 
120
- const serviceAdapter = new ExperimentalEmptyAdapter();
105
+ type WeatherRuntimeContext = {
106
+ "user-id": string;
107
+ "temperature-scale": "celsius" | "fahrenheit";
108
+ };
121
109
 
122
110
  export const mastra = new Mastra({
123
111
  agents: { weatherAgent },
124
- storage: new LibSQLStore({
125
- // stores telemetry, evals, ... into memory storage,
126
- // if you need to persist, change to file:../mastra.db
127
- url: ":memory:"
128
- }),
129
- logger: new PinoLogger({
130
- name: "Mastra",
131
- level: "info"
132
- }),
133
112
  server: {
134
- // We will be calling this from a Vite App. Allow CORS
135
113
  cors: {
136
114
  origin: "*",
137
115
  allowMethods: ["*"],
138
116
  allowHeaders: ["*"]
139
117
  },
140
118
  apiRoutes: [
141
- registerCopilotKit({
119
+ registerCopilotKit<WeatherRuntimeContext>({
142
120
  path: "/copilotkit",
143
121
  resourceId: "weatherAgent",
144
122
  setContext: (c, runtimeContext) => {
145
- // Add whatever you need to the runtimeContext
146
- runtimeContext.set("user-id", c.req.header("X-User-ID"));
123
+ runtimeContext.set("user-id", c.req.header("X-User-ID") || "anonymous");
147
124
  runtimeContext.set("temperature-scale", "celsius");
148
125
  }
149
126
  })
@@ -152,47 +129,64 @@ export const mastra = new Mastra({
152
129
  });
153
130
  ```
154
131
 
155
- With this setup you now have CopilotKit running on your Mastra server. You can start your Mastra server with `mastra dev`.
132
+ ## Usage in your React App
133
+
134
+ Use the component in your React app with your Mastra server URL:
135
+
136
+ ```tsx filename="App.tsx" showLineNumbers copy {5}
137
+ import { CopilotKitComponent } from "./components/copilotkit-component";
138
+
139
+ function App() {
140
+ return (
141
+ <CopilotKitComponent runtimeUrl="http://localhost:4111/copilotkit" />
142
+ );
143
+ }
144
+
145
+ export default App;
146
+ ```
147
+
148
+ </Steps>
149
+ </Tabs.Tab>
150
+
151
+ <Tabs.Tab>
156
152
 
157
- ## Set up the UI
153
+ <Steps>
154
+ ## Install Dependencies
158
155
 
159
- Install CopilotKit's React components:
160
- {/*
161
- LLM CONTEXT: This Tabs component shows installation commands for CopilotKit's React UI components.
162
- Each tab displays the installation command for that specific package manager.
163
- This installs the React components needed for the frontend CopilotKit integration.
164
- All commands install the same @copilotkit/react-core and @copilotkit/react-ui packages but use different package manager syntax.
165
- */}
156
+ In your Next.js app, install the required packages:
166
157
 
167
158
  <Tabs items={["npm", "yarn", "pnpm"]}>
168
159
  <Tabs.Tab>
169
160
  ```bash copy
170
- npm install @copilotkit/react-core @copilotkit/react-ui
161
+ npm install @copilotkit/react-core @copilotkit/react-ui @copilotkit/runtime @ag-ui/mastra
171
162
  ```
172
163
  </Tabs.Tab>
173
164
  <Tabs.Tab>
174
165
  ```bash copy
175
- yarn add @copilotkit/react-core @copilotkit/react-ui
166
+ yarn add @copilotkit/react-core @copilotkit/react-ui @copilotkit/runtime @ag-ui/mastra
176
167
  ```
177
168
  </Tabs.Tab>
178
169
  <Tabs.Tab>
179
170
  ```bash copy
180
- pnpm add @copilotkit/react-core @copilotkit/react-ui
171
+ pnpm add @copilotkit/react-core @copilotkit/react-ui @copilotkit/runtime @ag-ui/mastra
181
172
  ```
182
173
  </Tabs.Tab>
183
174
  </Tabs>
184
175
 
185
- Next, add CopilotKit's React components to your frontend.
176
+ ## Create CopilotKit Component [#full-stack-nextjs-create-copilotkit-component]
186
177
 
187
- ```jsx copy
178
+ Create a CopilotKit component:
179
+
180
+ ```tsx filename="components/copilotkit-component.tsx" showLineNumbers copy
181
+ 'use client';
188
182
  import { CopilotChat } from "@copilotkit/react-ui";
189
183
  import { CopilotKit } from "@copilotkit/react-core";
190
184
  import "@copilotkit/react-ui/styles.css";
191
185
 
192
- export function CopilotKitComponent() {
193
- return (
186
+ export function CopilotKitComponent({ runtimeUrl }: { runtimeUrl: string}) {
187
+ return ( y
194
188
  <CopilotKit
195
- runtimeUrl="http://localhost:4111/copilotkit"
189
+ runtimeUrl={runtimeUrl}
196
190
  agent="weatherAgent"
197
191
  >
198
192
  <CopilotChat
@@ -206,43 +200,32 @@ export function CopilotKitComponent() {
206
200
  }
207
201
  ```
208
202
 
209
- Render the component and start building the future!
203
+ ## Create API Route
210
204
 
211
- <br />
205
+ There are two approaches for the API route determined by how you're integrating Mastra in your Next.js application.
212
206
 
213
- <Image
214
- className="rounded-lg"
215
- src="/image/copilotkit/cpkoutput.jpg"
216
- alt="CopilotKit output"
217
- width={700}
218
- height={700}
219
- />
207
+ 1. For a full-stack Next.js app with an instance of Mastra integrated into the app.
208
+ 2. For a Next.js app with a separate Mastra server and the Mastra Client SDK.
220
209
 
221
- ## Using with other frameworks (NextJS)
210
+ <Tabs items={["With a Mastra instance", "With the Mastra Client SDK"]}>
211
+ <Tabs.Tab>
222
212
 
223
- You can still leverage AGUI without going through Mastra Server.
213
+ Create an API route that connects to local Mastra agents.
224
214
 
225
- ```typescript copy
226
- // import your mastra instance from dir
227
- import { mastra } from "../path/to/mastra";
215
+ ```typescript filename="app/api/copilotkit/route.ts" showLineNumbers copy {1-7,11-26}
216
+ import { mastra } from "../../mastra";
228
217
  import {
229
218
  CopilotRuntime,
230
219
  ExperimentalEmptyAdapter,
231
220
  copilotRuntimeNextJSAppRouterEndpoint,
232
221
  } from "@copilotkit/runtime";
233
- import { NextRequest } from "next/server";
234
222
  import { MastraAgent } from "@ag-ui/mastra";
223
+ import { NextRequest } from "next/server";
235
224
 
236
225
  export const POST = async (req: NextRequest) => {
237
- // Clone the request before reading the body
238
- const clonedReq = req.clone();
239
- const body = await clonedReq.json();
240
- const resourceId = body.resourceId || "TEST";
241
-
242
226
  const mastraAgents = MastraAgent.getLocalAgents({
243
- resourceId,
244
227
  mastra,
245
- runtimeContext,
228
+ agentId: "weatherAgent",
246
229
  });
247
230
 
248
231
  const runtime = new CopilotRuntime({
@@ -255,33 +238,50 @@ export const POST = async (req: NextRequest) => {
255
238
  endpoint: "/api/copilotkit",
256
239
  });
257
240
 
258
- // Use the original request for handleRequest
259
241
  return handleRequest(req);
260
242
  };
261
243
  ```
262
244
 
263
- ## Using with Mastra Client SDK
245
+ </Tabs.Tab>
246
+ <Tabs.Tab>
247
+
248
+ ## Install the Mastra Client SDK
249
+
250
+ Install the Mastra Client SDK.
251
+
252
+ <Tabs items={["npm", "yarn", "pnpm"]}>
253
+ <Tabs.Tab>
254
+ ```bash copy
255
+ npm install @mastra/client-js
256
+ ```
257
+ </Tabs.Tab>
258
+ <Tabs.Tab>
259
+ ```bash copy
260
+ yarn add @mastra/client-js
261
+ ```
262
+ </Tabs.Tab>
263
+ <Tabs.Tab>
264
+ ```bash copy
265
+ pnpm add @mastra/client-js
266
+ ```
267
+ </Tabs.Tab>
268
+ </Tabs>
269
+
270
+ Create an API route that connects to remote Mastra agents:
264
271
 
265
- ```typescript copy
272
+ ```typescript filename="app/api/copilotkit/route.ts" showLineNumbers copy {1-7,12-26}
266
273
  import { MastraClient } from "@mastra/client-js";
267
274
  import {
268
275
  CopilotRuntime,
269
276
  ExperimentalEmptyAdapter,
270
277
  copilotRuntimeNextJSAppRouterEndpoint,
271
278
  } from "@copilotkit/runtime";
272
- import { NextRequest } from "next/server";
273
279
  import { MastraAgent } from "@ag-ui/mastra";
280
+ import { NextRequest } from "next/server";
274
281
 
275
282
  export const POST = async (req: NextRequest) => {
276
- // Clone the request before reading the body
277
- const clonedReq = req.clone();
278
- const body = await clonedReq.json();
279
- const resourceId = body.resourceId || "TEST";
280
-
281
283
  const baseUrl = process.env.MASTRA_BASE_URL || "http://localhost:4111";
282
- const mastraClient = new MastraClient({
283
- baseUrl,
284
- });
284
+ const mastraClient = new MastraClient({ baseUrl });
285
285
 
286
286
  const mastraAgents = await MastraAgent.getRemoteAgents({ mastraClient });
287
287
 
@@ -295,66 +295,47 @@ export const POST = async (req: NextRequest) => {
295
295
  endpoint: "/api/copilotkit",
296
296
  });
297
297
 
298
- // Use the original request for handleRequest
299
298
  return handleRequest(req);
300
299
  };
301
300
  ```
302
301
 
302
+ </Tabs.Tab>
303
+ </Tabs>
303
304
 
304
- ## Using Typed Runtime Context
305
-
306
- For better type safety, you can specify the type of your runtime context:
305
+ ## Use Component
307
306
 
308
- ```typescript filename="src/mastra/index.ts" showLineNumbers copy
309
- import { Mastra } from "@mastra/core/mastra";
310
- import { PinoLogger } from "@mastra/loggers";
311
- import { LibSQLStore } from "@mastra/libsql";
312
- import { registerCopilotKit } from "@ag-ui/mastra";
313
- import { weatherAgent } from "./agents";
307
+ Use the component with the local API endpoint:
314
308
 
315
- // Define your runtime context type
316
- type WeatherRuntimeContext = {
317
- "user-id": string;
318
- "temperature-scale": "celsius" | "fahrenheit";
319
- "api-key": string;
320
- };
309
+ ```tsx filename="App.tsx" showLineNumbers copy {5}
310
+ import { CopilotKitComponent } from "./components/copilotkit-component";
321
311
 
322
- export const mastra = new Mastra({
323
- agents: { weatherAgent },
324
- storage: new LibSQLStore({
325
- url: ":memory:",
326
- }),
327
- logger: new PinoLogger({
328
- name: "Mastra",
329
- level: "info",
330
- }),
331
- server: {
332
- cors: {
333
- origin: "*",
334
- allowMethods: ["*"],
335
- allowHeaders: ["*"],
336
- },
337
- apiRoutes: [
338
- registerCopilotKit<WeatherRuntimeContext>({
339
- path: "/copilotkit",
340
- resourceId: "weatherAgent",
341
- setContext: (c, runtimeContext) => {
342
- // TypeScript will enforce the correct types here
343
- runtimeContext.set("user-id", c.req.header("X-User-ID") || "anonymous");
344
- runtimeContext.set("temperature-scale", "celsius"); // Only "celsius" | "fahrenheit" allowed
345
- runtimeContext.set("api-key", process.env.WEATHER_API_KEY || "");
312
+ function App() {
313
+ return (
314
+ <CopilotKitComponent runtimeUrl="/api/copilotkit" />
315
+ );
316
+ }
346
317
 
347
- // This would cause a TypeScript error:
348
- // runtimeContext.set("invalid-key", "value"); // ❌ Error: invalid key
349
- // runtimeContext.set("temperature-scale", "kelvin"); // ❌ Error: invalid value
350
- }
351
- }),
352
- ],
353
- },
354
- });
318
+ export default App;
355
319
  ```
356
320
 
357
- ## Further Reading
321
+ </Steps>
322
+ </Tabs.Tab>
323
+ </Tabs>
324
+
325
+ Start building the future!
326
+
327
+ <br />
328
+
329
+ <Image
330
+ className="rounded-lg"
331
+ src="/image/copilotkit/cpkoutput.jpg"
332
+ alt="CopilotKit output"
333
+ width={700}
334
+ height={700}
335
+ />
336
+
337
+ ## Next Steps
358
338
 
359
- - [CopilotKit Documentation](https://docs.copilotkit.ai)
360
- - [React Hooks with CopilotKit](https://docs.copilotkit.ai/reference/hooks/useCoAgent)
339
+ - [CopilotKit Documentation](https://docs.copilotkit.ai) - Complete CopilotKit reference
340
+ - [React Hooks with CopilotKit](https://docs.copilotkit.ai/reference/hooks/useCoAgent) - Advanced React integration patterns
341
+ - [Next.js Integration with Mastra](/docs/frameworks/web-frameworks/next-js) - Full-stack Next.js setup guide
@@ -136,7 +136,7 @@ Start the Mastra dev server to expose your agents as REST endpoints:
136
136
  </Tabs.Tab>
137
137
  </Tabs>
138
138
 
139
- > Once running, your agents are available locally. See [Local Development Environment](/docs/local-dev/mastra-dev) for more information.
139
+ > Once running, your agents are available locally. See [Local Development Environment](/docs/server-db/local-dev-playground) for more information.
140
140
 
141
141
  ## Example Express App
142
142
 
@@ -149,7 +149,7 @@ Start the Mastra Dev Server to expose your agents as REST endpoints:
149
149
  </Tabs.Tab>
150
150
  </Tabs>
151
151
 
152
- > Once running, your agents are available locally. See [Local Development Environment](/docs/local-dev/mastra-dev) for more information.
152
+ > Once running, your agents are available locally. See [Local Development Environment](/docs/server-db/local-dev-playground) for more information.
153
153
 
154
154
  ## Start Astro Dev Server
155
155
 
@@ -402,7 +402,7 @@ Start the Mastra Dev Server to expose your agents as REST endpoints:
402
402
  </Tabs.Tab>
403
403
  </Tabs>
404
404
 
405
- > Once running, your agents are available locally. See [Local Development Environment](/docs/local-dev/mastra-dev) for more information.
405
+ > Once running, your agents are available locally. See [Local Development Environment](/docs/server-db/local-dev-playground) for more information.
406
406
 
407
407
  ## Start Astro Dev Server
408
408
 
@@ -168,7 +168,7 @@ Start the Mastra Dev Server to expose your agents as REST endpoints:
168
168
  </Tabs.Tab>
169
169
  </Tabs>
170
170
 
171
- > Once running, your agents are available locally. See [Local Development Environment](/docs/local-dev/mastra-dev) for more information.
171
+ > Once running, your agents are available locally. See [Local Development Environment](/docs/server-db/local-dev-playground) for more information.
172
172
 
173
173
  ## Start Next.js Dev Server
174
174
 
@@ -99,7 +99,7 @@ Modify the `tsconfig.json` file in your project root:
99
99
 
100
100
  ## Set Up API Key
101
101
 
102
- The `VITE_` prefix is required for environment variables to be accessible in the Vite environment, that SvelteKit uses.
102
+ The `VITE_` prefix is required for environment variables to be accessible in the Vite environment, that SvelteKit uses.
103
103
  [Read more about Vite environment variables](https://vite.dev/guide/env-and-mode.html#env-variables).
104
104
 
105
105
  ```bash filename=".env" copy
@@ -147,7 +147,7 @@ Start the Mastra Dev Server to expose your agents as REST endpoints:
147
147
  </Tabs.Tab>
148
148
  </Tabs>
149
149
 
150
- > Once running, your agents are available locally. See [Local Development Environment](/docs/local-dev/mastra-dev) for more information.
150
+ > Once running, your agents are available locally. See [Local Development Environment](/docs/server-db/local-dev-playground) for more information.
151
151
 
152
152
  ## Start SvelteKit Dev Server
153
153
 
@@ -311,7 +311,7 @@ Modify the `tsconfig.json` file in your project root:
311
311
 
312
312
  ## Set Up API Key
313
313
 
314
- The `VITE_` prefix is required for environment variables to be accessible in the Vite environment, that SvelteKit uses.
314
+ The `VITE_` prefix is required for environment variables to be accessible in the Vite environment, that SvelteKit uses.
315
315
  [Read more about Vite environment variables](https://vite.dev/guide/env-and-mode.html#env-variables).
316
316
 
317
317
  ```bash filename=".env" copy
@@ -359,7 +359,7 @@ Start the Mastra Dev Server to expose your agents as REST endpoints:
359
359
  </Tabs.Tab>
360
360
  </Tabs>
361
361
 
362
- > Once running, your agents are available locally. See [Local Development Environment](/docs/local-dev/mastra-dev) for more information.
362
+ > Once running, your agents are available locally. See [Local Development Environment](/docs/server-db/local-dev-playground) for more information.
363
363
 
364
364
  ## Start SvelteKit Dev Server
365
365
 
@@ -150,7 +150,7 @@ Start the Mastra Dev Server to expose your agents as REST endpoints:
150
150
  </Tabs.Tab>
151
151
  </Tabs>
152
152
 
153
- > Once running, your agents are available locally. See [Local Development Environment](/docs/local-dev/mastra-dev) for more information.
153
+ > Once running, your agents are available locally. See [Local Development Environment](/docs/server-db/local-dev-playground) for more information.
154
154
 
155
155
  ## Start Vite Dev Server
156
156