@mastra/mcp-docs-server 0.13.4 → 0.13.5
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 +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fagui.md +12 -12
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +55 -55
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +47 -47
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +42 -42
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +24 -24
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +24 -24
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +72 -72
- package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +31 -31
- package/.docs/organized/changelogs/%40mastra%2Ffastembed.md +7 -0
- package/.docs/organized/changelogs/%40mastra%2Ffirecrawl.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Floggers.md +9 -9
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +21 -21
- package/.docs/organized/changelogs/%40mastra%2Fmcp.md +25 -25
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +25 -25
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +77 -77
- package/.docs/organized/changelogs/%40mastra%2Frag.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fschema-compat.md +6 -0
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +54 -54
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +13 -13
- package/.docs/organized/changelogs/create-mastra.md +34 -34
- package/.docs/organized/changelogs/mastra.md +79 -79
- package/.docs/organized/code-examples/bird-checker-with-express.md +1 -1
- package/.docs/organized/code-examples/crypto-chatbot.md +9 -9
- package/.docs/organized/code-examples/fireworks-r1.md +1 -1
- package/.docs/organized/code-examples/memory-per-resource-example.md +1 -1
- package/.docs/organized/code-examples/memory-with-pg.md +1 -1
- package/.docs/organized/code-examples/memory-with-upstash.md +1 -1
- package/.docs/organized/code-examples/openapi-spec-writer.md +4 -4
- package/.docs/raw/agents/overview.mdx +16 -33
- package/.docs/raw/community/licensing.mdx +27 -19
- package/.docs/raw/deployment/cloud-providers/aws-lambda.mdx +279 -0
- package/.docs/raw/deployment/cloud-providers/digital-ocean.mdx +1 -1
- package/.docs/raw/deployment/server-deployment.mdx +56 -0
- package/.docs/raw/deployment/serverless-platforms/index.mdx +0 -1
- package/.docs/raw/frameworks/agentic-uis/ai-sdk.mdx +97 -0
- package/.docs/raw/frameworks/agentic-uis/assistant-ui.mdx +34 -0
- package/.docs/raw/memory/overview.mdx +2 -1
- package/.docs/raw/rag/retrieval.mdx +24 -5
- package/.docs/raw/reference/agents/generate.mdx +3 -2
- package/.docs/raw/reference/agents/stream.mdx +3 -2
- package/.docs/raw/reference/cli/dev.mdx +12 -0
- package/.docs/raw/reference/legacyWorkflows/createRun.mdx +0 -4
- package/.docs/raw/reference/memory/Memory.mdx +12 -6
- package/.docs/raw/reference/rag/rerankWithScorer.mdx +213 -0
- package/.docs/raw/reference/workflows/create-run.mdx +4 -4
- package/.docs/raw/reference/workflows/sendEvent.mdx +49 -0
- package/.docs/raw/{local-dev/mastra-dev.mdx → server-db/local-dev-playground.mdx} +10 -3
- package/.docs/raw/{client-js/overview.mdx → server-db/mastra-client.mdx} +16 -0
- package/.docs/raw/server-db/production-server.mdx +66 -0
- package/.docs/raw/tools-mcp/mcp-overview.mdx +4 -6
- package/.docs/raw/workflows/control-flow.mdx +34 -34
- package/.docs/raw/workflows/overview.mdx +1 -1
- package/.docs/raw/workflows/pausing-execution.mdx +74 -37
- package/LICENSE.md +11 -42
- package/package.json +6 -6
- package/.docs/raw/deployment/server.mdx +0 -116
- /package/.docs/raw/{deployment → server-db}/custom-api-routes.mdx +0 -0
- /package/.docs/raw/{deployment → server-db}/middleware.mdx +0 -0
- /package/.docs/raw/{storage/overview.mdx → server-db/storage.mdx} +0 -0
|
@@ -271,10 +271,11 @@ Configuration options for memory management:
|
|
|
271
271
|
parameters: [
|
|
272
272
|
{
|
|
273
273
|
name: "generateTitle",
|
|
274
|
-
type: "boolean | { model: LanguageModelV1 | ((ctx: RuntimeContext) => LanguageModelV1 | Promise<LanguageModelV1>) }",
|
|
274
|
+
type: "boolean | { model: LanguageModelV1 | ((ctx: RuntimeContext) => LanguageModelV1 | Promise<LanguageModelV1>), instructions: string | ((ctx: RuntimeContext) => string | Promise<string>) }",
|
|
275
275
|
isOptional: true,
|
|
276
276
|
description:
|
|
277
|
-
|
|
277
|
+
`Controls automatic thread title generation from the user's first message. Can be a boolean to enable/disable using the agent's model, or an object specifying a custom model and/or custom instructions for title generation (useful for cost optimization or title customization).
|
|
278
|
+
Example: { model: openai('gpt-4.1-nano'), instructions: 'Generate a concise title based on the initial user message.' }`,
|
|
278
279
|
},
|
|
279
280
|
],
|
|
280
281
|
},
|
|
@@ -48,6 +48,18 @@ mastra dev [options]
|
|
|
48
48
|
description: "Path to custom environment file",
|
|
49
49
|
isOptional: true,
|
|
50
50
|
},
|
|
51
|
+
{
|
|
52
|
+
name: "--inspect",
|
|
53
|
+
type: "boolean",
|
|
54
|
+
description: "Start the dev server in inspect mode for debugging (cannot be used with --inspect-brk)",
|
|
55
|
+
isOptional: true,
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: "--inspect-brk",
|
|
59
|
+
type: "boolean",
|
|
60
|
+
description: "Start the dev server in inspect mode and break at the beginning of the script (cannot be used with --inspect)",
|
|
61
|
+
isOptional: true,
|
|
62
|
+
},
|
|
51
63
|
{
|
|
52
64
|
name: "--help",
|
|
53
65
|
type: "boolean",
|
|
@@ -63,6 +63,7 @@ const memory = new Memory({
|
|
|
63
63
|
// Or use a different model for title generation
|
|
64
64
|
// generateTitle: {
|
|
65
65
|
// model: openai("gpt-4.1-nano"), // Use cheaper model for titles
|
|
66
|
+
// instructions: "Generate a concise title based on the initial user message.", // Custom instructions for title
|
|
66
67
|
// },
|
|
67
68
|
},
|
|
68
69
|
},
|
|
@@ -109,9 +110,9 @@ const memory = new Memory({
|
|
|
109
110
|
});
|
|
110
111
|
```
|
|
111
112
|
|
|
112
|
-
#### Cost Optimization with Custom Models
|
|
113
|
+
#### Cost Optimization with Custom Models and Instructions
|
|
113
114
|
|
|
114
|
-
You can specify a different (typically cheaper) model for title generation while using a high-quality model for the main conversation:
|
|
115
|
+
You can specify a different (typically cheaper) model and custom instructions for title generation while using a high-quality model for the main conversation:
|
|
115
116
|
|
|
116
117
|
```typescript copy showLineNumbers
|
|
117
118
|
import { openai } from "@ai-sdk/openai";
|
|
@@ -121,6 +122,7 @@ const memory = new Memory({
|
|
|
121
122
|
threads: {
|
|
122
123
|
generateTitle: {
|
|
123
124
|
model: openai("gpt-4.1-nano"), // Cheaper model for titles
|
|
125
|
+
instructions: "Generate a concise, friendly title based on the initial user message.", // Custom title instructions
|
|
124
126
|
},
|
|
125
127
|
},
|
|
126
128
|
},
|
|
@@ -132,9 +134,9 @@ const agent = new Agent({
|
|
|
132
134
|
});
|
|
133
135
|
```
|
|
134
136
|
|
|
135
|
-
#### Dynamic Model Selection
|
|
137
|
+
#### Dynamic Model Selection and Instructions
|
|
136
138
|
|
|
137
|
-
You can also use a function to dynamically determine the model based on runtime context:
|
|
139
|
+
You can also use a function to dynamically determine the model and instructions based on runtime context:
|
|
138
140
|
|
|
139
141
|
```typescript copy showLineNumbers
|
|
140
142
|
const memory = new Memory({
|
|
@@ -148,6 +150,10 @@ const memory = new Memory({
|
|
|
148
150
|
? openai("gpt-4.1")
|
|
149
151
|
: openai("gpt-4.1-nano");
|
|
150
152
|
},
|
|
153
|
+
instructions: (ctx: RuntimeContext) => {
|
|
154
|
+
const language = ctx.get("userLanguage") || "English";
|
|
155
|
+
return `Generate a concise, engaging title in ${language} based on the user's first message.`;
|
|
156
|
+
},
|
|
151
157
|
},
|
|
152
158
|
},
|
|
153
159
|
},
|
|
@@ -285,9 +291,9 @@ Mastra supports many embedding models through the [Vercel AI SDK](https://sdk.ve
|
|
|
285
291
|
},
|
|
286
292
|
{
|
|
287
293
|
name: "threads",
|
|
288
|
-
type: "{ generateTitle?: boolean | { model: LanguageModelV1 | ((ctx: RuntimeContext) => LanguageModelV1 | Promise<LanguageModelV1>) } }",
|
|
294
|
+
type: "{ generateTitle?: boolean | { model: LanguageModelV1 | ((ctx: RuntimeContext) => LanguageModelV1 | Promise<LanguageModelV1>), instructions?: string | ((ctx: RuntimeContext) => string | Promise<string>) } }",
|
|
289
295
|
description:
|
|
290
|
-
"Settings related to memory thread creation. `generateTitle` controls automatic thread title generation from the user's first message. Can be a boolean to enable/disable using the agent's model, or an object
|
|
296
|
+
"Settings related to memory thread creation. `generateTitle` controls automatic thread title generation from the user's first message. Can be a boolean to enable/disable using the agent's model, or an object specifying a custom model or custom instructions for title generation (useful for cost optimization or title customization). Example: { generateTitle: { model: openai('gpt-4.1-nano'), instructions: 'Concise title based on the initial user message.' } }",
|
|
291
297
|
isOptional: true,
|
|
292
298
|
defaultValue: "{ generateTitle: false }",
|
|
293
299
|
},
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: Rerank | Document Retrieval | RAG | Mastra Docs"
|
|
3
|
+
description: Documentation for the rerank function in Mastra, which provides advanced reranking capabilities for vector search results.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# rerankWithScorer()
|
|
7
|
+
|
|
8
|
+
The `rerankWithScorer()` function provides advanced reranking capabilities for vector search results by combining semantic relevance, vector similarity, and position-based scoring.
|
|
9
|
+
|
|
10
|
+
```typescript
|
|
11
|
+
function rerankWithScorer({
|
|
12
|
+
results: QueryResult[],
|
|
13
|
+
query: string,
|
|
14
|
+
scorer: RelevanceScoreProvider,
|
|
15
|
+
options?: RerankerFunctionOptions,
|
|
16
|
+
}): Promise<RerankResult[]>;
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage Example
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { openai } from "@ai-sdk/openai";
|
|
23
|
+
import { rerankWithScorer as rerank, CohereRelevanceScorer } from "@mastra/rag";
|
|
24
|
+
|
|
25
|
+
const scorer = new CohereRelevanceScorer('rerank-v3.5');
|
|
26
|
+
|
|
27
|
+
const rerankedResults = await rerank({
|
|
28
|
+
results: vectorSearchResults,
|
|
29
|
+
query: "How do I deploy to production?",
|
|
30
|
+
scorer,
|
|
31
|
+
options: {
|
|
32
|
+
weights: {
|
|
33
|
+
semantic: 0.5,
|
|
34
|
+
vector: 0.3,
|
|
35
|
+
position: 0.2,
|
|
36
|
+
},
|
|
37
|
+
topK: 3,
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Parameters
|
|
43
|
+
|
|
44
|
+
<PropertiesTable
|
|
45
|
+
content={[
|
|
46
|
+
{
|
|
47
|
+
name: "results",
|
|
48
|
+
type: "QueryResult[]",
|
|
49
|
+
description: "The vector search results to rerank",
|
|
50
|
+
isOptional: false,
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: "query",
|
|
54
|
+
type: "string",
|
|
55
|
+
description: "The search query text used to evaluate relevance",
|
|
56
|
+
isOptional: false,
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
name: "scorer",
|
|
60
|
+
type: "RelevanceScoreProvider",
|
|
61
|
+
description: "The relevance scorer to use for reranking",
|
|
62
|
+
isOptional: false,
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: "options",
|
|
66
|
+
type: "RerankerFunctionOptions",
|
|
67
|
+
description: "Options for the reranking model",
|
|
68
|
+
isOptional: true,
|
|
69
|
+
},
|
|
70
|
+
]}
|
|
71
|
+
/>
|
|
72
|
+
|
|
73
|
+
The `rerankWithScorer` function accepts any `RelevanceScoreProvider` from @mastra/rag.
|
|
74
|
+
|
|
75
|
+
> **Note:** For semantic scoring to work properly during re-ranking, each result must include the text content in its `metadata.text` field.
|
|
76
|
+
|
|
77
|
+
### RerankerFunctionOptions
|
|
78
|
+
|
|
79
|
+
<PropertiesTable
|
|
80
|
+
content={[
|
|
81
|
+
{
|
|
82
|
+
name: "weights",
|
|
83
|
+
type: "WeightConfig",
|
|
84
|
+
description:
|
|
85
|
+
"Weights for different scoring components (must add up to 1)",
|
|
86
|
+
isOptional: true,
|
|
87
|
+
properties: [
|
|
88
|
+
{
|
|
89
|
+
type: "number",
|
|
90
|
+
parameters: [
|
|
91
|
+
{
|
|
92
|
+
name: "semantic",
|
|
93
|
+
description: "Weight for semantic relevance",
|
|
94
|
+
isOptional: true,
|
|
95
|
+
type: "number (default: 0.4)",
|
|
96
|
+
},
|
|
97
|
+
],
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
type: "number",
|
|
101
|
+
parameters: [
|
|
102
|
+
{
|
|
103
|
+
name: "vector",
|
|
104
|
+
description: "Weight for vector similarity",
|
|
105
|
+
isOptional: true,
|
|
106
|
+
type: "number (default: 0.4)",
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
type: "number",
|
|
112
|
+
parameters: [
|
|
113
|
+
{
|
|
114
|
+
name: "position",
|
|
115
|
+
description: "Weight for position-based scoring",
|
|
116
|
+
isOptional: true,
|
|
117
|
+
type: "number (default: 0.2)",
|
|
118
|
+
},
|
|
119
|
+
],
|
|
120
|
+
},
|
|
121
|
+
],
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
name: "queryEmbedding",
|
|
125
|
+
type: "number[]",
|
|
126
|
+
description: "Embedding of the query",
|
|
127
|
+
isOptional: true,
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
name: "topK",
|
|
131
|
+
type: "number",
|
|
132
|
+
description: "Number of top results to return",
|
|
133
|
+
isOptional: true,
|
|
134
|
+
defaultValue: "3",
|
|
135
|
+
},
|
|
136
|
+
]}
|
|
137
|
+
/>
|
|
138
|
+
|
|
139
|
+
## Returns
|
|
140
|
+
|
|
141
|
+
The function returns an array of `RerankResult` objects:
|
|
142
|
+
|
|
143
|
+
<PropertiesTable
|
|
144
|
+
content={[
|
|
145
|
+
{
|
|
146
|
+
name: "result",
|
|
147
|
+
type: "QueryResult",
|
|
148
|
+
description: "The original query result",
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
name: "score",
|
|
152
|
+
type: "number",
|
|
153
|
+
description: "Combined reranking score (0-1)",
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
name: "details",
|
|
157
|
+
type: "ScoringDetails",
|
|
158
|
+
description: "Detailed scoring information",
|
|
159
|
+
},
|
|
160
|
+
]}
|
|
161
|
+
/>
|
|
162
|
+
|
|
163
|
+
### ScoringDetails
|
|
164
|
+
|
|
165
|
+
<PropertiesTable
|
|
166
|
+
content={[
|
|
167
|
+
{
|
|
168
|
+
name: "semantic",
|
|
169
|
+
type: "number",
|
|
170
|
+
description: "Semantic relevance score (0-1)",
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
name: "vector",
|
|
174
|
+
type: "number",
|
|
175
|
+
description: "Vector similarity score (0-1)",
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
name: "position",
|
|
179
|
+
type: "number",
|
|
180
|
+
description: "Position-based score (0-1)",
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
name: "queryAnalysis",
|
|
184
|
+
type: "object",
|
|
185
|
+
description: "Query analysis details",
|
|
186
|
+
isOptional: true,
|
|
187
|
+
properties: [
|
|
188
|
+
{
|
|
189
|
+
type: "number",
|
|
190
|
+
parameters: [
|
|
191
|
+
{
|
|
192
|
+
name: "magnitude",
|
|
193
|
+
description: "Magnitude of the query",
|
|
194
|
+
},
|
|
195
|
+
],
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
type: "number[]",
|
|
199
|
+
parameters: [
|
|
200
|
+
{
|
|
201
|
+
name: "dominantFeatures",
|
|
202
|
+
description: "Dominant features of the query",
|
|
203
|
+
},
|
|
204
|
+
],
|
|
205
|
+
},
|
|
206
|
+
],
|
|
207
|
+
},
|
|
208
|
+
]}
|
|
209
|
+
/>
|
|
210
|
+
|
|
211
|
+
## Related
|
|
212
|
+
|
|
213
|
+
- [createVectorQueryTool](../tools/vector-query-tool)
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: "Reference: Workflow.
|
|
3
|
-
description: Documentation for the `.
|
|
2
|
+
title: "Reference: Workflow.createRunAsync() | Building Workflows | Mastra Docs"
|
|
3
|
+
description: Documentation for the `.createRunAsync()` method in workflows, which creates a new workflow run instance.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
# Workflow.
|
|
6
|
+
# Workflow.createRunAsync()
|
|
7
7
|
|
|
8
|
-
The `.
|
|
8
|
+
The `.createRunAsync()` method creates a new workflow run instance, allowing you to execute the workflow with specific input data.
|
|
9
9
|
|
|
10
10
|
## Usage
|
|
11
11
|
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: Workflow.sendEvent() | Building Workflows | Mastra Docs"
|
|
3
|
+
description: Documentation for the `.sendEvent()` method in workflows, which resumes execution when an event is sent.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Workflow.sendEvent()
|
|
7
|
+
|
|
8
|
+
The `.sendEvent()` resumes execution when an event is sent.
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
```typescript
|
|
13
|
+
workflow.sendEvent('my-event-name', step1);
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Parameters
|
|
17
|
+
|
|
18
|
+
<PropertiesTable
|
|
19
|
+
content={[
|
|
20
|
+
{
|
|
21
|
+
name: "eventName",
|
|
22
|
+
type: "string",
|
|
23
|
+
description: "The name of the event to send",
|
|
24
|
+
isOptional: false,
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: "step",
|
|
28
|
+
type: "Step",
|
|
29
|
+
description: "The step to resume after the event is sent",
|
|
30
|
+
isOptional: false,
|
|
31
|
+
},
|
|
32
|
+
]}
|
|
33
|
+
/>
|
|
34
|
+
|
|
35
|
+
## Returns
|
|
36
|
+
|
|
37
|
+
<PropertiesTable
|
|
38
|
+
content={[
|
|
39
|
+
{
|
|
40
|
+
name: "workflow",
|
|
41
|
+
type: "Workflow",
|
|
42
|
+
description: "The workflow instance for method chaining",
|
|
43
|
+
},
|
|
44
|
+
]}
|
|
45
|
+
/>
|
|
46
|
+
|
|
47
|
+
## Related
|
|
48
|
+
|
|
49
|
+
- [Sleep & Events](../../docs/workflows/pausing-execution.mdx)
|
|
@@ -4,6 +4,7 @@ description: Documentation for the Mastra local development environment for Mast
|
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
import YouTube from "@/components/youtube";
|
|
7
|
+
import { VideoPlayer } from "@/components/video-player"
|
|
7
8
|
import { Tabs, Tab } from "@/components/tabs";
|
|
8
9
|
|
|
9
10
|
# Playground
|
|
@@ -42,7 +43,9 @@ The Playground lets you interact with your agents, workflows, and tools. It prov
|
|
|
42
43
|
|
|
43
44
|
Quickly test and debug your agents during development using the interactive chat interface in the Agent Playground.
|
|
44
45
|
|
|
45
|
-
|
|
46
|
+
<VideoPlayer
|
|
47
|
+
src="https://res.cloudinary.com/dygi6femd/video/upload/v1751406022/local-dev-agents-playground_100_m3begx.mp4"
|
|
48
|
+
/>
|
|
46
49
|
|
|
47
50
|
Key features:
|
|
48
51
|
|
|
@@ -56,7 +59,9 @@ Key features:
|
|
|
56
59
|
|
|
57
60
|
Validate workflows by supplying defined inputs and visualizing each step within the Workflow Playground.
|
|
58
61
|
|
|
59
|
-
|
|
62
|
+
<VideoPlayer
|
|
63
|
+
src="https://res.cloudinary.com/dygi6femd/video/upload/v1751406027/local-dev-workflows-playground_100_rbc466.mp4"
|
|
64
|
+
/>
|
|
60
65
|
|
|
61
66
|
Key features:
|
|
62
67
|
|
|
@@ -70,7 +75,9 @@ Key features:
|
|
|
70
75
|
|
|
71
76
|
Quickly test and debug custom tools in isolation using the Tools Playground, without running a full agent or workflow.
|
|
72
77
|
|
|
73
|
-
|
|
78
|
+
<VideoPlayer
|
|
79
|
+
src="https://res.cloudinary.com/dygi6femd/video/upload/v1751406316/local-dev-agents-tools_100_fe1jdt.mp4"
|
|
80
|
+
/>
|
|
74
81
|
|
|
75
82
|
Key features:
|
|
76
83
|
|
|
@@ -78,6 +78,22 @@ const client = new MastraClient({
|
|
|
78
78
|
});
|
|
79
79
|
```
|
|
80
80
|
|
|
81
|
+
## AbortSignal
|
|
82
|
+
|
|
83
|
+
The Mastra Client SDK supports request cancellation using the standard Web API `AbortSignal`. Pass an `AbortSignal` to the client constructor to enable cancellation for all requests:
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
const controller = new AbortController();
|
|
87
|
+
|
|
88
|
+
const client = new MastraClient({
|
|
89
|
+
baseUrl: "http://localhost:4111",
|
|
90
|
+
abortSignal: controller.signal,
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
// Cancel all requests from this client
|
|
94
|
+
controller.abort();
|
|
95
|
+
```
|
|
96
|
+
|
|
81
97
|
## Example
|
|
82
98
|
|
|
83
99
|
Once your MastraClient is initialized you can start making client calls via the type-safe
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Create A Mastra Production Server"
|
|
3
|
+
description: "Learn how to configure and deploy a production-ready Mastra server with custom settings for APIs, CORS, and more"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Create a Mastra Production Server
|
|
7
|
+
|
|
8
|
+
When deploying your Mastra application to production, it runs as an HTTP server that exposes your agents, workflows, and other functionality as API endpoints. This page covers how to configure and customize the server for a production environment.
|
|
9
|
+
|
|
10
|
+
## Server Architecture
|
|
11
|
+
|
|
12
|
+
Mastra uses [Hono](https://hono.dev) as its underlying HTTP server framework. When you build a Mastra application using `mastra build`, it generates a Hono-based HTTP server in the `.mastra` directory.
|
|
13
|
+
|
|
14
|
+
The server provides:
|
|
15
|
+
|
|
16
|
+
- API endpoints for all registered agents
|
|
17
|
+
- API endpoints for all registered workflows
|
|
18
|
+
- Custom API route support
|
|
19
|
+
- Custom middleware support
|
|
20
|
+
- Configuration of timeout
|
|
21
|
+
- Configuration of port
|
|
22
|
+
- Configuration of body limit
|
|
23
|
+
|
|
24
|
+
See the [Middleware](/docs/server-db/middleware) and
|
|
25
|
+
[Custom API Routes](/docs/server-db/custom-api-routes) pages for details on
|
|
26
|
+
adding additional server behaviour.
|
|
27
|
+
|
|
28
|
+
## Server configuration
|
|
29
|
+
|
|
30
|
+
You can configure server `port` and `timeout` in the Mastra instance.
|
|
31
|
+
|
|
32
|
+
```typescript filename="src/mastra/index.ts" copy showLineNumbers
|
|
33
|
+
import { Mastra } from "@mastra/core/mastra";
|
|
34
|
+
|
|
35
|
+
export const mastra = new Mastra({
|
|
36
|
+
// ...
|
|
37
|
+
server: {
|
|
38
|
+
port: 3000, // Defaults to 4111
|
|
39
|
+
timeout: 10000, // Defaults to 30000 (30s)
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
The `method` option can be one of `"GET"`, `"POST"`, `"PUT"`,
|
|
45
|
+
`"DELETE"` or `"ALL"`. Using `"ALL"` will cause the handler to be
|
|
46
|
+
invoked for any HTTP method that matches the path.
|
|
47
|
+
|
|
48
|
+
## Custom CORS Config
|
|
49
|
+
|
|
50
|
+
Mastra allows you to configure CORS (Cross-Origin Resource Sharing) settings for your server.
|
|
51
|
+
|
|
52
|
+
```typescript filename="src/mastra/index.ts" copy showLineNumbers
|
|
53
|
+
import { Mastra } from "@mastra/core/mastra";
|
|
54
|
+
|
|
55
|
+
export const mastra = new Mastra({
|
|
56
|
+
// ...
|
|
57
|
+
server: {
|
|
58
|
+
cors: {
|
|
59
|
+
origin: ["https://example.com"], // Allow specific origins or '*' for all
|
|
60
|
+
allowMethods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
|
|
61
|
+
allowHeaders: ["Content-Type", "Authorization"],
|
|
62
|
+
credentials: false,
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
```
|
|
@@ -313,7 +313,7 @@ Workflows will use their `inputSchema` for the tool's input.
|
|
|
313
313
|
|
|
314
314
|
You can define an `outputSchema` for your tools to enforce a specific structure for the tool's output. This is useful for ensuring that the tool returns data in a consistent and predictable format, which can then be validated by the client.
|
|
315
315
|
|
|
316
|
-
When a tool includes an `outputSchema`, its `execute` function **must** return an object
|
|
316
|
+
When a tool includes an `outputSchema`, its `execute` function **must** return an object. The value of the object must conform to the `outputSchema`. Mastra will automatically validate this output on both the server and client sides.
|
|
317
317
|
|
|
318
318
|
Here's an example of a tool with an `outputSchema`:
|
|
319
319
|
|
|
@@ -331,12 +331,10 @@ export const structuredTool = createTool({
|
|
|
331
331
|
timestamp: z.string().describe('An ISO timestamp.'),
|
|
332
332
|
}),
|
|
333
333
|
execute: async ({ input }) => {
|
|
334
|
-
// When outputSchema is defined, you must return
|
|
334
|
+
// When outputSchema is defined, you must return an object
|
|
335
335
|
return {
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
timestamp: new Date().toISOString(),
|
|
339
|
-
},
|
|
336
|
+
processedInput: `processed: ${input}`,
|
|
337
|
+
timestamp: new Date().toISOString(),
|
|
340
338
|
};
|
|
341
339
|
},
|
|
342
340
|
});
|