@mastra/mcp-docs-server 1.0.0-beta.4 → 1.0.0-beta.5

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.
Files changed (213) hide show
  1. package/.docs/organized/changelogs/%40internal%2Fstorage-test-utils.md +201 -1
  2. package/.docs/organized/changelogs/%40mastra%2Fagent-builder.md +201 -1
  3. package/.docs/organized/changelogs/%40mastra%2Fai-sdk.md +201 -1
  4. package/.docs/organized/changelogs/%40mastra%2Fastra.md +201 -1
  5. package/.docs/organized/changelogs/%40mastra%2Fchroma.md +201 -1
  6. package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +201 -1
  7. package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +201 -1
  8. package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +201 -1
  9. package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +201 -1
  10. package/.docs/organized/changelogs/%40mastra%2Fcore.md +326 -126
  11. package/.docs/organized/changelogs/%40mastra%2Fcouchbase.md +201 -1
  12. package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +201 -1
  13. package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +201 -1
  14. package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +201 -1
  15. package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +201 -1
  16. package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +201 -1
  17. package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +201 -1
  18. package/.docs/organized/changelogs/%40mastra%2Fevals.md +201 -1
  19. package/.docs/organized/changelogs/%40mastra%2Flance.md +201 -1
  20. package/.docs/organized/changelogs/%40mastra%2Flibsql.md +201 -1
  21. package/.docs/organized/changelogs/%40mastra%2Floggers.md +201 -1
  22. package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +201 -1
  23. package/.docs/organized/changelogs/%40mastra%2Fmcp-registry-registry.md +201 -1
  24. package/.docs/organized/changelogs/%40mastra%2Fmcp.md +201 -1
  25. package/.docs/organized/changelogs/%40mastra%2Fmemory.md +201 -1
  26. package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +201 -1
  27. package/.docs/organized/changelogs/%40mastra%2Fmssql.md +201 -1
  28. package/.docs/organized/changelogs/%40mastra%2Fopensearch.md +201 -1
  29. package/.docs/organized/changelogs/%40mastra%2Fpg.md +201 -1
  30. package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +201 -1
  31. package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +201 -1
  32. package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +201 -1
  33. package/.docs/organized/changelogs/%40mastra%2Frag.md +201 -1
  34. package/.docs/organized/changelogs/%40mastra%2Freact.md +80 -1
  35. package/.docs/organized/changelogs/%40mastra%2Fs3vectors.md +9 -0
  36. package/.docs/organized/changelogs/%40mastra%2Fschema-compat.md +36 -0
  37. package/.docs/organized/changelogs/%40mastra%2Fserver.md +201 -1
  38. package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +201 -1
  39. package/.docs/organized/changelogs/%40mastra%2Fupstash.md +201 -1
  40. package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +201 -1
  41. package/.docs/organized/changelogs/%40mastra%2Fvoice-azure.md +201 -1
  42. package/.docs/organized/changelogs/%40mastra%2Fvoice-cloudflare.md +201 -1
  43. package/.docs/organized/changelogs/%40mastra%2Fvoice-deepgram.md +201 -1
  44. package/.docs/organized/changelogs/%40mastra%2Fvoice-elevenlabs.md +201 -1
  45. package/.docs/organized/changelogs/%40mastra%2Fvoice-gladia.md +92 -1
  46. package/.docs/organized/changelogs/%40mastra%2Fvoice-google-gemini-live.md +67 -1
  47. package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +201 -1
  48. package/.docs/organized/changelogs/%40mastra%2Fvoice-murf.md +201 -1
  49. package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +201 -1
  50. package/.docs/organized/changelogs/%40mastra%2Fvoice-openai.md +201 -1
  51. package/.docs/organized/changelogs/%40mastra%2Fvoice-playai.md +201 -1
  52. package/.docs/organized/changelogs/%40mastra%2Fvoice-sarvam.md +201 -1
  53. package/.docs/organized/changelogs/%40mastra%2Fvoice-speechify.md +201 -1
  54. package/.docs/organized/changelogs/create-mastra.md +201 -1
  55. package/.docs/organized/changelogs/mastra.md +201 -1
  56. package/.docs/organized/code-examples/memory-with-processors.md +1 -1
  57. package/.docs/organized/code-examples/quick-start.md +1 -1
  58. package/.docs/raw/agents/adding-voice.mdx +7 -10
  59. package/.docs/raw/agents/guardrails.mdx +19 -20
  60. package/.docs/raw/agents/human-in-the-loop-with-tools.mdx +6 -5
  61. package/.docs/raw/agents/networks.mdx +1 -2
  62. package/.docs/raw/agents/overview.mdx +5 -5
  63. package/.docs/raw/agents/using-tools.mdx +4 -5
  64. package/.docs/raw/course/01-first-agent/05-running-playground.md +5 -5
  65. package/.docs/raw/course/01-first-agent/09-testing-your-agent.md +3 -3
  66. package/.docs/raw/course/01-first-agent/13-testing-your-tool.md +3 -3
  67. package/.docs/raw/course/01-first-agent/17-testing-memory.md +2 -2
  68. package/.docs/raw/course/04-workflows/07-using-playground.md +1 -1
  69. package/.docs/raw/deployment/building-mastra.mdx +1 -1
  70. package/.docs/raw/deployment/cloud-providers/amazon-ec2.mdx +1 -1
  71. package/.docs/raw/deployment/cloud-providers/aws-lambda.mdx +1 -1
  72. package/.docs/raw/deployment/cloud-providers/azure-app-services.mdx +1 -1
  73. package/.docs/raw/deployment/cloud-providers/digital-ocean.mdx +1 -1
  74. package/.docs/raw/deployment/cloud-providers/index.mdx +1 -1
  75. package/.docs/raw/deployment/mastra-cloud/observability.mdx +19 -17
  76. package/.docs/raw/deployment/mastra-cloud/setting-up.mdx +1 -1
  77. package/.docs/raw/deployment/overview.mdx +2 -2
  78. package/.docs/raw/deployment/web-framework.mdx +5 -5
  79. package/.docs/raw/evals/custom-scorers.mdx +3 -5
  80. package/.docs/raw/evals/overview.mdx +2 -3
  81. package/.docs/raw/getting-started/project-structure.mdx +1 -1
  82. package/.docs/raw/getting-started/start.mdx +72 -0
  83. package/.docs/raw/getting-started/studio.mdx +1 -1
  84. package/.docs/raw/{frameworks/agentic-uis/ai-sdk.mdx → guides/build-your-ui/ai-sdk-ui.mdx} +105 -11
  85. package/.docs/raw/{frameworks/web-frameworks → guides/getting-started}/astro.mdx +23 -25
  86. package/.docs/raw/{frameworks/servers → guides/getting-started}/express.mdx +3 -4
  87. package/.docs/raw/guides/{guide → getting-started}/manual-install.mdx +1 -1
  88. package/.docs/raw/guides/{quickstarts/nextjs.mdx → getting-started/next-js.mdx} +11 -11
  89. package/.docs/raw/guides/{quickstarts/standalone-server.mdx → getting-started/quickstart.mdx} +7 -7
  90. package/.docs/raw/{frameworks/web-frameworks → guides/getting-started}/sveltekit.mdx +23 -25
  91. package/.docs/raw/{frameworks/web-frameworks → guides/getting-started}/vite-react.mdx +7 -7
  92. package/.docs/raw/guides/guide/ai-recruiter.mdx +2 -3
  93. package/.docs/raw/guides/guide/chef-michel.mdx +2 -3
  94. package/.docs/raw/guides/guide/notes-mcp-server.mdx +2 -2
  95. package/.docs/raw/guides/guide/research-assistant.mdx +7 -8
  96. package/.docs/raw/guides/guide/stock-agent.mdx +4 -6
  97. package/.docs/raw/guides/guide/web-search.mdx +12 -10
  98. package/.docs/raw/guides/migrations/agentnetwork.mdx +4 -4
  99. package/.docs/raw/guides/migrations/ai-sdk-v4-to-v5.mdx +1 -1
  100. package/.docs/raw/guides/migrations/upgrade-to-v1/agent.mdx +29 -0
  101. package/.docs/raw/guides/migrations/upgrade-to-v1/tools.mdx +5 -0
  102. package/.docs/raw/guides/migrations/upgrade-to-v1/workflows.mdx +22 -0
  103. package/.docs/raw/guides/migrations/vnext-to-standard-apis.mdx +2 -2
  104. package/.docs/raw/index.mdx +2 -2
  105. package/.docs/raw/mcp/overview.mdx +3 -5
  106. package/.docs/raw/memory/memory-processors.mdx +1 -2
  107. package/.docs/raw/memory/semantic-recall.mdx +7 -7
  108. package/.docs/raw/memory/storage/memory-with-libsql.mdx +2 -4
  109. package/.docs/raw/memory/storage/memory-with-mongodb.mdx +2 -4
  110. package/.docs/raw/memory/storage/memory-with-pg.mdx +2 -4
  111. package/.docs/raw/memory/storage/memory-with-upstash.mdx +2 -4
  112. package/.docs/raw/memory/threads-and-resources.mdx +3 -3
  113. package/.docs/raw/memory/working-memory.mdx +4 -5
  114. package/.docs/raw/{logging.mdx → observability/logging.mdx} +1 -1
  115. package/.docs/raw/observability/overview.mdx +2 -2
  116. package/.docs/raw/observability/tracing/exporters/otel.mdx +21 -2
  117. package/.docs/raw/observability/tracing/exporters/posthog.mdx +107 -0
  118. package/.docs/raw/observability/tracing/overview.mdx +3 -2
  119. package/.docs/raw/rag/chunking-and-embedding.mdx +16 -17
  120. package/.docs/raw/rag/overview.mdx +3 -2
  121. package/.docs/raw/rag/retrieval.mdx +20 -32
  122. package/.docs/raw/reference/agents/agent.mdx +7 -10
  123. package/.docs/raw/reference/agents/generateLegacy.mdx +2 -2
  124. package/.docs/raw/reference/agents/getLLM.mdx +1 -1
  125. package/.docs/raw/reference/agents/network.mdx +2 -3
  126. package/.docs/raw/reference/cli/mastra.mdx +2 -1
  127. package/.docs/raw/reference/client-js/agents.mdx +3 -3
  128. package/.docs/raw/reference/core/getLogger.mdx +1 -1
  129. package/.docs/raw/reference/core/listLogs.mdx +1 -1
  130. package/.docs/raw/reference/core/listLogsByRunId.mdx +1 -1
  131. package/.docs/raw/reference/core/mastra-model-gateway.mdx +5 -19
  132. package/.docs/raw/reference/core/setLogger.mdx +1 -1
  133. package/.docs/raw/reference/core/setTelemetry.mdx +1 -1
  134. package/.docs/raw/reference/evals/answer-relevancy.mdx +28 -98
  135. package/.docs/raw/reference/evals/answer-similarity.mdx +12 -258
  136. package/.docs/raw/reference/evals/bias.mdx +29 -87
  137. package/.docs/raw/reference/evals/completeness.mdx +31 -90
  138. package/.docs/raw/reference/evals/content-similarity.mdx +28 -88
  139. package/.docs/raw/reference/evals/context-precision.mdx +28 -130
  140. package/.docs/raw/reference/evals/context-relevance.mdx +11 -11
  141. package/.docs/raw/reference/evals/faithfulness.mdx +28 -101
  142. package/.docs/raw/reference/evals/hallucination.mdx +28 -103
  143. package/.docs/raw/reference/evals/keyword-coverage.mdx +28 -107
  144. package/.docs/raw/reference/evals/noise-sensitivity.mdx +11 -11
  145. package/.docs/raw/reference/evals/prompt-alignment.mdx +15 -15
  146. package/.docs/raw/reference/evals/textual-difference.mdx +27 -100
  147. package/.docs/raw/reference/evals/tone-consistency.mdx +25 -98
  148. package/.docs/raw/reference/evals/tool-call-accuracy.mdx +7 -7
  149. package/.docs/raw/reference/evals/toxicity.mdx +29 -92
  150. package/.docs/raw/reference/memory/memory-class.mdx +5 -7
  151. package/.docs/raw/reference/observability/tracing/exporters/posthog.mdx +132 -0
  152. package/.docs/raw/reference/processors/batch-parts-processor.mdx +1 -1
  153. package/.docs/raw/reference/processors/language-detector.mdx +1 -1
  154. package/.docs/raw/reference/processors/moderation-processor.mdx +2 -2
  155. package/.docs/raw/reference/processors/pii-detector.mdx +2 -2
  156. package/.docs/raw/reference/processors/prompt-injection-detector.mdx +1 -1
  157. package/.docs/raw/reference/processors/system-prompt-scrubber.mdx +2 -3
  158. package/.docs/raw/reference/processors/token-limiter-processor.mdx +2 -2
  159. package/.docs/raw/reference/processors/unicode-normalizer.mdx +1 -1
  160. package/.docs/raw/reference/rag/embeddings.mdx +5 -5
  161. package/.docs/raw/reference/rag/rerank.mdx +1 -2
  162. package/.docs/raw/reference/rag/rerankWithScorer.mdx +0 -1
  163. package/.docs/raw/reference/streaming/agents/stream.mdx +8 -1
  164. package/.docs/raw/reference/templates/overview.mdx +1 -4
  165. package/.docs/raw/reference/tools/client.mdx +1 -2
  166. package/.docs/raw/reference/tools/create-tool.mdx +132 -0
  167. package/.docs/raw/reference/tools/graph-rag-tool.mdx +5 -5
  168. package/.docs/raw/reference/tools/mcp-client.mdx +2 -4
  169. package/.docs/raw/reference/tools/mcp-server.mdx +1 -2
  170. package/.docs/raw/reference/tools/vector-query-tool.mdx +14 -15
  171. package/.docs/raw/reference/vectors/chroma.mdx +81 -1
  172. package/.docs/raw/reference/vectors/couchbase.mdx +24 -17
  173. package/.docs/raw/reference/vectors/lance.mdx +38 -22
  174. package/.docs/raw/reference/vectors/libsql.mdx +35 -2
  175. package/.docs/raw/reference/vectors/mongodb.mdx +35 -2
  176. package/.docs/raw/reference/vectors/opensearch.mdx +37 -16
  177. package/.docs/raw/reference/vectors/pg.mdx +43 -36
  178. package/.docs/raw/reference/vectors/pinecone.mdx +48 -1
  179. package/.docs/raw/reference/vectors/qdrant.mdx +36 -1
  180. package/.docs/raw/reference/vectors/turbopuffer.mdx +74 -0
  181. package/.docs/raw/reference/voice/openai-realtime.mdx +2 -2
  182. package/.docs/raw/reference/voice/voice.addInstructions.mdx +2 -3
  183. package/.docs/raw/reference/voice/voice.addTools.mdx +1 -1
  184. package/.docs/raw/reference/voice/voice.answer.mdx +1 -1
  185. package/.docs/raw/reference/voice/voice.close.mdx +1 -1
  186. package/.docs/raw/reference/voice/voice.connect.mdx +1 -1
  187. package/.docs/raw/reference/voice/voice.off.mdx +1 -1
  188. package/.docs/raw/reference/voice/voice.on.mdx +1 -1
  189. package/.docs/raw/reference/voice/voice.send.mdx +1 -1
  190. package/.docs/raw/reference/voice/voice.updateConfig.mdx +1 -1
  191. package/.docs/raw/server-db/mastra-client.mdx +1 -2
  192. package/.docs/raw/streaming/overview.mdx +20 -9
  193. package/.docs/raw/streaming/tool-streaming.mdx +47 -4
  194. package/.docs/raw/tools-mcp/advanced-usage.mdx +1 -2
  195. package/.docs/raw/tools-mcp/mcp-overview.mdx +3 -5
  196. package/.docs/raw/voice/overview.mdx +21 -41
  197. package/.docs/raw/voice/speech-to-speech.mdx +4 -4
  198. package/.docs/raw/voice/speech-to-text.mdx +1 -2
  199. package/.docs/raw/voice/text-to-speech.mdx +1 -2
  200. package/.docs/raw/workflows/control-flow.mdx +180 -0
  201. package/CHANGELOG.md +10 -0
  202. package/dist/{chunk-5NJC7NRO.js → chunk-4CM2BQNP.js} +24 -4
  203. package/dist/prepare-docs/package-changes.d.ts.map +1 -1
  204. package/dist/prepare-docs/prepare.js +1 -1
  205. package/dist/stdio.js +1 -1
  206. package/package.json +7 -7
  207. package/.docs/raw/frameworks/agentic-uis/cedar-os.mdx +0 -102
  208. package/.docs/raw/frameworks/agentic-uis/openrouter.mdx +0 -179
  209. package/.docs/raw/frameworks/web-frameworks/next-js.mdx +0 -379
  210. package/.docs/raw/getting-started/quickstart.mdx +0 -27
  211. package/.docs/raw/getting-started/templates.mdx +0 -73
  212. /package/.docs/raw/{frameworks/agentic-uis → guides/build-your-ui}/assistant-ui.mdx +0 -0
  213. /package/.docs/raw/{frameworks/agentic-uis → guides/build-your-ui}/copilotkit.mdx +0 -0
@@ -78,106 +78,46 @@ The scorer evaluates textual similarity through character-level matching and con
78
78
 
79
79
  Final score: `similarity_value * scale`
80
80
 
81
- ## Examples
81
+ ## Example
82
82
 
83
- ### High similarity example
83
+ Evaluate textual similarity between expected and actual agent outputs:
84
84
 
85
- In this example, the response closely resembles the query in both structure and meaning. Minor differences in tense and phrasing do not significantly affect the overall similarity.
86
-
87
- ```typescript title="src/example-high-similarity.ts" showLineNumbers copy
85
+ ```typescript title="src/example-content-similarity.ts" showLineNumbers copy
86
+ import { runEvals } from "@mastra/core/evals";
88
87
  import { createContentSimilarityScorer } from "@mastra/evals/scorers/prebuilt";
88
+ import { myAgent } from "./agent";
89
89
 
90
90
  const scorer = createContentSimilarityScorer();
91
91
 
92
- const query = "The quick brown fox jumps over the lazy dog.";
93
- const response = "A quick brown fox jumped over a lazy dog.";
94
-
95
- const result = await scorer.run({
96
- input: [{ role: "user", content: query }],
97
- output: { text: response },
98
- });
99
-
100
- console.log(result);
101
- ```
102
-
103
- #### High similarity output
104
-
105
- The output receives a high score because the response preserves the intent and content of the query with only subtle wording changes.
106
-
107
- ```typescript
108
- {
109
- score: 0.7761194029850746,
110
- analyzeStepResult: {
111
- similarity: 0.7761194029850746
92
+ const result = await runEvals({
93
+ data: [
94
+ {
95
+ input: "Summarize the benefits of TypeScript",
96
+ groundTruth:
97
+ "TypeScript provides static typing, better tooling support, and improved code maintainability.",
98
+ },
99
+ {
100
+ input: "What is machine learning?",
101
+ groundTruth:
102
+ "Machine learning is a subset of AI that enables systems to learn from data without explicit programming.",
103
+ },
104
+ ],
105
+ scorers: [scorer],
106
+ target: myAgent,
107
+ onItemComplete: ({ scorerResults }) => {
108
+ console.log({
109
+ score: scorerResults[scorer.id].score,
110
+ groundTruth: scorerResults[scorer.id].groundTruth,
111
+ });
112
112
  },
113
- }
114
- ```
115
-
116
- ### Moderate similarity example
117
-
118
- In this example, the response shares some conceptual overlap with the query but diverges in structure and wording. Key elements remain present, but the phrasing introduces moderate variation.
119
-
120
- ```typescript title="src/example-moderate-similarity.ts" showLineNumbers copy
121
- import { createContentSimilarityScorer } from "@mastra/evals/scorers/prebuilt";
122
-
123
- const scorer = createContentSimilarityScorer();
124
-
125
- const query = "A brown fox quickly leaps across a sleeping dog.";
126
- const response = "The quick brown fox jumps over the lazy dog.";
127
-
128
- const result = await scorer.run({
129
- input: [{ role: "user", content: query }],
130
- output: { text: response },
131
113
  });
132
114
 
133
- console.log(result);
134
- ```
135
-
136
- #### Moderate similarity output
137
-
138
- The output receives a mid-range score because the response captures the general idea of the query, though it differs enough in wording to reduce overall similarity.
139
-
140
- ```typescript
141
- {
142
- score: 0.40540540540540543,
143
- analyzeStepResult: {
144
- similarity: 0.40540540540540543
145
- }
146
- }
115
+ console.log(result.scores);
147
116
  ```
148
117
 
149
- ### Low similarity example
150
-
151
- In this example, the response and query are unrelated in meaning, despite having a similar grammatical structure. There is little to no shared content overlap.
152
-
153
- ```typescript title="src/example-low-similarity.ts" showLineNumbers copy
154
- import { createContentSimilarityScorer } from "@mastra/evals/scorers/prebuilt";
155
-
156
- const scorer = createContentSimilarityScorer();
118
+ For more details on `runEvals`, see the [runEvals reference](/reference/v1/evals/run-evals).
157
119
 
158
- const query = "The cat sleeps on the windowsill.";
159
- const response = "The quick brown fox jumps over the lazy dog.";
160
-
161
- const result = await scorer.run({
162
- input: [{ role: "user", content: query }],
163
- output: { text: response },
164
- });
165
-
166
- console.log(result);
167
- ```
168
-
169
- #### Low similarity output
170
-
171
- The output receives a low score because the response does not align with the content or intent of the query.
172
-
173
- ```typescript
174
- {
175
- score: 0.25806451612903225,
176
- analyzeStepResult: {
177
- similarity: 0.25806451612903225
178
- },
179
- }
180
- ```
120
+ To add this scorer to an agent, see the [Scorers overview](/docs/v1/evals/overview#adding-scorers-to-agents) guide.
181
121
 
182
122
  ### Score interpretation
183
123
 
@@ -152,7 +152,7 @@ MAP = (1.0 + 0.67) / 2 = 0.835 ≈ **0.83**
152
152
 
153
153
  ```typescript
154
154
  const scorer = createContextPrecisionScorer({
155
- model: "openai/gpt-4o-mini",
155
+ model: "openai/gpt-5.1",
156
156
  options: {
157
157
  contextExtractor: (input, output) => {
158
158
  // Extract context dynamically based on the query
@@ -171,7 +171,7 @@ const scorer = createContextPrecisionScorer({
171
171
 
172
172
  ```typescript
173
173
  const scorer = createContextPrecisionScorer({
174
- model: "openai/gpt-4o-mini",
174
+ model: "openai/gpt-5.1",
175
175
  options: {
176
176
  context: [
177
177
  // Simulate retrieved documents from vector database
@@ -186,152 +186,50 @@ const scorer = createContextPrecisionScorer({
186
186
  });
187
187
  ```
188
188
 
189
- ## Examples
189
+ ## Example
190
190
 
191
- ### High precision example
191
+ Evaluate RAG system context retrieval precision for different queries:
192
192
 
193
- This example shows perfect context precision where all relevant context appears early:
194
-
195
- ```typescript
196
- import { createContextPrecisionScorer } from "@mastra/evals";
193
+ ```typescript title="src/example-context-precision.ts" showLineNumbers copy
194
+ import { runEvals } from "@mastra/core/evals";
195
+ import { createContextPrecisionScorer } from "@mastra/evals/scorers/prebuilt";
196
+ import { myAgent } from "./agent";
197
197
 
198
198
  const scorer = createContextPrecisionScorer({
199
- model: "openai/gpt-4o-mini",
199
+ model: "openai/gpt-4o",
200
200
  options: {
201
- context: [
202
- "Photosynthesis is the process by which plants convert sunlight, carbon dioxide, and water into glucose and oxygen.",
203
- "The process occurs in the chloroplasts of plant cells, specifically in the thylakoids.",
204
- "Light-dependent reactions happen in the thylakoid membranes, while the Calvin cycle occurs in the stroma.",
205
- ],
206
- scale: 1,
201
+ contextExtractor: (input, output) => {
202
+ // Extract context from agent's retrieved documents
203
+ return output.metadata?.retrievedContext || [];
204
+ },
207
205
  },
208
206
  });
209
207
 
210
- const result = await scorer.run({
211
- input: {
212
- inputMessages: [
213
- {
214
- id: "1",
215
- role: "user",
216
- content: "How does photosynthesis work in plants?",
217
- },
218
- ],
219
- },
220
- output: [
208
+ const result = await runEvals({
209
+ data: [
221
210
  {
222
- id: "2",
223
- role: "assistant",
224
- content:
225
- "Photosynthesis is the process where plants convert sunlight, CO2, and water into glucose and oxygen using chloroplasts.",
211
+ input: "How does photosynthesis work in plants?",
226
212
  },
227
- ],
228
- });
229
-
230
- console.log(result);
231
- // Output:
232
- // {
233
- // score: 1.0,
234
- // reason: "The score is 1.0 because all context pieces are highly relevant to explaining photosynthesis and are optimally ordered to support the expected output."
235
- // }
236
- ```
237
-
238
- ### Mixed precision example
239
-
240
- This example shows moderate precision with both relevant and irrelevant context:
241
-
242
- ```typescript
243
- import { createContextPrecisionScorer } from "@mastra/evals";
244
-
245
- const scorer = createContextPrecisionScorer({
246
- model: "openai/gpt-4o-mini",
247
- options: {
248
- context: [
249
- "Regular exercise improves cardiovascular health by strengthening the heart muscle.",
250
- "A balanced diet should include fruits, vegetables, and whole grains.",
251
- "Physical activity releases endorphins which improve mood and reduce stress.",
252
- "The average person should drink 8 glasses of water per day.",
253
- "Exercise also helps maintain healthy body weight and muscle mass.",
254
- ],
255
- scale: 1,
256
- },
257
- });
258
-
259
- const result = await scorer.run({
260
- input: {
261
- inputMessages: [
262
- {
263
- id: "1",
264
- role: "user",
265
- content: "What are the mental and physical benefits of exercise?",
266
- },
267
- ],
268
- },
269
- output: [
270
213
  {
271
- id: "2",
272
- role: "assistant",
273
- content:
274
- "Exercise provides cardiovascular benefits, improves mood through endorphin release, and helps maintain healthy body composition.",
214
+ input: "What are the mental and physical benefits of exercise?",
275
215
  },
276
216
  ],
217
+ scorers: [scorer],
218
+ target: myAgent,
219
+ onItemComplete: ({ scorerResults }) => {
220
+ console.log({
221
+ score: scorerResults[scorer.id].score,
222
+ reason: scorerResults[scorer.id].reason,
223
+ });
224
+ },
277
225
  });
278
226
 
279
- console.log(result);
280
- // Output:
281
- // {
282
- // score: 0.72,
283
- // reason: "The score is 0.72 because contexts 1, 3, and 5 are relevant to exercise benefits, but irrelevant contexts about diet and hydration reduce the precision score."
284
- // }
227
+ console.log(result.scores);
285
228
  ```
286
229
 
287
- ### Low precision example
288
-
289
- This example shows poor context precision with mostly irrelevant context:
290
-
291
- ```typescript
292
- import { createContextPrecisionScorer } from "@mastra/evals";
293
-
294
- const scorer = createContextPrecisionScorer({
295
- model: "openai/gpt-4o-mini",
296
- options: {
297
- context: [
298
- "The weather forecast shows sunny skies this weekend.",
299
- "Coffee is one of the world's most popular beverages.",
300
- "Machine learning requires large amounts of training data.",
301
- "Cats typically sleep 12-16 hours per day.",
302
- "The capital of France is Paris.",
303
- ],
304
- scale: 1,
305
- },
306
- });
307
-
308
- const result = await scorer.run({
309
- input: {
310
- inputMessages: [
311
- {
312
- id: "1",
313
- role: "user",
314
- content: "How does photosynthesis work?",
315
- },
316
- ],
317
- },
318
- output: [
319
- {
320
- id: "2",
321
- role: "assistant",
322
- content:
323
- "Photosynthesis is the process by which plants convert sunlight into energy using chlorophyll.",
324
- },
325
- ],
326
- });
230
+ For more details on `runEvals`, see the [runEvals reference](/reference/v1/evals/run-evals).
327
231
 
328
- console.log(result);
329
- // Output:
330
- // {
331
- // score: 0.0,
332
- // reason: "The score is 0.0 because none of the retrieved context pieces are relevant to explaining photosynthesis."
333
- // }
334
- ```
232
+ To add this scorer to an agent, see the [Scorers overview](/docs/v1/evals/overview#adding-scorers-to-agents) guide.
335
233
 
336
234
  ## Comparison with Context Relevance
337
235
 
@@ -198,7 +198,7 @@ import { createContextRelevanceScorerLLM } from "@mastra/evals";
198
198
 
199
199
  // Stricter penalty configuration
200
200
  const strictScorer = createContextRelevanceScorerLLM({
201
- model: "openai/gpt-4o-mini",
201
+ model: "openai/gpt-5.1",
202
202
  options: {
203
203
  context: [
204
204
  "Einstein won the Nobel Prize for photoelectric effect",
@@ -216,7 +216,7 @@ const strictScorer = createContextRelevanceScorerLLM({
216
216
 
217
217
  // Lenient penalty configuration
218
218
  const lenientScorer = createContextRelevanceScorerLLM({
219
- model: "openai/gpt-4o-mini",
219
+ model: "openai/gpt-5.1",
220
220
  options: {
221
221
  context: [
222
222
  "Einstein won the Nobel Prize for photoelectric effect",
@@ -263,7 +263,7 @@ console.log("Lenient penalties:", lenientResult.score); // Higher score, less pe
263
263
 
264
264
  ```typescript
265
265
  const scorer = createContextRelevanceScorerLLM({
266
- model: "openai/gpt-4o",
266
+ model: "openai/gpt-5.1",
267
267
  options: {
268
268
  contextExtractor: (input, output) => {
269
269
  // Extract context based on the query
@@ -287,7 +287,7 @@ const scorer = createContextRelevanceScorerLLM({
287
287
 
288
288
  ```typescript
289
289
  const scorer = createContextRelevanceScorerLLM({
290
- model: "openai/gpt-4o-mini",
290
+ model: "openai/gpt-5.1",
291
291
  options: {
292
292
  context: ["Relevant information...", "Supporting details..."],
293
293
  scale: 100, // Scale scores from 0-100 instead of 0-1
@@ -301,7 +301,7 @@ const scorer = createContextRelevanceScorerLLM({
301
301
 
302
302
  ```typescript
303
303
  const scorer = createContextRelevanceScorerLLM({
304
- model: "openai/gpt-4o-mini",
304
+ model: "openai/gpt-5.1",
305
305
  options: {
306
306
  contextExtractor: (input, output) => {
307
307
  const query = input?.inputMessages?.[0]?.content || "";
@@ -328,7 +328,7 @@ This example shows excellent context relevance where all context directly suppor
328
328
  import { createContextRelevanceScorerLLM } from "@mastra/evals";
329
329
 
330
330
  const scorer = createContextRelevanceScorerLLM({
331
- model: "openai/gpt-4o-mini",
331
+ model: "openai/gpt-5.1",
332
332
  options: {
333
333
  context: [
334
334
  "Einstein won the Nobel Prize for his discovery of the photoelectric effect in 1921.",
@@ -375,7 +375,7 @@ This example shows moderate relevance with some context being irrelevant or unus
375
375
  import { createContextRelevanceScorerLLM } from "@mastra/evals";
376
376
 
377
377
  const scorer = createContextRelevanceScorerLLM({
378
- model: "openai/gpt-4o-mini",
378
+ model: "openai/gpt-5.1",
379
379
  options: {
380
380
  context: [
381
381
  "Solar eclipses occur when the Moon blocks the Sun.",
@@ -417,7 +417,7 @@ console.log(result);
417
417
 
418
418
  // With custom penalty configuration
419
419
  const customScorer = createContextRelevanceScorerLLM({
420
- model: "openai/gpt-4o-mini",
420
+ model: "openai/gpt-5.1",
421
421
  options: {
422
422
  context: [
423
423
  "Solar eclipses occur when the Moon blocks the Sun.",
@@ -466,7 +466,7 @@ This example shows poor context relevance with mostly irrelevant information:
466
466
  import { createContextRelevanceScorerLLM } from "@mastra/evals";
467
467
 
468
468
  const scorer = createContextRelevanceScorerLLM({
469
- model: "openai/gpt-4o-mini",
469
+ model: "openai/gpt-5.1",
470
470
  options: {
471
471
  context: [
472
472
  "The Great Barrier Reef is located in Australia.",
@@ -514,7 +514,7 @@ Extract context dynamically based on the run input:
514
514
  import { createContextRelevanceScorerLLM } from "@mastra/evals";
515
515
 
516
516
  const scorer = createContextRelevanceScorerLLM({
517
- model: "openai/gpt-4o-mini",
517
+ model: "openai/gpt-5.1",
518
518
  options: {
519
519
  contextExtractor: (input, output) => {
520
520
  // Extract query from input
@@ -557,7 +557,7 @@ Integrate with RAG pipelines to evaluate retrieved context:
557
557
  import { createContextRelevanceScorerLLM } from "@mastra/evals";
558
558
 
559
559
  const scorer = createContextRelevanceScorerLLM({
560
- model: "openai/gpt-4o-mini",
560
+ model: "openai/gpt-5.1",
561
561
  options: {
562
562
  contextExtractor: (input, output) => {
563
563
  // Extract from RAG retrieval results
@@ -122,118 +122,45 @@ A faithfulness score between 0 and 1:
122
122
  - **0.1–0.3**: Most of the content is inaccurate or unsupported.
123
123
  - **0.0**: All claims are false or contradict the context.
124
124
 
125
- ## Examples
125
+ ## Example
126
126
 
127
- ### High faithfulness example
127
+ Evaluate agent responses for faithfulness to provided context:
128
128
 
129
- In this example, the response closely aligns with the context. Each statement in the output is verifiable and supported by the provided context entries, resulting in a high score.
130
-
131
- ```typescript title="src/example-high-faithfulness.ts" showLineNumbers copy
132
- import { createFaithfulnessScorer } from "@mastra/evals/scorers/prebuilt";
133
-
134
- const scorer = createFaithfulnessScorer({ model: 'openai/gpt-4o-mini', options: {
135
- context: [
136
- "The Tesla Model 3 was launched in 2017.",
137
- "It has a range of up to 358 miles.",
138
- "The base model accelerates 0-60 mph in 5.8 seconds."
139
- ]
140
- });
141
-
142
- const query = "Tell me about the Tesla Model 3.";
143
- const response = "The Tesla Model 3 was introduced in 2017. It can travel up to 358 miles on a single charge and the base version goes from 0 to 60 mph in 5.8 seconds.";
144
-
145
- const result = await scorer.run({
146
- input: [{ role: 'user', content: query }],
147
- output: { text: response },
148
- });
149
-
150
- console.log(result);
151
- ```
152
-
153
- #### High faithfulness output
154
-
155
- The output receives a score of 1 because all the information it provides can be directly traced to the context. There are no missing or contradictory facts.
156
-
157
- ```typescript
158
- {
159
- score: 1,
160
- reason: 'The score is 1 because all claims made in the output are supported by the provided context.'
161
- }
162
- ```
163
-
164
- ### Mixed faithfulness example
165
-
166
- In this example, there are a mix of supported and unsupported claims. Some parts of the response are backed by the context, while others introduce new information not found in the source material.
167
-
168
- ```typescript title="src/example-mixed-faithfulness.ts" showLineNumbers copy
169
- import { createFaithfulnessScorer } from "@mastra/evals/scorers/prebuilt";
170
-
171
- const scorer = createFaithfulnessScorer({ model: 'openai/gpt-4o-mini', options: {
172
- context: [
173
- "Python was created by Guido van Rossum.",
174
- "The first version was released in 1991.",
175
- "Python emphasizes code readability."
176
- ]
177
- });
178
-
179
- const query = "What can you tell me about Python?";
180
- const response = "Python was created by Guido van Rossum and released in 1991. It is the most popular programming language today and is used by millions of developers worldwide.";
181
-
182
- const result = await scorer.run({
183
- input: [{ role: 'user', content: query }],
184
- output: { text: response },
185
- });
186
-
187
- console.log(result);
188
- ```
189
-
190
- #### Mixed faithfulness output
191
-
192
- The score is lower because only a portion of the response is verifiable. While some claims match the context, others are unconfirmed or out of scope, reducing the overall faithfulness.
193
-
194
- ```typescript
195
- {
196
- score: 0.5,
197
- reason: "The score is 0.5 because while two claims are supported by the context (Python was created by Guido van Rossum and Python was released in 1991), the other two claims regarding Python's popularity and usage cannot be verified as they are not mentioned in the context."
198
- }
199
- ```
200
-
201
- ### Low faithfulness example
202
-
203
- In this example, the response directly contradicts the context. None of the claims are supported, and several conflict with the facts provided.
204
-
205
- ```typescript title="src/example-low-faithfulness.ts" showLineNumbers copy
129
+ ```typescript title="src/example-faithfulness.ts" showLineNumbers copy
130
+ import { runEvals } from "@mastra/core/evals";
206
131
  import { createFaithfulnessScorer } from "@mastra/evals/scorers/prebuilt";
132
+ import { myAgent } from "./agent";
207
133
 
208
- const scorer = createFaithfulnessScorer({ model: 'openai/gpt-4o-mini', options: {
209
- context: [
210
- "Mars is the fourth planet from the Sun.",
211
- "It has a thin atmosphere of mostly carbon dioxide.",
212
- "Two small moons orbit Mars: Phobos and Deimos."
213
- ]
134
+ // Context is typically populated from agent tool calls or RAG retrieval
135
+ const scorer = createFaithfulnessScorer({
136
+ model: "openai/gpt-4o",
214
137
  });
215
138
 
216
- const query = "What do we know about Mars?";
217
- const response = "Mars is the third planet from the Sun. It has a thick atmosphere rich in oxygen and nitrogen, and is orbited by three large moons.";
218
-
219
- const result = await scorer.run({
220
- input: [{ role: 'user', content: query }],
221
- output: { text: response },
139
+ const result = await runEvals({
140
+ data: [
141
+ {
142
+ input: "Tell me about the Tesla Model 3.",
143
+ },
144
+ {
145
+ input: "What are the key features of this electric vehicle?",
146
+ },
147
+ ],
148
+ scorers: [scorer],
149
+ target: myAgent,
150
+ onItemComplete: ({ scorerResults }) => {
151
+ console.log({
152
+ score: scorerResults[scorer.id].score,
153
+ reason: scorerResults[scorer.id].reason,
154
+ });
155
+ },
222
156
  });
223
157
 
224
- console.log(result);
158
+ console.log(result.scores);
225
159
  ```
226
160
 
227
- #### Low faithfulness output
161
+ For more details on `runEvals`, see the [runEvals reference](/reference/v1/evals/run-evals).
228
162
 
229
- Each claim is inaccurate or conflicts with the context, resulting in a score of 0.
230
-
231
- ```typescript
232
- {
233
- score: 0,
234
- reason: "The score is 0 because all claims made in the output contradict the provided context. The output states that Mars is the third planet from the Sun, while the context clearly states it is the fourth. Additionally, it claims that Mars has a thick atmosphere rich in oxygen and nitrogen, contradicting the context's description of a thin atmosphere mostly composed of carbon dioxide. Finally, the output mentions that Mars is orbited by three large moons, while the context specifies that it has only two small moons, Phobos and Deimos. Therefore, there are no supported claims, leading to a score of 0."
235
- }
236
- ```
163
+ To add this scorer to an agent, see the [Scorers overview](/docs/v1/evals/overview#adding-scorers-to-agents) guide.
237
164
 
238
165
  ## Related
239
166