@mastra/mcp-docs-server 0.13.12-alpha.0 → 0.13.12-alpha.2
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.
- package/.docs/organized/changelogs/%40mastra%2Fchroma.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +20 -20
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +20 -20
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +17 -17
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +18 -18
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +18 -18
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +26 -26
- package/.docs/organized/changelogs/%40mastra%2Fevals.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Flibsql.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +22 -22
- package/.docs/organized/changelogs/%40mastra%2Fmcp.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +17 -17
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +22 -22
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google-gemini-live.md +14 -0
- package/.docs/organized/changelogs/create-mastra.md +8 -8
- package/.docs/organized/changelogs/mastra.md +21 -21
- package/.docs/organized/code-examples/agent.md +293 -276
- package/.docs/raw/agents/input-processors.mdx +25 -19
- package/.docs/raw/agents/output-processors.mdx +376 -0
- package/.docs/raw/agents/overview.mdx +165 -188
- package/.docs/raw/agents/streaming.mdx +11 -5
- package/.docs/raw/community/contributing-templates.mdx +1 -1
- package/.docs/raw/deployment/cloud-providers/amazon-ec2.mdx +9 -9
- package/.docs/raw/deployment/cloud-providers/aws-lambda.mdx +27 -33
- package/.docs/raw/deployment/cloud-providers/azure-app-services.mdx +12 -12
- package/.docs/raw/deployment/cloud-providers/digital-ocean.mdx +17 -17
- package/.docs/raw/getting-started/templates.mdx +1 -1
- package/.docs/raw/rag/vector-databases.mdx +9 -1
- package/.docs/raw/reference/agents/agent.mdx +8 -2
- package/.docs/raw/reference/agents/generate.mdx +80 -3
- package/.docs/raw/reference/agents/getLLM.mdx +1 -1
- package/.docs/raw/reference/agents/streamVNext.mdx +88 -5
- package/.docs/raw/reference/rag/chroma.mdx +158 -17
- package/.docs/raw/reference/tools/mcp-client.mdx +9 -9
- package/.docs/raw/reference/tools/mcp-server.mdx +5 -5
- package/.docs/raw/reference/workflows/run-methods/streamVNext.mdx +7 -1
- package/.docs/raw/voice/overview.mdx +81 -2
- package/.docs/raw/voice/speech-to-speech.mdx +45 -0
- package/.docs/raw/workflows/overview.mdx +8 -1
- package/package.json +5 -5
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: "Reference: Agent.streamVNext() | Agents | Mastra Docs"
|
|
2
|
+
title: "Reference: Agent.streamVNext() (Experimental) | Agents | Mastra Docs"
|
|
3
3
|
description: "Documentation for the `Agent.streamVNext()` method in Mastra agents, which enables real-time streaming of responses with enhanced capabilities."
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
import { Callout } from "nextra/components";
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
# Agent.streamVNext() (Experimental)
|
|
9
|
+
|
|
10
|
+
<Callout type="warning">
|
|
11
|
+
**Experimental Feature**: This is a new streaming implementation that will replace the existing `stream()` method once battle-tested. The API may change as we refine the feature based on feedback.
|
|
12
|
+
</Callout>
|
|
13
|
+
|
|
14
|
+
The `.streamVNext()` method enables real-time streaming of responses from an agent with enhanced capabilities. This method accepts messages and optional streaming options, providing a next-generation streaming experience that will eventually replace the current `stream()` method.
|
|
9
15
|
|
|
10
16
|
## Usage example
|
|
11
17
|
|
|
@@ -48,12 +54,72 @@ await agent.streamVNext("message for agent");
|
|
|
48
54
|
isOptional: true,
|
|
49
55
|
description: "Additional context messages to provide to the agent.",
|
|
50
56
|
},
|
|
57
|
+
{
|
|
58
|
+
name: "structuredOutput",
|
|
59
|
+
type: "StructuredOutputOptions<S extends ZodTypeAny = ZodTypeAny>",
|
|
60
|
+
isOptional: true,
|
|
61
|
+
description: "Enables structured output generation with better developer experience. Automatically creates and uses a StructuredOutputProcessor internally.",
|
|
62
|
+
properties: [
|
|
63
|
+
{
|
|
64
|
+
parameters: [{
|
|
65
|
+
name: "schema",
|
|
66
|
+
type: "z.ZodSchema<S>",
|
|
67
|
+
isOptional: false,
|
|
68
|
+
description: "Zod schema to validate the output against."
|
|
69
|
+
}]
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
parameters: [{
|
|
73
|
+
name: "model",
|
|
74
|
+
type: "MastraLanguageModel",
|
|
75
|
+
isOptional: false,
|
|
76
|
+
description: "Model to use for the internal structuring agent."
|
|
77
|
+
}]
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
parameters: [{
|
|
81
|
+
name: "errorStrategy",
|
|
82
|
+
type: "'strict' | 'warn' | 'fallback'",
|
|
83
|
+
isOptional: true,
|
|
84
|
+
description: "Strategy when parsing or validation fails. Defaults to 'strict'."
|
|
85
|
+
}]
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
parameters: [{
|
|
89
|
+
name: "fallbackValue",
|
|
90
|
+
type: "<S extends ZodTypeAny>",
|
|
91
|
+
isOptional: true,
|
|
92
|
+
description: "Fallback value when errorStrategy is 'fallback'."
|
|
93
|
+
}]
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
parameters: [{
|
|
97
|
+
name: "instructions",
|
|
98
|
+
type: "string",
|
|
99
|
+
isOptional: true,
|
|
100
|
+
description: "Custom instructions for the structuring agent."
|
|
101
|
+
}]
|
|
102
|
+
},
|
|
103
|
+
]
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
name: "outputProcessors",
|
|
107
|
+
type: "Processor[]",
|
|
108
|
+
isOptional: true,
|
|
109
|
+
description: "Overrides the output processors set on the agent. Output processors that can modify or validate messages from the agent before they are returned to the user. Must implement either (or both) of the `processOutputResult` and `processOutputStream` functions.",
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
name: "inputProcessors",
|
|
113
|
+
type: "Processor[]",
|
|
114
|
+
isOptional: true,
|
|
115
|
+
description: "Overrides the input processors set on the agent. Input processors that can modify or validate messages before they are processed by the agent. Must implement the `processInput` function.",
|
|
116
|
+
},
|
|
51
117
|
{
|
|
52
118
|
name: "experimental_output",
|
|
53
119
|
type: "Zod schema | JsonSchema7",
|
|
54
120
|
isOptional: true,
|
|
55
121
|
description:
|
|
56
|
-
"Enables structured output generation alongside text generation and tool calls. The model will generate responses that conform to the provided schema.",
|
|
122
|
+
"Note, the preferred route is to use the `structuredOutput` property. Enables structured output generation alongside text generation and tool calls. The model will generate responses that conform to the provided schema.",
|
|
57
123
|
},
|
|
58
124
|
{
|
|
59
125
|
name: "instructions",
|
|
@@ -391,6 +457,9 @@ await agent.streamVNext("message for agent");
|
|
|
391
457
|
## Extended usage example
|
|
392
458
|
|
|
393
459
|
```typescript showLineNumbers copy
|
|
460
|
+
import { z } from "zod";
|
|
461
|
+
import { ModerationProcessor, BatchPartsProcessor } from "@mastra/core/processors";
|
|
462
|
+
|
|
394
463
|
await agent.streamVNext("message for agent", {
|
|
395
464
|
temperature: 0.7,
|
|
396
465
|
maxSteps: 3,
|
|
@@ -398,6 +467,20 @@ await agent.streamVNext("message for agent", {
|
|
|
398
467
|
thread: "user-123",
|
|
399
468
|
resource: "test-app"
|
|
400
469
|
},
|
|
401
|
-
toolChoice: "auto"
|
|
470
|
+
toolChoice: "auto",
|
|
471
|
+
// Structured output with better DX
|
|
472
|
+
structuredOutput: {
|
|
473
|
+
schema: z.object({
|
|
474
|
+
sentiment: z.enum(['positive', 'negative', 'neutral']),
|
|
475
|
+
confidence: z.number(),
|
|
476
|
+
}),
|
|
477
|
+
model: openai("gpt-4o-mini"),
|
|
478
|
+
errorStrategy: 'warn',
|
|
479
|
+
},
|
|
480
|
+
// Output processors for streaming response validation
|
|
481
|
+
outputProcessors: [
|
|
482
|
+
new ModerationProcessor({ model: openai("gpt-4.1-nano") }),
|
|
483
|
+
new BatchPartsProcessor({ maxBatchSize: 3, maxWaitTime: 100 }),
|
|
484
|
+
],
|
|
402
485
|
});
|
|
403
486
|
```
|
|
@@ -3,46 +3,88 @@ title: "Reference: Chroma Vector Store | Vector Databases | RAG | Mastra Docs"
|
|
|
3
3
|
description: Documentation for the ChromaVector class in Mastra, which provides vector search using ChromaDB.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
+
import { Callout } from "nextra/components";
|
|
7
|
+
|
|
6
8
|
# Chroma Vector Store
|
|
7
9
|
|
|
8
|
-
The ChromaVector class provides vector search using [
|
|
10
|
+
The ChromaVector class provides vector search using [Chroma](https://docs.trychroma.com/docs/overview/getting-started), an open-source embedding database.
|
|
9
11
|
It offers efficient vector search with metadata filtering and hybrid search capabilities.
|
|
10
12
|
|
|
13
|
+
<Callout type="info">
|
|
14
|
+
<b>Chroma Cloud</b>
|
|
15
|
+
<p>
|
|
16
|
+
Chroma Cloud powers serverless vector and full-text search. It's extremely fast, cost-effective, scalable and painless. Create a DB and try it out in under 30 seconds with $5 of free credits.
|
|
17
|
+
|
|
18
|
+
[Get started with Chroma Cloud](https://trychroma.com/signup)
|
|
19
|
+
</p>
|
|
20
|
+
</Callout>
|
|
21
|
+
|
|
11
22
|
## Constructor Options
|
|
12
23
|
|
|
13
24
|
<PropertiesTable
|
|
14
25
|
content={[
|
|
15
26
|
{
|
|
16
|
-
name: "
|
|
27
|
+
name: "host",
|
|
17
28
|
type: "string",
|
|
18
|
-
|
|
29
|
+
isOptional: true,
|
|
30
|
+
description: "The host address of the Chroma server. Defaults to 'localhost'",
|
|
19
31
|
},
|
|
20
32
|
{
|
|
21
|
-
name: "
|
|
22
|
-
type: "
|
|
33
|
+
name: "port",
|
|
34
|
+
type: "number",
|
|
23
35
|
isOptional: true,
|
|
24
|
-
description: "
|
|
36
|
+
description: "The port number of the Chroma server. Defaults to 8000",
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: "ssl",
|
|
40
|
+
type: "boolean",
|
|
41
|
+
isOptional: true,
|
|
42
|
+
description: "Whether to use SSL/HTTPS for connections. Defaults to false",
|
|
25
43
|
},
|
|
26
|
-
]}
|
|
27
|
-
/>
|
|
28
|
-
|
|
29
|
-
### auth
|
|
30
|
-
|
|
31
|
-
<PropertiesTable
|
|
32
|
-
content={[
|
|
33
44
|
{
|
|
34
|
-
name: "
|
|
45
|
+
name: "apiKey",
|
|
35
46
|
type: "string",
|
|
36
|
-
|
|
47
|
+
isOptional: true,
|
|
48
|
+
description: "A Chroma Cloud API key",
|
|
37
49
|
},
|
|
38
50
|
{
|
|
39
|
-
name: "
|
|
51
|
+
name: "tenant",
|
|
40
52
|
type: "string",
|
|
41
|
-
|
|
53
|
+
isOptional: true,
|
|
54
|
+
description: "The tenant name in the Chroma server to connect to. Defaults to 'default_tenant' for single-node Chroma. Auto-resolved for Chroma Cloud users based on the provided API key",
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: "database",
|
|
58
|
+
type: "string",
|
|
59
|
+
isOptional: true,
|
|
60
|
+
description: "The database name to connect to. Defaults to 'default_database' for single-node Chroma. Auto-resolved for Chroma Cloud users based on the provided API key",
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
name: "headers",
|
|
64
|
+
type: "Record<string, any>",
|
|
65
|
+
isOptional: true,
|
|
66
|
+
description: "Additional HTTP headers to send with requests",
|
|
42
67
|
},
|
|
68
|
+
{
|
|
69
|
+
name: "fetchOptions",
|
|
70
|
+
type: "RequestInit",
|
|
71
|
+
isOptional: true,
|
|
72
|
+
description: "Additional fetch options for HTTP requests",
|
|
73
|
+
}
|
|
43
74
|
]}
|
|
44
75
|
/>
|
|
45
76
|
|
|
77
|
+
## Running a Chroma Server
|
|
78
|
+
|
|
79
|
+
If you are a Chroma Cloud user, simply provide the `ChromaVector` constructor your API key, tenant, and database name.
|
|
80
|
+
|
|
81
|
+
When you install the `@mastra/chroma` package, you get access to the [Chroma CLI](https://docs.trychroma.com/docs/cli/db), which can set these as environment variables for you: `chroma db connect [DB-NAME] --env-file`.
|
|
82
|
+
|
|
83
|
+
Otherwise, you have several options for setting up your single-node Chroma server:
|
|
84
|
+
* Run one locally using the Chroma CLI: `chroma run`. You can find more configuration options on the [Chroma docs](https://docs.trychroma.com/docs/cli/run).
|
|
85
|
+
* Run on [Docker](https://docs.trychroma.com/guides/deploy/docker) using the official Chroma image.
|
|
86
|
+
* Deploy your own Chroma server on your provider of choice. Chroma offers example templates for [AWS](https://docs.trychroma.com/guides/deploy/aws), [Azure](https://docs.trychroma.com/guides/deploy/azure), and [GCP](https://docs.trychroma.com/guides/deploy/gcp).
|
|
87
|
+
|
|
46
88
|
## Methods
|
|
47
89
|
|
|
48
90
|
### createIndex()
|
|
@@ -69,6 +111,27 @@ It offers efficient vector search with metadata filtering and hybrid search capa
|
|
|
69
111
|
]}
|
|
70
112
|
/>
|
|
71
113
|
|
|
114
|
+
### forkIndex()
|
|
115
|
+
|
|
116
|
+
Note: Forking is only supported on Chroma Cloud, or if you deploy your own OSS **distributed** Chroma.
|
|
117
|
+
|
|
118
|
+
`forkIndex` lets you fork an existing Chroma index instantly. Operations on the forked index do not affect the original one. Learn more on the [Chroma docs](https://docs.trychroma.com/cloud/collection-forking).
|
|
119
|
+
|
|
120
|
+
<PropertiesTable
|
|
121
|
+
content={[
|
|
122
|
+
{
|
|
123
|
+
name: "indexName",
|
|
124
|
+
type: "string",
|
|
125
|
+
description: "Name of the index to fork",
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
name: "newIndexName",
|
|
129
|
+
type: "string",
|
|
130
|
+
description: "The name of the forked index",
|
|
131
|
+
}
|
|
132
|
+
]}
|
|
133
|
+
/>
|
|
134
|
+
|
|
72
135
|
### upsert()
|
|
73
136
|
|
|
74
137
|
<PropertiesTable
|
|
@@ -107,6 +170,20 @@ It offers efficient vector search with metadata filtering and hybrid search capa
|
|
|
107
170
|
|
|
108
171
|
### query()
|
|
109
172
|
|
|
173
|
+
Query an index using a `queryVector`. Returns an array of semantically similar records in order of distance from the `queryVector`. Each record has the shape:
|
|
174
|
+
|
|
175
|
+
```typescript
|
|
176
|
+
{
|
|
177
|
+
id: string;
|
|
178
|
+
score: number;
|
|
179
|
+
document?: string;
|
|
180
|
+
metadata?: Record<string, string | number | boolean>;
|
|
181
|
+
embedding?: number[]
|
|
182
|
+
}
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
You can also provide the shape of your metadata to a `query` call for type inference: `query<T>()`.
|
|
186
|
+
|
|
110
187
|
<PropertiesTable
|
|
111
188
|
content={[
|
|
112
189
|
{
|
|
@@ -148,6 +225,70 @@ It offers efficient vector search with metadata filtering and hybrid search capa
|
|
|
148
225
|
]}
|
|
149
226
|
/>
|
|
150
227
|
|
|
228
|
+
### get()
|
|
229
|
+
|
|
230
|
+
Get records from your Chroma index by IDs, metadata, and document filters. It returns an array of records of the shape:
|
|
231
|
+
|
|
232
|
+
```typescript
|
|
233
|
+
{
|
|
234
|
+
id: string;
|
|
235
|
+
document?: string;
|
|
236
|
+
metadata?: Record<string, string | number | boolean>;
|
|
237
|
+
embedding?: number[]
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
You can also provide the shape of your metadata to a `get` call for type inference: `get<T>()`.
|
|
242
|
+
|
|
243
|
+
<PropertiesTable
|
|
244
|
+
content={[
|
|
245
|
+
{
|
|
246
|
+
name: "indexName",
|
|
247
|
+
type: "string",
|
|
248
|
+
description: "Name of the index to query",
|
|
249
|
+
},
|
|
250
|
+
{
|
|
251
|
+
name: "ids",
|
|
252
|
+
type: "string[]",
|
|
253
|
+
isOptional: true,
|
|
254
|
+
description: "A list of record IDs to return. If not provided, all records are returned.",
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
name: "filter",
|
|
258
|
+
type: "Record<string, any>",
|
|
259
|
+
isOptional: true,
|
|
260
|
+
description: "Metadata filters.",
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
name: "includeVector",
|
|
264
|
+
type: "boolean",
|
|
265
|
+
isOptional: true,
|
|
266
|
+
defaultValue: "false",
|
|
267
|
+
description: "Whether to include vectors in the results",
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
name: "documentFilter",
|
|
271
|
+
type: "Record<string, any>",
|
|
272
|
+
isOptional: true,
|
|
273
|
+
description: "Chroma-specific: Filter to apply on the document content",
|
|
274
|
+
},
|
|
275
|
+
{
|
|
276
|
+
name: "limit",
|
|
277
|
+
type: "number",
|
|
278
|
+
isOptional: true,
|
|
279
|
+
defaultValue: 100,
|
|
280
|
+
description: "The maximum number of records to return",
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
name: "offset",
|
|
284
|
+
type: "number",
|
|
285
|
+
isOptional: true,
|
|
286
|
+
defaultValue: 0,
|
|
287
|
+
description: "Offset for returning records. Use with `limit` to paginate results.",
|
|
288
|
+
},
|
|
289
|
+
]}
|
|
290
|
+
/>
|
|
291
|
+
|
|
151
292
|
### listIndexes()
|
|
152
293
|
|
|
153
294
|
Returns an array of index names as strings.
|
|
@@ -342,7 +342,7 @@ The handler function receives a request object with:
|
|
|
342
342
|
- `requestedSchema`: A JSON schema defining the structure of the expected response
|
|
343
343
|
|
|
344
344
|
The handler must return an `ElicitResult` with:
|
|
345
|
-
- `action`: One of `'accept'`, `'
|
|
345
|
+
- `action`: One of `'accept'`, `'decline'`, or `'cancel'`
|
|
346
346
|
- `content`: The user's data (only when action is `'accept'`)
|
|
347
347
|
|
|
348
348
|
**Example:**
|
|
@@ -363,8 +363,8 @@ mcpClient.elicitation.onRequest('serverName', async (request) => {
|
|
|
363
363
|
};
|
|
364
364
|
}
|
|
365
365
|
|
|
366
|
-
// Simulate user
|
|
367
|
-
return { action: '
|
|
366
|
+
// Simulate user declining the request
|
|
367
|
+
return { action: 'decline' };
|
|
368
368
|
});
|
|
369
369
|
```
|
|
370
370
|
|
|
@@ -423,7 +423,7 @@ await mcpClient.elicitation.onRequest('interactiveServer', async (request) => {
|
|
|
423
423
|
// Validate required fields
|
|
424
424
|
if (answer === '' && isRequired) {
|
|
425
425
|
console.log(`❌ ${fieldName} is required`);
|
|
426
|
-
return { action: '
|
|
426
|
+
return { action: 'decline' };
|
|
427
427
|
}
|
|
428
428
|
|
|
429
429
|
if (answer !== '') {
|
|
@@ -442,7 +442,7 @@ await mcpClient.elicitation.onRequest('interactiveServer', async (request) => {
|
|
|
442
442
|
} else if (confirm.toLowerCase() === 'cancel') {
|
|
443
443
|
return { action: 'cancel' };
|
|
444
444
|
} else {
|
|
445
|
-
return { action: '
|
|
445
|
+
return { action: 'decline' };
|
|
446
446
|
}
|
|
447
447
|
});
|
|
448
448
|
```
|
|
@@ -521,7 +521,7 @@ Elicitation is a feature that allows MCP servers to request structured informati
|
|
|
521
521
|
1. **Server Request**: An MCP server tool calls `server.elicitation.sendRequest()` with a message and schema
|
|
522
522
|
2. **Client Handler**: Your elicitation handler function is called with the request
|
|
523
523
|
3. **User Interaction**: Your handler collects user input (via UI, CLI, etc.)
|
|
524
|
-
4. **Response**: Your handler returns the user's response (accept/
|
|
524
|
+
4. **Response**: Your handler returns the user's response (accept/decline/cancel)
|
|
525
525
|
5. **Tool Continuation**: The server tool receives the response and continues execution
|
|
526
526
|
|
|
527
527
|
### Setting Up Elicitation
|
|
@@ -566,9 +566,9 @@ Your elicitation handler must return one of three response types:
|
|
|
566
566
|
};
|
|
567
567
|
```
|
|
568
568
|
|
|
569
|
-
- **
|
|
569
|
+
- **Decline**: User explicitly declined to provide the information
|
|
570
570
|
```typescript
|
|
571
|
-
return { action: '
|
|
571
|
+
return { action: 'decline' };
|
|
572
572
|
```
|
|
573
573
|
|
|
574
574
|
- **Cancel**: User dismissed or cancelled the request
|
|
@@ -613,7 +613,7 @@ await mcpClient.elicitation.onRequest('interactiveServer', async (request) => {
|
|
|
613
613
|
|
|
614
614
|
- **Always handle elicitation**: Set up your handler before calling tools that might use elicitation
|
|
615
615
|
- **Validate input**: Check that required fields are provided
|
|
616
|
-
- **Respect user choice**: Handle
|
|
616
|
+
- **Respect user choice**: Handle decline and cancel responses gracefully
|
|
617
617
|
- **Clear UI**: Make it obvious what information is being requested and why
|
|
618
618
|
- **Security**: Never auto-accept requests for sensitive information
|
|
619
619
|
|
|
@@ -872,7 +872,7 @@ A common use case is during tool execution. When a tool needs user input, it can
|
|
|
872
872
|
1. The tool calls `options.elicitation.sendRequest()` with a message and schema
|
|
873
873
|
2. The request is sent to the connected MCP client
|
|
874
874
|
3. The client presents the request to the user (via UI, command line, etc.)
|
|
875
|
-
4. The user provides input,
|
|
875
|
+
4. The user provides input, declines, or cancels the request
|
|
876
876
|
5. The client sends the response back to the server
|
|
877
877
|
6. The tool receives the response and continues execution
|
|
878
878
|
|
|
@@ -934,7 +934,7 @@ const server = new MCPServer({
|
|
|
934
934
|
// Handle the user's response
|
|
935
935
|
if (result.action === 'accept') {
|
|
936
936
|
return `Contact information collected: ${JSON.stringify(result.content, null, 2)}`;
|
|
937
|
-
} else if (result.action === '
|
|
937
|
+
} else if (result.action === 'decline') {
|
|
938
938
|
return 'Contact information collection was declined by the user.';
|
|
939
939
|
} else {
|
|
940
940
|
return 'Contact information collection was cancelled by the user.';
|
|
@@ -990,7 +990,7 @@ Users can respond to elicitation requests in three ways:
|
|
|
990
990
|
|
|
991
991
|
1. **Accept** (`action: 'accept'`): User provided data and confirmed submission
|
|
992
992
|
- Contains `content` field with the submitted data
|
|
993
|
-
2. **
|
|
993
|
+
2. **Decline** (`action: 'decline'`): User explicitly declined to provide information
|
|
994
994
|
- No content field
|
|
995
995
|
3. **Cancel** (`action: 'cancel'`): User dismissed the request without deciding
|
|
996
996
|
- No content field
|
|
@@ -1001,7 +1001,7 @@ Tools should handle all three response types appropriately.
|
|
|
1001
1001
|
|
|
1002
1002
|
- **Never request sensitive information** like passwords, SSNs, or credit card numbers
|
|
1003
1003
|
- Validate all user input against the provided schema
|
|
1004
|
-
- Handle
|
|
1004
|
+
- Handle declining and cancellation gracefully
|
|
1005
1005
|
- Provide clear reasons for data collection
|
|
1006
1006
|
- Respect user privacy and preferences
|
|
1007
1007
|
|
|
@@ -1031,7 +1031,7 @@ The `ElicitResult` type:
|
|
|
1031
1031
|
|
|
1032
1032
|
```typescript
|
|
1033
1033
|
type ElicitResult = {
|
|
1034
|
-
action: 'accept' | '
|
|
1034
|
+
action: 'accept' | 'decline' | 'cancel';
|
|
1035
1035
|
content?: any; // Only present when action is 'accept'
|
|
1036
1036
|
}
|
|
1037
1037
|
```
|
|
@@ -3,9 +3,15 @@ title: "Reference: Run.streamVNext() | Workflows | Mastra Docs"
|
|
|
3
3
|
description: Documentation for the `Run.streamVNext()` method in workflows, which enables real-time streaming of responses.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
+
import { Callout } from "nextra/components";
|
|
7
|
+
|
|
6
8
|
# Run.streamVNext()
|
|
7
9
|
|
|
8
|
-
|
|
10
|
+
<Callout type="warning">
|
|
11
|
+
**Experimental Feature**: This is a new streaming implementation that will replace the existing `stream()` method once battle-tested. The API may change as we refine the feature based on feedback.
|
|
12
|
+
</Callout>
|
|
13
|
+
|
|
14
|
+
The `.streamVNext()` method enables real-time streaming of responses from a workflow. This enhanced streaming capability will eventually replace the current `stream()` method.
|
|
9
15
|
|
|
10
16
|
## Usage example
|
|
11
17
|
|
|
@@ -548,7 +548,7 @@ For detailed configuration options and advanced features, check out [Speech to S
|
|
|
548
548
|
The tab shows how to set up real-time voice communication with event handling for audio responses.
|
|
549
549
|
This enables conversational AI experiences with continuous audio streaming.
|
|
550
550
|
*/}
|
|
551
|
-
<Tabs items={["OpenAI"]}>
|
|
551
|
+
<Tabs items={["OpenAI", "Google Gemini Live"]}>
|
|
552
552
|
<Tabs.Tab>
|
|
553
553
|
```typescript
|
|
554
554
|
import { Agent } from '@mastra/core/agent';
|
|
@@ -578,6 +578,53 @@ await voiceAgent.voice.send(micStream);
|
|
|
578
578
|
|
|
579
579
|
Visit the [OpenAI Voice Reference](/reference/voice/openai-realtime) for more information on the OpenAI voice provider.
|
|
580
580
|
|
|
581
|
+
</Tabs.Tab>
|
|
582
|
+
<Tabs.Tab>
|
|
583
|
+
```typescript
|
|
584
|
+
import { Agent } from '@mastra/core/agent';
|
|
585
|
+
import { openai } from '@ai-sdk/openai';
|
|
586
|
+
import { playAudio, getMicrophoneStream } from '@mastra/node-audio';
|
|
587
|
+
import { GeminiLiveVoice } from "@mastra/voice-google-gemini-live";
|
|
588
|
+
|
|
589
|
+
const voiceAgent = new Agent({
|
|
590
|
+
name: "Voice Agent",
|
|
591
|
+
instructions: "You are a voice assistant that can help users with their tasks.",
|
|
592
|
+
model: openai("gpt-4o"),
|
|
593
|
+
voice: new GeminiLiveVoice({
|
|
594
|
+
// Live API mode
|
|
595
|
+
apiKey: process.env.GOOGLE_API_KEY,
|
|
596
|
+
model: 'gemini-2.0-flash-exp',
|
|
597
|
+
speaker: 'Puck',
|
|
598
|
+
debug: true,
|
|
599
|
+
// Vertex AI alternative:
|
|
600
|
+
// vertexAI: true,
|
|
601
|
+
// project: 'your-gcp-project',
|
|
602
|
+
// location: 'us-central1',
|
|
603
|
+
// serviceAccountKeyFile: '/path/to/service-account.json',
|
|
604
|
+
}),
|
|
605
|
+
});
|
|
606
|
+
|
|
607
|
+
// Connect before using speak/send
|
|
608
|
+
await voiceAgent.voice.connect();
|
|
609
|
+
|
|
610
|
+
// Listen for agent audio responses
|
|
611
|
+
voiceAgent.voice.on('speaker', ({ audio }) => {
|
|
612
|
+
playAudio(audio);
|
|
613
|
+
});
|
|
614
|
+
|
|
615
|
+
// Listen for text responses and transcriptions
|
|
616
|
+
voiceAgent.voice.on('writing', ({ text, role }) => {
|
|
617
|
+
console.log(`${role}: ${text}`);
|
|
618
|
+
});
|
|
619
|
+
|
|
620
|
+
// Initiate the conversation
|
|
621
|
+
await voiceAgent.voice.speak('How can I help you today?');
|
|
622
|
+
|
|
623
|
+
// Send continuous audio from the microphone
|
|
624
|
+
const micStream = getMicrophoneStream();
|
|
625
|
+
await voiceAgent.voice.send(micStream);
|
|
626
|
+
```
|
|
627
|
+
|
|
581
628
|
</Tabs.Tab>
|
|
582
629
|
</Tabs>
|
|
583
630
|
|
|
@@ -592,7 +639,7 @@ The tabs help users understand the full configuration capabilities of each provi
|
|
|
592
639
|
Each tab shows both speech and listening model configurations where applicable.
|
|
593
640
|
*/}
|
|
594
641
|
|
|
595
|
-
<Tabs items={["OpenAI", "Azure", "ElevenLabs", "PlayAI", "Google", "Cloudflare", "Deepgram", "Speechify", "Sarvam", "Murf", "OpenAI Realtime"]}>
|
|
642
|
+
<Tabs items={["OpenAI", "Azure", "ElevenLabs", "PlayAI", "Google", "Cloudflare", "Deepgram", "Speechify", "Sarvam", "Murf", "OpenAI Realtime", "Google Gemini Live"]}>
|
|
596
643
|
<Tabs.Tab>
|
|
597
644
|
```typescript
|
|
598
645
|
// OpenAI Voice Configuration
|
|
@@ -618,6 +665,38 @@ Visit the [OpenAI Voice Reference](/reference/voice/openai) for more information
|
|
|
618
665
|
</Tabs.Tab>
|
|
619
666
|
<Tabs.Tab>
|
|
620
667
|
```typescript
|
|
668
|
+
// Google Gemini Live Voice Configuration
|
|
669
|
+
import { GeminiLiveVoice } from '@mastra/voice-google-gemini-live';
|
|
670
|
+
|
|
671
|
+
const voice = new GeminiLiveVoice({
|
|
672
|
+
// Live API
|
|
673
|
+
apiKey: process.env.GOOGLE_API_KEY,
|
|
674
|
+
model: 'gemini-2.0-flash-exp',
|
|
675
|
+
speaker: 'Puck',
|
|
676
|
+
debug: true,
|
|
677
|
+
// Vertex AI alternative:
|
|
678
|
+
// vertexAI: true,
|
|
679
|
+
// project: 'your-gcp-project',
|
|
680
|
+
// location: 'us-central1',
|
|
681
|
+
// serviceAccountKeyFile: '/path/to/service-account.json',
|
|
682
|
+
// sessionConfig: {
|
|
683
|
+
// vad: { enabled: true, sensitivity: 0.5, silenceDurationMs: 1000 },
|
|
684
|
+
// interrupts: { enabled: true, allowUserInterruption: true },
|
|
685
|
+
// contextCompression: false,
|
|
686
|
+
// }
|
|
687
|
+
});
|
|
688
|
+
|
|
689
|
+
// Per-turn overrides
|
|
690
|
+
await voice.speak('Hello', {
|
|
691
|
+
languageCode: 'en-US',
|
|
692
|
+
responseModalities: ['AUDIO'] as any,
|
|
693
|
+
speaker: 'Puck',
|
|
694
|
+
});
|
|
695
|
+
```
|
|
696
|
+
|
|
697
|
+
</Tabs.Tab>
|
|
698
|
+
<Tabs.Tab>
|
|
699
|
+
```typescript
|
|
621
700
|
// Azure Voice Configuration
|
|
622
701
|
const voice = new AzureVoice({
|
|
623
702
|
speechModel: {
|
|
@@ -58,3 +58,48 @@ await agent.voice.send(micStream);
|
|
|
58
58
|
```
|
|
59
59
|
|
|
60
60
|
For integrating Speech-to-Speech capabilities with agents, refer to the [Adding Voice to Agents](../agents/adding-voice.mdx) documentation.
|
|
61
|
+
|
|
62
|
+
## Google Gemini Live (Realtime)
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
import { Agent } from "@mastra/core/agent";
|
|
66
|
+
import { GeminiLiveVoice } from "@mastra/voice-google-gemini-live";
|
|
67
|
+
import { playAudio, getMicrophoneStream } from "@mastra/node-audio";
|
|
68
|
+
|
|
69
|
+
const agent = new Agent({
|
|
70
|
+
name: 'Agent',
|
|
71
|
+
instructions: 'You are a helpful assistant with real-time voice capabilities.',
|
|
72
|
+
// Model used for text generation; voice provider handles realtime audio
|
|
73
|
+
model: openai("gpt-4o"),
|
|
74
|
+
voice: new GeminiLiveVoice({
|
|
75
|
+
apiKey: process.env.GOOGLE_API_KEY,
|
|
76
|
+
model: 'gemini-2.0-flash-exp',
|
|
77
|
+
speaker: 'Puck',
|
|
78
|
+
debug: true,
|
|
79
|
+
// Vertex AI option:
|
|
80
|
+
// vertexAI: true,
|
|
81
|
+
// project: 'your-gcp-project',
|
|
82
|
+
// location: 'us-central1',
|
|
83
|
+
// serviceAccountKeyFile: '/path/to/service-account.json',
|
|
84
|
+
}),
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
await agent.voice.connect();
|
|
88
|
+
|
|
89
|
+
agent.voice.on('speaker', ({ audio }) => {
|
|
90
|
+
playAudio(audio);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
agent.voice.on('writing', ({ role, text }) => {
|
|
94
|
+
console.log(`${role}: ${text}`);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
await agent.voice.speak('How can I help you today?');
|
|
98
|
+
|
|
99
|
+
const micStream = getMicrophoneStream();
|
|
100
|
+
await agent.voice.send(micStream);
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Note:
|
|
104
|
+
- Live API requires `GOOGLE_API_KEY`. Vertex AI requires project/location and service account credentials.
|
|
105
|
+
- Events: `speaker` (audio stream), `writing` (text), `turnComplete`, `usage`, and `error`.
|
|
@@ -21,10 +21,17 @@ You create workflows by:
|
|
|
21
21
|
|
|
22
22
|
This structure provides full type safety and runtime validation, ensuring data integrity across the entire workflow.
|
|
23
23
|
|
|
24
|
+
> **📹 Watch**: → An introduction to workflows, and how they compare to agents [YouTube (7 minutes)](https://youtu.be/0jg2g3sNvgw)
|
|
24
25
|
|
|
25
26
|
## Getting started
|
|
26
27
|
|
|
27
|
-
To use workflows,
|
|
28
|
+
To use workflows, install the required dependencies:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npm install @mastra/core
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Import the necessary functions from the `workflows` subpath:
|
|
28
35
|
|
|
29
36
|
```typescript filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
30
37
|
import { createWorkflow, createStep } from "@mastra/core/workflows";
|