@mastra/mcp-docs-server 0.13.5-alpha.0 → 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/%40mastra%2Fclient-js.md +18 -18
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +16 -16
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +21 -21
- package/.docs/organized/changelogs/%40mastra%2Ffirecrawl.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fmcp.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +23 -23
- 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 +18 -18
- package/.docs/organized/changelogs/create-mastra.md +8 -8
- package/.docs/organized/changelogs/mastra.md +17 -17
- package/.docs/raw/agents/overview.mdx +16 -33
- package/.docs/raw/community/licensing.mdx +27 -19
- package/.docs/raw/deployment/cloud-providers/digital-ocean.mdx +1 -1
- package/.docs/raw/deployment/server-deployment.mdx +56 -0
- package/.docs/raw/rag/retrieval.mdx +24 -5
- package/.docs/raw/reference/rag/rerankWithScorer.mdx +213 -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/LICENSE.md +11 -42
- package/package.json +5 -5
- package/.docs/raw/deployment/server.mdx +0 -116
- /package/.docs/raw/{deployment → server-db}/custom-api-routes.mdx +0 -0
- /package/.docs/raw/{local-dev/mastra-dev.mdx → server-db/local-dev-playground.mdx} +0 -0
- /package/.docs/raw/{client-js/overview.mdx → server-db/mastra-client.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
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Deploy A Mastra Server"
|
|
3
|
+
description: "Deploy a Mastra server with middleware and other options"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Deploy A Mastra Server
|
|
7
|
+
|
|
8
|
+
Mastra builds to a standard Node.js server, so you can deploy it to any platform that supports Node.js applications.
|
|
9
|
+
|
|
10
|
+
- Cloud VMs (AWS EC2, DigitalOcean Droplets, GCP Compute Engine)
|
|
11
|
+
- Container platforms (Docker, Kubernetes)
|
|
12
|
+
- Platform as a Service (Heroku, Railway)
|
|
13
|
+
- Self-hosted servers
|
|
14
|
+
|
|
15
|
+
See the [Cloud Providers](/docs/deployment/cloud-providers/) for more information.
|
|
16
|
+
|
|
17
|
+
### Building
|
|
18
|
+
|
|
19
|
+
Build the application:
|
|
20
|
+
|
|
21
|
+
```bash copy
|
|
22
|
+
# Build from current directory
|
|
23
|
+
mastra build
|
|
24
|
+
|
|
25
|
+
# Or specify a directory
|
|
26
|
+
mastra build --dir ./my-project
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
The build process:
|
|
30
|
+
|
|
31
|
+
1. Locates entry file (`src/mastra/index.ts` or `src/mastra/index.js`)
|
|
32
|
+
2. Creates `.mastra` output directory
|
|
33
|
+
3. Bundles code using Rollup with tree shaking and source maps
|
|
34
|
+
4. Generates [Hono](https://hono.dev) HTTP server
|
|
35
|
+
|
|
36
|
+
See [`mastra build`](/reference/cli/build) for all options.
|
|
37
|
+
|
|
38
|
+
### Running the Server
|
|
39
|
+
|
|
40
|
+
Start the HTTP server:
|
|
41
|
+
|
|
42
|
+
```bash copy
|
|
43
|
+
node .mastra/output/index.mjs
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Enable Telemetry for build output
|
|
47
|
+
|
|
48
|
+
Load instrumentation for the build output like so:
|
|
49
|
+
|
|
50
|
+
```bash copy
|
|
51
|
+
node --import=./.mastra/output/instrumentation.mjs .mastra/output/index.mjs
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Serverless Deployment
|
|
55
|
+
|
|
56
|
+
Mastra also supports serverless deployment on Cloudflare Workers, Vercel, and Netlify. See [Serverless Platforms](/docs/deployment/serverless-platforms/) for more information.
|
|
@@ -456,7 +456,10 @@ Here's how to use re-ranking:
|
|
|
456
456
|
|
|
457
457
|
```ts showLineNumbers copy
|
|
458
458
|
import { openai } from "@ai-sdk/openai";
|
|
459
|
-
import {
|
|
459
|
+
import {
|
|
460
|
+
rerankWithScorer as rerank,
|
|
461
|
+
MastraAgentRelevanceScorer
|
|
462
|
+
} from "@mastra/rag";
|
|
460
463
|
|
|
461
464
|
// Get initial results from vector search
|
|
462
465
|
const initialResults = await pgVector.query({
|
|
@@ -465,19 +468,35 @@ const initialResults = await pgVector.query({
|
|
|
465
468
|
topK: 10,
|
|
466
469
|
});
|
|
467
470
|
|
|
471
|
+
// Create a relevance scorer
|
|
472
|
+
const relevanceProvider = new MastraAgentRelevanceScorer('relevance-scorer', openai("gpt-4o-mini"));
|
|
473
|
+
|
|
468
474
|
// Re-rank the results
|
|
469
|
-
const rerankedResults = await rerank(
|
|
470
|
-
initialResults,
|
|
475
|
+
const rerankedResults = await rerank({
|
|
476
|
+
results: initialResults,
|
|
471
477
|
query,
|
|
472
|
-
|
|
478
|
+
provider: relevanceProvider,
|
|
479
|
+
options: {
|
|
480
|
+
topK: 10,
|
|
481
|
+
},
|
|
473
482
|
);
|
|
474
483
|
```
|
|
475
484
|
|
|
476
485
|
> **Note:** For semantic scoring to work properly during re-ranking, each result must include the text content in its `metadata.text` field.
|
|
477
486
|
|
|
487
|
+
You can also use other relevance score providers like Cohere or ZeroEntropy:
|
|
488
|
+
|
|
489
|
+
```ts showLineNumbers copy
|
|
490
|
+
const relevanceProvider = new CohereRelevanceScorer('rerank-v3.5');
|
|
491
|
+
```
|
|
492
|
+
|
|
493
|
+
```ts showLineNumbers copy
|
|
494
|
+
const relevanceProvider = new ZeroEntropyRelevanceScorer('zerank-1');
|
|
495
|
+
```
|
|
496
|
+
|
|
478
497
|
The re-ranked results combine vector similarity with semantic understanding to improve retrieval quality.
|
|
479
498
|
|
|
480
|
-
For more details about re-ranking, see the [rerank()](/reference/rag/
|
|
499
|
+
For more details about re-ranking, see the [rerank()](/reference/rag/rerankWithScorer) method.
|
|
481
500
|
|
|
482
501
|
For an example of how to use the re-ranking method, see the [Re-ranking Results](../../examples/rag/rerank/rerank.mdx) example.
|
|
483
502
|
|
|
@@ -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)
|
|
@@ -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
|
});
|
|
@@ -10,9 +10,9 @@ When you build a workflow, you typically break down operations into smaller task
|
|
|
10
10
|
- If the schemas match, the `outputSchema` from each step is automatically passed to the `inputSchema` of the next step.
|
|
11
11
|
- If the schemas don't match, use [Input data mapping](./input-data-mapping.mdx) to transform the `outputSchema` into the expected `inputSchema`.
|
|
12
12
|
|
|
13
|
-
##
|
|
13
|
+
## Chaining steps with `.then()`
|
|
14
14
|
|
|
15
|
-
Chain steps to execute
|
|
15
|
+
Chain steps to execute sequentially using `.then()`:
|
|
16
16
|
|
|
17
17
|
```typescript {8-9} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
18
18
|
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
@@ -27,7 +27,9 @@ export const testWorkflow = createWorkflow({...})
|
|
|
27
27
|
.commit();
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
This does what you'd expect: it executes `step1`, then it executes `step2`.
|
|
31
|
+
|
|
32
|
+
## Parallel steps with `.parallel()`:
|
|
31
33
|
|
|
32
34
|
Execute steps in parallel using `.parallel()`:
|
|
33
35
|
|
|
@@ -37,17 +39,19 @@ import { z } from "zod";
|
|
|
37
39
|
|
|
38
40
|
const step1 = createStep({...});
|
|
39
41
|
const step2 = createStep({...});
|
|
42
|
+
const step3 = createStep({...});
|
|
40
43
|
|
|
41
44
|
export const testWorkflow = createWorkflow({...})
|
|
42
45
|
.parallel([step1, step2])
|
|
46
|
+
.then(step3)
|
|
43
47
|
.commit();
|
|
44
48
|
```
|
|
45
49
|
|
|
46
|
-
This executes
|
|
50
|
+
This executes `step1` and `step2` concurrently, then continues to `step3` after both complete.
|
|
47
51
|
|
|
48
52
|
> See [Parallel Execution with Steps](/examples/workflows/parallel-steps) for more information.
|
|
49
53
|
|
|
50
|
-
##
|
|
54
|
+
## Conditional branching (`.branch()`)
|
|
51
55
|
|
|
52
56
|
Create conditional branches using `.branch()`:
|
|
53
57
|
|
|
@@ -60,8 +64,8 @@ const greaterThanStep = createStep({...});
|
|
|
60
64
|
|
|
61
65
|
export const testWorkflow = createWorkflow({...})
|
|
62
66
|
.branch([
|
|
63
|
-
[async ({ inputData: {
|
|
64
|
-
[async ({ inputData: {
|
|
67
|
+
[async ({ inputData: { value } }) => (value < 9), lessThanStep],
|
|
68
|
+
[async ({ inputData: { value } }) => (value >= 9), greaterThanStep]
|
|
65
69
|
])
|
|
66
70
|
.commit();
|
|
67
71
|
```
|
|
@@ -70,17 +74,13 @@ Branch conditions are evaluated sequentially, but steps with matching conditions
|
|
|
70
74
|
|
|
71
75
|
> See [Workflow with Conditional Branching](/examples/workflows/conditional-branching) for more information.
|
|
72
76
|
|
|
73
|
-
##
|
|
77
|
+
## Looping commands
|
|
74
78
|
|
|
75
79
|
Workflows support two types of loops. When looping a step, or any step-compatible construct like a nested workflow, the initial `inputData` is sourced from the output of the previous step.
|
|
76
80
|
|
|
77
|
-
To ensure compatibility, the loop’s initial input must either
|
|
78
|
-
|
|
79
|
-
- Match the shape of the previous step’s output, or
|
|
80
|
-
- Be explicitly transformed using the `map` function.
|
|
81
|
+
To ensure compatibility, the loop’s initial input must either match the shape of the previous step’s output, or be explicitly transformed using the `map` function.
|
|
81
82
|
|
|
82
|
-
|
|
83
|
-
### Dowhile
|
|
83
|
+
### `.dowhile()`
|
|
84
84
|
|
|
85
85
|
Executes a step repeatedly while a condition is true.
|
|
86
86
|
|
|
@@ -95,7 +95,7 @@ export const testWorkflow = createWorkflow({...})
|
|
|
95
95
|
.commit();
|
|
96
96
|
```
|
|
97
97
|
|
|
98
|
-
###
|
|
98
|
+
### `.dountil()`
|
|
99
99
|
|
|
100
100
|
Executes a step repeatedly until a condition becomes true.
|
|
101
101
|
|
|
@@ -110,8 +110,7 @@ export const testWorkflow = createWorkflow({...})
|
|
|
110
110
|
.commit();
|
|
111
111
|
```
|
|
112
112
|
|
|
113
|
-
|
|
114
|
-
### Foreach
|
|
113
|
+
### `.foreach()`
|
|
115
114
|
|
|
116
115
|
Sequentially executes the same step for each item from the `inputSchema`.
|
|
117
116
|
|
|
@@ -126,7 +125,7 @@ export const testWorkflow = createWorkflow({...})
|
|
|
126
125
|
.commit();
|
|
127
126
|
```
|
|
128
127
|
|
|
129
|
-
### Early exit
|
|
128
|
+
### Early exit with `.bail()`
|
|
130
129
|
|
|
131
130
|
You can bail out of a workflow execution successfully by calling `bail()` in a step. This returns whatever payload is passed to the `bail()` function as the result of the workflow.
|
|
132
131
|
|
|
@@ -167,6 +166,7 @@ export const testWorkflow = createWorkflow({...})
|
|
|
167
166
|
.then(step1)
|
|
168
167
|
.commit();
|
|
169
168
|
```
|
|
169
|
+
|
|
170
170
|
#### Example Run Instance
|
|
171
171
|
|
|
172
172
|
The following example demonstrates how to start a run with multiple inputs. Each input will pass through the `mapStep` sequentially.
|
|
@@ -202,44 +202,44 @@ export const testWorkflow = createWorkflow({...})
|
|
|
202
202
|
.commit();
|
|
203
203
|
```
|
|
204
204
|
|
|
205
|
-
##
|
|
205
|
+
## Using a workflow as a step
|
|
206
206
|
|
|
207
|
-
|
|
207
|
+
For greater composability, you can re-use a workflow as a step in another workflow.
|
|
208
208
|
|
|
209
|
-
|
|
209
|
+
In the example below, `nestedWorkflow` is used as a step within `testWorkflow`. The `testWorkflow` uses `step1` while the `nestedWorkflow` composes `step2` and `step3`:
|
|
210
|
+
|
|
211
|
+
```typescript {4,7} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
210
212
|
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
211
213
|
import { z } from "zod";
|
|
212
214
|
|
|
213
|
-
const
|
|
214
|
-
const workflow2 = createWorkflow({...});
|
|
215
|
+
export const nestedWorkflow = createWorkflow({...})
|
|
215
216
|
|
|
216
217
|
export const testWorkflow = createWorkflow({...})
|
|
217
|
-
.
|
|
218
|
+
.then(nestedWorkflow)
|
|
218
219
|
.commit();
|
|
219
220
|
```
|
|
220
221
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
## Nested Workflows
|
|
222
|
+
When using `.branch()` or `.parallel()` to build more complex control flows, executing more than one step requires wrapping those steps in a nested workflow, along with a clear definition of how they should be executed.
|
|
224
223
|
|
|
225
|
-
|
|
224
|
+
## Running nested workflows in parallel
|
|
226
225
|
|
|
226
|
+
Workflows themselves can also be executed in parallel.
|
|
227
227
|
|
|
228
|
-
```typescript {4,
|
|
228
|
+
```typescript {4-5,8} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
229
229
|
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
230
230
|
import { z } from "zod";
|
|
231
231
|
|
|
232
|
-
|
|
232
|
+
const workflow1 = createWorkflow({...});
|
|
233
|
+
const workflow2 = createWorkflow({...});
|
|
233
234
|
|
|
234
235
|
export const testWorkflow = createWorkflow({...})
|
|
235
|
-
.
|
|
236
|
+
.parallel([workflow1, workflow2])
|
|
236
237
|
.commit();
|
|
237
238
|
```
|
|
238
239
|
|
|
239
|
-
|
|
240
|
-
|
|
240
|
+
Parallel steps receive previous step results as input. Their outputs are passed into the next step input as an object where the key is the step `id` and the value is the step `output`.
|
|
241
241
|
|
|
242
|
-
##
|
|
242
|
+
## Cloning workflows
|
|
243
243
|
|
|
244
244
|
In the example below, `clonedWorkflow` is a clone of `workflow1` and is used as a step within `testWorkflow`. The `clonedWorkflow` is run sequentially after `step1`.
|
|
245
245
|
|
package/LICENSE.md
CHANGED
|
@@ -1,46 +1,15 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Apache License 2.0
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2025
|
|
3
|
+
Copyright (c) 2025 Kepler Software, Inc.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
you may not use this file except in compliance with the License.
|
|
7
|
+
You may obtain a copy of the License at
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
The licensor grants you a non-exclusive, royalty-free, worldwide, non-sublicensable, non-transferable license to use, copy, distribute, make available, and prepare derivative works of the software, in each case subject to the limitations and conditions below
|
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
You may not alter, remove, or obscure any licensing, copyright, or other notices of the licensor in the software. Any use of the licensor’s trademarks is subject to applicable law.
|
|
17
|
-
|
|
18
|
-
**Patents**
|
|
19
|
-
The licensor grants you a license, under any patent claims the licensor can license, or becomes able to license, to make, have made, use, sell, offer for sale, import and have imported the software, in each case subject to the limitations and conditions in this license. This license does not cover any patent claims that you cause to be infringed by modifications or additions to the software. If you or your company make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
|
|
20
|
-
|
|
21
|
-
**Notices**
|
|
22
|
-
You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms.
|
|
23
|
-
|
|
24
|
-
If you modify the software, you must include in any modified copies of the software prominent notices stating that you have modified the software.
|
|
25
|
-
|
|
26
|
-
**No Other Rights**
|
|
27
|
-
These terms do not imply any licenses other than those expressly granted in these terms.
|
|
28
|
-
|
|
29
|
-
**Termination**
|
|
30
|
-
If you use the software in violation of these terms, such use is not licensed, and your licenses will automatically terminate. If the licensor provides you with a notice of your violation, and you cease all violation of this license no later than 30 days after you receive that notice, your licenses will be reinstated retroactively. However, if you violate these terms after such reinstatement, any additional violation of these terms will cause your licenses to terminate automatically and permanently.
|
|
31
|
-
|
|
32
|
-
**No Liability**
|
|
33
|
-
As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.
|
|
34
|
-
|
|
35
|
-
**Definitions**
|
|
36
|
-
The _licensor_ is the entity offering these terms, and the _software_ is the software the licensor makes available under these terms, including any portion of it.
|
|
37
|
-
|
|
38
|
-
_you_ refers to the individual or entity agreeing to these terms.
|
|
39
|
-
|
|
40
|
-
_your company_ is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. _control_ means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
|
|
41
|
-
|
|
42
|
-
_your licenses_ are all the licenses granted to you for the software under these terms.
|
|
43
|
-
|
|
44
|
-
_use_ means anything you do with the software requiring one of your licenses.
|
|
45
|
-
|
|
46
|
-
_trademark_ means trademarks, service marks, and similar rights.
|
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
See the License for the specific language governing permissions and
|
|
15
|
+
limitations under the License.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/mcp-docs-server",
|
|
3
|
-
"version": "0.13.5
|
|
3
|
+
"version": "0.13.5",
|
|
4
4
|
"description": "MCP server for accessing Mastra.ai documentation, changelogs, and news.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
"keywords": [],
|
|
24
24
|
"author": "",
|
|
25
|
-
"license": "
|
|
25
|
+
"license": "Apache-2.0",
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@modelcontextprotocol/sdk": "^1.13.0",
|
|
28
28
|
"date-fns": "^4.1.0",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"uuid": "^11.1.0",
|
|
33
33
|
"zod": "^3.25.67",
|
|
34
34
|
"zod-to-json-schema": "^3.24.5",
|
|
35
|
-
"@mastra/mcp": "^0.10.6
|
|
35
|
+
"@mastra/mcp": "^0.10.6"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@hono/node-server": "^1.14.4",
|
|
@@ -47,8 +47,8 @@
|
|
|
47
47
|
"tsx": "^4.19.4",
|
|
48
48
|
"typescript": "^5.8.3",
|
|
49
49
|
"vitest": "^3.2.4",
|
|
50
|
-
"@internal/lint": "0.0.
|
|
51
|
-
"@mastra/core": "0.10.11
|
|
50
|
+
"@internal/lint": "0.0.18",
|
|
51
|
+
"@mastra/core": "0.10.11"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
54
|
"@mastra/core": "^0.10.0-alpha.0"
|