@mastra/mcp-docs-server 0.13.2-alpha.2 → 0.13.2-alpha.3
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%2Fdynamodb.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +8 -8
- package/.docs/raw/course/01-first-agent/04-project-structure.md +8 -3
- package/.docs/raw/course/01-first-agent/07-creating-your-agent.md +5 -3
- package/.docs/raw/course/01-first-agent/08-exporting-your-agent.md +20 -6
- package/.docs/raw/course/01-first-agent/11-creating-transactions-tool.md +5 -3
- package/.docs/raw/course/01-first-agent/12-connecting-tool-to-agent.md +2 -2
- package/.docs/raw/course/04-workflows/01-introduction-to-workflows.md +44 -0
- package/.docs/raw/course/04-workflows/02-understanding-steps.md +53 -0
- package/.docs/raw/course/04-workflows/03-creating-your-first-step.md +57 -0
- package/.docs/raw/course/04-workflows/04-creating-a-second-step.md +58 -0
- package/.docs/raw/course/04-workflows/05-chaining-steps-together.md +56 -0
- package/.docs/raw/course/04-workflows/06-registering-with-mastra.md +24 -0
- package/.docs/raw/course/04-workflows/07-using-playground.md +58 -0
- package/.docs/raw/course/04-workflows/08-running-workflows-programmatically.md +77 -0
- package/.docs/raw/course/04-workflows/09-adding-a-third-step.md +70 -0
- package/.docs/raw/course/04-workflows/10-updating-the-workflow.md +55 -0
- package/.docs/raw/course/04-workflows/11-creating-an-ai-agent.md +67 -0
- package/.docs/raw/course/04-workflows/12-using-agent-in-workflow.md +91 -0
- package/.docs/raw/course/04-workflows/13-creating-ai-enhanced-workflow.md +75 -0
- package/.docs/raw/course/04-workflows/14-understanding-parallel-execution.md +38 -0
- package/.docs/raw/course/04-workflows/15-creating-parallel-steps.md +115 -0
- package/.docs/raw/course/04-workflows/16-building-parallel-workflow.md +100 -0
- package/.docs/raw/course/04-workflows/17-testing-parallel-performance.md +40 -0
- package/.docs/raw/course/04-workflows/18-understanding-conditional-branching.md +58 -0
- package/.docs/raw/course/04-workflows/19-creating-conditional-steps.md +128 -0
- package/.docs/raw/course/04-workflows/20-building-conditional-workflow.md +60 -0
- package/.docs/raw/course/04-workflows/21-testing-conditional-logic.md +58 -0
- package/.docs/raw/course/04-workflows/22-conclusion.md +58 -0
- package/package.json +1 -1
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Understanding Conditional Branching
|
|
2
|
+
|
|
3
|
+
Learn how to create workflows that take different paths based on data conditions, making your workflows more intelligent and adaptive.
|
|
4
|
+
|
|
5
|
+
## What is Conditional Branching?
|
|
6
|
+
|
|
7
|
+
Conditional branching allows workflows to:
|
|
8
|
+
- **Make decisions**: Choose different processing paths based on data
|
|
9
|
+
- **Handle variations**: Process different content types differently
|
|
10
|
+
- **Optimize performance**: Skip unnecessary steps for certain inputs
|
|
11
|
+
- **Customize behavior**: Provide different experiences based on conditions
|
|
12
|
+
|
|
13
|
+
## Real-World Example
|
|
14
|
+
|
|
15
|
+
Imagine a content processing workflow that:
|
|
16
|
+
- **Short content** (< 50 words): Gets quick processing
|
|
17
|
+
- **Medium content** (50-200 words): Gets standard processing
|
|
18
|
+
- **Long content** (> 200 words): Gets detailed processing with extra analysis
|
|
19
|
+
|
|
20
|
+
## Basic Branching Syntax
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
.branch([
|
|
24
|
+
[condition1, step1],
|
|
25
|
+
[condition2, step2],
|
|
26
|
+
[condition3, step3]
|
|
27
|
+
])
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Where:
|
|
31
|
+
- **condition**: An async function that returns `true` or `false`
|
|
32
|
+
- **step**: The step to execute if the condition is `true`
|
|
33
|
+
|
|
34
|
+
## Condition Functions
|
|
35
|
+
|
|
36
|
+
Conditions are functions that examine the input data:
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
// Example condition function
|
|
40
|
+
async ({ inputData }) => {
|
|
41
|
+
return inputData.wordCount < 50;
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Multiple Paths
|
|
46
|
+
|
|
47
|
+
- If multiple conditions are `true`, **all matching steps run in parallel**
|
|
48
|
+
- If no conditions are `true`, the workflow continues without executing any branch steps
|
|
49
|
+
- Conditions are evaluated in order, but matching steps run simultaneously
|
|
50
|
+
|
|
51
|
+
## Benefits
|
|
52
|
+
|
|
53
|
+
- **Smart routing**: Send data down the most appropriate path
|
|
54
|
+
- **Performance**: Skip expensive operations when not needed
|
|
55
|
+
- **Flexibility**: Handle different scenarios in one workflow
|
|
56
|
+
- **Maintainability**: Clear logic for different processing paths
|
|
57
|
+
|
|
58
|
+
Next, you'll create a workflow with conditional branches!
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# Creating Conditional Steps
|
|
2
|
+
|
|
3
|
+
Let's create two processing steps for different types of content: one for short and simple content, and one for everything else.
|
|
4
|
+
|
|
5
|
+
## Assessment Step
|
|
6
|
+
|
|
7
|
+
First, create a step that analyzes content to determine which path to take:
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
const assessContentStep = createStep({
|
|
11
|
+
id: "assess-content",
|
|
12
|
+
description: "Assesses content to determine processing path",
|
|
13
|
+
inputSchema: z.object({
|
|
14
|
+
content: z.string(),
|
|
15
|
+
type: z.enum(["article", "blog", "social"]).default("article"),
|
|
16
|
+
}),
|
|
17
|
+
outputSchema: z.object({
|
|
18
|
+
content: z.string(),
|
|
19
|
+
type: z.enum(["article", "blog", "social"]).default("article"),
|
|
20
|
+
wordCount: z.number(),
|
|
21
|
+
complexity: z.enum(["simple", "moderate", "complex"]),
|
|
22
|
+
category: z.enum(["short", "medium", "long"]),
|
|
23
|
+
}),
|
|
24
|
+
execute: async ({ inputData }) => {
|
|
25
|
+
const { content, type } = inputData;
|
|
26
|
+
const words = content.trim().split(/\s+/);
|
|
27
|
+
const wordCount = words.length;
|
|
28
|
+
|
|
29
|
+
// Determine category by length
|
|
30
|
+
let category: "short" | "medium" | "long" = "short";
|
|
31
|
+
if (wordCount >= 50) category = "medium";
|
|
32
|
+
if (wordCount >= 200) category = "long";
|
|
33
|
+
|
|
34
|
+
// Determine complexity by average word length
|
|
35
|
+
const avgWordLength =
|
|
36
|
+
words.reduce((sum, word) => sum + word.length, 0) / wordCount;
|
|
37
|
+
let complexity: "simple" | "moderate" | "complex" = "simple";
|
|
38
|
+
if (avgWordLength > 5) complexity = "moderate";
|
|
39
|
+
if (avgWordLength > 7) complexity = "complex";
|
|
40
|
+
|
|
41
|
+
console.log(`📋 Assessment: ${category} content, ${complexity} complexity`);
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
content,
|
|
45
|
+
type,
|
|
46
|
+
wordCount,
|
|
47
|
+
complexity,
|
|
48
|
+
category,
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Quick Processing Step
|
|
55
|
+
|
|
56
|
+
For short, simple content:
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
const quickProcessingStep = createStep({
|
|
60
|
+
id: "quick-processing",
|
|
61
|
+
description: "Quick processing for short and simple content",
|
|
62
|
+
inputSchema: z.object({
|
|
63
|
+
content: z.string(),
|
|
64
|
+
type: z.enum(["article", "blog", "social"]).default("article"),
|
|
65
|
+
wordCount: z.number(),
|
|
66
|
+
complexity: z.enum(["simple", "moderate", "complex"]),
|
|
67
|
+
category: z.enum(["short", "medium", "long"]),
|
|
68
|
+
}),
|
|
69
|
+
outputSchema: z.object({
|
|
70
|
+
processedContent: z.string(),
|
|
71
|
+
processingType: z.string(),
|
|
72
|
+
recommendations: z.array(z.string()),
|
|
73
|
+
}),
|
|
74
|
+
execute: async ({ inputData }) => {
|
|
75
|
+
console.log("⚡ Quick processing for short and simple content...");
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
processedContent: inputData.content,
|
|
79
|
+
processingType: "quick",
|
|
80
|
+
recommendations: [
|
|
81
|
+
"Content is concise",
|
|
82
|
+
"Consider expanding for more detail",
|
|
83
|
+
],
|
|
84
|
+
};
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## General Processing Step
|
|
90
|
+
|
|
91
|
+
For all other content (not short and simple):
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
const generalProcessingStep = createStep({
|
|
95
|
+
id: "general-processing",
|
|
96
|
+
description: "General processing for all other content",
|
|
97
|
+
inputSchema: z.object({
|
|
98
|
+
content: z.string(),
|
|
99
|
+
type: z.enum(["article", "blog", "social"]).default("article"),
|
|
100
|
+
wordCount: z.number(),
|
|
101
|
+
complexity: z.enum(["simple", "moderate", "complex"]),
|
|
102
|
+
category: z.enum(["short", "medium", "long"]),
|
|
103
|
+
}),
|
|
104
|
+
outputSchema: z.object({
|
|
105
|
+
processedContent: z.string(),
|
|
106
|
+
processingType: z.string(),
|
|
107
|
+
recommendations: z.array(z.string()),
|
|
108
|
+
}),
|
|
109
|
+
execute: async ({ inputData }) => {
|
|
110
|
+
console.log("📝 General processing for non-short/simple content...");
|
|
111
|
+
|
|
112
|
+
// Simulate more involved processing
|
|
113
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
114
|
+
|
|
115
|
+
return {
|
|
116
|
+
processedContent: inputData.content,
|
|
117
|
+
processingType: "general",
|
|
118
|
+
recommendations: [
|
|
119
|
+
"Consider simplifying content",
|
|
120
|
+
"Break up long paragraphs",
|
|
121
|
+
"Add examples or explanations if needed",
|
|
122
|
+
],
|
|
123
|
+
};
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
These two steps will be used in different branches based on the content assessment. Next, you'll create the conditional workflow!
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# Building Conditional Workflow
|
|
2
|
+
|
|
3
|
+
Now you'll create a workflow that uses conditional branching to route content through two different processing paths.
|
|
4
|
+
|
|
5
|
+
## Creating the Conditional Workflow
|
|
6
|
+
|
|
7
|
+
Add this workflow to your file:
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
export const conditionalWorkflow = createWorkflow({
|
|
11
|
+
id: "conditional-workflow",
|
|
12
|
+
description: "Content processing with conditional branching",
|
|
13
|
+
inputSchema: z.object({
|
|
14
|
+
content: z.string(),
|
|
15
|
+
type: z.enum(["article", "blog", "social"]).default("article"),
|
|
16
|
+
}),
|
|
17
|
+
outputSchema: z.object({
|
|
18
|
+
processedContent: z.string(),
|
|
19
|
+
processingType: z.string(),
|
|
20
|
+
recommendations: z.array(z.string()),
|
|
21
|
+
}),
|
|
22
|
+
})
|
|
23
|
+
.then(assessContentStep)
|
|
24
|
+
.branch([
|
|
25
|
+
// Branch 1: Short and simple content
|
|
26
|
+
[
|
|
27
|
+
async ({ inputData }) =>
|
|
28
|
+
inputData.category === "short" && inputData.complexity === "simple",
|
|
29
|
+
quickProcessingStep,
|
|
30
|
+
],
|
|
31
|
+
// Branch 2: Everything else
|
|
32
|
+
[
|
|
33
|
+
async ({ inputData }) =>
|
|
34
|
+
!(inputData.category === "short" && inputData.complexity === "simple"),
|
|
35
|
+
generalProcessingStep,
|
|
36
|
+
],
|
|
37
|
+
])
|
|
38
|
+
.commit();
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Understanding the Conditions
|
|
42
|
+
|
|
43
|
+
1. **Short + Simple**: Quick processing with minimal recommendations
|
|
44
|
+
2. **Everything Else**: General processing with more suggestions
|
|
45
|
+
|
|
46
|
+
## Multiple Conditions
|
|
47
|
+
|
|
48
|
+
You can combine conditions using logical operators:
|
|
49
|
+
|
|
50
|
+
- **`&&`**: AND - both conditions must be true
|
|
51
|
+
- **`||`**: OR - either condition can be true
|
|
52
|
+
- **`!`**: NOT - condition must be false
|
|
53
|
+
|
|
54
|
+
## Condition Evaluation
|
|
55
|
+
|
|
56
|
+
- Conditions are checked in order
|
|
57
|
+
- Multiple conditions can be true (steps run in parallel)
|
|
58
|
+
- If no conditions match, the branch is skipped
|
|
59
|
+
|
|
60
|
+
Next, you'll test this conditional workflow with different types of content!
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Testing Conditional Logic
|
|
2
|
+
|
|
3
|
+
Let's test your conditional workflow with different types of content to see how it routes to different processing paths.
|
|
4
|
+
|
|
5
|
+
## Registering the New Workflow
|
|
6
|
+
|
|
7
|
+
Update your Mastra configuration to include your new workflow workflows:
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
// In src/mastra/index.ts
|
|
11
|
+
import {
|
|
12
|
+
contentWorkflow,
|
|
13
|
+
aiContentWorkflow,
|
|
14
|
+
parallelAnalysisWorkflow,
|
|
15
|
+
conditionalWorkflow,
|
|
16
|
+
} from "./workflows/content-workflow";
|
|
17
|
+
|
|
18
|
+
export const mastra = new Mastra({
|
|
19
|
+
workflows: {
|
|
20
|
+
contentWorkflow,
|
|
21
|
+
aiContentWorkflow,
|
|
22
|
+
parallelAnalysisWorkflow,
|
|
23
|
+
conditionalWorkflow, // Add the conditional workflow
|
|
24
|
+
},
|
|
25
|
+
// ... rest of configuration
|
|
26
|
+
});
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Testing the conditional workflow
|
|
30
|
+
|
|
31
|
+
You can now test this new conditional workflow in the playground. Be sure to test different content lengths and content types.
|
|
32
|
+
|
|
33
|
+
## Understanding the Flow
|
|
34
|
+
|
|
35
|
+
1. **Assessment step** analyzes content and determines category/complexity
|
|
36
|
+
2. **Branch conditions** are evaluated against the assessment results
|
|
37
|
+
3. **Matching step** executes based on which condition(s) are true
|
|
38
|
+
4. **Results** show which processing path was taken
|
|
39
|
+
|
|
40
|
+
## Debugging Conditions
|
|
41
|
+
|
|
42
|
+
If a condition isn't working as expected:
|
|
43
|
+
|
|
44
|
+
- Check the assessment step output
|
|
45
|
+
- Verify condition logic matches your expectations
|
|
46
|
+
- Test individual conditions in isolation
|
|
47
|
+
- Add console.log statements to track condition evaluation
|
|
48
|
+
|
|
49
|
+
## Branch Benefits
|
|
50
|
+
|
|
51
|
+
Conditional workflows provide:
|
|
52
|
+
|
|
53
|
+
- **Intelligent routing**: Right processing for right content
|
|
54
|
+
- **Performance optimization**: Skip heavy processing for simple content
|
|
55
|
+
- **Customized experience**: Different handling for different scenarios
|
|
56
|
+
- **Scalable logic**: Easy to add new conditions and processing paths
|
|
57
|
+
|
|
58
|
+
Next, you'll learn about streaming workflow results for better user experience!
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Conclusion
|
|
2
|
+
|
|
3
|
+
Congratulations! You've completed the Mastra Workflows course and learned how to build powerful, type-safe workflows that can handle complex automation tasks.
|
|
4
|
+
|
|
5
|
+
## What You've Accomplished
|
|
6
|
+
|
|
7
|
+
Throughout this course, you've learned to:
|
|
8
|
+
|
|
9
|
+
### Core Concepts
|
|
10
|
+
|
|
11
|
+
- **Understanding workflows**: How they break complex tasks into manageable steps
|
|
12
|
+
- **Creating steps**: Building reusable units with clear inputs and outputs
|
|
13
|
+
- **Schema validation**: Using Zod for type safety and runtime validation
|
|
14
|
+
- **Error handling**: Making workflows robust and user-friendly
|
|
15
|
+
|
|
16
|
+
### Building Workflows
|
|
17
|
+
|
|
18
|
+
- **Chaining steps**: Connecting steps to create complete workflows
|
|
19
|
+
- **Testing thoroughly**: Ensuring reliability with comprehensive tests
|
|
20
|
+
- **Registering with Mastra**: Integrating workflows into your application
|
|
21
|
+
- **Using the playground**: Visual testing and debugging
|
|
22
|
+
|
|
23
|
+
### Advanced Features
|
|
24
|
+
|
|
25
|
+
- **AI integration**: Combining workflows with agents for intelligent processing
|
|
26
|
+
- **Parallel execution**: Running multiple steps simultaneously for better performance
|
|
27
|
+
- **Conditional branching**: Creating smart workflows that adapt to different scenarios
|
|
28
|
+
|
|
29
|
+
## Key Workflows You Built
|
|
30
|
+
|
|
31
|
+
1. **Content Processing Workflow**: Validates, enhances, and summarizes content
|
|
32
|
+
2. **AI-Enhanced Workflow**: Adds intelligent analysis with AI agents
|
|
33
|
+
3. **Parallel Analysis Workflow**: Demonstrates high-performance parallel execution
|
|
34
|
+
4. **Conditional Workflow**: Shows intelligent routing based on content characteristics
|
|
35
|
+
|
|
36
|
+
## Next Steps
|
|
37
|
+
|
|
38
|
+
Now that you understand workflows, you can:
|
|
39
|
+
|
|
40
|
+
### Expand Your Skills
|
|
41
|
+
|
|
42
|
+
- **Explore more integrations**: Connect workflows with databases, APIs, and external services
|
|
43
|
+
- **Build complex automations**: Create multi-step business processes
|
|
44
|
+
- **Integrate with web applications**: Use workflows in your frontend applications
|
|
45
|
+
- **Scale for production**: Deploy workflows with proper monitoring and error handling
|
|
46
|
+
|
|
47
|
+
## Final Thoughts
|
|
48
|
+
|
|
49
|
+
Workflows are a powerful way to build reliable, maintainable automation systems. The patterns and principles you've learned in this course will help you tackle increasingly complex challenges as you build AI-powered applications.
|
|
50
|
+
|
|
51
|
+
Remember:
|
|
52
|
+
|
|
53
|
+
- **Start simple**: Begin with basic workflows and add complexity gradually
|
|
54
|
+
- **Test thoroughly**: Good testing prevents production issues
|
|
55
|
+
- **Think in steps**: Break complex problems into smaller, manageable pieces
|
|
56
|
+
- **Embrace type safety**: Let schemas catch errors early
|
|
57
|
+
|
|
58
|
+
Thank you for completing the Mastra Workflows lesson. Happy building! 🚀
|
package/package.json
CHANGED