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

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 (163) hide show
  1. package/.docs/organized/changelogs/%40mastra%2Fagent-builder.md +9 -9
  2. package/.docs/organized/changelogs/%40mastra%2Fai-sdk.md +67 -67
  3. package/.docs/organized/changelogs/%40mastra%2Fastra.md +10 -10
  4. package/.docs/organized/changelogs/%40mastra%2Fchroma.md +12 -12
  5. package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +57 -57
  6. package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +110 -110
  7. package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +57 -57
  8. package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +57 -57
  9. package/.docs/organized/changelogs/%40mastra%2Fcodemod.md +6 -0
  10. package/.docs/organized/changelogs/%40mastra%2Fconvex.md +60 -0
  11. package/.docs/organized/changelogs/%40mastra%2Fcore.md +358 -358
  12. package/.docs/organized/changelogs/%40mastra%2Fcouchbase.md +11 -11
  13. package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +24 -24
  14. package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +12 -12
  15. package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +79 -79
  16. package/.docs/organized/changelogs/%40mastra%2Fduckdb.md +42 -0
  17. package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +57 -57
  18. package/.docs/organized/changelogs/%40mastra%2Felasticsearch.md +61 -0
  19. package/.docs/organized/changelogs/%40mastra%2Fevals.md +12 -12
  20. package/.docs/organized/changelogs/%40mastra%2Flance.md +57 -57
  21. package/.docs/organized/changelogs/%40mastra%2Flibsql.md +55 -55
  22. package/.docs/organized/changelogs/%40mastra%2Floggers.md +12 -12
  23. package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +17 -17
  24. package/.docs/organized/changelogs/%40mastra%2Fmcp.md +125 -125
  25. package/.docs/organized/changelogs/%40mastra%2Fmemory.md +36 -36
  26. package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +57 -57
  27. package/.docs/organized/changelogs/%40mastra%2Fmssql.md +57 -57
  28. package/.docs/organized/changelogs/%40mastra%2Fopensearch.md +10 -10
  29. package/.docs/organized/changelogs/%40mastra%2Fpg.md +59 -59
  30. package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +10 -10
  31. package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +77 -77
  32. package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +10 -10
  33. package/.docs/organized/changelogs/%40mastra%2Frag.md +43 -43
  34. package/.docs/organized/changelogs/%40mastra%2Freact.md +16 -0
  35. package/.docs/organized/changelogs/%40mastra%2Fs3vectors.md +9 -0
  36. package/.docs/organized/changelogs/%40mastra%2Fschema-compat.md +6 -0
  37. package/.docs/organized/changelogs/%40mastra%2Fserver.md +113 -113
  38. package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +10 -10
  39. package/.docs/organized/changelogs/%40mastra%2Fupstash.md +57 -57
  40. package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +10 -10
  41. package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +19 -19
  42. package/.docs/organized/changelogs/create-mastra.md +15 -15
  43. package/.docs/organized/changelogs/mastra.md +30 -30
  44. package/.docs/organized/code-examples/agui.md +1 -0
  45. package/.docs/organized/code-examples/ai-elements.md +1 -1
  46. package/.docs/organized/code-examples/ai-sdk-useChat.md +1 -1
  47. package/.docs/organized/code-examples/ai-sdk-v5.md +2 -1
  48. package/.docs/organized/code-examples/assistant-ui.md +1 -1
  49. package/.docs/organized/code-examples/bird-checker-with-nextjs-and-eval.md +1 -1
  50. package/.docs/organized/code-examples/bird-checker-with-nextjs.md +1 -1
  51. package/.docs/organized/code-examples/crypto-chatbot.md +1 -1
  52. package/.docs/organized/code-examples/mcp-server-adapters.md +721 -0
  53. package/.docs/organized/code-examples/server-app-access.md +342 -0
  54. package/.docs/organized/code-examples/server-express-adapter.md +87 -0
  55. package/.docs/organized/code-examples/server-hono-adapter.md +85 -0
  56. package/.docs/raw/agents/agent-approval.mdx +189 -0
  57. package/.docs/raw/agents/guardrails.mdx +13 -9
  58. package/.docs/raw/agents/networks.mdx +1 -0
  59. package/.docs/raw/agents/overview.mdx +8 -152
  60. package/.docs/raw/agents/processors.mdx +279 -0
  61. package/.docs/raw/agents/structured-output.mdx +224 -0
  62. package/.docs/raw/deployment/cloud-providers/index.mdx +19 -26
  63. package/.docs/raw/deployment/cloud-providers/netlify-deployer.mdx +44 -13
  64. package/.docs/raw/evals/running-in-ci.mdx +0 -2
  65. package/.docs/raw/{guides/getting-started → getting-started}/manual-install.mdx +2 -2
  66. package/.docs/raw/getting-started/start.mdx +1 -1
  67. package/.docs/raw/guides/build-your-ui/ai-sdk-ui.mdx +8 -0
  68. package/.docs/raw/guides/getting-started/quickstart.mdx +1 -1
  69. package/.docs/raw/guides/guide/whatsapp-chat-bot.mdx +421 -0
  70. package/.docs/raw/guides/index.mdx +3 -35
  71. package/.docs/raw/guides/migrations/upgrade-to-v1/agent.mdx +11 -0
  72. package/.docs/raw/guides/migrations/upgrade-to-v1/workflows.mdx +37 -0
  73. package/.docs/raw/index.mdx +1 -1
  74. package/.docs/raw/memory/memory-processors.mdx +265 -79
  75. package/.docs/raw/memory/working-memory.mdx +11 -2
  76. package/.docs/raw/observability/overview.mdx +0 -1
  77. package/.docs/raw/observability/tracing/bridges/otel.mdx +200 -0
  78. package/.docs/raw/observability/tracing/exporters/arize.mdx +36 -0
  79. package/.docs/raw/observability/tracing/exporters/braintrust.mdx +19 -0
  80. package/.docs/raw/observability/tracing/exporters/langfuse.mdx +83 -0
  81. package/.docs/raw/observability/tracing/exporters/langsmith.mdx +12 -0
  82. package/.docs/raw/observability/tracing/exporters/otel.mdx +34 -22
  83. package/.docs/raw/observability/tracing/exporters/posthog.mdx +20 -0
  84. package/.docs/raw/observability/tracing/overview.mdx +76 -6
  85. package/.docs/raw/observability/tracing/processors/sensitive-data-filter.mdx +0 -1
  86. package/.docs/raw/rag/retrieval.mdx +23 -6
  87. package/.docs/raw/rag/vector-databases.mdx +93 -2
  88. package/.docs/raw/reference/agents/generate.mdx +55 -6
  89. package/.docs/raw/reference/agents/network.mdx +44 -0
  90. package/.docs/raw/reference/client-js/memory.mdx +43 -0
  91. package/.docs/raw/reference/client-js/workflows.mdx +92 -63
  92. package/.docs/raw/reference/deployer/netlify.mdx +1 -2
  93. package/.docs/raw/reference/evals/scorer-utils.mdx +362 -0
  94. package/.docs/raw/reference/index.mdx +1 -0
  95. package/.docs/raw/reference/observability/tracing/bridges/otel.mdx +177 -0
  96. package/.docs/raw/reference/observability/tracing/configuration.mdx +0 -4
  97. package/.docs/raw/reference/observability/tracing/exporters/arize.mdx +29 -0
  98. package/.docs/raw/reference/observability/tracing/exporters/langfuse.mdx +43 -0
  99. package/.docs/raw/reference/observability/tracing/exporters/langsmith.mdx +17 -1
  100. package/.docs/raw/reference/observability/tracing/exporters/otel.mdx +33 -43
  101. package/.docs/raw/reference/observability/tracing/instances.mdx +0 -4
  102. package/.docs/raw/reference/observability/tracing/interfaces.mdx +29 -4
  103. package/.docs/raw/reference/observability/tracing/spans.mdx +0 -4
  104. package/.docs/raw/reference/processors/language-detector.mdx +9 -2
  105. package/.docs/raw/reference/processors/message-history-processor.mdx +131 -0
  106. package/.docs/raw/reference/processors/moderation-processor.mdx +10 -3
  107. package/.docs/raw/reference/processors/pii-detector.mdx +10 -3
  108. package/.docs/raw/reference/processors/processor-interface.mdx +502 -0
  109. package/.docs/raw/reference/processors/prompt-injection-detector.mdx +9 -2
  110. package/.docs/raw/reference/processors/semantic-recall-processor.mdx +197 -0
  111. package/.docs/raw/reference/processors/system-prompt-scrubber.mdx +2 -2
  112. package/.docs/raw/reference/processors/tool-call-filter.mdx +125 -0
  113. package/.docs/raw/reference/processors/working-memory-processor.mdx +221 -0
  114. package/.docs/raw/reference/server/create-route.mdx +314 -0
  115. package/.docs/raw/reference/server/express-adapter.mdx +193 -0
  116. package/.docs/raw/reference/server/hono-adapter.mdx +174 -0
  117. package/.docs/raw/reference/server/mastra-server.mdx +316 -0
  118. package/.docs/raw/reference/server/routes.mdx +250 -0
  119. package/.docs/raw/reference/storage/cloudflare-d1.mdx +37 -0
  120. package/.docs/raw/reference/storage/convex.mdx +164 -0
  121. package/.docs/raw/reference/storage/lance.mdx +33 -0
  122. package/.docs/raw/reference/storage/libsql.mdx +37 -0
  123. package/.docs/raw/reference/storage/mongodb.mdx +39 -0
  124. package/.docs/raw/reference/storage/mssql.mdx +37 -0
  125. package/.docs/raw/reference/storage/postgresql.mdx +37 -0
  126. package/.docs/raw/reference/streaming/ChunkType.mdx +1 -1
  127. package/.docs/raw/reference/streaming/agents/stream.mdx +56 -1
  128. package/.docs/raw/reference/streaming/workflows/observeStream.mdx +7 -9
  129. package/.docs/raw/reference/streaming/workflows/{resumeStreamVNext.mdx → resumeStream.mdx} +51 -11
  130. package/.docs/raw/reference/streaming/workflows/stream.mdx +83 -24
  131. package/.docs/raw/reference/streaming/workflows/timeTravelStream.mdx +170 -0
  132. package/.docs/raw/reference/tools/mcp-client.mdx +128 -18
  133. package/.docs/raw/reference/vectors/convex.mdx +429 -0
  134. package/.docs/raw/reference/vectors/duckdb.mdx +462 -0
  135. package/.docs/raw/reference/vectors/elasticsearch.mdx +310 -0
  136. package/.docs/raw/reference/voice/google.mdx +159 -20
  137. package/.docs/raw/reference/workflows/run-methods/restart.mdx +142 -0
  138. package/.docs/raw/reference/workflows/run-methods/resume.mdx +44 -0
  139. package/.docs/raw/reference/workflows/run-methods/start.mdx +44 -0
  140. package/.docs/raw/reference/workflows/run-methods/timeTravel.mdx +310 -0
  141. package/.docs/raw/reference/workflows/run.mdx +27 -5
  142. package/.docs/raw/reference/workflows/step.mdx +13 -0
  143. package/.docs/raw/reference/workflows/workflow.mdx +19 -0
  144. package/.docs/raw/server-db/custom-adapters.mdx +380 -0
  145. package/.docs/raw/server-db/mastra-server.mdx +16 -8
  146. package/.docs/raw/server-db/request-context.mdx +0 -1
  147. package/.docs/raw/server-db/server-adapters.mdx +286 -0
  148. package/.docs/raw/server-db/storage.mdx +11 -0
  149. package/.docs/raw/streaming/overview.mdx +6 -6
  150. package/.docs/raw/streaming/tool-streaming.mdx +2 -2
  151. package/.docs/raw/streaming/workflow-streaming.mdx +5 -11
  152. package/.docs/raw/workflows/error-handling.mdx +1 -0
  153. package/.docs/raw/workflows/human-in-the-loop.mdx +4 -4
  154. package/.docs/raw/workflows/overview.mdx +56 -44
  155. package/.docs/raw/workflows/snapshots.mdx +1 -0
  156. package/.docs/raw/workflows/suspend-and-resume.mdx +85 -16
  157. package/.docs/raw/workflows/time-travel.mdx +313 -0
  158. package/.docs/raw/workflows/workflow-state.mdx +191 -0
  159. package/CHANGELOG.md +16 -0
  160. package/package.json +4 -4
  161. package/.docs/raw/agents/human-in-the-loop-with-tools.mdx +0 -91
  162. package/.docs/raw/reference/streaming/workflows/observeStreamVNext.mdx +0 -47
  163. package/.docs/raw/reference/streaming/workflows/streamVNext.mdx +0 -153
@@ -7,12 +7,6 @@ import PropertiesTable from "@site/src/components/PropertiesTable";
7
7
 
8
8
  # OtelExporter
9
9
 
10
- :::warning
11
-
12
- The OtelExporter is currently **experimental**. APIs and configuration options may change in future releases.
13
-
14
- :::
15
-
16
10
  Sends Tracing data to any OpenTelemetry-compatible observability platform using standardized GenAI semantic conventions.
17
11
 
18
12
  ## Constructor
@@ -317,38 +311,6 @@ const exporter = new OtelExporter({
317
311
  });
318
312
  ```
319
313
 
320
- ## Span Mapping
321
-
322
- The exporter maps Mastra AI spans to OpenTelemetry spans following GenAI semantic conventions:
323
-
324
- ### Span Names
325
-
326
- - `MODEL_GENERATION` → `chat {model}` or `tool_selection {model}`
327
- - `TOOL_CALL` → `tool.execute {tool_name}`
328
- - `AGENT_RUN` → `agent.{agent_id}`
329
- - `WORKFLOW_RUN` → `workflow.{workflow_id}`
330
-
331
- ### Span Kinds
332
-
333
- - Root agent/workflow spans → `SERVER`
334
- - LLM calls → `CLIENT`
335
- - Tool calls → `INTERNAL` or `CLIENT`
336
- - Workflow steps → `INTERNAL`
337
-
338
- ### Attributes
339
-
340
- The exporter maps to standard OTEL GenAI attributes:
341
-
342
- | Mastra Attribute | OTEL Attribute |
343
- | ----------------------------------- | -------------------------------- |
344
- | `model` | `gen_ai.request.model` |
345
- | `provider` | `gen_ai.system` |
346
- | `inputTokens` / `promptTokens` | `gen_ai.usage.input_tokens` |
347
- | `outputTokens` / `completionTokens` | `gen_ai.usage.output_tokens` |
348
- | `temperature` | `gen_ai.request.temperature` |
349
- | `maxOutputTokens` | `gen_ai.request.max_tokens` |
350
- | `finishReason` | `gen_ai.response.finish_reasons` |
351
-
352
314
  ## Protocol Requirements
353
315
 
354
316
  Different providers require different OTEL exporter packages:
@@ -360,10 +322,38 @@ Different providers require different OTEL exporter packages:
360
322
  | HTTP/JSON | `@opentelemetry/exporter-trace-otlp-http` | Traceloop, Custom |
361
323
  | Zipkin | `@opentelemetry/exporter-zipkin` | Zipkin collectors |
362
324
 
363
- ## Parent-Child Relationships
364
325
 
365
- The exporter preserves span hierarchy from Mastra's Tracing:
326
+ ## Tags Support
327
+
328
+ The OtelExporter supports trace tagging for categorization and filtering. Tags are only applied to root spans and are stored as the `mastra.tags` attribute.
329
+
330
+ ### Usage
331
+
332
+ ```typescript
333
+ const result = await agent.generate({
334
+ messages: [{ role: "user", content: "Hello" }],
335
+ tracingOptions: {
336
+ tags: ["production", "experiment-v2", "user-request"],
337
+ },
338
+ });
339
+ ```
340
+
341
+ ### How Tags Are Stored
342
+
343
+ Tags are stored as a JSON-stringified array in the `mastra.tags` span attribute for maximum backend compatibility:
344
+
345
+ ```json
346
+ {
347
+ "mastra.tags": "[\"production\",\"experiment-v2\",\"user-request\"]"
348
+ }
349
+ ```
350
+
351
+ :::note
352
+ While the OpenTelemetry specification supports native array attributes, many backends (Jaeger, Zipkin, Tempo) have limited array support. JSON strings ensure consistent behavior across all observability platforms.
353
+ :::
354
+
355
+ ## Related
366
356
 
367
- - Uses `parentSpanId` directly from Mastra spans
368
- - Maintains correct nesting for agents, workflows, LLM calls, and tools
369
- - Exports complete traces with all relationships intact
357
+ - [OtelExporter Guide](/docs/v1/observability/tracing/exporters/otel) - Setup guide with provider configurations
358
+ - [OtelBridge](/docs/v1/observability/tracing/bridges/otel) - For bidirectional OTEL context integration
359
+ - [Tracing Overview](/docs/v1/observability/tracing/overview) - General tracing concepts
@@ -157,10 +157,6 @@ class CustomObservabilityInstance extends BaseObservabilityInstance {
157
157
  - [Interfaces Reference](/reference/v1/observability/tracing/interfaces) - Type definitions
158
158
  - [Spans Reference](/reference/v1/observability/tracing/spans) - Span lifecycle and methods
159
159
 
160
- ### Examples
161
-
162
- - [Basic Tracing](/examples/v1/observability/basic-ai-tracing) - Getting started example
163
-
164
160
  ### Exporters
165
161
 
166
162
  - [DefaultExporter](/reference/v1/observability/tracing/exporters/default-exporter) - Storage persistence
@@ -90,6 +90,9 @@ interface Span<TType extends SpanType> {
90
90
  output?: any;
91
91
  errorInfo?: any;
92
92
 
93
+ /** Tags for categorizing traces (only present on root spans) */
94
+ tags?: string[];
95
+
93
96
  /** End the span */
94
97
  end(options?: EndSpanOptions<TType>): void;
95
98
 
@@ -549,6 +552,32 @@ Options passed when starting a new agent or workflow execution.
549
552
  interface TracingOptions {
550
553
  /** Metadata to add to the root trace span */
551
554
  metadata?: Record<string, any>;
555
+
556
+ /**
557
+ * Additional RequestContext keys to extract as metadata for this trace.
558
+ * These keys are added to the requestContextKeys config.
559
+ * Supports dot notation for nested values (e.g., 'user.id', 'session.data.experimentId').
560
+ */
561
+ requestContextKeys?: string[];
562
+
563
+ /**
564
+ * Trace ID to use for this execution (1-32 hexadecimal characters).
565
+ * If provided, this trace will be part of the specified trace rather than starting a new one.
566
+ */
567
+ traceId?: string;
568
+
569
+ /**
570
+ * Parent span ID to use for this execution (1-16 hexadecimal characters).
571
+ * If provided, the root span will be created as a child of this span.
572
+ */
573
+ parentSpanId?: string;
574
+
575
+ /**
576
+ * Tags to apply to this trace.
577
+ * Tags are string labels that can be used to categorize and filter traces
578
+ * Note: Tags are only applied to the root span of a trace.
579
+ */
580
+ tags?: string[];
552
581
  }
553
582
  ```
554
583
 
@@ -707,7 +736,3 @@ enum InternalSpans {
707
736
  - [Configuration](/reference/v1/observability/tracing/configuration) - Registry and configuration
708
737
  - [Tracing Classes](/reference/v1/observability/tracing/instances) - Core implementations
709
738
  - [Spans Reference](/reference/v1/observability/tracing/spans) - Span lifecycle methods
710
-
711
- ### Examples
712
-
713
- - [Basic Tracing](/examples/v1/observability/basic-ai-tracing) - Implementation example
@@ -386,7 +386,3 @@ A span that performs no operations. All methods are no-ops:
386
386
  - [Tracing Classes](/reference/v1/observability/tracing/instances) - Core tracing classes
387
387
  - [Interfaces](/reference/v1/observability/tracing/interfaces) - Complete type reference
388
388
  - [Configuration](/reference/v1/observability/tracing/configuration) - Configuration options
389
-
390
- ### Examples
391
-
392
- - [Basic Tracing](/examples/v1/observability/basic-ai-tracing) - Working with spans
@@ -13,7 +13,7 @@ The `LanguageDetector` is an **input processor** that identifies the language of
13
13
  import { LanguageDetector } from "@mastra/core/processors";
14
14
 
15
15
  const processor = new LanguageDetector({
16
- model: "openai/gpt-4.1-nano",
16
+ model: "openrouter/openai/gpt-oss-safeguard-20b",
17
17
  targetLanguages: ["English", "en"],
18
18
  threshold: 0.8,
19
19
  strategy: "translate"
@@ -99,6 +99,13 @@ const processor = new LanguageDetector({
99
99
  isOptional: true,
100
100
  default: "'quality'",
101
101
  },
102
+ {
103
+ name: "providerOptions",
104
+ type: "ProviderOptions",
105
+ description: "Provider-specific options passed to the internal detection agent. Use this to control model behavior like reasoning effort for thinking models (e.g., `{ openai: { reasoningEffort: 'low' } }`)",
106
+ isOptional: true,
107
+ default: "undefined",
108
+ },
102
109
  ]}
103
110
  />
104
111
 
@@ -139,7 +146,7 @@ export const agent = new Agent({
139
146
  model: "openai/gpt-5.1",
140
147
  inputProcessors: [
141
148
  new LanguageDetector({
142
- model: "openai/gpt-4.1-nano",
149
+ model: "openrouter/openai/gpt-oss-safeguard-20b",
143
150
  targetLanguages: ["English", "en"],
144
151
  threshold: 0.8,
145
152
  strategy: "translate",
@@ -0,0 +1,131 @@
1
+ ---
2
+ title: "Reference: Message History Processor | Processors"
3
+ description: "Documentation for the MessageHistory processor in Mastra, which handles retrieval and persistence of conversation history."
4
+ ---
5
+
6
+ # MessageHistory
7
+
8
+ The `MessageHistory` is a **hybrid processor** that handles both retrieval and persistence of message history. On input, it fetches historical messages from storage and prepends them to the conversation. On output, it persists new messages to storage.
9
+
10
+ ## Usage example
11
+
12
+ ```typescript copy
13
+ import { MessageHistory } from "@mastra/core/processors";
14
+
15
+ const processor = new MessageHistory({
16
+ storage: memoryStorage,
17
+ lastMessages: 50,
18
+ });
19
+ ```
20
+
21
+ ## Constructor parameters
22
+
23
+ <PropertiesTable
24
+ content={[
25
+ {
26
+ name: "options",
27
+ type: "MessageHistoryOptions",
28
+ description: "Configuration options for the message history processor",
29
+ isOptional: false,
30
+ },
31
+ ]}
32
+ />
33
+
34
+ ### Options
35
+
36
+ <PropertiesTable
37
+ content={[
38
+ {
39
+ name: "storage",
40
+ type: "MemoryStorage",
41
+ description: "Storage instance for retrieving and persisting messages",
42
+ isOptional: false,
43
+ },
44
+ {
45
+ name: "lastMessages",
46
+ type: "number",
47
+ description: "Maximum number of historical messages to retrieve. If not specified, retrieves all messages",
48
+ isOptional: true,
49
+ },
50
+ ]}
51
+ />
52
+
53
+ ## Returns
54
+
55
+ <PropertiesTable
56
+ content={[
57
+ {
58
+ name: "id",
59
+ type: "string",
60
+ description: "Processor identifier set to 'message-history'",
61
+ isOptional: false,
62
+ },
63
+ {
64
+ name: "name",
65
+ type: "string",
66
+ description: "Processor display name set to 'MessageHistory'",
67
+ isOptional: false,
68
+ },
69
+ {
70
+ name: "processInput",
71
+ type: "(args: { messages: MastraDBMessage[]; messageList: MessageList; abort: (reason?: string) => never; tracingContext?: TracingContext; requestContext?: RequestContext }) => Promise<MessageList | MastraDBMessage[]>",
72
+ description: "Fetches historical messages from storage and adds them to the message list",
73
+ isOptional: false,
74
+ },
75
+ {
76
+ name: "processOutputResult",
77
+ type: "(args: { messages: MastraDBMessage[]; messageList: MessageList; abort: (reason?: string) => never; tracingContext?: TracingContext; requestContext?: RequestContext }) => Promise<MessageList>",
78
+ description: "Persists new messages (user input and assistant response) to storage, excluding system messages",
79
+ isOptional: false,
80
+ },
81
+ ]}
82
+ />
83
+
84
+ ## Extended usage example
85
+
86
+ ```typescript title="src/mastra/agents/memory-agent.ts" showLineNumbers copy
87
+ import { Agent } from "@mastra/core/agent";
88
+ import { MessageHistory } from "@mastra/core/processors";
89
+ import { PostgresStorage } from "@mastra/pg";
90
+
91
+ const storage = new PostgresStorage({
92
+ connectionString: process.env.DATABASE_URL,
93
+ });
94
+
95
+ export const agent = new Agent({
96
+ name: "memory-agent",
97
+ instructions: "You are a helpful assistant with conversation memory",
98
+ model: "openai:gpt-4o",
99
+ inputProcessors: [
100
+ new MessageHistory({
101
+ storage,
102
+ lastMessages: 100,
103
+ }),
104
+ ],
105
+ outputProcessors: [
106
+ new MessageHistory({
107
+ storage,
108
+ }),
109
+ ],
110
+ });
111
+ ```
112
+
113
+ ## Behavior
114
+
115
+ ### Input processing
116
+ 1. Retrieves `threadId` from the request context
117
+ 2. Fetches historical messages from storage (ordered by creation date, descending)
118
+ 3. Filters out system messages (they should not be stored in the database)
119
+ 4. Merges historical messages with incoming messages, avoiding duplicates by ID
120
+ 5. Adds historical messages with `source: 'memory'` tag
121
+
122
+ ### Output processing
123
+ 1. Retrieves `threadId` from the request context
124
+ 2. Skips persistence if `readOnly` is set in memory config
125
+ 3. Filters out incomplete tool calls from messages
126
+ 4. Persists new user input and assistant response messages to storage
127
+ 5. Updates the thread's `updatedAt` timestamp
128
+
129
+ ## Related
130
+
131
+ - [Guardrails](/docs/v1/agents/guardrails)
@@ -13,7 +13,7 @@ The `ModerationProcessor` is a **hybrid processor** that can be used for both in
13
13
  import { ModerationProcessor } from "@mastra/core/processors";
14
14
 
15
15
  const processor = new ModerationProcessor({
16
- model: "openai/gpt-4.1-nano",
16
+ model: "openrouter/openai/gpt-oss-safeguard-20b",
17
17
  threshold: 0.7,
18
18
  strategy: "block",
19
19
  categories: ["hate", "harassment", "violence"]
@@ -85,6 +85,13 @@ const processor = new ModerationProcessor({
85
85
  isOptional: true,
86
86
  default: "0 (no context window)",
87
87
  },
88
+ {
89
+ name: "providerOptions",
90
+ type: "ProviderOptions",
91
+ description: "Provider-specific options passed to the internal moderation agent. Use this to control model behavior like reasoning effort for thinking models (e.g., `{ openai: { reasoningEffort: 'low' } }`)",
92
+ isOptional: true,
93
+ default: "undefined",
94
+ },
88
95
  ]}
89
96
  />
90
97
 
@@ -133,7 +140,7 @@ export const agent = new Agent({
133
140
  model: "openai/gpt-5.1",
134
141
  inputProcessors: [
135
142
  new ModerationProcessor({
136
- model: "openai/gpt-4.1-nano",
143
+ model: "openrouter/openai/gpt-oss-safeguard-20b",
137
144
  categories: ["hate", "harassment", "violence"],
138
145
  threshold: 0.7,
139
146
  strategy: "block",
@@ -163,7 +170,7 @@ export const agent = new Agent({
163
170
  }),
164
171
  // Then apply moderation on batched content
165
172
  new ModerationProcessor({
166
- model: "openai/gpt-4.1-nano",
173
+ model: "openrouter/openai/gpt-oss-safeguard-20b",
167
174
  strategy: "filter",
168
175
  chunkWindow: 1,
169
176
  }),
@@ -13,7 +13,7 @@ The `PIIDetector` is a **hybrid processor** that can be used for both input and
13
13
  import { PIIDetector } from "@mastra/core/processors";
14
14
 
15
15
  const processor = new PIIDetector({
16
- model: "openai/gpt-4.1-nano",
16
+ model: "openrouter/openai/gpt-oss-safeguard-20b",
17
17
  threshold: 0.6,
18
18
  strategy: "redact",
19
19
  detectionTypes: ["email", "phone", "credit-card", "ssn"]
@@ -92,6 +92,13 @@ const processor = new PIIDetector({
92
92
  isOptional: true,
93
93
  default: "true",
94
94
  },
95
+ {
96
+ name: "providerOptions",
97
+ type: "ProviderOptions",
98
+ description: "Provider-specific options passed to the internal detection agent. Use this to control model behavior like reasoning effort for thinking models (e.g., `{ openai: { reasoningEffort: 'low' } }`)",
99
+ isOptional: true,
100
+ default: "undefined",
101
+ },
95
102
  ]}
96
103
  />
97
104
 
@@ -140,7 +147,7 @@ export const agent = new Agent({
140
147
  model: "openai/gpt-5.1",
141
148
  inputProcessors: [
142
149
  new PIIDetector({
143
- model: "openai/gpt-4.1-nano",
150
+ model: "openrouter/openai/gpt-oss-safeguard-20b",
144
151
  detectionTypes: ["email", "phone", "credit-card", "ssn"],
145
152
  threshold: 0.6,
146
153
  strategy: "redact",
@@ -172,7 +179,7 @@ export const agent = new Agent({
172
179
  }),
173
180
  // Then apply PII detection on batched content
174
181
  new PIIDetector({
175
- model: "openai/gpt-4.1-nano",
182
+ model: "openrouter/openai/gpt-oss-safeguard-20b",
176
183
  strategy: "redact",
177
184
  })
178
185
  ]