@mastra/mcp-docs-server 0.13.7-alpha.0 → 0.13.7-alpha.2
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 +39 -39
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +18 -18
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +18 -18
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +45 -45
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +21 -21
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +44 -44
- package/.docs/organized/changelogs/%40mastra%2Fevals.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Flibsql.md +29 -29
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +25 -25
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +39 -39
- package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +20 -20
- package/.docs/organized/changelogs/%40mastra%2Fmssql.md +17 -0
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +29 -29
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +12 -12
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +38 -38
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +29 -29
- package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +18 -18
- package/.docs/organized/changelogs/%40mastra%2Fvoice-cloudflare.md +18 -18
- package/.docs/organized/changelogs/create-mastra.md +7 -7
- package/.docs/organized/changelogs/mastra.md +32 -32
- package/.docs/organized/code-examples/agent.md +93 -3
- package/.docs/organized/code-examples/ai-sdk-v5.md +4 -4
- package/.docs/raw/agents/input-processors.mdx +268 -0
- package/.docs/raw/agents/using-tools-and-mcp.mdx +39 -0
- package/.docs/raw/community/contributing-templates.mdx +192 -0
- package/.docs/raw/getting-started/installation.mdx +16 -0
- package/.docs/raw/getting-started/templates.mdx +95 -0
- package/.docs/raw/observability/tracing.mdx +44 -0
- package/.docs/raw/reference/agents/agent.mdx +7 -0
- package/.docs/raw/reference/agents/generate.mdx +18 -1
- package/.docs/raw/reference/agents/stream.mdx +18 -1
- package/.docs/raw/reference/cli/dev.mdx +6 -0
- package/.docs/raw/reference/client-js/memory.mdx +18 -0
- package/.docs/raw/reference/core/mastra-class.mdx +1 -1
- package/.docs/raw/reference/memory/Memory.mdx +1 -0
- package/.docs/raw/reference/memory/deleteMessages.mdx +95 -0
- package/.docs/raw/reference/memory/getThreadsByResourceId.mdx +33 -1
- package/.docs/raw/reference/rag/upstash.mdx +112 -5
- package/.docs/raw/reference/scorers/answer-relevancy.mdx +114 -0
- package/.docs/raw/reference/scorers/bias.mdx +127 -0
- package/.docs/raw/reference/scorers/completeness.mdx +89 -0
- package/.docs/raw/reference/scorers/content-similarity.mdx +96 -0
- package/.docs/raw/reference/scorers/custom-code-scorer.mdx +155 -0
- package/.docs/raw/reference/scorers/faithfulness.mdx +122 -0
- package/.docs/raw/reference/scorers/hallucination.mdx +133 -0
- package/.docs/raw/reference/scorers/keyword-coverage.mdx +92 -0
- package/.docs/raw/reference/scorers/llm-scorer.mdx +210 -0
- package/.docs/raw/reference/scorers/mastra-scorer.mdx +218 -0
- package/.docs/raw/reference/scorers/textual-difference.mdx +76 -0
- package/.docs/raw/reference/scorers/tone-consistency.mdx +75 -0
- package/.docs/raw/reference/scorers/toxicity.mdx +109 -0
- package/.docs/raw/reference/storage/libsql.mdx +7 -4
- package/.docs/raw/reference/storage/mssql.mdx +7 -3
- package/.docs/raw/reference/storage/postgresql.mdx +7 -3
- package/.docs/raw/reference/templates.mdx +228 -0
- package/.docs/raw/scorers/custom-scorers.mdx +319 -0
- package/.docs/raw/scorers/off-the-shelf-scorers.mdx +30 -0
- package/.docs/raw/scorers/overview.mdx +124 -0
- package/package.json +4 -4
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: Textual Difference | Scorers | Mastra Docs"
|
|
3
|
+
description: Documentation for the Textual Difference Scorer in Mastra, which measures textual differences between strings using sequence matching.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Textual Difference Scorer
|
|
7
|
+
|
|
8
|
+
The `createTextualDifferenceScorer()` function uses sequence matching to measure the textual differences between two strings. It provides detailed information about changes, including the number of operations needed to transform one text into another.
|
|
9
|
+
|
|
10
|
+
For a usage example, see the [Textual Difference Examples](/examples/scorers/textual-difference).
|
|
11
|
+
|
|
12
|
+
## Parameters
|
|
13
|
+
|
|
14
|
+
The `createTextualDifferenceScorer()` function does not take any options.
|
|
15
|
+
|
|
16
|
+
This function returns an instance of the MastraScorer class. See the [MastraScorer reference](./mastra-scorer) for details on the `.run()` method and its input/output.
|
|
17
|
+
|
|
18
|
+
## .run() Returns
|
|
19
|
+
|
|
20
|
+
<PropertiesTable
|
|
21
|
+
content={[
|
|
22
|
+
{
|
|
23
|
+
name: "runId",
|
|
24
|
+
type: "string",
|
|
25
|
+
description: "The id of the run (optional).",
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: "analyzeStepResult",
|
|
29
|
+
type: "object",
|
|
30
|
+
description: "Object with difference metrics: { confidence: number, changes: number, lengthDiff: number }",
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: "score",
|
|
34
|
+
type: "number",
|
|
35
|
+
description: "Similarity ratio (0-1) where 1 indicates identical texts.",
|
|
36
|
+
},
|
|
37
|
+
]}
|
|
38
|
+
/>
|
|
39
|
+
|
|
40
|
+
## Scoring Details
|
|
41
|
+
|
|
42
|
+
The scorer calculates several measures:
|
|
43
|
+
|
|
44
|
+
- **Similarity Ratio**: Based on sequence matching between texts (0-1)
|
|
45
|
+
- **Changes**: Count of non-matching operations needed
|
|
46
|
+
- **Length Difference**: Normalized difference in text lengths
|
|
47
|
+
- **Confidence**: Inversely proportional to length difference
|
|
48
|
+
|
|
49
|
+
### Scoring Process
|
|
50
|
+
|
|
51
|
+
1. Analyzes textual differences:
|
|
52
|
+
- Performs sequence matching between input and output
|
|
53
|
+
- Counts the number of change operations required
|
|
54
|
+
- Measures length differences
|
|
55
|
+
2. Calculates metrics:
|
|
56
|
+
- Computes similarity ratio
|
|
57
|
+
- Determines confidence score
|
|
58
|
+
- Combines into weighted score
|
|
59
|
+
|
|
60
|
+
Final score: `(similarity_ratio * confidence) * scale`
|
|
61
|
+
|
|
62
|
+
### Score interpretation
|
|
63
|
+
|
|
64
|
+
(0 to scale, default 0-1)
|
|
65
|
+
|
|
66
|
+
- 1.0: Identical texts - no differences
|
|
67
|
+
- 0.7-0.9: Minor differences - few changes needed
|
|
68
|
+
- 0.4-0.6: Moderate differences - significant changes
|
|
69
|
+
- 0.1-0.3: Major differences - extensive changes
|
|
70
|
+
- 0.0: Completely different texts
|
|
71
|
+
|
|
72
|
+
## Related
|
|
73
|
+
|
|
74
|
+
- [Content Similarity Scorer](./content-similarity)
|
|
75
|
+
- [Completeness Scorer](./completeness)
|
|
76
|
+
- [Keyword Coverage Scorer](./keyword-coverage)
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: Tone Consistency | Scorers | Mastra Docs"
|
|
3
|
+
description: Documentation for the Tone Consistency Scorer in Mastra, which evaluates emotional tone and sentiment consistency in text.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Tone Consistency Scorer
|
|
7
|
+
|
|
8
|
+
The `createToneScorer()` function evaluates the text's emotional tone and sentiment consistency. It can operate in two modes: comparing tone between input/output pairs or analyzing tone stability within a single text.
|
|
9
|
+
|
|
10
|
+
For a usage example, see the [Tone Consistency Examples](/examples/scorers/tone-consistency).
|
|
11
|
+
|
|
12
|
+
## Parameters
|
|
13
|
+
|
|
14
|
+
The `createToneScorer()` function does not take any options.
|
|
15
|
+
|
|
16
|
+
This function returns an instance of the MastraScorer class. See the [MastraScorer reference](./mastra-scorer) for details on the `.run()` method and its input/output.
|
|
17
|
+
|
|
18
|
+
## .run() Returns
|
|
19
|
+
|
|
20
|
+
<PropertiesTable
|
|
21
|
+
content={[
|
|
22
|
+
{
|
|
23
|
+
name: "runId",
|
|
24
|
+
type: "string",
|
|
25
|
+
description: "The id of the run (optional).",
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: "analyzeStepResult",
|
|
29
|
+
type: "object",
|
|
30
|
+
description: "Object with tone metrics: { responseSentiment: number, referenceSentiment: number, difference: number } (for comparison mode) OR { avgSentiment: number, sentimentVariance: number } (for stability mode)",
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: "score",
|
|
34
|
+
type: "number",
|
|
35
|
+
description: "Tone consistency/stability score (0-1).",
|
|
36
|
+
},
|
|
37
|
+
]}
|
|
38
|
+
/>
|
|
39
|
+
|
|
40
|
+
## Scoring Details
|
|
41
|
+
|
|
42
|
+
The scorer evaluates sentiment consistency through tone pattern analysis and mode-specific scoring.
|
|
43
|
+
|
|
44
|
+
### Scoring Process
|
|
45
|
+
|
|
46
|
+
1. Analyzes tone patterns:
|
|
47
|
+
- Extracts sentiment features
|
|
48
|
+
- Computes sentiment scores
|
|
49
|
+
- Measures tone variations
|
|
50
|
+
2. Calculates mode-specific score:
|
|
51
|
+
**Tone Consistency** (input and output):
|
|
52
|
+
- Compares sentiment between texts
|
|
53
|
+
- Calculates sentiment difference
|
|
54
|
+
- Score = 1 - (sentiment_difference / max_difference)
|
|
55
|
+
**Tone Stability** (single input):
|
|
56
|
+
- Analyzes sentiment across sentences
|
|
57
|
+
- Calculates sentiment variance
|
|
58
|
+
- Score = 1 - (sentiment_variance / max_variance)
|
|
59
|
+
|
|
60
|
+
Final score: `mode_specific_score * scale`
|
|
61
|
+
|
|
62
|
+
### Score interpretation
|
|
63
|
+
|
|
64
|
+
(0 to scale, default 0-1)
|
|
65
|
+
|
|
66
|
+
- 1.0: Perfect tone consistency/stability
|
|
67
|
+
- 0.7-0.9: Strong consistency with minor variations
|
|
68
|
+
- 0.4-0.6: Moderate consistency with noticeable shifts
|
|
69
|
+
- 0.1-0.3: Poor consistency with major tone changes
|
|
70
|
+
- 0.0: No consistency - completely different tones
|
|
71
|
+
|
|
72
|
+
## Related
|
|
73
|
+
|
|
74
|
+
- [Content Similarity Scorer](./content-similarity)
|
|
75
|
+
- [Toxicity Scorer](./toxicity)
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: Toxicity | Scorers | Mastra Docs"
|
|
3
|
+
description: Documentation for the Toxicity Scorer in Mastra, which evaluates LLM outputs for racist, biased, or toxic elements.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Toxicity Scorer
|
|
7
|
+
|
|
8
|
+
The `createToxicityScorer()` function evaluates whether an LLM's output contains racist, biased, or toxic elements. It uses a judge-based system to analyze responses for various forms of toxicity including personal attacks, mockery, hate speech, dismissive statements, and threats.
|
|
9
|
+
|
|
10
|
+
For a usage example, see the [Toxicity Examples](/examples/scorers/toxicity).
|
|
11
|
+
|
|
12
|
+
## Parameters
|
|
13
|
+
|
|
14
|
+
The `createToxicityScorer()` function accepts a single options object with the following properties:
|
|
15
|
+
|
|
16
|
+
<PropertiesTable
|
|
17
|
+
content={[
|
|
18
|
+
{
|
|
19
|
+
name: "model",
|
|
20
|
+
type: "LanguageModel",
|
|
21
|
+
required: true,
|
|
22
|
+
description: "Configuration for the model used to evaluate toxicity.",
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: "scale",
|
|
26
|
+
type: "number",
|
|
27
|
+
required: false,
|
|
28
|
+
defaultValue: "1",
|
|
29
|
+
description: "Maximum score value (default is 1).",
|
|
30
|
+
},
|
|
31
|
+
]}
|
|
32
|
+
/>
|
|
33
|
+
|
|
34
|
+
This function returns an instance of the MastraScorer class. The `.run()` method accepts the same input as other scorers (see the [MastraScorer reference](./mastra-scorer)), but the return value includes LLM-specific fields as documented below.
|
|
35
|
+
|
|
36
|
+
## .run() Returns
|
|
37
|
+
|
|
38
|
+
<PropertiesTable
|
|
39
|
+
content={[
|
|
40
|
+
{
|
|
41
|
+
name: "runId",
|
|
42
|
+
type: "string",
|
|
43
|
+
description: "The id of the run (optional).",
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: "analyzeStepResult",
|
|
47
|
+
type: "object",
|
|
48
|
+
description: "Object with verdicts: { verdicts: Array<{ verdict: 'yes' | 'no', reason: string }> }",
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: "analyzePrompt",
|
|
52
|
+
type: "string",
|
|
53
|
+
description: "The prompt sent to the LLM for the analyze step (optional).",
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
name: "score",
|
|
57
|
+
type: "number",
|
|
58
|
+
description: "Toxicity score (0 to scale, default 0-1).",
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: "reason",
|
|
62
|
+
type: "string",
|
|
63
|
+
description: "Detailed explanation of the toxicity assessment.",
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
name: "reasonPrompt",
|
|
67
|
+
type: "string",
|
|
68
|
+
description: "The prompt sent to the LLM for the reason step (optional).",
|
|
69
|
+
},
|
|
70
|
+
]}
|
|
71
|
+
/>
|
|
72
|
+
|
|
73
|
+
## Scoring Details
|
|
74
|
+
|
|
75
|
+
The scorer evaluates toxicity through multiple aspects:
|
|
76
|
+
|
|
77
|
+
- Personal attacks
|
|
78
|
+
- Mockery or sarcasm
|
|
79
|
+
- Hate speech
|
|
80
|
+
- Dismissive statements
|
|
81
|
+
- Threats or intimidation
|
|
82
|
+
|
|
83
|
+
### Scoring Process
|
|
84
|
+
|
|
85
|
+
1. Analyzes toxic elements:
|
|
86
|
+
- Identifies personal attacks and mockery
|
|
87
|
+
- Detects hate speech and threats
|
|
88
|
+
- Evaluates dismissive statements
|
|
89
|
+
- Assesses severity levels
|
|
90
|
+
2. Calculates toxicity score:
|
|
91
|
+
- Weighs detected elements
|
|
92
|
+
- Combines severity ratings
|
|
93
|
+
- Normalizes to scale
|
|
94
|
+
|
|
95
|
+
Final score: `(toxicity_weighted_sum / max_toxicity) * scale`
|
|
96
|
+
|
|
97
|
+
### Score interpretation
|
|
98
|
+
|
|
99
|
+
(0 to scale, default 0-1)
|
|
100
|
+
|
|
101
|
+
- 0.8-1.0: Severe toxicity
|
|
102
|
+
- 0.4-0.7: Moderate toxicity
|
|
103
|
+
- 0.1-0.3: Mild toxicity
|
|
104
|
+
- 0.0: No toxic elements detected
|
|
105
|
+
|
|
106
|
+
## Related
|
|
107
|
+
|
|
108
|
+
- [Tone Consistency Scorer](./tone-consistency)
|
|
109
|
+
- [Bias Scorer](./bias)
|
|
@@ -65,7 +65,10 @@ For production use cases, use a persistent database URL: `libsql://your-database
|
|
|
65
65
|
|
|
66
66
|
The storage implementation handles schema creation and updates automatically. It creates the following tables:
|
|
67
67
|
|
|
68
|
-
- `
|
|
69
|
-
- `
|
|
70
|
-
- `
|
|
71
|
-
- `
|
|
68
|
+
- `mastra_workflow_snapshot`: Stores workflow state and execution data
|
|
69
|
+
- `mastra_evals`: Stores evaluation results and metadata
|
|
70
|
+
- `mastra_threads`: Stores conversation threads
|
|
71
|
+
- `mastra_messages`: Stores individual messages
|
|
72
|
+
- `mastra_traces`: Stores telemetry and tracing data
|
|
73
|
+
- `mastra_scorers`: Stores scoring and evaluation data
|
|
74
|
+
- `mastra_resources`: Stores resource working memory data
|
|
@@ -88,9 +88,13 @@ const store5 = new MSSQLStore({
|
|
|
88
88
|
|
|
89
89
|
The storage implementation handles schema creation and updates automatically. It creates the following tables:
|
|
90
90
|
|
|
91
|
-
- `
|
|
92
|
-
- `
|
|
93
|
-
- `
|
|
91
|
+
- `mastra_workflow_snapshot`: Stores workflow state and execution data
|
|
92
|
+
- `mastra_evals`: Stores evaluation results and metadata
|
|
93
|
+
- `mastra_threads`: Stores conversation threads
|
|
94
|
+
- `mastra_messages`: Stores individual messages
|
|
95
|
+
- `mastra_traces`: Stores telemetry and tracing data
|
|
96
|
+
- `mastra_scorers`: Stores scoring and evaluation data
|
|
97
|
+
- `mastra_resources`: Stores resource working memory data
|
|
94
98
|
|
|
95
99
|
### Direct Database and Pool Access
|
|
96
100
|
|
|
@@ -88,9 +88,13 @@ const store5 = new PostgresStore({
|
|
|
88
88
|
|
|
89
89
|
The storage implementation handles schema creation and updates automatically. It creates the following tables:
|
|
90
90
|
|
|
91
|
-
- `
|
|
92
|
-
- `
|
|
93
|
-
- `
|
|
91
|
+
- `mastra_workflow_snapshot`: Stores workflow state and execution data
|
|
92
|
+
- `mastra_evals`: Stores evaluation results and metadata
|
|
93
|
+
- `mastra_threads`: Stores conversation threads
|
|
94
|
+
- `mastra_messages`: Stores individual messages
|
|
95
|
+
- `mastra_traces`: Stores telemetry and tracing data
|
|
96
|
+
- `mastra_scorers`: Stores scoring and evaluation data
|
|
97
|
+
- `mastra_resources`: Stores resource working memory data
|
|
94
98
|
|
|
95
99
|
### Direct Database and Pool Access
|
|
96
100
|
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Templates Reference"
|
|
3
|
+
description: "Complete guide to creating, using, and contributing Mastra templates"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
import { FileTree, Tabs, Callout } from 'nextra/components'
|
|
7
|
+
|
|
8
|
+
This reference provides comprehensive information about Mastra templates, including how to use existing templates, create your own, and contribute to the community ecosystem.
|
|
9
|
+
|
|
10
|
+
## Overview
|
|
11
|
+
|
|
12
|
+
Mastra templates are pre-built project structures that demonstrate specific use cases and patterns. They provide:
|
|
13
|
+
|
|
14
|
+
- **Working examples** - Complete, functional Mastra applications
|
|
15
|
+
- **Best practices** - Proper project structure and coding conventions
|
|
16
|
+
- **Educational resources** - Learn Mastra patterns through real implementations
|
|
17
|
+
- **Quick starts** - Bootstrap projects faster than building from scratch
|
|
18
|
+
|
|
19
|
+
## Using Templates
|
|
20
|
+
|
|
21
|
+
### Installation
|
|
22
|
+
|
|
23
|
+
Install a template using the `create-mastra` command:
|
|
24
|
+
|
|
25
|
+
```bash copy
|
|
26
|
+
npx create-mastra@latest --template template-name
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
This creates a complete project with all necessary code and configuration.
|
|
30
|
+
|
|
31
|
+
### Setup Process
|
|
32
|
+
|
|
33
|
+
After installation:
|
|
34
|
+
|
|
35
|
+
1. **Navigate to project directory**:
|
|
36
|
+
|
|
37
|
+
```bash copy
|
|
38
|
+
cd your-project-name
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
2. **Configure environment variables**:
|
|
42
|
+
|
|
43
|
+
```bash copy
|
|
44
|
+
cp .env.example .env
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Edit `.env` with required API keys as documented in the template's README.
|
|
48
|
+
|
|
49
|
+
3. **Install dependencies** (if not done automatically):
|
|
50
|
+
|
|
51
|
+
```bash copy
|
|
52
|
+
npm install
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
4. **Start development server**:
|
|
56
|
+
|
|
57
|
+
```bash copy
|
|
58
|
+
npm run dev
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Template Structure
|
|
62
|
+
|
|
63
|
+
All templates follow this standardized structure:
|
|
64
|
+
|
|
65
|
+
<FileTree>
|
|
66
|
+
<FileTree.Folder name="template-name" defaultOpen>
|
|
67
|
+
<FileTree.Folder name="src" defaultOpen>
|
|
68
|
+
<FileTree.Folder name="mastra" defaultOpen>
|
|
69
|
+
<FileTree.Folder name="agents">
|
|
70
|
+
<FileTree.File name="example-agent.ts" />
|
|
71
|
+
</FileTree.Folder>
|
|
72
|
+
<FileTree.Folder name="tools">
|
|
73
|
+
<FileTree.File name="example-tool.ts" />
|
|
74
|
+
</FileTree.Folder>
|
|
75
|
+
<FileTree.Folder name="workflows">
|
|
76
|
+
<FileTree.File name="example-workflow.ts" />
|
|
77
|
+
</FileTree.Folder>
|
|
78
|
+
<FileTree.File name="index.ts" />
|
|
79
|
+
</FileTree.Folder>
|
|
80
|
+
</FileTree.Folder>
|
|
81
|
+
<FileTree.File name=".env.example" />
|
|
82
|
+
<FileTree.File name="package.json" />
|
|
83
|
+
<FileTree.File name="README.md" />
|
|
84
|
+
<FileTree.File name="tsconfig.json" />
|
|
85
|
+
</FileTree.Folder>
|
|
86
|
+
</FileTree>
|
|
87
|
+
|
|
88
|
+
## Creating Templates
|
|
89
|
+
|
|
90
|
+
### Requirements
|
|
91
|
+
|
|
92
|
+
Templates must meet these technical requirements:
|
|
93
|
+
|
|
94
|
+
#### Project Structure
|
|
95
|
+
|
|
96
|
+
- **Mastra code location**: All Mastra code must be in `src/mastra/` directory
|
|
97
|
+
- **Component organization**:
|
|
98
|
+
- Agents: `src/mastra/agents/`
|
|
99
|
+
- Tools: `src/mastra/tools/`
|
|
100
|
+
- Workflows: `src/mastra/workflows/`
|
|
101
|
+
- Main config: `src/mastra/index.ts`
|
|
102
|
+
|
|
103
|
+
#### TypeScript Configuration
|
|
104
|
+
|
|
105
|
+
Use the standard Mastra TypeScript configuration:
|
|
106
|
+
|
|
107
|
+
```json filename="tsconfig.json"
|
|
108
|
+
{
|
|
109
|
+
"compilerOptions": {
|
|
110
|
+
"target": "ES2022",
|
|
111
|
+
"module": "ES2022",
|
|
112
|
+
"moduleResolution": "bundler",
|
|
113
|
+
"esModuleInterop": true,
|
|
114
|
+
"forceConsistentCasingInFileNames": true,
|
|
115
|
+
"strict": true,
|
|
116
|
+
"skipLibCheck": true,
|
|
117
|
+
"noEmit": true,
|
|
118
|
+
"outDir": "dist"
|
|
119
|
+
},
|
|
120
|
+
"include": ["src/**/*"]
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
#### Environment Configuration
|
|
125
|
+
|
|
126
|
+
Include a `.env.example` file with all required environment variables:
|
|
127
|
+
|
|
128
|
+
```bash filename=".env.example"
|
|
129
|
+
# LLM provider API keys (choose one or more)
|
|
130
|
+
OPENAI_API_KEY=your_openai_api_key_here
|
|
131
|
+
ANTHROPIC_API_KEY=your_anthropic_api_key_here
|
|
132
|
+
GOOGLE_GENERATIVE_AI_API_KEY=your_google_api_key_here
|
|
133
|
+
|
|
134
|
+
# Other service API keys as needed
|
|
135
|
+
OTHER_SERVICE_API_KEY=your_api_key_here
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Code Standards
|
|
139
|
+
|
|
140
|
+
#### LLM Provider
|
|
141
|
+
|
|
142
|
+
We recommend using OpenAI, Anthropic, or Google model providers for templates. Choose the provider that best fits your use case:
|
|
143
|
+
|
|
144
|
+
```typescript filename="src/mastra/agents/example-agent.ts"
|
|
145
|
+
import { Agent } from '@mastra/core/agent';
|
|
146
|
+
import { openai } from '@ai-sdk/openai';
|
|
147
|
+
// Or use: import { anthropic } from '@ai-sdk/anthropic';
|
|
148
|
+
// Or use: import { google } from '@ai-sdk/google';
|
|
149
|
+
|
|
150
|
+
const agent = new Agent({
|
|
151
|
+
name: 'example-agent',
|
|
152
|
+
model: openai('gpt-4'), // or anthropic('') or google('')
|
|
153
|
+
instructions: 'Your agent instructions here',
|
|
154
|
+
// ... other configuration
|
|
155
|
+
});
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
#### Compatibility Requirements
|
|
159
|
+
|
|
160
|
+
Templates must be:
|
|
161
|
+
|
|
162
|
+
- **Single projects** - Not monorepos with multiple applications
|
|
163
|
+
- **Framework-free** - No Next.js, Express, or other web framework boilerplate
|
|
164
|
+
- **Mastra-focused** - Demonstrate Mastra functionality without additional layers
|
|
165
|
+
- **Mergeable** - Structure code for easy integration into existing projects
|
|
166
|
+
- **Node.js compatible** - Support Node.js 18 and higher
|
|
167
|
+
- **ESM modules** - Use ES modules (`"type": "module"` in package.json)
|
|
168
|
+
|
|
169
|
+
### Documentation Requirements
|
|
170
|
+
|
|
171
|
+
#### README Structure
|
|
172
|
+
|
|
173
|
+
Every template must include a comprehensive README:
|
|
174
|
+
|
|
175
|
+
```markdown filename="README.md"
|
|
176
|
+
# Template Name
|
|
177
|
+
|
|
178
|
+
Brief description of what the template demonstrates.
|
|
179
|
+
|
|
180
|
+
## Overview
|
|
181
|
+
|
|
182
|
+
Detailed explanation of the template's functionality and use case.
|
|
183
|
+
|
|
184
|
+
## Setup
|
|
185
|
+
|
|
186
|
+
1. Copy `.env.example` to `.env` and fill in your API keys
|
|
187
|
+
2. Install dependencies: `npm install`
|
|
188
|
+
3. Run the project: `npm run dev`
|
|
189
|
+
|
|
190
|
+
## Environment Variables
|
|
191
|
+
|
|
192
|
+
- `OPENAI_API_KEY`: Your OpenAI API key. Get one at [OpenAI Platform](https://platform.openai.com/api-keys)
|
|
193
|
+
- `ANTHROPIC_API_KEY`: Your Anthropic API key. Get one at [Anthropic Console](https://console.anthropic.com/settings/keys)
|
|
194
|
+
- `GOOGLE_GENERATIVE_AI_API_KEY`: Your Google AI API key. Get one at [Google AI Studio](https://makersuite.google.com/app/apikey)
|
|
195
|
+
- `OTHER_API_KEY`: Description of what this key is for
|
|
196
|
+
|
|
197
|
+
## Usage
|
|
198
|
+
|
|
199
|
+
Instructions on how to use the template and examples of expected behavior.
|
|
200
|
+
|
|
201
|
+
## Customization
|
|
202
|
+
|
|
203
|
+
Guidelines for modifying the template for different use cases.
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
#### Code Comments
|
|
207
|
+
|
|
208
|
+
Include clear comments explaining:
|
|
209
|
+
|
|
210
|
+
- Complex logic or algorithms
|
|
211
|
+
- API integrations and their purpose
|
|
212
|
+
- Configuration options and their effects
|
|
213
|
+
- Example usage patterns
|
|
214
|
+
|
|
215
|
+
### Quality Standards
|
|
216
|
+
|
|
217
|
+
Templates must demonstrate:
|
|
218
|
+
|
|
219
|
+
- **Code quality** - Clean, well-commented, maintainable code
|
|
220
|
+
- **Error handling** - Proper handling for external APIs and user inputs
|
|
221
|
+
- **Type safety** - Full TypeScript typing with Zod validation
|
|
222
|
+
- **Testing** - Verified functionality with fresh installations
|
|
223
|
+
|
|
224
|
+
For information on contributing your own templates to the Mastra ecosystem, see the [Contributing Templates](/docs/community/contributing-templates) guide in the community section.
|
|
225
|
+
|
|
226
|
+
<Callout type="info">
|
|
227
|
+
Templates provide an excellent way to learn Mastra patterns and accelerate development. Contributing templates helps the entire community build better AI applications.
|
|
228
|
+
</Callout>
|