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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/.docs/organized/changelogs/%40internal%2Fchangeset-cli.md +1 -15
  2. package/.docs/organized/changelogs/%40internal%2Fexternal-types.md +1 -7
  3. package/.docs/organized/changelogs/%40internal%2Ftypes-builder.md +1 -55
  4. package/.docs/organized/changelogs/%40mastra%2Fai-sdk.md +39 -39
  5. package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +10 -10
  6. package/.docs/organized/changelogs/%40mastra%2Fcodemod.md +6 -0
  7. package/.docs/organized/changelogs/%40mastra%2Fcore.md +58 -58
  8. package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +9 -9
  9. package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +11 -11
  10. package/.docs/organized/changelogs/%40mastra%2Flibsql.md +49 -49
  11. package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +9 -9
  12. package/.docs/organized/changelogs/%40mastra%2Fmcp.md +12 -12
  13. package/.docs/organized/changelogs/%40mastra%2Fpg.md +49 -49
  14. package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +21 -21
  15. package/.docs/organized/changelogs/%40mastra%2Freact.md +7 -0
  16. package/.docs/organized/changelogs/%40mastra%2Fserver.md +49 -49
  17. package/.docs/organized/changelogs/create-mastra.md +13 -13
  18. package/.docs/organized/changelogs/mastra.md +21 -21
  19. package/.docs/organized/code-examples/mcp-server-adapters.md +1 -2
  20. package/.docs/organized/code-examples/processors-with-ai-sdk.md +14 -0
  21. package/.docs/organized/code-examples/server-app-access.md +1 -1
  22. package/.docs/organized/code-examples/server-hono-adapter.md +1 -1
  23. package/.docs/raw/getting-started/studio.mdx +4 -2
  24. package/.docs/raw/guides/agent-frameworks/ai-sdk.mdx +161 -0
  25. package/.docs/raw/guides/build-your-ui/ai-sdk-ui.mdx +4 -4
  26. package/.docs/raw/guides/migrations/upgrade-to-v1/tools.mdx +3 -3
  27. package/.docs/raw/reference/client-js/agents.mdx +251 -67
  28. package/.docs/raw/reference/client-js/mastra-client.mdx +2 -2
  29. package/.docs/raw/reference/client-js/memory.mdx +4 -1
  30. package/.docs/raw/reference/core/getMemory.mdx +73 -0
  31. package/.docs/raw/reference/core/getStoredAgentById.mdx +183 -0
  32. package/.docs/raw/reference/core/listMemory.mdx +70 -0
  33. package/.docs/raw/reference/core/listStoredAgents.mdx +151 -0
  34. package/.docs/raw/reference/core/mastra-class.mdx +8 -0
  35. package/.docs/raw/reference/server/express-adapter.mdx +52 -0
  36. package/.docs/raw/reference/server/hono-adapter.mdx +54 -0
  37. package/.docs/raw/server-db/server-adapters.mdx +94 -91
  38. package/.docs/raw/streaming/tool-streaming.mdx +10 -14
  39. package/CHANGELOG.md +8 -0
  40. package/package.json +4 -4
@@ -11,11 +11,11 @@ Tool execution signatures have been updated to use separate input and context pa
11
11
 
12
12
  ### `createTool` execute signature to `(inputData, context)` format
13
13
 
14
- All **`createTool`** execute functions now use a new signature with separate `inputData` and `context` parameters instead of a single destructured object. This change provides clearer separation between tool inputs and execution context.
14
+ All `createTool` execute functions now use a new signature with separate `inputData` and `context` parameters instead of a single destructured object. This change provides clearer separation between tool inputs and execution context.
15
15
 
16
16
  **Note:** This change only applies to `createTool`. If you're using `createStep` for workflows, the signature remains `async (inputData, context)` and does not need to be changed.
17
17
 
18
- To migrate, update **`createTool`** signatures to use `inputData` as the first parameter (typed from `inputSchema`) and `context` as the second parameter.
18
+ To migrate, update `createTool` signatures to use `inputData` as the first parameter (typed from `inputSchema`) and `context` as the second parameter.
19
19
 
20
20
  ```diff
21
21
  createTool({
@@ -35,7 +35,7 @@ To migrate, update **`createTool`** signatures to use `inputData` as the first p
35
35
 
36
36
  ### `createTool` context properties organization
37
37
 
38
- Context properties in **`createTool`** are now organized into namespaces. Agent-specific properties are under `context.agent`, workflow-specific properties are under `context.workflow`, and MCP-specific properties are under `context.mcp`. This change provides better organization and clearer API surface.
38
+ Context properties in `createTool` are now organized into namespaces. Agent-specific properties are under `context.agent`, workflow-specific properties are under `context.workflow`, and MCP-specific properties are under `context.mcp`. This change provides better organization and clearer API surface.
39
39
 
40
40
  For tools that are executed inside an agent, access agent-specific properties through `context.agent`.
41
41
 
@@ -15,19 +15,26 @@ Retrieve a list of all available agents:
15
15
  const agents = await mastraClient.listAgents();
16
16
  ```
17
17
 
18
- Returns a record of agent IDs to their serialized agent configurations. See the [Agent class reference](/reference/v1/agents/agent) for details on agent properties.
18
+ Returns a record of agent IDs to their serialized agent configurations.
19
19
 
20
20
  ## Working with a Specific Agent
21
21
 
22
- Get an instance of a specific agent:
22
+ Get an instance of a specific agent by its ID:
23
+
24
+ ```typescript title="src/mastra/agents/my-agent.ts"
25
+ export const myAgent = new Agent({
26
+ id: "my-agent",
27
+ // ...
28
+ });
29
+ ```
23
30
 
24
31
  ```typescript
25
- const agent = mastraClient.getAgent("agent-id");
32
+ const agent = mastraClient.getAgent("my-agent");
26
33
  ```
27
34
 
28
35
  ## Agent Methods
29
36
 
30
- ### Get Agent Details
37
+ ### details()
31
38
 
32
39
  Retrieve detailed information about an agent:
33
40
 
@@ -35,9 +42,7 @@ Retrieve detailed information about an agent:
35
42
  const details = await agent.details();
36
43
  ```
37
44
 
38
- Returns the serialized agent configuration. See the [Agent class reference](/reference/v1/agents/agent) for details on agent properties.
39
-
40
- ### Generate Response
45
+ ### generate()
41
46
 
42
47
  Generate a response from the agent:
43
48
 
@@ -55,7 +60,16 @@ const response = await agent.generate({
55
60
  });
56
61
  ```
57
62
 
58
- ### Stream Response
63
+ You can also use the simplified string format:
64
+
65
+ ```typescript
66
+ const response = await agent.generate("Hello, how are you?", {
67
+ threadId: "thread-1",
68
+ resourceId: "resource-1",
69
+ });
70
+ ```
71
+
72
+ ### stream()
59
73
 
60
74
  Stream responses from the agent for real-time interactions:
61
75
 
@@ -75,8 +89,28 @@ response.processDataStream({
75
89
  console.log(chunk);
76
90
  },
77
91
  });
92
+ ```
93
+
94
+ You can also use the simplified string format:
95
+
96
+ ```typescript
97
+ const response = await agent.stream("Tell me a story", {
98
+ threadId: "thread-1",
99
+ clientTools: { colorChangeTool },
100
+ });
101
+
102
+ response.processDataStream({
103
+ onChunk: async (chunk) => {
104
+ if (chunk.type === "text-delta") {
105
+ console.log(chunk.payload.text);
106
+ }
107
+ },
108
+ });
109
+ ```
110
+
111
+ You can also read from response body directly:
78
112
 
79
- // You can also read from response body directly
113
+ ```typescript
80
114
  const reader = response.body.getReader();
81
115
  while (true) {
82
116
  const { done, value } = await reader.read();
@@ -85,11 +119,119 @@ while (true) {
85
119
  }
86
120
  ```
87
121
 
88
- ### Client tools
122
+ #### AI SDK compatible format
89
123
 
90
- Client-side tools allow you to execute custom functions on the client side when the agent requests them.
124
+ To stream AI SDK-formatted parts on the client from an `agent.stream(...)` response, wrap `response.processDataStream` into a `ReadableStream<ChunkType>` and use `toAISdkStream`:
125
+
126
+ ```typescript title="client-ai-sdk-transform.ts" copy
127
+ import { createUIMessageStream } from "ai";
128
+ import { toAISdkStream } from "@mastra/ai-sdk";
129
+ import type { ChunkType, MastraModelOutput } from "@mastra/core/stream";
130
+
131
+ const response = await agent.stream({ messages: "Tell me a story" });
132
+
133
+ const chunkStream: ReadableStream<ChunkType> = new ReadableStream<ChunkType>({
134
+ start(controller) {
135
+ response
136
+ .processDataStream({
137
+ onChunk: async (chunk) => controller.enqueue(chunk as ChunkType),
138
+ })
139
+ .finally(() => controller.close());
140
+ },
141
+ });
142
+
143
+ const uiMessageStream = createUIMessageStream({
144
+ execute: async ({ writer }) => {
145
+ for await (const part of toAISdkStream(
146
+ chunkStream as unknown as MastraModelOutput,
147
+ { from: "agent" },
148
+ )) {
149
+ writer.write(part);
150
+ }
151
+ },
152
+ });
153
+
154
+ for await (const part of uiMessageStream) {
155
+ console.log(part);
156
+ }
157
+ ```
158
+
159
+ ### getTool()
160
+
161
+ Retrieve information about a specific tool available to the agent:
162
+
163
+ ```typescript
164
+ const tool = await agent.getTool("tool-id");
165
+ ```
166
+
167
+ ### executeTool()
168
+
169
+ Execute a specific tool for the agent:
170
+
171
+ ```typescript
172
+ const result = await agent.executeTool("tool-id", {
173
+ data: { input: "value" },
174
+ });
175
+ ```
176
+
177
+ ### network()
178
+
179
+ Stream responses from an agent network for multi-agent interactions:
180
+
181
+ ```typescript
182
+ const response = await agent.network({
183
+ messages: [
184
+ {
185
+ role: "user",
186
+ content: "Research this topic and write a summary",
187
+ },
188
+ ],
189
+ });
190
+
191
+ response.processDataStream({
192
+ onChunk: async (chunk) => {
193
+ console.log(chunk);
194
+ },
195
+ });
196
+ ```
197
+
198
+ ### approveToolCall()
199
+
200
+ Approve a pending tool call that requires human confirmation:
201
+
202
+ ```typescript
203
+ const response = await agent.approveToolCall({
204
+ runId: "run-123",
205
+ toolCallId: "tool-call-456",
206
+ });
207
+
208
+ response.processDataStream({
209
+ onChunk: async (chunk) => {
210
+ console.log(chunk);
211
+ },
212
+ });
213
+ ```
214
+
215
+ ### declineToolCall()
216
+
217
+ Decline a pending tool call that requires human confirmation:
218
+
219
+ ```typescript
220
+ const response = await agent.declineToolCall({
221
+ runId: "run-123",
222
+ toolCallId: "tool-call-456",
223
+ });
224
+
225
+ response.processDataStream({
226
+ onChunk: async (chunk) => {
227
+ console.log(chunk);
228
+ },
229
+ });
230
+ ```
231
+
232
+ ## Client Tools
91
233
 
92
- #### Basic Usage
234
+ Client-side tools allow you to execute custom functions on the client side when the agent requests them.
93
235
 
94
236
  ```typescript
95
237
  import { createTool } from "@mastra/client-js";
@@ -132,90 +274,132 @@ response.processDataStream({
132
274
  });
133
275
  ```
134
276
 
135
- ### Get Agent Tool
277
+ ## Stored Agents
136
278
 
137
- Retrieve information about a specific tool available to the agent:
279
+ Stored agents are agent configurations stored in a database that can be created, updated, and deleted at runtime. They reference primitives (tools, workflows, other agents, memory, scorers) by key, which are resolved from the Mastra registry when the agent is instantiated.
280
+
281
+ ### listStoredAgents()
282
+
283
+ Retrieve a paginated list of all stored agents:
138
284
 
139
285
  ```typescript
140
- const tool = await agent.getTool("tool-id");
286
+ const result = await mastraClient.listStoredAgents();
287
+ console.log(result.agents); // Array of stored agents
288
+ console.log(result.total); // Total count
141
289
  ```
142
290
 
143
- ### Get Agent Evaluations
144
-
145
- Get evaluation results for the agent:
291
+ With pagination and ordering:
146
292
 
147
293
  ```typescript
148
- // Get CI evaluations
149
- const evals = await agent.evals();
150
-
151
- // Get live evaluations
152
- const liveEvals = await agent.liveEvals();
294
+ const result = await mastraClient.listStoredAgents({
295
+ page: 0,
296
+ perPage: 20,
297
+ orderBy: {
298
+ field: "createdAt",
299
+ direction: "DESC",
300
+ },
301
+ });
153
302
  ```
154
303
 
155
- ### Stream
304
+ ### createStoredAgent()
156
305
 
157
- Stream responses using the enhanced API with improved method signatures. This method provides enhanced capabilities and format flexibility, with support for Mastra's native format.
306
+ Create a new stored agent:
158
307
 
159
308
  ```typescript
160
- const response = await agent.stream("Tell me a story", {
161
- threadId: "thread-1",
162
- clientTools: { colorChangeTool },
309
+ const agent = await mastraClient.createStoredAgent({
310
+ id: "my-agent",
311
+ name: "My Assistant",
312
+ instructions: "You are a helpful assistant.",
313
+ model: {
314
+ provider: "openai",
315
+ name: "gpt-4",
316
+ },
163
317
  });
318
+ ```
164
319
 
165
- // Process the stream
166
- response.processDataStream({
167
- onChunk: async (chunk) => {
168
- if (chunk.type === "text-delta") {
169
- console.log(chunk.payload.text);
170
- }
320
+ With all options:
321
+
322
+ ```typescript
323
+ const agent = await mastraClient.createStoredAgent({
324
+ id: "full-agent",
325
+ name: "Full Agent",
326
+ description: "A fully configured agent",
327
+ instructions: "You are a helpful assistant.",
328
+ model: {
329
+ provider: "openai",
330
+ name: "gpt-4",
331
+ },
332
+ tools: ["calculator", "weather"],
333
+ workflows: ["data-processing"],
334
+ agents: ["sub-agent-1"],
335
+ memory: "my-memory",
336
+ scorers: {
337
+ "quality-scorer": {
338
+ sampling: { type: "ratio", rate: 0.1 },
339
+ },
340
+ },
341
+ defaultOptions: {
342
+ maxSteps: 10,
343
+ },
344
+ metadata: {
345
+ version: "1.0",
346
+ team: "engineering",
171
347
  },
172
348
  });
173
349
  ```
174
350
 
175
- #### AI SDK compatible format
351
+ ### getStoredAgent()
176
352
 
177
- To stream AI SDK-formatted parts on the client from an `agent.stream(...)` response, wrap `response.processDataStream` into a `ReadableStream<ChunkType>` and use `toAISdkStream`:
353
+ Get an instance of a specific stored agent:
178
354
 
179
- ```typescript title="client-ai-sdk-transform.ts" copy
180
- import { createUIMessageStream } from "ai";
181
- import { toAISdkStream } from "@mastra/ai-sdk";
182
- import type { ChunkType, MastraModelOutput } from "@mastra/core/stream";
355
+ ```typescript
356
+ const storedAgent = mastraClient.getStoredAgent("my-agent");
357
+ ```
183
358
 
184
- const response = await agent.stream({ messages: "Tell me a story" });
359
+ ## Stored Agent Methods
185
360
 
186
- const chunkStream: ReadableStream<ChunkType> = new ReadableStream<ChunkType>({
187
- start(controller) {
188
- response
189
- .processDataStream({
190
- onChunk: async (chunk) => controller.enqueue(chunk as ChunkType),
191
- })
192
- .finally(() => controller.close());
193
- },
361
+ ### details()
362
+
363
+ Retrieve the stored agent configuration:
364
+
365
+ ```typescript
366
+ const details = await storedAgent.details();
367
+ console.log(details.name);
368
+ console.log(details.instructions);
369
+ console.log(details.model);
370
+ ```
371
+
372
+ ### update()
373
+
374
+ Update specific fields of a stored agent. All fields are optional:
375
+
376
+ ```typescript
377
+ const updated = await storedAgent.update({
378
+ name: "Updated Agent Name",
379
+ instructions: "New instructions for the agent.",
194
380
  });
381
+ ```
195
382
 
196
- const uiMessageStream = createUIMessageStream({
197
- execute: async ({ writer }) => {
198
- for await (const part of toAISdkStream(
199
- chunkStream as unknown as MastraModelOutput,
200
- { from: "agent" },
201
- )) {
202
- writer.write(part);
203
- }
204
- },
383
+ ```typescript
384
+ // Update just the tools
385
+ await storedAgent.update({
386
+ tools: ["new-tool-1", "new-tool-2"],
205
387
  });
206
388
 
207
- for await (const part of uiMessageStream) {
208
- console.log(part);
209
- }
389
+ // Update metadata
390
+ await storedAgent.update({
391
+ metadata: {
392
+ version: "2.0",
393
+ lastModifiedBy: "admin",
394
+ },
395
+ });
210
396
  ```
211
397
 
212
- ### Generate
398
+ ### delete()
213
399
 
214
- Generate a response using the enhanced API with improved method signatures and AI SDK v5 compatibility:
400
+ Delete a stored agent:
215
401
 
216
402
  ```typescript
217
- const response = await agent.generate("Hello, how are you?", {
218
- threadId: "thread-1",
219
- resourceId: "resource-1",
220
- });
403
+ const result = await storedAgent.delete();
404
+ console.log(result.success); // true
221
405
  ```
@@ -101,8 +101,8 @@ export const mastraClient = new MastraClient({
101
101
  },
102
102
  {
103
103
  name: "saveMessageToMemory(params)",
104
- type: "Promise<void>",
105
- description: "Saves one or more messages to the memory system.",
104
+ type: "Promise<{ messages: (MastraMessageV1 | MastraDBMessage)[] }>",
105
+ description: "Saves one or more messages to the memory system. Returns the saved messages.",
106
106
  },
107
107
  {
108
108
  name: "getMemoryStatus()",
@@ -76,7 +76,7 @@ await thread.delete();
76
76
  Save messages to memory:
77
77
 
78
78
  ```typescript
79
- const savedMessages = await mastraClient.saveMessageToMemory({
79
+ const result = await mastraClient.saveMessageToMemory({
80
80
  messages: [
81
81
  {
82
82
  role: "user",
@@ -90,6 +90,9 @@ const savedMessages = await mastraClient.saveMessageToMemory({
90
90
  ],
91
91
  agentId: "agent-1",
92
92
  });
93
+
94
+ // result.messages contains the saved messages
95
+ console.log(result.messages);
93
96
  ```
94
97
 
95
98
  ### Retrieve Thread Messages
@@ -0,0 +1,73 @@
1
+ ---
2
+ title: "Reference: Mastra.getMemory() | Core"
3
+ description: "Documentation for the `Mastra.getMemory()` method in Mastra, which retrieves a registered memory instance by its registry key."
4
+ ---
5
+
6
+ # Mastra.getMemory()
7
+
8
+ The `.getMemory()` method retrieves a memory instance from the Mastra registry by its key. Memory instances are registered in the Mastra constructor and can be referenced by stored agents.
9
+
10
+ ## Usage example
11
+
12
+ ```typescript copy
13
+ const memory = mastra.getMemory("conversationMemory");
14
+
15
+ // Use the memory instance
16
+ const thread = await memory.createThread({
17
+ resourceId: "user-123",
18
+ title: "New Conversation",
19
+ });
20
+ ```
21
+
22
+ ## Parameters
23
+
24
+ <PropertiesTable
25
+ content={[
26
+ {
27
+ name: "key",
28
+ type: "TMemoryKey extends keyof TMemory",
29
+ description:
30
+ "The registry key of the memory instance to retrieve. Must match a key used when registering memory in the Mastra constructor.",
31
+ },
32
+ ]}
33
+ />
34
+
35
+ ## Returns
36
+
37
+ <PropertiesTable
38
+ content={[
39
+ {
40
+ name: "memory",
41
+ type: "TMemory[TMemoryKey]",
42
+ description:
43
+ "The memory instance with the specified key. Throws an error if the memory is not found.",
44
+ },
45
+ ]}
46
+ />
47
+
48
+ ## Example: Registering and Retrieving Memory
49
+
50
+ ```typescript copy
51
+ import { Mastra } from "@mastra/core";
52
+ import { Memory } from "@mastra/memory";
53
+ import { LibSQLStore } from "@mastra/libsql";
54
+
55
+ const conversationMemory = new Memory({
56
+ storage: new LibSQLStore({ url: ":memory:" }),
57
+ });
58
+
59
+ const mastra = new Mastra({
60
+ memory: {
61
+ conversationMemory,
62
+ },
63
+ });
64
+
65
+ // Later, retrieve the memory instance
66
+ const memory = mastra.getMemory("conversationMemory");
67
+ ```
68
+
69
+ ## Related
70
+
71
+ - [Mastra.listMemory()](/reference/v1/core/listMemory)
72
+ - [Memory overview](/docs/v1/memory/overview)
73
+ - [Agent Memory](/docs/v1/agents/agent-memory)