@mastra/mcp-docs-server 0.13.11 → 0.13.12-alpha.1
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/%40internal%2Fstorage-test-utils.md +19 -19
- package/.docs/organized/changelogs/%40internal%2Ftypes-builder.md +2 -0
- 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 +42 -42
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +45 -45
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +53 -53
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +49 -49
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +49 -49
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +54 -54
- package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +20 -20
- package/.docs/organized/changelogs/%40mastra%2Fevals.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Ffirecrawl.md +21 -21
- package/.docs/organized/changelogs/%40mastra%2Flance.md +22 -22
- package/.docs/organized/changelogs/%40mastra%2Flibsql.md +34 -34
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +41 -41
- package/.docs/organized/changelogs/%40mastra%2Fmcp.md +33 -33
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +23 -23
- package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +20 -20
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +37 -37
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +49 -49
- package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +21 -21
- package/.docs/organized/changelogs/%40mastra%2Frag.md +20 -20
- package/.docs/organized/changelogs/%40mastra%2Fschema-compat.md +8 -0
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +44 -44
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google-gemini-live.md +14 -0
- package/.docs/organized/changelogs/create-mastra.md +26 -26
- package/.docs/organized/changelogs/mastra.md +63 -63
- package/.docs/organized/code-examples/agent.md +292 -275
- 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 +9 -3
- package/.docs/raw/reference/agents/generate.mdx +80 -3
- package/.docs/raw/reference/agents/getDefaultGenerateOptions.mdx +1 -1
- package/.docs/raw/reference/agents/getDefaultStreamOptions.mdx +1 -1
- package/.docs/raw/reference/agents/getDefaultVNextStreamOptions.mdx +1 -1
- package/.docs/raw/reference/agents/getLLM.mdx +1 -1
- package/.docs/raw/reference/agents/streamVNext.mdx +88 -5
- package/.docs/raw/reference/cli/scorers.mdx +160 -0
- package/.docs/raw/reference/rag/chroma.mdx +158 -17
- package/.docs/raw/reference/templates.mdx +3 -3
- package/.docs/raw/reference/tools/create-tool.mdx +2 -2
- 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/branch.mdx +1 -1
- package/.docs/raw/reference/workflows/create-run.mdx +4 -4
- package/.docs/raw/reference/workflows/execute.mdx +2 -2
- package/.docs/raw/reference/workflows/foreach.mdx +1 -1
- package/.docs/raw/reference/workflows/run-methods/cancel.mdx +58 -0
- package/.docs/raw/reference/workflows/{resume.mdx → run-methods/resume.mdx} +7 -5
- package/.docs/raw/reference/workflows/{start.mdx → run-methods/start.mdx} +5 -5
- package/.docs/raw/reference/workflows/{stream.mdx → run-methods/stream.mdx} +6 -3
- package/.docs/raw/reference/workflows/{streamVNext.mdx → run-methods/streamVNext.mdx} +14 -9
- package/.docs/raw/reference/workflows/{watch.mdx → run-methods/watch.mdx} +12 -12
- package/.docs/raw/reference/workflows/run.mdx +104 -0
- package/.docs/raw/reference/workflows/step.mdx +0 -1
- package/.docs/raw/reference/workflows/workflow.mdx +3 -2
- package/.docs/raw/{reference/workflows → server-db}/snapshots.mdx +2 -2
- package/.docs/raw/voice/overview.mdx +81 -2
- package/.docs/raw/voice/speech-to-speech.mdx +45 -0
- package/.docs/raw/workflows/overview.mdx +11 -4
- package/.docs/raw/workflows-legacy/overview.mdx +8 -8
- package/package.json +4 -4
|
@@ -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
|
```
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "mastra scorers | Evaluation Management | Mastra CLI"
|
|
3
|
+
description: "Manage scorers for evaluating AI outputs with the Mastra CLI"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# mastra scorers
|
|
7
|
+
|
|
8
|
+
The `mastra scorers` command provides management capabilities for evaluation scorers that measure the quality, accuracy, and performance of AI-generated outputs.
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
mastra scorers <command> [options]
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Commands
|
|
17
|
+
|
|
18
|
+
### mastra scorers add
|
|
19
|
+
|
|
20
|
+
Add a new scorer template to your project.
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
mastra scorers add [scorer-name] [options]
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
#### Options
|
|
27
|
+
|
|
28
|
+
<PropertiesTable
|
|
29
|
+
content={[
|
|
30
|
+
{
|
|
31
|
+
name: "--dir",
|
|
32
|
+
type: "string",
|
|
33
|
+
description: "Path to your Mastra directory (default: auto-detect)",
|
|
34
|
+
isOptional: true,
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
name: "--help",
|
|
38
|
+
type: "boolean",
|
|
39
|
+
description: "Display help for command",
|
|
40
|
+
isOptional: true,
|
|
41
|
+
},
|
|
42
|
+
]}
|
|
43
|
+
/>
|
|
44
|
+
|
|
45
|
+
#### Examples
|
|
46
|
+
|
|
47
|
+
Add a specific scorer by name:
|
|
48
|
+
|
|
49
|
+
```bash copy
|
|
50
|
+
mastra scorers add answer-relevancy
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Interactive scorer selection (when no name provided):
|
|
54
|
+
|
|
55
|
+
```bash copy
|
|
56
|
+
mastra scorers add
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Add scorer to custom directory:
|
|
60
|
+
|
|
61
|
+
```bash copy
|
|
62
|
+
mastra scorers add toxicity-detection --dir ./custom/scorers
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### mastra scorers list
|
|
66
|
+
|
|
67
|
+
List all available scorer templates.
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
mastra scorers list
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
This command displays built-in scorer templates organized by category:
|
|
74
|
+
|
|
75
|
+
- **Accuracy and Reliability**: answer-relevancy, bias-detection, faithfulness, hallucination, toxicity-detection
|
|
76
|
+
- **Output Quality**: completeness, content-similarity, keyword-coverage, textual-difference, tone-consistency
|
|
77
|
+
|
|
78
|
+
## Available Scorers
|
|
79
|
+
|
|
80
|
+
When running `mastra scorers add` without specifying a scorer name, you can select from these built-in templates:
|
|
81
|
+
|
|
82
|
+
### Accuracy and Reliability
|
|
83
|
+
|
|
84
|
+
- **answer-relevancy**: Evaluates how relevant an AI response is to the input question
|
|
85
|
+
- **bias-detection**: Identifies potential biases in AI-generated content
|
|
86
|
+
- **faithfulness**: Measures how faithful the response is to provided context
|
|
87
|
+
- **hallucination**: Detects when AI generates information not grounded in the input
|
|
88
|
+
- **toxicity-detection**: Identifies harmful or inappropriate content
|
|
89
|
+
|
|
90
|
+
### Output Quality
|
|
91
|
+
|
|
92
|
+
- **completeness**: Assesses whether the response fully addresses the input
|
|
93
|
+
- **content-similarity**: Measures semantic similarity between expected and actual outputs
|
|
94
|
+
- **keyword-coverage**: Evaluates coverage of expected keywords or topics
|
|
95
|
+
- **textual-difference**: Measures textual differences between responses
|
|
96
|
+
- **tone-consistency**: Evaluates consistency of tone and style
|
|
97
|
+
|
|
98
|
+
## What It Does
|
|
99
|
+
|
|
100
|
+
1. **Dependency Management**: Automatically installs `@mastra/evals` package if needed
|
|
101
|
+
2. **Template Selection**: Provides interactive selection when no scorer specified
|
|
102
|
+
3. **File Generation**: Creates scorer files from built-in templates
|
|
103
|
+
4. **Directory Structure**: Places scorers in `src/mastra/scorers/` or custom directory
|
|
104
|
+
5. **Duplicate Detection**: Prevents overwriting existing scorer files
|
|
105
|
+
|
|
106
|
+
## Integration
|
|
107
|
+
|
|
108
|
+
After adding scorers, integrate them with your agents or workflows:
|
|
109
|
+
|
|
110
|
+
### With Agents
|
|
111
|
+
|
|
112
|
+
```typescript filename="src/mastra/agents/evaluated-agent.ts"
|
|
113
|
+
import { Agent } from "@mastra/core/agent";
|
|
114
|
+
import { openai } from "@ai-sdk/openai";
|
|
115
|
+
import { createAnswerRelevancyScorer } from "../scorers/answer-relevancy-scorer";
|
|
116
|
+
|
|
117
|
+
export const evaluatedAgent = new Agent({
|
|
118
|
+
// ... other config
|
|
119
|
+
scorers: {
|
|
120
|
+
relevancy: {
|
|
121
|
+
scorer: createAnswerRelevancyScorer({ model: openai("gpt-4o-mini") }),
|
|
122
|
+
sampling: { type: "ratio", rate: 0.5 }
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### With Workflow Steps
|
|
129
|
+
|
|
130
|
+
```typescript filename="src/mastra/workflows/content-generation.ts"
|
|
131
|
+
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
132
|
+
import { customStepScorer } from "../scorers/custom-step-scorer";
|
|
133
|
+
|
|
134
|
+
const contentStep = createStep({
|
|
135
|
+
// ... other config
|
|
136
|
+
scorers: {
|
|
137
|
+
customStepScorer: {
|
|
138
|
+
scorer: customStepScorer(),
|
|
139
|
+
sampling: { type: "ratio", rate: 1 }
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
});
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Testing Scorers
|
|
146
|
+
|
|
147
|
+
Use the [Local Dev Playground](/docs/server-db/local-dev-playground) to test your scorers:
|
|
148
|
+
|
|
149
|
+
```bash copy
|
|
150
|
+
mastra dev
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Navigate to [http://localhost:4111/](http://localhost:4111/) and access the scorers section to run individual scorers against test inputs and view detailed results.
|
|
154
|
+
|
|
155
|
+
## Next Steps
|
|
156
|
+
|
|
157
|
+
- Learn about scorer implementation in [Creating Custom Scorers](/docs/scorers/custom-scorers)
|
|
158
|
+
- Explore built-in options in [Off-the-shelf Scorers](/docs/scorers/off-the-shelf-scorers)
|
|
159
|
+
- See [Scorers Overview](/docs/scorers/overview) for evaluation pipeline details
|
|
160
|
+
- Test scorers with the [Local Dev Playground](/docs/server-db/local-dev-playground)
|
|
@@ -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.
|
|
@@ -5,10 +5,10 @@ description: "Complete guide to creating, using, and contributing Mastra templat
|
|
|
5
5
|
|
|
6
6
|
import { FileTree, Tabs, Callout } from 'nextra/components'
|
|
7
7
|
|
|
8
|
-
This reference provides comprehensive information about Mastra templates, including how to use existing templates, create your own, and contribute to the community ecosystem.
|
|
9
|
-
|
|
10
8
|
## Overview
|
|
11
9
|
|
|
10
|
+
This reference provides comprehensive information about Mastra templates, including how to use existing templates, create your own, and contribute to the community ecosystem.
|
|
11
|
+
|
|
12
12
|
Mastra templates are pre-built project structures that demonstrate specific use cases and patterns. They provide:
|
|
13
13
|
|
|
14
14
|
- **Working examples** - Complete, functional Mastra applications
|
|
@@ -184,7 +184,7 @@ Detailed explanation of the template's functionality and use case.
|
|
|
184
184
|
## Setup
|
|
185
185
|
|
|
186
186
|
1. Copy `.env.example` to `.env` and fill in your API keys
|
|
187
|
-
2. Install dependencies: `npm install`
|
|
187
|
+
2. Install dependencies: `npm install`
|
|
188
188
|
3. Run the project: `npm run dev`
|
|
189
189
|
|
|
190
190
|
## Environment Variables
|
|
@@ -13,8 +13,8 @@ The `createTool()` function is used to define custom tools that your Mastra agen
|
|
|
13
13
|
import { createTool } from "@mastra/core/tools";
|
|
14
14
|
import { z } from "zod";
|
|
15
15
|
|
|
16
|
-
export const
|
|
17
|
-
id: "
|
|
16
|
+
export const tool = createTool({
|
|
17
|
+
id: "test-tool",
|
|
18
18
|
description: "Reverse the input string",
|
|
19
19
|
inputSchema: z.object({
|
|
20
20
|
input: z.string()
|
|
@@ -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
|
```
|
|
@@ -44,5 +44,5 @@ workflow.branch([
|
|
|
44
44
|
|
|
45
45
|
## Related
|
|
46
46
|
|
|
47
|
-
- [Conditional branching](../../docs/workflows/flow
|
|
47
|
+
- [Conditional branching](../../docs/workflows/control-flow.mdx)
|
|
48
48
|
- [Conditional branching example](../../examples/workflows/conditional-branching.mdx)
|
|
@@ -24,10 +24,9 @@ await workflow.createRunAsync();
|
|
|
24
24
|
<PropertiesTable
|
|
25
25
|
content={[
|
|
26
26
|
{
|
|
27
|
-
name: "
|
|
28
|
-
type: "
|
|
29
|
-
description:
|
|
30
|
-
"Optional configuration for the run, including a custom run ID",
|
|
27
|
+
name: "runId",
|
|
28
|
+
type: "string",
|
|
29
|
+
description: "Optional custom identifier for the workflow run",
|
|
31
30
|
isOptional: true,
|
|
32
31
|
},
|
|
33
32
|
]}
|
|
@@ -62,4 +61,5 @@ const result = await run.start({
|
|
|
62
61
|
|
|
63
62
|
## Related
|
|
64
63
|
|
|
64
|
+
- [Run Class](./run.mdx)
|
|
65
65
|
- [Running workflows](../../examples/workflows/running-workflows.mdx)
|