@mastra/mcp-docs-server 1.0.0-beta.10 → 1.0.0-beta.11
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%2Fai-sdk.md +27 -27
- package/.docs/organized/changelogs/%40mastra%2Fchroma.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +27 -27
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +91 -91
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +9 -9
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +30 -30
- package/.docs/organized/changelogs/%40mastra%2Freact.md +26 -0
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +31 -31
- package/.docs/organized/changelogs/create-mastra.md +3 -3
- package/.docs/organized/changelogs/mastra.md +15 -15
- package/.docs/raw/agents/guardrails.mdx +43 -6
- package/.docs/raw/agents/processors.mdx +151 -0
- package/.docs/raw/getting-started/mcp-docs-server.mdx +57 -0
- package/.docs/raw/getting-started/studio.mdx +24 -1
- package/.docs/raw/guides/migrations/upgrade-to-v1/agent.mdx +70 -0
- package/.docs/raw/reference/agents/agent.mdx +11 -4
- package/.docs/raw/reference/core/getServer.mdx +1 -1
- package/.docs/raw/reference/processors/processor-interface.mdx +314 -13
- package/.docs/raw/reference/streaming/ChunkType.mdx +23 -2
- package/.docs/raw/reference/streaming/agents/stream.mdx +16 -29
- package/.docs/raw/reference/workflows/workflow-methods/foreach.mdx +68 -3
- package/.docs/raw/reference/workflows/workflow.mdx +23 -0
- package/.docs/raw/server-db/mastra-server.mdx +7 -5
- package/.docs/raw/workflows/control-flow.mdx +348 -2
- package/CHANGELOG.md +7 -0
- package/package.json +5 -5
|
@@ -33,20 +33,23 @@ adding additional server behaviour.
|
|
|
33
33
|
|
|
34
34
|
## Server configuration
|
|
35
35
|
|
|
36
|
-
You can configure server `port` and `timeout` in the Mastra instance.
|
|
36
|
+
You can configure server `port`, `host`, `studioBase`, and `timeout` in the Mastra instance.
|
|
37
37
|
|
|
38
|
-
```typescript title="src/mastra/index.ts" copy
|
|
38
|
+
```typescript title="src/mastra/index.ts" copy
|
|
39
39
|
import { Mastra } from "@mastra/core";
|
|
40
40
|
|
|
41
41
|
export const mastra = new Mastra({
|
|
42
|
-
// ...
|
|
43
42
|
server: {
|
|
44
43
|
port: 3000, // Defaults to 4111
|
|
44
|
+
host: "0.0.0.0", // Defaults to 'localhost'
|
|
45
|
+
studioBase: "/my-mastra-studio", // Sub-path for the studio (optional)
|
|
45
46
|
timeout: 10000, // Defaults to 3 * 60 * 1000 (3 minutes)
|
|
46
47
|
},
|
|
47
48
|
});
|
|
48
49
|
```
|
|
49
50
|
|
|
51
|
+
The `studioBase` option allows you to host Mastra Studio on a sub-path of your existing application. For example, with `studioBase: "/my-mastra-studio"`, the studio will be available at `http://your-host:port/my-mastra-studio` instead of the root.
|
|
52
|
+
|
|
50
53
|
## TypeScript configuration
|
|
51
54
|
|
|
52
55
|
Mastra requires `module` and `moduleResolution` values that support modern Node.js versions. Older settings like `CommonJS` or `node` are incompatible with Mastra’s packages and will cause resolution errors.
|
|
@@ -74,11 +77,10 @@ Mastra requires `module` and `moduleResolution` values that support modern Node.
|
|
|
74
77
|
|
|
75
78
|
Mastra allows you to configure CORS (Cross-Origin Resource Sharing) settings for your server.
|
|
76
79
|
|
|
77
|
-
```typescript title="src/mastra/index.ts" copy
|
|
80
|
+
```typescript title="src/mastra/index.ts" copy
|
|
78
81
|
import { Mastra } from "@mastra/core";
|
|
79
82
|
|
|
80
83
|
export const mastra = new Mastra({
|
|
81
|
-
// ...
|
|
82
84
|
server: {
|
|
83
85
|
cors: {
|
|
84
86
|
origin: ["https://example.com"], // Allow specific origins or '*' for all
|
|
@@ -59,7 +59,7 @@ export const testWorkflow = createWorkflow({
|
|
|
59
59
|
|
|
60
60
|
## Simultaneous steps with `.parallel()`
|
|
61
61
|
|
|
62
|
-
Use `.parallel()` to run steps at the same time. Each step's `id` is used when defining a following step's `inputSchema` and becomes the key on the `inputData` object used to access the previous step's values. The outputs of parallel steps can then be referenced or combined by a following step.
|
|
62
|
+
Use `.parallel()` to run steps at the same time. All parallel steps must complete before the workflow continues to the next step. Each step's `id` is used when defining a following step's `inputSchema` and becomes the key on the `inputData` object used to access the previous step's values. The outputs of parallel steps can then be referenced or combined by a following step.
|
|
63
63
|
|
|
64
64
|

|
|
65
65
|
|
|
@@ -176,6 +176,8 @@ export const testWorkflow = createWorkflow({
|
|
|
176
176
|
- The next step receives an object containing all parallel step outputs
|
|
177
177
|
- You must define the `inputSchema` of the following step to match this structure
|
|
178
178
|
|
|
179
|
+
> See [Choosing the right pattern](#choosing-the-right-pattern) to understand when to use `.parallel()` vs `.foreach()`.
|
|
180
|
+
|
|
179
181
|
## Conditional logic with `.branch()`
|
|
180
182
|
|
|
181
183
|
Use `.branch()` to choose which step to run based on a condition. All steps in a branch need the same `inputSchema` and `outputSchema` because branching requires consistent schemas so workflows can follow different paths.
|
|
@@ -428,7 +430,7 @@ export const testWorkflow = createWorkflow({
|
|
|
428
430
|
|
|
429
431
|
### Looping with `.foreach()`
|
|
430
432
|
|
|
431
|
-
Use `.foreach()` to run the same step for each item in an array. The input must be of type `array` so the loop can iterate over its values, applying the step
|
|
433
|
+
Use `.foreach()` to run the same step for each item in an array. The input must be of type `array` so the loop can iterate over its values, applying the step's logic to each one. See [Choosing the right pattern](#choosing-the-right-pattern) for guidance on when to use `.foreach()` vs other methods.
|
|
432
434
|
|
|
433
435
|

|
|
434
436
|
|
|
@@ -454,6 +456,32 @@ export const testWorkflow = createWorkflow({
|
|
|
454
456
|
.commit();
|
|
455
457
|
```
|
|
456
458
|
|
|
459
|
+
#### Output structure
|
|
460
|
+
|
|
461
|
+
The `.foreach()` method always returns an array containing the output of each iteration. The order of outputs matches the order of inputs.
|
|
462
|
+
|
|
463
|
+
```typescript title="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
464
|
+
const addTenStep = createStep({
|
|
465
|
+
id: "add-ten",
|
|
466
|
+
inputSchema: z.object({ value: z.number() }),
|
|
467
|
+
outputSchema: z.object({ value: z.number() }),
|
|
468
|
+
execute: async ({ inputData }) => ({
|
|
469
|
+
value: inputData.value + 10
|
|
470
|
+
})
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
export const testWorkflow = createWorkflow({
|
|
474
|
+
id: "foreach-output-example",
|
|
475
|
+
inputSchema: z.array(z.object({ value: z.number() })),
|
|
476
|
+
outputSchema: z.array(z.object({ value: z.number() }))
|
|
477
|
+
})
|
|
478
|
+
.foreach(addTenStep)
|
|
479
|
+
.commit();
|
|
480
|
+
|
|
481
|
+
// When executed with [{ value: 1 }, { value: 22 }, { value: 333 }]
|
|
482
|
+
// Output: [{ value: 11 }, { value: 32 }, { value: 343 }]
|
|
483
|
+
```
|
|
484
|
+
|
|
457
485
|
#### Concurrency limits
|
|
458
486
|
|
|
459
487
|
Use `concurrency` to control the number of array items processed at the same time. The default is `1`, which runs steps sequentially. Increasing the value allows `.foreach()` to process multiple items simultaneously.
|
|
@@ -466,6 +494,324 @@ export const testWorkflow = createWorkflow({...})
|
|
|
466
494
|
.commit();
|
|
467
495
|
```
|
|
468
496
|
|
|
497
|
+
#### Aggregating results after `.foreach()`
|
|
498
|
+
|
|
499
|
+
Since `.foreach()` outputs an array, you can use `.then()` or `.map()` to aggregate or transform the results. The step following `.foreach()` receives the entire array as its input.
|
|
500
|
+
|
|
501
|
+
```typescript title="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
502
|
+
const processItemStep = createStep({
|
|
503
|
+
id: "process-item",
|
|
504
|
+
inputSchema: z.object({ value: z.number() }),
|
|
505
|
+
outputSchema: z.object({ processed: z.number() }),
|
|
506
|
+
execute: async ({ inputData }) => ({
|
|
507
|
+
processed: inputData.value * 2
|
|
508
|
+
})
|
|
509
|
+
});
|
|
510
|
+
|
|
511
|
+
const aggregateStep = createStep({
|
|
512
|
+
id: "aggregate",
|
|
513
|
+
// Input is an array of outputs from foreach
|
|
514
|
+
inputSchema: z.array(z.object({ processed: z.number() })),
|
|
515
|
+
outputSchema: z.object({ total: z.number() }),
|
|
516
|
+
execute: async ({ inputData }) => ({
|
|
517
|
+
// Sum all processed values
|
|
518
|
+
total: inputData.reduce((sum, item) => sum + item.processed, 0)
|
|
519
|
+
})
|
|
520
|
+
});
|
|
521
|
+
|
|
522
|
+
export const testWorkflow = createWorkflow({
|
|
523
|
+
id: "foreach-aggregate-example",
|
|
524
|
+
inputSchema: z.array(z.object({ value: z.number() })),
|
|
525
|
+
outputSchema: z.object({ total: z.number() })
|
|
526
|
+
})
|
|
527
|
+
.foreach(processItemStep)
|
|
528
|
+
.then(aggregateStep) // Receives the full array from foreach
|
|
529
|
+
.commit();
|
|
530
|
+
|
|
531
|
+
// When executed with [{ value: 1 }, { value: 2 }, { value: 3 }]
|
|
532
|
+
// After foreach: [{ processed: 2 }, { processed: 4 }, { processed: 6 }]
|
|
533
|
+
// After aggregate: { total: 12 }
|
|
534
|
+
```
|
|
535
|
+
|
|
536
|
+
You can also use `.map()` to transform the array output:
|
|
537
|
+
|
|
538
|
+
```typescript title="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
539
|
+
export const testWorkflow = createWorkflow({...})
|
|
540
|
+
.foreach(processItemStep)
|
|
541
|
+
.map(async ({ inputData }) => ({
|
|
542
|
+
// Transform the array into a different structure
|
|
543
|
+
values: inputData.map(item => item.processed),
|
|
544
|
+
count: inputData.length
|
|
545
|
+
}))
|
|
546
|
+
.then(nextStep)
|
|
547
|
+
.commit();
|
|
548
|
+
```
|
|
549
|
+
|
|
550
|
+
#### Chaining multiple `.foreach()` calls
|
|
551
|
+
|
|
552
|
+
When you chain `.foreach()` calls, each operates on the array output of the previous step. This is useful when each item in your array needs to be transformed by multiple steps in sequence.
|
|
553
|
+
|
|
554
|
+
```typescript title="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
555
|
+
const chunkStep = createStep({
|
|
556
|
+
id: "chunk",
|
|
557
|
+
// Takes a document, returns an array of chunks
|
|
558
|
+
inputSchema: z.object({ content: z.string() }),
|
|
559
|
+
outputSchema: z.array(z.object({ chunk: z.string() })),
|
|
560
|
+
execute: async ({ inputData }) => {
|
|
561
|
+
// Split document into chunks
|
|
562
|
+
const chunks = inputData.content.match(/.{1,100}/g) || [];
|
|
563
|
+
return chunks.map(chunk => ({ chunk }));
|
|
564
|
+
}
|
|
565
|
+
});
|
|
566
|
+
|
|
567
|
+
const embedStep = createStep({
|
|
568
|
+
id: "embed",
|
|
569
|
+
// Takes a single chunk, returns embedding
|
|
570
|
+
inputSchema: z.object({ chunk: z.string() }),
|
|
571
|
+
outputSchema: z.object({ embedding: z.array(z.number()) }),
|
|
572
|
+
execute: async ({ inputData }) => ({
|
|
573
|
+
embedding: [/* vector embedding */]
|
|
574
|
+
})
|
|
575
|
+
});
|
|
576
|
+
|
|
577
|
+
// For a single document that produces multiple chunks:
|
|
578
|
+
export const singleDocWorkflow = createWorkflow({
|
|
579
|
+
id: "single-doc-rag",
|
|
580
|
+
inputSchema: z.object({ content: z.string() }),
|
|
581
|
+
outputSchema: z.array(z.object({ embedding: z.array(z.number()) }))
|
|
582
|
+
})
|
|
583
|
+
.then(chunkStep) // Returns array of chunks
|
|
584
|
+
.foreach(embedStep) // Process each chunk -> array of embeddings
|
|
585
|
+
.commit();
|
|
586
|
+
```
|
|
587
|
+
|
|
588
|
+
For processing multiple documents where each produces multiple chunks, you have options:
|
|
589
|
+
|
|
590
|
+
**Option 1: Process all documents in a single step with batching control**
|
|
591
|
+
|
|
592
|
+
```typescript title="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
593
|
+
const downloadAndChunkStep = createStep({
|
|
594
|
+
id: "download-and-chunk",
|
|
595
|
+
inputSchema: z.array(z.string()), // Array of URLs
|
|
596
|
+
outputSchema: z.array(z.object({ chunk: z.string(), source: z.string() })),
|
|
597
|
+
execute: async ({ inputData: urls }) => {
|
|
598
|
+
// Control batching/parallelization within the step
|
|
599
|
+
const allChunks = [];
|
|
600
|
+
for (const url of urls) {
|
|
601
|
+
const content = await fetch(url).then(r => r.text());
|
|
602
|
+
const chunks = content.match(/.{1,100}/g) || [];
|
|
603
|
+
allChunks.push(...chunks.map(chunk => ({ chunk, source: url })));
|
|
604
|
+
}
|
|
605
|
+
return allChunks;
|
|
606
|
+
}
|
|
607
|
+
});
|
|
608
|
+
|
|
609
|
+
export const multiDocWorkflow = createWorkflow({...})
|
|
610
|
+
.then(downloadAndChunkStep) // Returns flat array of all chunks
|
|
611
|
+
.foreach(embedStep, { concurrency: 10 }) // Embed each chunk in parallel
|
|
612
|
+
.commit();
|
|
613
|
+
```
|
|
614
|
+
|
|
615
|
+
**Option 2: Use foreach for documents, aggregate chunks, then foreach for embeddings**
|
|
616
|
+
|
|
617
|
+
```typescript title="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
618
|
+
const downloadStep = createStep({
|
|
619
|
+
id: "download",
|
|
620
|
+
inputSchema: z.string(), // Single URL
|
|
621
|
+
outputSchema: z.object({ content: z.string(), source: z.string() }),
|
|
622
|
+
execute: async ({ inputData: url }) => ({
|
|
623
|
+
content: await fetch(url).then(r => r.text()),
|
|
624
|
+
source: url
|
|
625
|
+
})
|
|
626
|
+
});
|
|
627
|
+
|
|
628
|
+
const chunkDocStep = createStep({
|
|
629
|
+
id: "chunk-doc",
|
|
630
|
+
inputSchema: z.object({ content: z.string(), source: z.string() }),
|
|
631
|
+
outputSchema: z.array(z.object({ chunk: z.string(), source: z.string() })),
|
|
632
|
+
execute: async ({ inputData }) => {
|
|
633
|
+
const chunks = inputData.content.match(/.{1,100}/g) || [];
|
|
634
|
+
return chunks.map(chunk => ({ chunk, source: inputData.source }));
|
|
635
|
+
}
|
|
636
|
+
});
|
|
637
|
+
|
|
638
|
+
export const multiDocWorkflow = createWorkflow({
|
|
639
|
+
id: "multi-doc-rag",
|
|
640
|
+
inputSchema: z.array(z.string()), // Array of URLs
|
|
641
|
+
outputSchema: z.array(z.object({ embedding: z.array(z.number()) }))
|
|
642
|
+
})
|
|
643
|
+
.foreach(downloadStep, { concurrency: 5 }) // Download docs in parallel
|
|
644
|
+
.foreach(chunkDocStep) // Chunk each doc -> array of chunk arrays
|
|
645
|
+
.map(async ({ inputData }) => {
|
|
646
|
+
// Flatten nested arrays: [[chunks], [chunks]] -> [chunks]
|
|
647
|
+
return inputData.flat();
|
|
648
|
+
})
|
|
649
|
+
.foreach(embedStep, { concurrency: 10 }) // Embed all chunks
|
|
650
|
+
.commit();
|
|
651
|
+
```
|
|
652
|
+
|
|
653
|
+
**Key points about chaining `.foreach()`:**
|
|
654
|
+
- Each `.foreach()` operates on the array from the previous step
|
|
655
|
+
- If a step inside `.foreach()` returns an array, the output becomes an array of arrays
|
|
656
|
+
- Use `.map()` with `.flat()` to flatten nested arrays when needed
|
|
657
|
+
- For complex RAG pipelines, Option 1 (handling batching in a single step) often provides better control
|
|
658
|
+
|
|
659
|
+
#### Nested workflows inside foreach
|
|
660
|
+
|
|
661
|
+
The step after `.foreach()` only executes after all iterations complete. If you need to run multiple sequential operations per item, use a nested workflow instead of chaining multiple `.foreach()` calls. This keeps all operations for each item together and makes the data flow clearer.
|
|
662
|
+
|
|
663
|
+
```typescript title="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
664
|
+
// Define a workflow that processes a single document
|
|
665
|
+
const processDocumentWorkflow = createWorkflow({
|
|
666
|
+
id: "process-document",
|
|
667
|
+
inputSchema: z.object({ url: z.string() }),
|
|
668
|
+
outputSchema: z.object({
|
|
669
|
+
embeddings: z.array(z.array(z.number())),
|
|
670
|
+
metadata: z.object({ url: z.string(), chunkCount: z.number() })
|
|
671
|
+
})
|
|
672
|
+
})
|
|
673
|
+
.then(downloadStep) // Download the document
|
|
674
|
+
.then(chunkStep) // Split into chunks
|
|
675
|
+
.then(embedChunksStep) // Embed all chunks for this document
|
|
676
|
+
.then(formatResultStep) // Format the final output
|
|
677
|
+
.commit();
|
|
678
|
+
|
|
679
|
+
// Use the nested workflow inside foreach
|
|
680
|
+
export const batchProcessWorkflow = createWorkflow({
|
|
681
|
+
id: "batch-process-documents",
|
|
682
|
+
inputSchema: z.array(z.object({ url: z.string() })),
|
|
683
|
+
outputSchema: z.array(z.object({
|
|
684
|
+
embeddings: z.array(z.array(z.number())),
|
|
685
|
+
metadata: z.object({ url: z.string(), chunkCount: z.number() })
|
|
686
|
+
}))
|
|
687
|
+
})
|
|
688
|
+
.foreach(processDocumentWorkflow, { concurrency: 3 })
|
|
689
|
+
.commit();
|
|
690
|
+
|
|
691
|
+
// Each document goes through all 4 steps before the next document starts (with concurrency: 1)
|
|
692
|
+
// With concurrency: 3, up to 3 documents process their full pipelines in parallel
|
|
693
|
+
```
|
|
694
|
+
|
|
695
|
+
**Why use nested workflows:**
|
|
696
|
+
- **Better parallelism**: With `concurrency: N`, multiple items run their full pipelines simultaneously. Chained `.foreach().foreach()` processes all items through step 1, waits, then all through step 2 - nested workflows let each item progress independently
|
|
697
|
+
- All steps for one item complete together before results are collected
|
|
698
|
+
- Cleaner than multiple `.foreach()` calls which create nested arrays
|
|
699
|
+
- Each nested workflow execution is independent with its own data flow
|
|
700
|
+
- Easier to test and reuse the per-item logic separately
|
|
701
|
+
|
|
702
|
+
**How it works:**
|
|
703
|
+
1. The parent workflow passes each array item to an instance of the nested workflow
|
|
704
|
+
2. Each nested workflow runs its full step sequence for that item
|
|
705
|
+
3. With `concurrency > 1`, multiple nested workflows execute in parallel
|
|
706
|
+
4. The nested workflow's final output becomes one element in the result array
|
|
707
|
+
5. After all nested workflows complete, the next step in the parent receives the full array
|
|
708
|
+
|
|
709
|
+
## Choosing the right pattern
|
|
710
|
+
|
|
711
|
+
Use this section as a reference for selecting the appropriate control flow method.
|
|
712
|
+
|
|
713
|
+
### Quick reference
|
|
714
|
+
|
|
715
|
+
| Method | Purpose | Input | Output | Concurrency |
|
|
716
|
+
|--------|---------|-------|--------|-------------|
|
|
717
|
+
| `.then(step)` | Sequential processing | `T` | `U` | N/A (one at a time) |
|
|
718
|
+
| `.parallel([a, b])` | Different operations on same input | `T` | `{ a: U, b: V }` | All run simultaneously |
|
|
719
|
+
| `.foreach(step)` | Same operation on each array item | `T[]` | `U[]` | Configurable (default: 1) |
|
|
720
|
+
| `.branch([...])` | Conditional path selection | `T` | `{ selectedStep: U }` | Only one branch runs |
|
|
721
|
+
|
|
722
|
+
### `.parallel()` vs `.foreach()`
|
|
723
|
+
|
|
724
|
+
**Use `.parallel()` when you have one input that needs different processing:**
|
|
725
|
+
|
|
726
|
+
```typescript
|
|
727
|
+
// Same user data processed differently in parallel
|
|
728
|
+
workflow
|
|
729
|
+
.parallel([validateStep, enrichStep, scoreStep])
|
|
730
|
+
.then(combineResultsStep)
|
|
731
|
+
```
|
|
732
|
+
|
|
733
|
+
**Use `.foreach()` when you have many inputs that need the same processing:**
|
|
734
|
+
|
|
735
|
+
```typescript
|
|
736
|
+
// Multiple URLs each processed the same way
|
|
737
|
+
workflow
|
|
738
|
+
.foreach(downloadStep, { concurrency: 5 })
|
|
739
|
+
.then(aggregateStep)
|
|
740
|
+
```
|
|
741
|
+
|
|
742
|
+
### When to use nested workflows
|
|
743
|
+
|
|
744
|
+
**Inside `.foreach()`** - when each array item needs multiple sequential steps:
|
|
745
|
+
|
|
746
|
+
```typescript
|
|
747
|
+
// Each document goes through a full pipeline
|
|
748
|
+
const processDocWorkflow = createWorkflow({...})
|
|
749
|
+
.then(downloadStep)
|
|
750
|
+
.then(parseStep)
|
|
751
|
+
.then(embedStep)
|
|
752
|
+
.commit();
|
|
753
|
+
|
|
754
|
+
workflow.foreach(processDocWorkflow, { concurrency: 3 })
|
|
755
|
+
```
|
|
756
|
+
|
|
757
|
+
This is cleaner than chaining `.foreach().foreach()`, which creates nested arrays.
|
|
758
|
+
|
|
759
|
+
**Inside `.parallel()`** - when a parallel branch needs its own multi-step pipeline:
|
|
760
|
+
|
|
761
|
+
```typescript
|
|
762
|
+
const pipelineA = createWorkflow({...}).then(step1).then(step2).commit();
|
|
763
|
+
const pipelineB = createWorkflow({...}).then(step3).then(step4).commit();
|
|
764
|
+
|
|
765
|
+
workflow.parallel([pipelineA, pipelineB])
|
|
766
|
+
```
|
|
767
|
+
|
|
768
|
+
### Chaining patterns
|
|
769
|
+
|
|
770
|
+
| Pattern | What happens | Common use case |
|
|
771
|
+
|---------|--------------|-----------------|
|
|
772
|
+
| `.then().then()` | Sequential steps | Simple pipelines |
|
|
773
|
+
| `.parallel().then()` | Run in parallel, then combine | Fan-out/fan-in |
|
|
774
|
+
| `.foreach().then()` | Process all items, then aggregate | Map-reduce |
|
|
775
|
+
| `.foreach().foreach()` | Creates array of arrays | Avoid - use nested workflow or `.map()` with `.flat()` |
|
|
776
|
+
| `.foreach(workflow)` | Full pipeline per item | Multi-step processing per array item |
|
|
777
|
+
|
|
778
|
+
### Synchronization: when does the next step run?
|
|
779
|
+
|
|
780
|
+
Both `.parallel()` and `.foreach()` are synchronization points. The next step in the workflow only executes after all parallel branches or all array iterations have completed.
|
|
781
|
+
|
|
782
|
+
```typescript
|
|
783
|
+
workflow
|
|
784
|
+
.parallel([stepA, stepB, stepC]) // All 3 run simultaneously
|
|
785
|
+
.then(combineStep) // Waits for ALL 3 to finish before running
|
|
786
|
+
.commit();
|
|
787
|
+
|
|
788
|
+
workflow
|
|
789
|
+
.foreach(processStep, { concurrency: 5 }) // Up to 5 items process at once
|
|
790
|
+
.then(aggregateStep) // Waits for ALL items to finish before running
|
|
791
|
+
.commit();
|
|
792
|
+
```
|
|
793
|
+
|
|
794
|
+
This means:
|
|
795
|
+
- `.parallel()` collects all branch outputs into an object, then passes it to the next step
|
|
796
|
+
- `.foreach()` collects all iteration outputs into an array, then passes it to the next step
|
|
797
|
+
- There is no way to "stream" results to the next step as they complete
|
|
798
|
+
|
|
799
|
+
### Concurrency behavior
|
|
800
|
+
|
|
801
|
+
| Method | Behavior |
|
|
802
|
+
|--------|----------|
|
|
803
|
+
| `.then()` | Sequential - one step at a time |
|
|
804
|
+
| `.parallel()` | All branches run simultaneously (no limit option) |
|
|
805
|
+
| `.foreach()` | Controlled via `{ concurrency: N }` - default is 1 (sequential) |
|
|
806
|
+
| Nested workflow in `.foreach()` | Respects parent's concurrency setting |
|
|
807
|
+
|
|
808
|
+
**Performance tip:** For I/O-bound operations in `.foreach()`, increase concurrency to process items in parallel:
|
|
809
|
+
|
|
810
|
+
```typescript
|
|
811
|
+
// Process up to 10 items simultaneously
|
|
812
|
+
workflow.foreach(fetchDataStep, { concurrency: 10 })
|
|
813
|
+
```
|
|
814
|
+
|
|
469
815
|
## Loop management
|
|
470
816
|
|
|
471
817
|
Loop conditions can be implemented in different ways depending on how you want the loop to end. Common patterns include checking values returned in `inputData`, setting a maximum number of iterations, or aborting execution when a limit is reached.
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @mastra/mcp-docs-server
|
|
2
2
|
|
|
3
|
+
## 1.0.0-beta.11
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`38380b6`](https://github.com/mastra-ai/mastra/commit/38380b60fca905824bdf6b43df307a58efb1aa15), [`798d0c7`](https://github.com/mastra-ai/mastra/commit/798d0c740232653b1d754870e6b43a55c364ffe2), [`ffe84d5`](https://github.com/mastra-ai/mastra/commit/ffe84d54f3b0f85167fe977efd027dba027eb998), [`2c212e7`](https://github.com/mastra-ai/mastra/commit/2c212e704c90e2db83d4109e62c03f0f6ebd2667), [`4ca4306`](https://github.com/mastra-ai/mastra/commit/4ca430614daa5fa04730205a302a43bf4accfe9f), [`3bf6c5f`](https://github.com/mastra-ai/mastra/commit/3bf6c5f104c25226cd84e0c77f9dec15f2cac2db)]:
|
|
8
|
+
- @mastra/core@1.0.0-beta.11
|
|
9
|
+
|
|
3
10
|
## 1.0.0-beta.10
|
|
4
11
|
|
|
5
12
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/mcp-docs-server",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.11",
|
|
4
4
|
"description": "MCP server for accessing Mastra.ai documentation, changelogs, and news.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"@modelcontextprotocol/sdk": "^1.17.5",
|
|
29
29
|
"jsdom": "^26.1.0",
|
|
30
30
|
"zod": "^3.25.76",
|
|
31
|
-
"@mastra/
|
|
32
|
-
"@mastra/
|
|
31
|
+
"@mastra/core": "1.0.0-beta.11",
|
|
32
|
+
"@mastra/mcp": "^1.0.0-beta.6"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@hono/node-server": "^1.19.6",
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
"tsx": "^4.19.4",
|
|
46
46
|
"typescript": "^5.8.3",
|
|
47
47
|
"vitest": "4.0.12",
|
|
48
|
-
"@
|
|
49
|
-
"@
|
|
48
|
+
"@internal/lint": "0.0.53",
|
|
49
|
+
"@mastra/core": "1.0.0-beta.11"
|
|
50
50
|
},
|
|
51
51
|
"homepage": "https://mastra.ai",
|
|
52
52
|
"repository": {
|