@mastra/mcp-docs-server 0.0.0-default-storage-virtual-file-20250410035748
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%2Fastra.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fchroma.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +131 -0
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +80 -0
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fevals.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Ffirecrawl.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fgithub.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Floggers.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fmcp.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fmem0.md +166 -0
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Frag.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fragie.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-azure.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-deepgram.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-elevenlabs.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-google.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-ibm.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-murf.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-openai.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-playai.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-replicate.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-speechify.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-azure.md +220 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-cloudflare.md +220 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-deepgram.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-elevenlabs.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-murf.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-playai.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-sarvam.md +299 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-speechify.md +302 -0
- package/.docs/organized/changelogs/create-mastra.md +302 -0
- package/.docs/organized/changelogs/mastra.md +302 -0
- package/.docs/organized/code-examples/agent-network.md +282 -0
- package/.docs/organized/code-examples/agent.md +390 -0
- package/.docs/organized/code-examples/ai-sdk-useChat.md +378 -0
- package/.docs/organized/code-examples/assistant-ui.md +37 -0
- package/.docs/organized/code-examples/bird-checker-with-express.md +235 -0
- package/.docs/organized/code-examples/bird-checker-with-nextjs-and-eval.md +360 -0
- package/.docs/organized/code-examples/bird-checker-with-nextjs.md +250 -0
- package/.docs/organized/code-examples/crypto-chatbot.md +96 -0
- package/.docs/organized/code-examples/fireworks-r1.md +159 -0
- package/.docs/organized/code-examples/memory-todo-agent.md +164 -0
- package/.docs/organized/code-examples/memory-with-context.md +167 -0
- package/.docs/organized/code-examples/memory-with-libsql.md +204 -0
- package/.docs/organized/code-examples/memory-with-mem0.md +121 -0
- package/.docs/organized/code-examples/memory-with-pg.md +224 -0
- package/.docs/organized/code-examples/memory-with-upstash.md +268 -0
- package/.docs/organized/code-examples/quick-start.md +129 -0
- package/.docs/organized/code-examples/stock-price-tool.md +124 -0
- package/.docs/organized/code-examples/weather-agent.md +353 -0
- package/.docs/organized/code-examples/workflow-ai-recruiter.md +159 -0
- package/.docs/organized/code-examples/workflow-with-inline-steps.md +111 -0
- package/.docs/organized/code-examples/workflow-with-memory.md +393 -0
- package/.docs/organized/code-examples/workflow-with-separate-steps.md +131 -0
- package/.docs/raw/agents/adding-tools.mdx +239 -0
- package/.docs/raw/agents/adding-voice.mdx +175 -0
- package/.docs/raw/agents/agent-memory.mdx +62 -0
- package/.docs/raw/agents/mcp-guide.mdx +192 -0
- package/.docs/raw/agents/overview.mdx +303 -0
- package/.docs/raw/community/discord.mdx +12 -0
- package/.docs/raw/community/licensing.mdx +63 -0
- package/.docs/raw/deployment/client.mdx +120 -0
- package/.docs/raw/deployment/deployment.mdx +119 -0
- package/.docs/raw/deployment/server.mdx +276 -0
- package/.docs/raw/evals/custom-eval.mdx +22 -0
- package/.docs/raw/evals/overview.mdx +95 -0
- package/.docs/raw/evals/running-in-ci.mdx +81 -0
- package/.docs/raw/evals/textual-evals.mdx +54 -0
- package/.docs/raw/faq/index.mdx +63 -0
- package/.docs/raw/frameworks/ai-sdk.mdx +296 -0
- package/.docs/raw/frameworks/next-js.mdx +238 -0
- package/.docs/raw/getting-started/installation.mdx +436 -0
- package/.docs/raw/getting-started/mcp-docs-server.mdx +141 -0
- package/.docs/raw/getting-started/project-structure.mdx +80 -0
- package/.docs/raw/index.mdx +22 -0
- package/.docs/raw/integrations/index.mdx +213 -0
- package/.docs/raw/local-dev/add-to-existing-project.mdx +48 -0
- package/.docs/raw/local-dev/creating-a-new-project.mdx +54 -0
- package/.docs/raw/local-dev/mastra-dev.mdx +108 -0
- package/.docs/raw/memory/memory-processors.mdx +131 -0
- package/.docs/raw/memory/overview.mdx +119 -0
- package/.docs/raw/memory/semantic-recall.mdx +122 -0
- package/.docs/raw/memory/working-memory.mdx +87 -0
- package/.docs/raw/observability/logging.mdx +38 -0
- package/.docs/raw/observability/nextjs-tracing.mdx +108 -0
- package/.docs/raw/observability/tracing.mdx +115 -0
- package/.docs/raw/rag/chunking-and-embedding.mdx +156 -0
- package/.docs/raw/rag/overview.mdx +85 -0
- package/.docs/raw/rag/retrieval.mdx +365 -0
- package/.docs/raw/rag/vector-databases.mdx +340 -0
- package/.docs/raw/reference/agents/createTool.mdx +229 -0
- package/.docs/raw/reference/agents/generate.mdx +327 -0
- package/.docs/raw/reference/agents/getAgent.mdx +54 -0
- package/.docs/raw/reference/agents/stream.mdx +362 -0
- package/.docs/raw/reference/cli/build.mdx +48 -0
- package/.docs/raw/reference/cli/deploy.mdx +22 -0
- package/.docs/raw/reference/cli/dev.mdx +134 -0
- package/.docs/raw/reference/cli/init.mdx +43 -0
- package/.docs/raw/reference/client-js/agents.mdx +107 -0
- package/.docs/raw/reference/client-js/error-handling.mdx +38 -0
- package/.docs/raw/reference/client-js/logs.mdx +24 -0
- package/.docs/raw/reference/client-js/memory.mdx +97 -0
- package/.docs/raw/reference/client-js/telemetry.mdx +20 -0
- package/.docs/raw/reference/client-js/tools.mdx +44 -0
- package/.docs/raw/reference/client-js/vectors.mdx +79 -0
- package/.docs/raw/reference/client-js/workflows.mdx +136 -0
- package/.docs/raw/reference/core/mastra-class.mdx +232 -0
- package/.docs/raw/reference/deployer/cloudflare.mdx +176 -0
- package/.docs/raw/reference/deployer/deployer.mdx +159 -0
- package/.docs/raw/reference/deployer/netlify.mdx +88 -0
- package/.docs/raw/reference/deployer/vercel.mdx +97 -0
- package/.docs/raw/reference/evals/answer-relevancy.mdx +186 -0
- package/.docs/raw/reference/evals/bias.mdx +186 -0
- package/.docs/raw/reference/evals/completeness.mdx +174 -0
- package/.docs/raw/reference/evals/content-similarity.mdx +183 -0
- package/.docs/raw/reference/evals/context-position.mdx +190 -0
- package/.docs/raw/reference/evals/context-precision.mdx +189 -0
- package/.docs/raw/reference/evals/context-relevancy.mdx +188 -0
- package/.docs/raw/reference/evals/contextual-recall.mdx +191 -0
- package/.docs/raw/reference/evals/faithfulness.mdx +193 -0
- package/.docs/raw/reference/evals/hallucination.mdx +219 -0
- package/.docs/raw/reference/evals/keyword-coverage.mdx +176 -0
- package/.docs/raw/reference/evals/prompt-alignment.mdx +238 -0
- package/.docs/raw/reference/evals/summarization.mdx +205 -0
- package/.docs/raw/reference/evals/textual-difference.mdx +161 -0
- package/.docs/raw/reference/evals/tone-consistency.mdx +181 -0
- package/.docs/raw/reference/evals/toxicity.mdx +165 -0
- package/.docs/raw/reference/index.mdx +8 -0
- package/.docs/raw/reference/memory/Memory.mdx +212 -0
- package/.docs/raw/reference/memory/createThread.mdx +95 -0
- package/.docs/raw/reference/memory/getThreadById.mdx +46 -0
- package/.docs/raw/reference/memory/getThreadsByResourceId.mdx +48 -0
- package/.docs/raw/reference/memory/query.mdx +167 -0
- package/.docs/raw/reference/networks/agent-network.mdx +159 -0
- package/.docs/raw/reference/observability/create-logger.mdx +106 -0
- package/.docs/raw/reference/observability/logger.mdx +55 -0
- package/.docs/raw/reference/observability/otel-config.mdx +120 -0
- package/.docs/raw/reference/observability/providers/braintrust.mdx +40 -0
- package/.docs/raw/reference/observability/providers/dash0.mdx +40 -0
- package/.docs/raw/reference/observability/providers/index.mdx +16 -0
- package/.docs/raw/reference/observability/providers/laminar.mdx +41 -0
- package/.docs/raw/reference/observability/providers/langfuse.mdx +51 -0
- package/.docs/raw/reference/observability/providers/langsmith.mdx +48 -0
- package/.docs/raw/reference/observability/providers/langwatch.mdx +45 -0
- package/.docs/raw/reference/observability/providers/new-relic.mdx +40 -0
- package/.docs/raw/reference/observability/providers/signoz.mdx +40 -0
- package/.docs/raw/reference/observability/providers/traceloop.mdx +40 -0
- package/.docs/raw/reference/rag/astra.mdx +258 -0
- package/.docs/raw/reference/rag/chroma.mdx +281 -0
- package/.docs/raw/reference/rag/chunk.mdx +235 -0
- package/.docs/raw/reference/rag/document.mdx +127 -0
- package/.docs/raw/reference/rag/embeddings.mdx +160 -0
- package/.docs/raw/reference/rag/extract-params.mdx +226 -0
- package/.docs/raw/reference/rag/graph-rag.mdx +182 -0
- package/.docs/raw/reference/rag/libsql.mdx +357 -0
- package/.docs/raw/reference/rag/metadata-filters.mdx +298 -0
- package/.docs/raw/reference/rag/pg.mdx +477 -0
- package/.docs/raw/reference/rag/pinecone.mdx +281 -0
- package/.docs/raw/reference/rag/qdrant.mdx +236 -0
- package/.docs/raw/reference/rag/rerank.mdx +212 -0
- package/.docs/raw/reference/rag/turbopuffer.mdx +249 -0
- package/.docs/raw/reference/rag/upstash.mdx +247 -0
- package/.docs/raw/reference/rag/vectorize.mdx +298 -0
- package/.docs/raw/reference/storage/libsql.mdx +74 -0
- package/.docs/raw/reference/storage/postgresql.mdx +48 -0
- package/.docs/raw/reference/storage/upstash.mdx +86 -0
- package/.docs/raw/reference/tools/client.mdx +188 -0
- package/.docs/raw/reference/tools/document-chunker-tool.mdx +141 -0
- package/.docs/raw/reference/tools/graph-rag-tool.mdx +154 -0
- package/.docs/raw/reference/tools/mcp-configuration.mdx +206 -0
- package/.docs/raw/reference/tools/vector-query-tool.mdx +212 -0
- package/.docs/raw/reference/voice/composite-voice.mdx +140 -0
- package/.docs/raw/reference/voice/deepgram.mdx +164 -0
- package/.docs/raw/reference/voice/elevenlabs.mdx +216 -0
- package/.docs/raw/reference/voice/google.mdx +198 -0
- package/.docs/raw/reference/voice/mastra-voice.mdx +394 -0
- package/.docs/raw/reference/voice/murf.mdx +251 -0
- package/.docs/raw/reference/voice/openai-realtime.mdx +431 -0
- package/.docs/raw/reference/voice/openai.mdx +168 -0
- package/.docs/raw/reference/voice/playai.mdx +159 -0
- package/.docs/raw/reference/voice/sarvam.mdx +260 -0
- package/.docs/raw/reference/voice/speechify.mdx +145 -0
- package/.docs/raw/reference/voice/voice.answer.mdx +122 -0
- package/.docs/raw/reference/voice/voice.connect.mdx +124 -0
- package/.docs/raw/reference/voice/voice.listen.mdx +195 -0
- package/.docs/raw/reference/voice/voice.on.mdx +189 -0
- package/.docs/raw/reference/voice/voice.send.mdx +118 -0
- package/.docs/raw/reference/voice/voice.speak.mdx +203 -0
- package/.docs/raw/reference/workflows/after.mdx +88 -0
- package/.docs/raw/reference/workflows/afterEvent.mdx +76 -0
- package/.docs/raw/reference/workflows/commit.mdx +37 -0
- package/.docs/raw/reference/workflows/createRun.mdx +77 -0
- package/.docs/raw/reference/workflows/else.mdx +72 -0
- package/.docs/raw/reference/workflows/events.mdx +305 -0
- package/.docs/raw/reference/workflows/execute.mdx +110 -0
- package/.docs/raw/reference/workflows/if.mdx +107 -0
- package/.docs/raw/reference/workflows/resume.mdx +155 -0
- package/.docs/raw/reference/workflows/resumeWithEvent.mdx +133 -0
- package/.docs/raw/reference/workflows/snapshots.mdx +207 -0
- package/.docs/raw/reference/workflows/start.mdx +84 -0
- package/.docs/raw/reference/workflows/step-class.mdx +100 -0
- package/.docs/raw/reference/workflows/step-condition.mdx +134 -0
- package/.docs/raw/reference/workflows/step-function.mdx +92 -0
- package/.docs/raw/reference/workflows/step-options.mdx +69 -0
- package/.docs/raw/reference/workflows/step-retries.mdx +203 -0
- package/.docs/raw/reference/workflows/suspend.mdx +70 -0
- package/.docs/raw/reference/workflows/then.mdx +74 -0
- package/.docs/raw/reference/workflows/until.mdx +165 -0
- package/.docs/raw/reference/workflows/watch.mdx +118 -0
- package/.docs/raw/reference/workflows/while.mdx +168 -0
- package/.docs/raw/reference/workflows/workflow.mdx +233 -0
- package/.docs/raw/storage/overview.mdx +378 -0
- package/.docs/raw/voice/overview.mdx +135 -0
- package/.docs/raw/voice/speech-to-text.mdx +45 -0
- package/.docs/raw/voice/text-to-speech.mdx +52 -0
- package/.docs/raw/voice/voice-to-voice.mdx +310 -0
- package/.docs/raw/workflows/control-flow.mdx +778 -0
- package/.docs/raw/workflows/dynamic-workflows.mdx +236 -0
- package/.docs/raw/workflows/error-handling.mdx +183 -0
- package/.docs/raw/workflows/nested-workflows.mdx +352 -0
- package/.docs/raw/workflows/overview.mdx +167 -0
- package/.docs/raw/workflows/steps.mdx +108 -0
- package/.docs/raw/workflows/suspend-and-resume.mdx +404 -0
- package/.docs/raw/workflows/variables.mdx +313 -0
- package/LICENSE +44 -0
- package/README.md +129 -0
- package/dist/_tsup-dts-rollup.d.ts +149 -0
- package/dist/chunk-QWYMT5LP.js +194 -0
- package/dist/prepare-docs/prepare.d.ts +1 -0
- package/dist/prepare-docs/prepare.js +1 -0
- package/dist/stdio.d.ts +1 -0
- package/dist/stdio.js +518 -0
- package/package.json +60 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Serverless Deployment"
|
|
3
|
+
description: "Build and deploy Mastra applications using platform-specific deployers or standard HTTP servers"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Serverless Deployment
|
|
7
|
+
|
|
8
|
+
This guide covers deploying Mastra to Cloudflare Workers, Vercel, and Netlify using platform-specific deployers
|
|
9
|
+
|
|
10
|
+
For self-hosted Node.js server deployment, see the [Creating A Mastra Server](/docs/deployment/server) guide.
|
|
11
|
+
|
|
12
|
+
## Prerequisites
|
|
13
|
+
|
|
14
|
+
Before you begin, ensure you have:
|
|
15
|
+
|
|
16
|
+
- **Node.js** installed (version 18 or higher is recommended)
|
|
17
|
+
- If using a platform-specific deployer:
|
|
18
|
+
- An account with your chosen platform
|
|
19
|
+
- Required API keys or credentials
|
|
20
|
+
|
|
21
|
+
## Serverless Platform Deployers
|
|
22
|
+
|
|
23
|
+
Platform-specific deployers handle configuration and deployment for:
|
|
24
|
+
- **[Cloudflare Workers](/docs/reference/deployer/cloudflare)**
|
|
25
|
+
- **[Vercel](/docs/reference/deployer/vercel)**
|
|
26
|
+
- **[Netlify](/docs/reference/deployer/netlify)**
|
|
27
|
+
|
|
28
|
+
### Installing Deployers
|
|
29
|
+
|
|
30
|
+
```bash copy
|
|
31
|
+
# For Cloudflare
|
|
32
|
+
npm install @mastra/deployer-cloudflare
|
|
33
|
+
|
|
34
|
+
# For Vercel
|
|
35
|
+
npm install @mastra/deployer-vercel
|
|
36
|
+
|
|
37
|
+
# For Netlify
|
|
38
|
+
npm install @mastra/deployer-netlify
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Configuring Deployers
|
|
42
|
+
|
|
43
|
+
Configure the deployer in your entry file:
|
|
44
|
+
|
|
45
|
+
```typescript copy showLineNumbers
|
|
46
|
+
import { Mastra, createLogger } from '@mastra/core';
|
|
47
|
+
import { CloudflareDeployer } from '@mastra/deployer-cloudflare';
|
|
48
|
+
|
|
49
|
+
export const mastra = new Mastra({
|
|
50
|
+
agents: { /* your agents here */ },
|
|
51
|
+
logger: createLogger({ name: 'MyApp', level: 'debug' }),
|
|
52
|
+
deployer: new CloudflareDeployer({
|
|
53
|
+
scope: 'your-cloudflare-scope',
|
|
54
|
+
projectName: 'your-project-name',
|
|
55
|
+
// See complete configuration options in the reference docs
|
|
56
|
+
}),
|
|
57
|
+
});
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Deployer Configuration
|
|
61
|
+
|
|
62
|
+
Each deployer has specific configuration options. Below are basic examples, but refer to the reference documentation for complete details.
|
|
63
|
+
|
|
64
|
+
#### Cloudflare Deployer
|
|
65
|
+
|
|
66
|
+
```typescript copy showLineNumbers
|
|
67
|
+
new CloudflareDeployer({
|
|
68
|
+
scope: 'your-cloudflare-account-id',
|
|
69
|
+
projectName: 'your-project-name',
|
|
70
|
+
// For complete configuration options, see the reference documentation
|
|
71
|
+
})
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
[View Cloudflare Deployer Reference →](/docs/reference/deployer/cloudflare)
|
|
75
|
+
|
|
76
|
+
#### Vercel Deployer
|
|
77
|
+
|
|
78
|
+
```typescript copy showLineNumbers
|
|
79
|
+
new VercelDeployer({
|
|
80
|
+
teamSlug: 'your-vercel-team-slug',
|
|
81
|
+
projectName: 'your-project-name',
|
|
82
|
+
token: 'your-vercel-token'
|
|
83
|
+
// For complete configuration options, see the reference documentation
|
|
84
|
+
})
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
[View Vercel Deployer Reference →](/docs/reference/deployer/vercel)
|
|
88
|
+
|
|
89
|
+
#### Netlify Deployer
|
|
90
|
+
|
|
91
|
+
```typescript copy showLineNumbers
|
|
92
|
+
new NetlifyDeployer({
|
|
93
|
+
scope: 'your-netlify-team-slug',
|
|
94
|
+
projectName: 'your-project-name',
|
|
95
|
+
token: 'your-netlify-token'
|
|
96
|
+
})
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
[View Netlify Deployer Reference →](/docs/reference/deployer/netlify)
|
|
100
|
+
|
|
101
|
+
## Environment Variables
|
|
102
|
+
|
|
103
|
+
Required variables:
|
|
104
|
+
|
|
105
|
+
1. Platform deployer variables (if using platform deployers):
|
|
106
|
+
- Platform credentials
|
|
107
|
+
2. Agent API keys:
|
|
108
|
+
- `OPENAI_API_KEY`
|
|
109
|
+
- `ANTHROPIC_API_KEY`
|
|
110
|
+
3. Server configuration (for universal deployment):
|
|
111
|
+
- `PORT`: HTTP server port (default: 3000)
|
|
112
|
+
- `HOST`: Server host (default: 0.0.0.0)
|
|
113
|
+
|
|
114
|
+
## Platform Documentation
|
|
115
|
+
|
|
116
|
+
Platform deployment references:
|
|
117
|
+
- [Cloudflare Workers](https://developers.cloudflare.com/workers/)
|
|
118
|
+
- [Vercel](https://vercel.com/docs)
|
|
119
|
+
- [Netlify](https://docs.netlify.com/)
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Creating A Mastra Server"
|
|
3
|
+
description: "Configure and customize the Mastra server with middleware and other options"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Creating A Mastra Server
|
|
7
|
+
|
|
8
|
+
While developing or when you deploy a Mastra application, it runs as an HTTP server that exposes your agents, workflows, and other functionality as API endpoints. This page explains how to configure and customize the server behavior.
|
|
9
|
+
|
|
10
|
+
## Server Architecture
|
|
11
|
+
|
|
12
|
+
Mastra uses [Hono](https://hono.dev) as its underlying HTTP server framework. When you build a Mastra application using `mastra build`, it generates a Hono-based HTTP server in the `.mastra` directory.
|
|
13
|
+
|
|
14
|
+
The server provides:
|
|
15
|
+
- API endpoints for all registered agents
|
|
16
|
+
- API endpoints for all registered workflows
|
|
17
|
+
- Custom api route supports
|
|
18
|
+
- Custom middleware support
|
|
19
|
+
- Configuration of timeout
|
|
20
|
+
- Configuration of port
|
|
21
|
+
|
|
22
|
+
## Server configuration
|
|
23
|
+
|
|
24
|
+
You can configure server `port` and `timeout` in the Mastra instance.
|
|
25
|
+
|
|
26
|
+
```typescript copy showLineNumbers
|
|
27
|
+
import { Mastra } from '@mastra/core';
|
|
28
|
+
|
|
29
|
+
export const mastra = new Mastra({
|
|
30
|
+
server: {
|
|
31
|
+
port: 3000, // Defaults to 4111
|
|
32
|
+
timeout: 10000, // Defaults to 30000 (30s)
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Custom API Routes
|
|
38
|
+
|
|
39
|
+
Mastra provides a list of api routes that are automatically generated based on the registered agents and workflows. You can also define custom api routes the Mastra instance.
|
|
40
|
+
|
|
41
|
+
These routes can live in the same file as the Mastra instance or in a separate file. We recommend keeping them in a separate file to keep the Mastra instance clean.
|
|
42
|
+
|
|
43
|
+
```typescript copy showLineNumbers
|
|
44
|
+
import { Mastra } from '@mastra/core';
|
|
45
|
+
import { registerApiRoute } from "@mastra/core/server"
|
|
46
|
+
|
|
47
|
+
export const mastra = new Mastra({
|
|
48
|
+
server: {
|
|
49
|
+
apiRoutes: [
|
|
50
|
+
registerApiRoute('/my-custom-route', {
|
|
51
|
+
method: 'GET',
|
|
52
|
+
handler: async (c) => {
|
|
53
|
+
// you have access to mastra instance here
|
|
54
|
+
const mastra = c.get('mastra')
|
|
55
|
+
|
|
56
|
+
// you can use the mastra instance to get agents, workflows, etc.
|
|
57
|
+
const agents = await mastra.getAgent('my-agent')
|
|
58
|
+
|
|
59
|
+
return c.json({ message: 'Hello, world!' });
|
|
60
|
+
}
|
|
61
|
+
})
|
|
62
|
+
]
|
|
63
|
+
}
|
|
64
|
+
// Other configuration options
|
|
65
|
+
});
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Custom CORS Config
|
|
69
|
+
|
|
70
|
+
Mastra allows you to configure CORS (Cross-Origin Resource Sharing) settings for your server.
|
|
71
|
+
|
|
72
|
+
```typescript copy showLineNumbers
|
|
73
|
+
import { Mastra } from '@mastra/core';
|
|
74
|
+
|
|
75
|
+
export const mastra = new Mastra({
|
|
76
|
+
server: {
|
|
77
|
+
cors: {
|
|
78
|
+
origin: ['https://example.com'], // Allow specific origins or '*' for all
|
|
79
|
+
allowMethods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
|
|
80
|
+
allowHeaders: ['Content-Type', 'Authorization'],
|
|
81
|
+
credentials: false,
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Middleware
|
|
88
|
+
|
|
89
|
+
Mastra allows you to configure custom middleware functions that will be applied to API routes. This is useful for adding authentication, logging, CORS, or other HTTP-level functionality to your API endpoints.
|
|
90
|
+
|
|
91
|
+
```typescript copy showLineNumbers
|
|
92
|
+
import { Mastra } from '@mastra/core';
|
|
93
|
+
|
|
94
|
+
export const mastra = new Mastra({
|
|
95
|
+
// Other configuration options
|
|
96
|
+
server: {
|
|
97
|
+
middleware: [
|
|
98
|
+
{
|
|
99
|
+
handler: async (c, next) => {
|
|
100
|
+
// Example: Add authentication check
|
|
101
|
+
const authHeader = c.req.header('Authorization');
|
|
102
|
+
if (!authHeader) {
|
|
103
|
+
return new Response('Unauthorized', { status: 401 });
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Continue to the next middleware or route handler
|
|
107
|
+
await next();
|
|
108
|
+
},
|
|
109
|
+
path: '/api/*'
|
|
110
|
+
},
|
|
111
|
+
// add middleware to all routes
|
|
112
|
+
async (c, next) => {
|
|
113
|
+
// Example: Add request logging
|
|
114
|
+
console.log(`${c.req.method} ${c.req.url}`);
|
|
115
|
+
await next();
|
|
116
|
+
},
|
|
117
|
+
]
|
|
118
|
+
});
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
if you want to add a middleware to a single route, you can also specify that in the registerApiRoute using `registerApiRoute`.
|
|
122
|
+
|
|
123
|
+
```typescript copy showLineNumbers
|
|
124
|
+
registerApiRoute('/my-custom-route', {
|
|
125
|
+
method: 'GET',
|
|
126
|
+
middleware: [
|
|
127
|
+
async (c, next) => {
|
|
128
|
+
// Example: Add request logging
|
|
129
|
+
console.log(`${c.req.method} ${c.req.url}`);
|
|
130
|
+
await next();
|
|
131
|
+
},
|
|
132
|
+
],
|
|
133
|
+
handler: async (c) => {
|
|
134
|
+
// you have access to mastra instance here
|
|
135
|
+
const mastra = c.get('mastra')
|
|
136
|
+
|
|
137
|
+
// you can use the mastra instance to get agents, workflows, etc.
|
|
138
|
+
const agents = await mastra.getAgent('my-agent')
|
|
139
|
+
|
|
140
|
+
return c.json({ message: 'Hello, world!' });
|
|
141
|
+
}
|
|
142
|
+
})
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Middleware Behavior
|
|
146
|
+
|
|
147
|
+
Each middleware function:
|
|
148
|
+
- Receives a Hono context object (`c`) and a `next` function
|
|
149
|
+
- Can return a `Response` to short-circuit the request handling
|
|
150
|
+
- Can call `next()` to continue to the next middleware or route handler
|
|
151
|
+
- Can optionally specify a path pattern (defaults to '/api/*')
|
|
152
|
+
|
|
153
|
+
### Common Middleware Use Cases
|
|
154
|
+
|
|
155
|
+
#### Authentication
|
|
156
|
+
|
|
157
|
+
```typescript copy
|
|
158
|
+
{
|
|
159
|
+
handler: async (c, next) => {
|
|
160
|
+
const authHeader = c.req.header('Authorization');
|
|
161
|
+
if (!authHeader || !authHeader.startsWith('Bearer ')) {
|
|
162
|
+
return new Response('Unauthorized', { status: 401 });
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const token = authHeader.split(' ')[1];
|
|
166
|
+
// Validate token here
|
|
167
|
+
|
|
168
|
+
await next();
|
|
169
|
+
},
|
|
170
|
+
path: '/api/*',
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
#### CORS Support
|
|
175
|
+
|
|
176
|
+
```typescript copy
|
|
177
|
+
{
|
|
178
|
+
handler: async (c, next) => {
|
|
179
|
+
// Add CORS headers
|
|
180
|
+
c.header('Access-Control-Allow-Origin', '*');
|
|
181
|
+
c.header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
|
|
182
|
+
c.header('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
|
183
|
+
|
|
184
|
+
// Handle preflight requests
|
|
185
|
+
if (c.req.method === 'OPTIONS') {
|
|
186
|
+
return new Response(null, { status: 204 });
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
await next();
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
#### Request Logging
|
|
195
|
+
|
|
196
|
+
```typescript copy
|
|
197
|
+
{
|
|
198
|
+
handler: async (c, next) => {
|
|
199
|
+
const start = Date.now();
|
|
200
|
+
await next();
|
|
201
|
+
const duration = Date.now() - start;
|
|
202
|
+
console.log(`${c.req.method} ${c.req.url} - ${duration}ms`);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
### Special Mastra Headers
|
|
208
|
+
|
|
209
|
+
When integrating with Mastra Cloud or building custom clients, there are special headers that clients send to identify themselves and enable specific features. Your server middleware can check for these headers to customize behavior:
|
|
210
|
+
|
|
211
|
+
```typescript copy
|
|
212
|
+
{
|
|
213
|
+
handler: async (c, next) => {
|
|
214
|
+
// Check for Mastra-specific headers in incoming requests
|
|
215
|
+
const isFromMastraCloud = c.req.header('x-mastra-cloud') === 'true';
|
|
216
|
+
const clientType = c.req.header('x-mastra-client-type'); // e.g., 'js', 'python'
|
|
217
|
+
const isDevPlayground = c.req.header('x-mastra-dev-playground') === 'true';
|
|
218
|
+
|
|
219
|
+
// Customize behavior based on client information
|
|
220
|
+
if (isFromMastraCloud) {
|
|
221
|
+
// Special handling for Mastra Cloud requests
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
await next();
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
These headers have the following purposes:
|
|
230
|
+
- `x-mastra-cloud`: Indicates that the request is coming from Mastra Cloud
|
|
231
|
+
- `x-mastra-client-type`: Specifies the client SDK type (e.g., 'js', 'python')
|
|
232
|
+
- `x-mastra-dev-playground`: Indicates that the request is from the development playground
|
|
233
|
+
|
|
234
|
+
You can use these headers in your middleware to implement client-specific logic or enable features only for certain environments.
|
|
235
|
+
|
|
236
|
+
## Deployment
|
|
237
|
+
|
|
238
|
+
Since Mastra builds to a standard Node.js server, you can deploy to any platform that runs Node.js applications:
|
|
239
|
+
- Cloud VMs (AWS EC2, DigitalOcean Droplets, GCP Compute Engine)
|
|
240
|
+
- Container platforms (Docker, Kubernetes)
|
|
241
|
+
- Platform as a Service (Heroku, Railway)
|
|
242
|
+
- Self-hosted servers
|
|
243
|
+
|
|
244
|
+
### Building
|
|
245
|
+
|
|
246
|
+
Build the application:
|
|
247
|
+
|
|
248
|
+
```bash copy
|
|
249
|
+
# Build from current directory
|
|
250
|
+
mastra build
|
|
251
|
+
|
|
252
|
+
# Or specify a directory
|
|
253
|
+
mastra build --dir ./my-project
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
The build process:
|
|
257
|
+
1. Locates entry file (`src/mastra/index.ts` or `src/mastra/index.js`)
|
|
258
|
+
2. Creates `.mastra` output directory
|
|
259
|
+
3. Bundles code using Rollup with tree shaking and source maps
|
|
260
|
+
4. Generates [Hono](https://hono.dev) HTTP server
|
|
261
|
+
|
|
262
|
+
See [`mastra build`](/docs/reference/cli/build) for all options.
|
|
263
|
+
|
|
264
|
+
### Running the Server
|
|
265
|
+
|
|
266
|
+
Start the HTTP server:
|
|
267
|
+
|
|
268
|
+
```bash copy
|
|
269
|
+
node .mastra/output/index.mjs
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
## Serverless Deployment
|
|
273
|
+
|
|
274
|
+
Mastra also supports serverless deployment on Cloudflare Workers, Vercel, and Netlify.
|
|
275
|
+
|
|
276
|
+
See our [Serverless Deployment](/docs/deployment/deployment) guide for setup instructions.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Create your own Eval"
|
|
3
|
+
description: "Mastra allows so create your own evals, here is how."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Create your own Eval
|
|
7
|
+
|
|
8
|
+
Creating your own eval is as easy as creating a new function. You simply create a class that extends the `Metric` class and implement the `measure` method.
|
|
9
|
+
|
|
10
|
+
## Basic example
|
|
11
|
+
|
|
12
|
+
For a simple example of creating a custom metric that checks if the output contains certain words, see our [Word Inclusion example](/examples/evals/word-inclusion).
|
|
13
|
+
|
|
14
|
+
## Creating a custom LLM-Judge
|
|
15
|
+
|
|
16
|
+
A custom LLM judge helps evaluate specific aspects of your AI's responses. Think of it like having an expert reviewer for your particular use case:
|
|
17
|
+
|
|
18
|
+
- Medical Q&A → Judge checks for medical accuracy and safety
|
|
19
|
+
- Customer Service → Judge evaluates tone and helpfulness
|
|
20
|
+
- Code Generation → Judge verifies code correctness and style
|
|
21
|
+
|
|
22
|
+
For a practical example, see how we evaluate [Chef Michel's](/docs/guides/chef-michel) recipes for gluten content in our [Gluten Checker example](/examples/evals/custom-eval).
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Overview"
|
|
3
|
+
description: "Understanding how to evaluate and measure AI agent quality using Mastra evals."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Testing your agents with evals
|
|
7
|
+
|
|
8
|
+
While traditional software tests have clear pass/fail conditions, AI outputs are non-deterministic — they can vary with the same input. Evals help bridge this gap by providing quantifiable metrics for measuring agent quality.
|
|
9
|
+
|
|
10
|
+
Evals are automated tests that evaluate Agents outputs using model-graded, rule-based, and statistical methods. Each eval returns a normalized score between 0-1 that can be logged and compared. Evals can be customized with your own prompts and scoring functions.
|
|
11
|
+
|
|
12
|
+
Evals can be run in the cloud, capturing real-time results. But evals can also be part of your CI/CD pipeline, allowing you to test and monitor your agents over time.
|
|
13
|
+
|
|
14
|
+
## Types of Evals
|
|
15
|
+
|
|
16
|
+
There are different kinds of evals, each serving a specific purpose. Here are some common types:
|
|
17
|
+
|
|
18
|
+
1. **Textual Evals**: Evaluate accuracy, reliability, and context understanding of agent responses
|
|
19
|
+
2. **Classification Evals**: Measure accuracy in categorizing data based on predefined categories
|
|
20
|
+
3. **Tool Usage Evals**: Assess how effectively an agent uses external tools or APIs
|
|
21
|
+
4. **Prompt Engineering Evals**: Explore impact of different instructions and input formats
|
|
22
|
+
|
|
23
|
+
## Getting Started
|
|
24
|
+
|
|
25
|
+
Evals need to be added to an agent. Here's an example using the summarization, content similarity, and tone consistency metrics:
|
|
26
|
+
|
|
27
|
+
```typescript copy showLineNumbers filename="src/mastra/agents/index.ts"
|
|
28
|
+
import { Agent } from "@mastra/core/agent";
|
|
29
|
+
import { openai } from "@ai-sdk/openai";
|
|
30
|
+
import { SummarizationMetric } from "@mastra/evals/llm";
|
|
31
|
+
import {
|
|
32
|
+
ContentSimilarityMetric,
|
|
33
|
+
ToneConsistencyMetric,
|
|
34
|
+
} from "@mastra/evals/nlp";
|
|
35
|
+
|
|
36
|
+
const model = openai("gpt-4o");
|
|
37
|
+
|
|
38
|
+
export const myAgent = new Agent({
|
|
39
|
+
name: "ContentWriter",
|
|
40
|
+
instructions: "You are a content writer that creates accurate summaries",
|
|
41
|
+
model,
|
|
42
|
+
evals: {
|
|
43
|
+
summarization: new SummarizationMetric(model),
|
|
44
|
+
contentSimilarity: new ContentSimilarityMetric(),
|
|
45
|
+
tone: new ToneConsistencyMetric(),
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
You can view eval results in the Mastra dashboard when using `mastra dev`.
|
|
51
|
+
|
|
52
|
+
## Beyond Automated Testing
|
|
53
|
+
|
|
54
|
+
While automated evals are valuable, high-performing AI teams often combine them with:
|
|
55
|
+
|
|
56
|
+
1. **A/B Testing**: Compare different versions with real users
|
|
57
|
+
2. **Human Review**: Regular review of production data and traces
|
|
58
|
+
3. **Continuous Monitoring**: Track eval metrics over time to detect regressions
|
|
59
|
+
|
|
60
|
+
## Understanding Eval Results
|
|
61
|
+
|
|
62
|
+
Each eval metric measures a specific aspect of your agent's output. Here's how to interpret and improve your results:
|
|
63
|
+
|
|
64
|
+
### Understanding Scores
|
|
65
|
+
|
|
66
|
+
For any metric:
|
|
67
|
+
|
|
68
|
+
1. Check the metric documentation to understand the scoring process
|
|
69
|
+
2. Look for patterns in when scores change
|
|
70
|
+
3. Compare scores across different inputs and contexts
|
|
71
|
+
4. Track changes over time to spot trends
|
|
72
|
+
|
|
73
|
+
### Improving Results
|
|
74
|
+
|
|
75
|
+
When scores aren't meeting your targets:
|
|
76
|
+
|
|
77
|
+
1. Check your instructions - Are they clear? Try making them more specific
|
|
78
|
+
2. Look at your context - Is it giving the agent what it needs?
|
|
79
|
+
3. Simplify your prompts - Break complex tasks into smaller steps
|
|
80
|
+
4. Add guardrails - Include specific rules for tricky cases
|
|
81
|
+
|
|
82
|
+
### Maintaining Quality
|
|
83
|
+
|
|
84
|
+
Once you're hitting your targets:
|
|
85
|
+
|
|
86
|
+
1. Monitor stability - Do scores remain consistent?
|
|
87
|
+
2. Document what works - Keep notes on successful approaches
|
|
88
|
+
3. Test edge cases - Add examples that cover unusual scenarios
|
|
89
|
+
4. Fine-tune - Look for ways to improve efficiency
|
|
90
|
+
|
|
91
|
+
See [Textual Evals](/docs/evals/textual-evals) for more info on what evals can do.
|
|
92
|
+
|
|
93
|
+
For more info on how to create your own evals, see the [Custom Evals](/docs/evals/custom-eval) guide.
|
|
94
|
+
|
|
95
|
+
For running evals in your CI pipeline, see the [Running in CI](/docs/evals/running-in-ci) guide.
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Running in CI"
|
|
3
|
+
description: "Learn how to run Mastra evals in your CI/CD pipeline to monitor agent quality over time."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Running Evals in CI
|
|
7
|
+
|
|
8
|
+
Running evals in your CI pipeline helps bridge this gap by providing quantifiable metrics for measuring agent quality over time.
|
|
9
|
+
|
|
10
|
+
## Setting Up CI Integration
|
|
11
|
+
|
|
12
|
+
We support any testing framework that supports ESM modules. For example, you can use [Vitest](https://vitest.dev/), [Jest](https://jestjs.io/) or [Mocha](https://mochajs.org/) to run evals in your CI/CD pipeline.
|
|
13
|
+
|
|
14
|
+
```typescript copy showLineNumbers filename="src/mastra/agents/index.test.ts"
|
|
15
|
+
import { describe, it, expect } from 'vitest';
|
|
16
|
+
import { evaluate } from "@mastra/evals";
|
|
17
|
+
import { ToneConsistencyMetric } from "@mastra/evals/nlp";
|
|
18
|
+
import { myAgent } from './index';
|
|
19
|
+
|
|
20
|
+
describe('My Agent', () => {
|
|
21
|
+
it('should validate tone consistency', async () => {
|
|
22
|
+
const metric = new ToneConsistencyMetric();
|
|
23
|
+
const result = await evaluate(myAgent, 'Hello, world!', metric)
|
|
24
|
+
|
|
25
|
+
expect(result.score).toBe(1);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
You will need to configure a testSetup and globalSetup script for your testing framework to capture the eval results. It allows us to show these results in your mastra dashboard.
|
|
31
|
+
|
|
32
|
+
## Framework Configuration
|
|
33
|
+
|
|
34
|
+
### Vitest Setup
|
|
35
|
+
|
|
36
|
+
Add these files to your project to run evals in your CI/CD pipeline:
|
|
37
|
+
|
|
38
|
+
```typescript copy showLineNumbers filename="globalSetup.ts"
|
|
39
|
+
import { globalSetup } from '@mastra/evals';
|
|
40
|
+
|
|
41
|
+
export default function setup() {
|
|
42
|
+
globalSetup()
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
```typescript copy showLineNumbers filename="testSetup.ts"
|
|
47
|
+
import { beforeAll } from 'vitest';
|
|
48
|
+
import { attachListeners } from '@mastra/evals';
|
|
49
|
+
|
|
50
|
+
beforeAll(async () => {
|
|
51
|
+
await attachListeners();
|
|
52
|
+
});
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
```typescript copy showLineNumbers filename="vitest.config.ts"
|
|
56
|
+
import { defineConfig } from 'vitest/config'
|
|
57
|
+
|
|
58
|
+
export default defineConfig({
|
|
59
|
+
test: {
|
|
60
|
+
globalSetup: './globalSetup.ts',
|
|
61
|
+
setupFiles: ['./testSetup.ts'],
|
|
62
|
+
},
|
|
63
|
+
})
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Storage Configuration
|
|
67
|
+
|
|
68
|
+
To store eval results in Mastra Storage and capture results in the Mastra dashboard:
|
|
69
|
+
|
|
70
|
+
```typescript copy showLineNumbers filename="testSetup.ts"
|
|
71
|
+
import { beforeAll } from 'vitest';
|
|
72
|
+
import { attachListeners } from '@mastra/evals';
|
|
73
|
+
import { mastra } from './your-mastra-setup';
|
|
74
|
+
|
|
75
|
+
beforeAll(async () => {
|
|
76
|
+
// Store evals in Mastra Storage (requires storage to be enabled)
|
|
77
|
+
await attachListeners(mastra);
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
With file storage, evals persist and can be queried later. With memory storage, evals are isolated to the test process.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Textual Evals"
|
|
3
|
+
description: "Understand how Mastra uses LLM-as-judge methodology to evaluate text quality."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Textual Evals
|
|
7
|
+
|
|
8
|
+
Textual evals use an LLM-as-judge methodology to evaluate agent outputs. This approach leverages language models to assess various aspects of text quality, similar to how a teaching assistant might grade assignments using a rubric.
|
|
9
|
+
|
|
10
|
+
Each eval focuses on specific quality aspects and returns a score between 0 and 1, providing quantifiable metrics for non-deterministic AI outputs.
|
|
11
|
+
|
|
12
|
+
Mastra provides several eval metrics for assessing Agent outputs. Mastra is not limited to these metrics, and you can also [define your own evals](/docs/evals/custom-eval).
|
|
13
|
+
|
|
14
|
+
## Why Use Textual Evals?
|
|
15
|
+
|
|
16
|
+
Textual evals help ensure your agent:
|
|
17
|
+
|
|
18
|
+
- Produces accurate and reliable responses
|
|
19
|
+
- Uses context effectively
|
|
20
|
+
- Follows output requirements
|
|
21
|
+
- Maintains consistent quality over time
|
|
22
|
+
|
|
23
|
+
## Available Metrics
|
|
24
|
+
|
|
25
|
+
### Accuracy and Reliability
|
|
26
|
+
|
|
27
|
+
These metrics evaluate how correct, truthful, and complete your agent's answers are:
|
|
28
|
+
|
|
29
|
+
- [`hallucination`](/docs/reference/evals/hallucination): Detects facts or claims not present in provided context
|
|
30
|
+
- [`faithfulness`](/docs/reference/evals/faithfulness): Measures how accurately responses represent provided context
|
|
31
|
+
- [`content-similarity`](/docs/reference/evals/content-similarity): Evaluates consistency of information across different phrasings
|
|
32
|
+
- [`completeness`](/docs/reference/evals/completeness): Checks if responses include all necessary information
|
|
33
|
+
- [`answer-relevancy`](/docs/reference/evals/answer-relevancy): Assesses how well responses address the original query
|
|
34
|
+
- [`textual-difference`](/docs/reference/evals/textual-difference): Measures textual differences between strings
|
|
35
|
+
|
|
36
|
+
### Understanding Context
|
|
37
|
+
|
|
38
|
+
These metrics evaluate how well your agent uses provided context:
|
|
39
|
+
|
|
40
|
+
- [`context-position`](/docs/reference/evals/context-position): Analyzes where context appears in responses
|
|
41
|
+
- [`context-precision`](/docs/reference/evals/context-precision): Evaluates whether context chunks are grouped logically
|
|
42
|
+
- [`context-relevancy`](/docs/reference/evals/context-relevancy): Measures use of appropriate context pieces
|
|
43
|
+
- [`contextual-recall`](/docs/reference/evals/contextual-recall): Assesses completeness of context usage
|
|
44
|
+
|
|
45
|
+
### Output Quality
|
|
46
|
+
|
|
47
|
+
These metrics evaluate adherence to format and style requirements:
|
|
48
|
+
|
|
49
|
+
- [`tone`](/docs/reference/evals/tone-consistency): Measures consistency in formality, complexity, and style
|
|
50
|
+
- [`toxicity`](/docs/reference/evals/toxicity): Detects harmful or inappropriate content
|
|
51
|
+
- [`bias`](/docs/reference/evals/bias): Detects potential biases in the output
|
|
52
|
+
- [`prompt-alignment`](/docs/reference/evals/prompt-alignment): Checks adherence to explicit instructions like length restrictions, formatting requirements, or other constraints
|
|
53
|
+
- [`summarization`](/docs/reference/evals/summarization): Evaluates information retention and conciseness
|
|
54
|
+
- [`keyword-coverage`](/docs/reference/evals/keyword-coverage): Assesses technical terminology usage
|