@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,268 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Input Processors"
|
|
3
|
+
description: "Learn how to use input processors to intercept and modify agent messages before they reach the language model."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Input Processors
|
|
7
|
+
|
|
8
|
+
Input Processors allow you to intercept, modify, validate, or filter messages _before_ they are sent to the language model. This is useful for implementing guardrails, content moderation, message transformation, and security controls.
|
|
9
|
+
|
|
10
|
+
Processors operate on the messages in your conversation thread. They can modify, filter, or validate content, and even abort the request entirely if certain conditions are met.
|
|
11
|
+
|
|
12
|
+
## Built-in Processors
|
|
13
|
+
|
|
14
|
+
Mastra provides several built-in processors for common use cases:
|
|
15
|
+
|
|
16
|
+
### `UnicodeNormalizer`
|
|
17
|
+
|
|
18
|
+
This processor normalizes Unicode text to ensure consistent formatting and remove potentially problematic characters.
|
|
19
|
+
|
|
20
|
+
```typescript copy showLineNumbers {9-11}
|
|
21
|
+
import { Agent } from "@mastra/core/agent";
|
|
22
|
+
import { UnicodeNormalizer } from "@mastra/core/agent/input-processor/processors";
|
|
23
|
+
import { openai } from "@ai-sdk/openai";
|
|
24
|
+
|
|
25
|
+
const agent = new Agent({
|
|
26
|
+
name: 'normalized-agent',
|
|
27
|
+
instructions: 'You are a helpful assistant',
|
|
28
|
+
model: openai("gpt-4o"),
|
|
29
|
+
inputProcessors: [
|
|
30
|
+
new UnicodeNormalizer({
|
|
31
|
+
stripControlChars: true,
|
|
32
|
+
collapseWhitespace: true,
|
|
33
|
+
}),
|
|
34
|
+
],
|
|
35
|
+
});
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Available options:
|
|
39
|
+
- `stripControlChars`: Remove control characters (default: false)
|
|
40
|
+
- `preserveEmojis`: Keep emojis intact (default: true)
|
|
41
|
+
- `collapseWhitespace`: Collapse multiple spaces/newlines (default: true)
|
|
42
|
+
- `trim`: Remove leading/trailing whitespace (default: true)
|
|
43
|
+
|
|
44
|
+
### `ModerationInputProcessor`
|
|
45
|
+
|
|
46
|
+
This processor provides content moderation using an LLM to detect inappropriate content across multiple categories.
|
|
47
|
+
|
|
48
|
+
```typescript copy showLineNumbers {5-13}
|
|
49
|
+
import { ModerationInputProcessor } from "@mastra/core/agent/input-processor/processors";
|
|
50
|
+
|
|
51
|
+
const agent = new Agent({
|
|
52
|
+
inputProcessors: [
|
|
53
|
+
new ModerationInputProcessor({
|
|
54
|
+
model: openai("gpt-4.1-nano"), // Use a fast, cost-effective model
|
|
55
|
+
threshold: 0.7, // Confidence threshold for flagging
|
|
56
|
+
strategy: 'block', // Block flagged content
|
|
57
|
+
categories: ['hate', 'harassment', 'violence'], // Custom categories
|
|
58
|
+
}),
|
|
59
|
+
],
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Available options:
|
|
64
|
+
- `model`: Language model for moderation analysis (required)
|
|
65
|
+
- `categories`: Array of categories to check (default: ['hate','hate/threatening','harassment','harassment/threatening','self-harm','self-harm/intent','self-harm/instructions','sexual','sexual/minors','violence','violence/graphic'])
|
|
66
|
+
- `threshold`: Confidence threshold for flagging (0-1, default: 0.5)
|
|
67
|
+
- `strategy`: Action when content is flagged (default: 'block')
|
|
68
|
+
- `customInstructions`: Custom instructions for the moderation agent
|
|
69
|
+
|
|
70
|
+
Strategies available:
|
|
71
|
+
- `block`: Reject the request with an error (default)
|
|
72
|
+
- `warn`: Log warning but allow content through
|
|
73
|
+
- `filter`: Remove flagged messages but continue processing
|
|
74
|
+
|
|
75
|
+
### `PromptInjectionDetector`
|
|
76
|
+
|
|
77
|
+
This processor detects and prevents prompt injection attacks, jailbreaks, and system manipulation attempts.
|
|
78
|
+
|
|
79
|
+
```typescript copy showLineNumbers {5-12}
|
|
80
|
+
import { PromptInjectionDetector } from "@mastra/core/agent/input-processor/processors";
|
|
81
|
+
|
|
82
|
+
const agent = new Agent({
|
|
83
|
+
inputProcessors: [
|
|
84
|
+
new PromptInjectionDetector({
|
|
85
|
+
model: openai("gpt-4.1-nano"),
|
|
86
|
+
threshold: 0.8, // Higher threshold for fewer false positives
|
|
87
|
+
strategy: 'rewrite', // Attempt to neutralize while preserving intent
|
|
88
|
+
detectionTypes: ['injection', 'jailbreak', 'system-override'],
|
|
89
|
+
}),
|
|
90
|
+
],
|
|
91
|
+
});
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Available options:
|
|
95
|
+
- `model`: Language model for injection detection (required)
|
|
96
|
+
- `detectionTypes`: Array of injection types to detect (default: ['injection', 'jailbreak', 'system-override'])
|
|
97
|
+
- `threshold`: Confidence threshold for flagging (0-1, default: 0.7)
|
|
98
|
+
- `strategy`: Action when injection is detected (default: 'block')
|
|
99
|
+
- `instructions`: Custom detection instructions for the agent
|
|
100
|
+
- `includeScores`: Whether to include confidence scores in logs (default: false)
|
|
101
|
+
|
|
102
|
+
Strategies available:
|
|
103
|
+
- `block`: Reject the request (default)
|
|
104
|
+
- `warn`: Log warning but allow through
|
|
105
|
+
- `filter`: Remove flagged messages
|
|
106
|
+
- `rewrite`: Attempt to neutralize the injection while preserving legitimate intent
|
|
107
|
+
|
|
108
|
+
### `PIIDetector`
|
|
109
|
+
|
|
110
|
+
This processor detects and optionally redacts personally identifiable information (PII) from messages.
|
|
111
|
+
|
|
112
|
+
```typescript copy showLineNumbers {5-14}
|
|
113
|
+
import { PIIDetector } from "@mastra/core/agent/input-processor/processors";
|
|
114
|
+
|
|
115
|
+
const agent = new Agent({
|
|
116
|
+
inputProcessors: [
|
|
117
|
+
new PIIDetector({
|
|
118
|
+
model: openai("gpt-4.1-nano"),
|
|
119
|
+
threshold: 0.6,
|
|
120
|
+
strategy: 'redact', // Automatically redact detected PII
|
|
121
|
+
detectionTypes: ['email', 'phone', 'credit-card', 'ssn', 'api-key', 'crypto-wallet', 'iban'],
|
|
122
|
+
redactionMethod: 'mask', // Preserve format while masking
|
|
123
|
+
preserveFormat: true, // Keep original structure in redacted values
|
|
124
|
+
includeDetections: true, // Log details for compliance auditing
|
|
125
|
+
}),
|
|
126
|
+
],
|
|
127
|
+
});
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Available options:
|
|
131
|
+
- `model`: Language model for PII detection (required)
|
|
132
|
+
- `detectionTypes`: Array of PII types to detect (default: ['email', 'phone', 'credit-card', 'ssn', 'api-key', 'ip-address', 'name', 'address', 'date-of-birth', 'url', 'uuid', 'crypto-wallet', 'iban'])
|
|
133
|
+
- `threshold`: Confidence threshold for flagging (0-1, default: 0.6)
|
|
134
|
+
- `strategy`: Action when PII is detected (default: 'block')
|
|
135
|
+
- `redactionMethod`: How to redact PII ('mask', 'hash', 'remove', 'placeholder', default: 'mask')
|
|
136
|
+
- `preserveFormat`: Maintain PII structure during redaction (default: true)
|
|
137
|
+
- `includeDetections`: Include detection details in logs for compliance (default: false)
|
|
138
|
+
- `instructions`: Custom detection instructions for the agent
|
|
139
|
+
|
|
140
|
+
Strategies available:
|
|
141
|
+
- `block`: Reject requests containing PII (default)
|
|
142
|
+
- `warn`: Log warning but allow through
|
|
143
|
+
- `filter`: Remove messages containing PII
|
|
144
|
+
- `redact`: Replace PII with placeholder values
|
|
145
|
+
|
|
146
|
+
### `LanguageDetector`
|
|
147
|
+
|
|
148
|
+
This processor detects the language of incoming messages and can automatically translate them to a target language.
|
|
149
|
+
|
|
150
|
+
```typescript copy showLineNumbers {5-12}
|
|
151
|
+
import { LanguageDetector } from "@mastra/core/agent/input-processor/processors";
|
|
152
|
+
|
|
153
|
+
const agent = new Agent({
|
|
154
|
+
inputProcessors: [
|
|
155
|
+
new LanguageDetector({
|
|
156
|
+
model: openai("gpt-4o"),
|
|
157
|
+
targetLanguages: ['English', 'en'], // Accept English content
|
|
158
|
+
strategy: 'translate', // Auto-translate non-English content
|
|
159
|
+
threshold: 0.8, // High confidence threshold
|
|
160
|
+
}),
|
|
161
|
+
],
|
|
162
|
+
});
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Available options:
|
|
166
|
+
- `model`: Language model for detection and translation (required)
|
|
167
|
+
- `targetLanguages`: Array of target languages (language names or ISO codes)
|
|
168
|
+
- `threshold`: Confidence threshold for language detection (0-1, default: 0.7)
|
|
169
|
+
- `strategy`: Action when non-target language is detected (default: 'detect')
|
|
170
|
+
- `preserveOriginal`: Keep original content in metadata (default: true)
|
|
171
|
+
- `instructions`: Custom detection instructions for the agent
|
|
172
|
+
|
|
173
|
+
Strategies available:
|
|
174
|
+
- `detect`: Only detect language, don't translate (default)
|
|
175
|
+
- `translate`: Automatically translate to target language
|
|
176
|
+
- `block`: Reject content not in target language
|
|
177
|
+
- `warn`: Log warning but allow content through
|
|
178
|
+
|
|
179
|
+
## Applying Multiple Processors
|
|
180
|
+
|
|
181
|
+
You can chain multiple processors. They execute sequentially in the order they appear in the `inputProcessors` array. The output of one processor becomes the input for the next.
|
|
182
|
+
|
|
183
|
+
**Order matters!** Generally, it's best practice to place text normalization first, security checks next, and content modification last.
|
|
184
|
+
|
|
185
|
+
```typescript copy showLineNumbers {9-18}
|
|
186
|
+
import { Agent } from "@mastra/core/agent";
|
|
187
|
+
import {
|
|
188
|
+
UnicodeNormalizer,
|
|
189
|
+
ModerationInputProcessor,
|
|
190
|
+
PromptInjectionDetector,
|
|
191
|
+
PIIDetector
|
|
192
|
+
} from "@mastra/core/agent/input-processor/processors";
|
|
193
|
+
|
|
194
|
+
const secureAgent = new Agent({
|
|
195
|
+
inputProcessors: [
|
|
196
|
+
// 1. Normalize text first
|
|
197
|
+
new UnicodeNormalizer({ stripControlChars: true }),
|
|
198
|
+
// 2. Check for security threats
|
|
199
|
+
new PromptInjectionDetector({ model: openai("gpt-4.1-nano") }),
|
|
200
|
+
// 3. Moderate content
|
|
201
|
+
new ModerationInputProcessor({ model: openai("gpt-4.1-nano") }),
|
|
202
|
+
// 4. Handle PII last
|
|
203
|
+
new PIIDetector({ model: openai("gpt-4.1-nano"), strategy: 'redact' }),
|
|
204
|
+
],
|
|
205
|
+
});
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## Creating Custom Processors
|
|
209
|
+
|
|
210
|
+
You can create custom processors by implementing the `InputProcessor` interface.
|
|
211
|
+
|
|
212
|
+
```typescript copy showLineNumbers {4-19,23-26}
|
|
213
|
+
import type { InputProcessor, MastraMessageV2 } from "@mastra/core/agent";
|
|
214
|
+
|
|
215
|
+
class MessageLengthLimiter implements InputProcessor {
|
|
216
|
+
readonly name = 'message-length-limiter';
|
|
217
|
+
|
|
218
|
+
constructor(private maxLength: number = 1000) {}
|
|
219
|
+
|
|
220
|
+
process({ messages, abort }: {
|
|
221
|
+
messages: MastraMessageV2[];
|
|
222
|
+
abort: (reason?: string) => never
|
|
223
|
+
}): MastraMessageV2[] {
|
|
224
|
+
// Check total message length
|
|
225
|
+
const totalLength = messages.reduce((sum, msg) => {
|
|
226
|
+
return sum + msg.content.parts
|
|
227
|
+
.filter(part => part.type === 'text')
|
|
228
|
+
.reduce((partSum, part) => partSum + (part as any).text.length, 0);
|
|
229
|
+
}, 0);
|
|
230
|
+
|
|
231
|
+
if (totalLength > this.maxLength) {
|
|
232
|
+
abort(`Message too long: ${totalLength} characters (max: ${this.maxLength})`);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return messages;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// Use the custom processor
|
|
240
|
+
const agent = new Agent({
|
|
241
|
+
inputProcessors: [
|
|
242
|
+
new MessageLengthLimiter(2000), // Limit to 2000 characters
|
|
243
|
+
],
|
|
244
|
+
});
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
When creating custom processors:
|
|
248
|
+
- Always return the `messages` array (potentially modified)
|
|
249
|
+
- Use `abort(reason)` to terminate processing early
|
|
250
|
+
- Mutate the input messages directly
|
|
251
|
+
- Keep processors focused on a single responsibility
|
|
252
|
+
|
|
253
|
+
## Integration with Agent Methods
|
|
254
|
+
|
|
255
|
+
Input processors work with both `generate()` and `stream()` methods. The entire processor pipeline completes before the agent begins generating or streaming a response.
|
|
256
|
+
|
|
257
|
+
```typescript copy showLineNumbers
|
|
258
|
+
// Processors run before generate()
|
|
259
|
+
const result = await agent.generate('Hello');
|
|
260
|
+
|
|
261
|
+
// Processors also run before stream()
|
|
262
|
+
const stream = await agent.stream('Hello');
|
|
263
|
+
for await (const chunk of stream.textStream) {
|
|
264
|
+
console.log(chunk);
|
|
265
|
+
}
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
If any processor calls `abort()`, the request terminates immediately and subsequent processors are not executed. The agent returns an error response with details about why the request was blocked.
|
|
@@ -7,6 +7,10 @@ description: Learn how to create tools, add them to Mastra agents, and integrate
|
|
|
7
7
|
|
|
8
8
|
Tools are typed functions that can be executed by agents or workflows. Each tool has a schema defining its inputs, an executor function implementing its logic, and optional access to configured integrations.
|
|
9
9
|
|
|
10
|
+
Mastra supports two patterns for providing tools to agents:
|
|
11
|
+
- **Direct assignment**: Static tools available at initialization
|
|
12
|
+
- **Function-based**: Dynamic tools resolved based on runtime context
|
|
13
|
+
|
|
10
14
|
## Creating Tools
|
|
11
15
|
|
|
12
16
|
Here's a basic example of creating a tool:
|
|
@@ -107,6 +111,41 @@ const agent = new Agent({
|
|
|
107
111
|
});
|
|
108
112
|
```
|
|
109
113
|
|
|
114
|
+
When creating agents that will consume an MCP server in the same repo they need to connect to, always use function based tools to prevent race conditions.
|
|
115
|
+
|
|
116
|
+
```typescript filename="src/mastra/agents/selfReferencingAgent.ts"
|
|
117
|
+
import { Agent } from "@mastra/core/agent";
|
|
118
|
+
import { MCPServer } from "@mastra/mcp";
|
|
119
|
+
import { MCPClient } from "@mastra/mcp";
|
|
120
|
+
import { openai } from "@ai-sdk/openai";
|
|
121
|
+
|
|
122
|
+
const myAgent = new Agent({
|
|
123
|
+
name: "My Agent",
|
|
124
|
+
description: "An agent that can use tools from an http MCP server",
|
|
125
|
+
instructions: "You can use remote calculation tools.",
|
|
126
|
+
model: openai("gpt-4o-mini"),
|
|
127
|
+
tools: async () => {
|
|
128
|
+
// Tools resolve when needed, not during initialization
|
|
129
|
+
const mcpClient = new MCPClient({
|
|
130
|
+
servers: {
|
|
131
|
+
myServer: {
|
|
132
|
+
url: new URL("http://localhost:4111/api/mcp/mcpServer/mcp"),
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
return await mcpClient.getTools();
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
// This works because tools resolve after server startup
|
|
141
|
+
export const mcpServer = new MCPServer({
|
|
142
|
+
name: "My MCP Server",
|
|
143
|
+
agents: {
|
|
144
|
+
myAgent
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
```
|
|
148
|
+
|
|
110
149
|
For more details on configuring `MCPClient` and the difference between static and dynamic MCP server configurations, see the [MCP Overview](/docs/tools-mcp/mcp-overview).
|
|
111
150
|
|
|
112
151
|
## Accessing MCP Resources
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Contributing Templates"
|
|
3
|
+
description: "How to contribute your own templates to the Mastra ecosystem"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
import { Callout } from "nextra/components";
|
|
7
|
+
|
|
8
|
+
# Contributing Templates
|
|
9
|
+
|
|
10
|
+
The Mastra community plays a vital role in creating templates that showcase innovative application patterns. This guide explains how to contribute your own templates to the Mastra ecosystem.
|
|
11
|
+
|
|
12
|
+
## Template Contribution Process
|
|
13
|
+
|
|
14
|
+
### 1. Review Requirements
|
|
15
|
+
|
|
16
|
+
Before creating a template, ensure you understand:
|
|
17
|
+
|
|
18
|
+
- [Templates Reference](/reference/templates) - Technical requirements and conventions
|
|
19
|
+
- [Project Structure](/docs/getting-started/project-structure) - Standard Mastra project organization
|
|
20
|
+
- Community guidelines and quality standards
|
|
21
|
+
|
|
22
|
+
### 2. Develop Your Template
|
|
23
|
+
|
|
24
|
+
Create your template following the established patterns:
|
|
25
|
+
|
|
26
|
+
- Focus on a specific use case or pattern
|
|
27
|
+
- Include comprehensive documentation
|
|
28
|
+
- Test thoroughly with fresh installations
|
|
29
|
+
- Follow all technical requirements
|
|
30
|
+
|
|
31
|
+
### 3. Submit for Review
|
|
32
|
+
|
|
33
|
+
Once your template is ready, submit it through our contribution form. Templates undergo an approval process to ensure quality and consistency.
|
|
34
|
+
|
|
35
|
+
## Submission Guidelines
|
|
36
|
+
|
|
37
|
+
### Template Criteria
|
|
38
|
+
|
|
39
|
+
We accept templates that:
|
|
40
|
+
|
|
41
|
+
- **Demonstrate unique value** - Show innovative use cases or patterns not covered by existing templates
|
|
42
|
+
- **Follow conventions** - Adhere to all technical requirements and structural guidelines
|
|
43
|
+
- **Include quality documentation** - Provide clear setup instructions and usage examples
|
|
44
|
+
- **Work reliably** - Function correctly with minimal setup after installation
|
|
45
|
+
|
|
46
|
+
### Quality Standards
|
|
47
|
+
|
|
48
|
+
Templates must meet these quality benchmarks:
|
|
49
|
+
|
|
50
|
+
- **Code quality** - Clean, well-commented, and maintainable code
|
|
51
|
+
- **Error handling** - Proper error handling for external APIs and user inputs
|
|
52
|
+
- **Type safety** - Full TypeScript typing with Zod validation where appropriate
|
|
53
|
+
- **Documentation** - Comprehensive README with setup and usage instructions
|
|
54
|
+
- **Testing** - Verified to work with fresh installations
|
|
55
|
+
|
|
56
|
+
## Submission Process
|
|
57
|
+
|
|
58
|
+
### 1. Prepare Your Template
|
|
59
|
+
|
|
60
|
+
Ensure your template meets all requirements outlined in the [Templates Reference](/reference/templates):
|
|
61
|
+
|
|
62
|
+
- Proper project structure in `src/mastra/` directory
|
|
63
|
+
- Standard TypeScript configuration
|
|
64
|
+
- Comprehensive `.env.example` file
|
|
65
|
+
- Detailed README with setup instructions
|
|
66
|
+
|
|
67
|
+
### 2. Submit Your Template
|
|
68
|
+
|
|
69
|
+
Submit your template using our contribution form:
|
|
70
|
+
|
|
71
|
+
**[Submit Template Contribution](https://docs.google.com/forms/d/e/1FAIpQLSfiqD4oeOVaqoE3t10KZJw4QM3fxAQPIOcZBqUYkewJIsQKFw/viewform)**
|
|
72
|
+
|
|
73
|
+
### Required Information
|
|
74
|
+
|
|
75
|
+
When submitting your template, provide:
|
|
76
|
+
|
|
77
|
+
- **Template Name** - Clear, descriptive name indicating the use case
|
|
78
|
+
- **Template Author Name** - Your name or organization name
|
|
79
|
+
- **Template Author Email** - Contact email for communication about your submission
|
|
80
|
+
- **GitHub URL** - Link to your template repository
|
|
81
|
+
- **Description** - Detailed explanation of what the template does and its value
|
|
82
|
+
- **Optional Image** - Screenshot or diagram showing the template in action
|
|
83
|
+
- **Optional Demo Video** - Link to a video demonstrating the template's functionality
|
|
84
|
+
|
|
85
|
+
## Review Process
|
|
86
|
+
|
|
87
|
+
### Review Criteria
|
|
88
|
+
|
|
89
|
+
Templates are evaluated on:
|
|
90
|
+
|
|
91
|
+
- **Technical compliance** - Adherence to template rules and conventions
|
|
92
|
+
- **Code quality** - Clean, maintainable, and well-documented code
|
|
93
|
+
- **Uniqueness** - Novel use cases or innovative implementation patterns
|
|
94
|
+
- **Educational value** - Ability to teach Mastra concepts effectively
|
|
95
|
+
- **Community benefit** - Potential value to the broader Mastra community
|
|
96
|
+
|
|
97
|
+
### Feedback and Iteration
|
|
98
|
+
|
|
99
|
+
If your template needs improvements:
|
|
100
|
+
|
|
101
|
+
- You'll receive specific feedback on required changes
|
|
102
|
+
- Make the requested modifications and resubmit
|
|
103
|
+
- The review process continues until the template meets standards
|
|
104
|
+
|
|
105
|
+
## Community Guidelines
|
|
106
|
+
|
|
107
|
+
### Template Ideas
|
|
108
|
+
|
|
109
|
+
Consider creating templates for:
|
|
110
|
+
|
|
111
|
+
- **Industry-specific use cases** - Healthcare, finance, education, etc.
|
|
112
|
+
- **Integration patterns** - Specific API or service integrations
|
|
113
|
+
- **Advanced techniques** - Complex workflows, multi-agent systems, or novel patterns
|
|
114
|
+
- **Learning resources** - Step-by-step tutorials for specific concepts
|
|
115
|
+
|
|
116
|
+
### Development Best Practices
|
|
117
|
+
|
|
118
|
+
- **Start simple** - Begin with a minimal working example and add complexity gradually
|
|
119
|
+
- **Document thoroughly** - Include detailed comments and comprehensive README
|
|
120
|
+
- **Test extensively** - Verify your template works across different environments
|
|
121
|
+
- **Seek feedback** - Share with the community for early feedback before submission
|
|
122
|
+
|
|
123
|
+
### Community Engagement
|
|
124
|
+
|
|
125
|
+
- **Join Discord** - Participate in the [Mastra Discord community](https://discord.gg/BTYqqHKUrf)
|
|
126
|
+
- **Share progress** - Update the community on your template development
|
|
127
|
+
- **Help others** - Assist other contributors with their templates
|
|
128
|
+
- **Stay updated** - Keep track of new Mastra features and conventions
|
|
129
|
+
|
|
130
|
+
## Template Maintenance
|
|
131
|
+
|
|
132
|
+
### Ongoing Responsibilities
|
|
133
|
+
|
|
134
|
+
As a template contributor, you may be asked to:
|
|
135
|
+
|
|
136
|
+
- **Update dependencies** - Keep templates current with latest Mastra versions
|
|
137
|
+
- **Fix issues** - Address bugs or compatibility problems
|
|
138
|
+
- **Improve documentation** - Enhance instructions based on user feedback
|
|
139
|
+
- **Add features** - Extend templates with new capabilities
|
|
140
|
+
|
|
141
|
+
### Community Support
|
|
142
|
+
|
|
143
|
+
The Mastra team and community provide:
|
|
144
|
+
|
|
145
|
+
- **Technical guidance** - Help with complex implementation challenges
|
|
146
|
+
- **Review feedback** - Detailed feedback to improve template quality
|
|
147
|
+
- **Promotion** - Showcase approved templates to the community
|
|
148
|
+
- **Maintenance assistance** - Support for keeping templates up-to-date
|
|
149
|
+
|
|
150
|
+
## Validation Checklist
|
|
151
|
+
|
|
152
|
+
Before submitting a template, verify:
|
|
153
|
+
|
|
154
|
+
- [ ] All code organized in `src/mastra/` directory
|
|
155
|
+
- [ ] Uses standard Mastra TypeScript configuration
|
|
156
|
+
- [ ] Includes comprehensive `.env.example`
|
|
157
|
+
- [ ] Has detailed README with setup instructions
|
|
158
|
+
- [ ] No monorepo or web framework boilerplate
|
|
159
|
+
- [ ] Successfully runs after fresh install and environment setup
|
|
160
|
+
- [ ] Follows all code quality standards
|
|
161
|
+
- [ ] Demonstrates clear, valuable use case
|
|
162
|
+
|
|
163
|
+
## Community Showcase
|
|
164
|
+
|
|
165
|
+
### Template Gallery
|
|
166
|
+
|
|
167
|
+
Approved templates will be featured in:
|
|
168
|
+
|
|
169
|
+
- **mastra.ai/templates** - Community template gallery (coming soon)
|
|
170
|
+
- **Documentation** - Referenced in relevant documentation sections
|
|
171
|
+
- **Community highlights** - Featured in newsletters and community updates
|
|
172
|
+
|
|
173
|
+
### Recognition
|
|
174
|
+
|
|
175
|
+
Template contributors receive:
|
|
176
|
+
|
|
177
|
+
- **Attribution** - Your name and contact information with the template
|
|
178
|
+
- **Community recognition** - Acknowledgment in community channels
|
|
179
|
+
|
|
180
|
+
## Getting Started
|
|
181
|
+
|
|
182
|
+
Ready to contribute a template?
|
|
183
|
+
|
|
184
|
+
1. **Explore existing templates** - Review current templates for inspiration and patterns
|
|
185
|
+
2. **Plan your template** - Define the use case and value proposition
|
|
186
|
+
3. **Follow the requirements** - Ensure compliance with all technical requirements
|
|
187
|
+
4. **Build and test** - Create a working, well-documented template
|
|
188
|
+
5. **Submit for review** - Use the contribution form to submit your template
|
|
189
|
+
|
|
190
|
+
<Callout type="info">
|
|
191
|
+
Your contributions help grow the Mastra ecosystem and provide valuable resources for the entire community. We look forward to seeing your innovative templates!
|
|
192
|
+
</Callout>
|
|
@@ -68,6 +68,22 @@ You can also run the Mastra CLI in non-interactive mode by passing all required
|
|
|
68
68
|
npx create-mastra@latest --project-name hello-mastra --example --components tools,agents,workflows --llm openai
|
|
69
69
|
```
|
|
70
70
|
|
|
71
|
+
**Install with a template**
|
|
72
|
+
|
|
73
|
+
Start with a pre-built template that demonstrates specific use cases:
|
|
74
|
+
|
|
75
|
+
```bash copy
|
|
76
|
+
npx create-mastra@latest --template template-name
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
For example, to create a text-to-SQL application:
|
|
80
|
+
|
|
81
|
+
```bash copy
|
|
82
|
+
npx create-mastra@latest --template text-to-sql
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
> Browse available templates and learn more in [Templates](/docs/getting-started/templates).
|
|
86
|
+
|
|
71
87
|
> See the [create-mastra](/reference/cli/create-mastra) documentation for a full list of available CLI options.
|
|
72
88
|
|
|
73
89
|
### Add your API key
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Templates | Getting Started | Mastra Docs"
|
|
3
|
+
description: Pre-built project structures that demonstrate common Mastra use cases and patterns
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
import { Callout } from "nextra/components";
|
|
7
|
+
import { Tabs, Tab } from "@/components/tabs";
|
|
8
|
+
|
|
9
|
+
# Templates
|
|
10
|
+
|
|
11
|
+
Templates are pre-built Mastra projects that demonstrate specific use cases and patterns. They provide working examples you can run immediately and customize for your needs.
|
|
12
|
+
|
|
13
|
+
## What Templates Offer
|
|
14
|
+
|
|
15
|
+
Templates include:
|
|
16
|
+
|
|
17
|
+
- **Complete working examples** - Functional code demonstrating specific patterns
|
|
18
|
+
- **Best practices** - Proper project structure and Mastra conventions
|
|
19
|
+
- **Educational value** - Learn different Mastra features through examples
|
|
20
|
+
- **Quick start** - Bootstrap projects faster than starting from scratch
|
|
21
|
+
|
|
22
|
+
## Using Templates
|
|
23
|
+
|
|
24
|
+
Install a template using the `create-mastra` command:
|
|
25
|
+
|
|
26
|
+
<Tabs items={["npx", "npm", "yarn", "pnpm", "bun"]}>
|
|
27
|
+
<Tab>
|
|
28
|
+
```bash copy
|
|
29
|
+
npx create-mastra@latest --template template-name
|
|
30
|
+
```
|
|
31
|
+
</Tab>
|
|
32
|
+
<Tab>
|
|
33
|
+
```bash copy
|
|
34
|
+
npm create mastra@latest --template template-name
|
|
35
|
+
```
|
|
36
|
+
</Tab>
|
|
37
|
+
<Tab>
|
|
38
|
+
```bash copy
|
|
39
|
+
yarn create mastra@latest --template template-name
|
|
40
|
+
```
|
|
41
|
+
</Tab>
|
|
42
|
+
<Tab>
|
|
43
|
+
```bash copy
|
|
44
|
+
pnpm create mastra@latest --template template-name
|
|
45
|
+
```
|
|
46
|
+
</Tab>
|
|
47
|
+
<Tab>
|
|
48
|
+
```bash copy
|
|
49
|
+
bun create mastra@latest --template template-name
|
|
50
|
+
```
|
|
51
|
+
</Tab>
|
|
52
|
+
</Tabs>
|
|
53
|
+
|
|
54
|
+
For example, to create a text-to-SQL application:
|
|
55
|
+
|
|
56
|
+
```bash copy
|
|
57
|
+
npx create-mastra@latest --template text-to-sql
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Setting Up a Template
|
|
61
|
+
|
|
62
|
+
After installation:
|
|
63
|
+
|
|
64
|
+
1. **Navigate to your project**:
|
|
65
|
+
```bash copy
|
|
66
|
+
cd your-project-name
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
2. **Configure environment variables**:
|
|
70
|
+
```bash copy
|
|
71
|
+
cp .env.example .env
|
|
72
|
+
```
|
|
73
|
+
Edit `.env` with your API keys as specified in the template's README.
|
|
74
|
+
|
|
75
|
+
3. **Start development**:
|
|
76
|
+
```bash copy
|
|
77
|
+
npm run dev
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
<Callout type="info">
|
|
81
|
+
Each template includes a comprehensive README with specific setup instructions and usage examples.
|
|
82
|
+
</Callout>
|
|
83
|
+
|
|
84
|
+
## Available Templates
|
|
85
|
+
|
|
86
|
+
Browse available templates in the [templates directory](https://github.com/mastra-ai/mastra/tree/main/templates) on GitHub.
|
|
87
|
+
|
|
88
|
+
## Next Steps
|
|
89
|
+
|
|
90
|
+
- **Explore code** - Understand how templates implement functionality
|
|
91
|
+
- **Customize** - Modify agents, tools, and workflows for your use case
|
|
92
|
+
- **Learn patterns** - Study templates to understand Mastra best practices
|
|
93
|
+
- **Contribute** - Create your own templates for the community
|
|
94
|
+
|
|
95
|
+
For detailed information on creating templates, see the [Templates Reference](/reference/templates).
|
|
@@ -135,6 +135,50 @@ sdk.start();
|
|
|
135
135
|
|
|
136
136
|
When Mastra finds a custom instrumentation file, it automatically replaces the default instrumentation and bundles it during the build process.
|
|
137
137
|
|
|
138
|
+
### Tracing Outside Mastra Server Environment
|
|
139
|
+
|
|
140
|
+
When using `mastra start` or `mastra dev` commands, Mastra automatically provisions and loads the necessary instrumentation files for tracing. However, when using Mastra as a dependency in your own application (outside the Mastra server environment), you'll need to manually provide the instrumentation file.
|
|
141
|
+
|
|
142
|
+
To enable tracing in this case:
|
|
143
|
+
|
|
144
|
+
1. Enable Mastra telemetry in your configuration:
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
export const mastra = new Mastra({
|
|
148
|
+
telemetry: {
|
|
149
|
+
enabled: true,
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
2. Create an instrumentation file in your project (e.g., `instrumentation.mjs`):
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
import { NodeSDK } from '@opentelemetry/sdk-node';
|
|
158
|
+
import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
|
|
159
|
+
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
|
|
160
|
+
|
|
161
|
+
const sdk = new NodeSDK({
|
|
162
|
+
traceExporter: new OTLPTraceExporter(),
|
|
163
|
+
instrumentations: [getNodeAutoInstrumentations()],
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
sdk.start();
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
3. Add OpenTelemetry environment variables:
|
|
170
|
+
|
|
171
|
+
```bash
|
|
172
|
+
OTEL_EXPORTER_OTLP_ENDPOINT=https://api.braintrust.dev/otel
|
|
173
|
+
OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer <Your API Key>, x-bt-parent=project_name:<Your Project Name>"
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
4. Run the OpenTelemetry SDK before your application:
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
node --import=./instrumentation.mjs --import=@opentelemetry/instrumentation/hook.mjs src/index.js
|
|
180
|
+
```
|
|
181
|
+
|
|
138
182
|
### Next.js-specific Tracing steps
|
|
139
183
|
|
|
140
184
|
If you're using Next.js, you have three additional configuration steps:
|