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

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 (132) 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%2Fclickhouse.md +26 -26
  4. package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +53 -53
  5. package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +26 -26
  6. package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +27 -27
  7. package/.docs/organized/changelogs/%40mastra%2Fconvex.md +29 -0
  8. package/.docs/organized/changelogs/%40mastra%2Fcore.md +274 -274
  9. package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +15 -15
  10. package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +12 -12
  11. package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +65 -65
  12. package/.docs/organized/changelogs/%40mastra%2Fduckdb.md +42 -0
  13. package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +26 -26
  14. package/.docs/organized/changelogs/%40mastra%2Felasticsearch.md +52 -0
  15. package/.docs/organized/changelogs/%40mastra%2Fevals.md +12 -12
  16. package/.docs/organized/changelogs/%40mastra%2Flance.md +26 -26
  17. package/.docs/organized/changelogs/%40mastra%2Flibsql.md +24 -24
  18. package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +9 -9
  19. package/.docs/organized/changelogs/%40mastra%2Fmcp.md +84 -84
  20. package/.docs/organized/changelogs/%40mastra%2Fmemory.md +36 -36
  21. package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +26 -26
  22. package/.docs/organized/changelogs/%40mastra%2Fmssql.md +27 -27
  23. package/.docs/organized/changelogs/%40mastra%2Fpg.md +28 -28
  24. package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +47 -47
  25. package/.docs/organized/changelogs/%40mastra%2Frag.md +43 -43
  26. package/.docs/organized/changelogs/%40mastra%2Freact.md +9 -0
  27. package/.docs/organized/changelogs/%40mastra%2Fschema-compat.md +6 -0
  28. package/.docs/organized/changelogs/%40mastra%2Fserver.md +56 -56
  29. package/.docs/organized/changelogs/%40mastra%2Fupstash.md +26 -26
  30. package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +19 -19
  31. package/.docs/organized/changelogs/create-mastra.md +9 -9
  32. package/.docs/organized/changelogs/mastra.md +17 -17
  33. package/.docs/organized/code-examples/agui.md +1 -0
  34. package/.docs/organized/code-examples/ai-sdk-v5.md +1 -0
  35. package/.docs/organized/code-examples/mcp-server-adapters.md +721 -0
  36. package/.docs/organized/code-examples/server-app-access.md +342 -0
  37. package/.docs/raw/agents/agent-approval.mdx +189 -0
  38. package/.docs/raw/agents/guardrails.mdx +13 -9
  39. package/.docs/raw/agents/networks.mdx +1 -0
  40. package/.docs/raw/agents/overview.mdx +23 -58
  41. package/.docs/raw/agents/processors.mdx +279 -0
  42. package/.docs/raw/deployment/cloud-providers/index.mdx +19 -26
  43. package/.docs/raw/deployment/cloud-providers/netlify-deployer.mdx +44 -13
  44. package/.docs/raw/evals/running-in-ci.mdx +0 -2
  45. package/.docs/raw/{guides/getting-started → getting-started}/manual-install.mdx +2 -2
  46. package/.docs/raw/getting-started/start.mdx +1 -1
  47. package/.docs/raw/guides/build-your-ui/ai-sdk-ui.mdx +8 -0
  48. package/.docs/raw/guides/getting-started/quickstart.mdx +1 -1
  49. package/.docs/raw/guides/guide/whatsapp-chat-bot.mdx +421 -0
  50. package/.docs/raw/guides/index.mdx +3 -35
  51. package/.docs/raw/guides/migrations/upgrade-to-v1/agent.mdx +11 -0
  52. package/.docs/raw/guides/migrations/upgrade-to-v1/workflows.mdx +29 -0
  53. package/.docs/raw/index.mdx +1 -1
  54. package/.docs/raw/memory/memory-processors.mdx +265 -79
  55. package/.docs/raw/memory/working-memory.mdx +10 -2
  56. package/.docs/raw/observability/overview.mdx +0 -1
  57. package/.docs/raw/observability/tracing/bridges/otel.mdx +176 -0
  58. package/.docs/raw/observability/tracing/exporters/arize.mdx +17 -0
  59. package/.docs/raw/observability/tracing/exporters/braintrust.mdx +19 -0
  60. package/.docs/raw/observability/tracing/exporters/langfuse.mdx +20 -0
  61. package/.docs/raw/observability/tracing/exporters/langsmith.mdx +12 -0
  62. package/.docs/raw/observability/tracing/exporters/otel.mdx +5 -4
  63. package/.docs/raw/observability/tracing/overview.mdx +71 -6
  64. package/.docs/raw/observability/tracing/processors/sensitive-data-filter.mdx +0 -1
  65. package/.docs/raw/rag/retrieval.mdx +23 -6
  66. package/.docs/raw/rag/vector-databases.mdx +93 -2
  67. package/.docs/raw/reference/agents/generate.mdx +55 -6
  68. package/.docs/raw/reference/agents/network.mdx +44 -0
  69. package/.docs/raw/reference/client-js/memory.mdx +43 -0
  70. package/.docs/raw/reference/client-js/workflows.mdx +92 -63
  71. package/.docs/raw/reference/deployer/netlify.mdx +1 -2
  72. package/.docs/raw/reference/evals/scorer-utils.mdx +362 -0
  73. package/.docs/raw/reference/index.mdx +1 -0
  74. package/.docs/raw/reference/observability/tracing/bridges/otel.mdx +150 -0
  75. package/.docs/raw/reference/observability/tracing/configuration.mdx +0 -4
  76. package/.docs/raw/reference/observability/tracing/exporters/arize.mdx +4 -0
  77. package/.docs/raw/reference/observability/tracing/exporters/langsmith.mdx +17 -1
  78. package/.docs/raw/reference/observability/tracing/exporters/otel.mdx +6 -0
  79. package/.docs/raw/reference/observability/tracing/instances.mdx +0 -4
  80. package/.docs/raw/reference/observability/tracing/interfaces.mdx +29 -4
  81. package/.docs/raw/reference/observability/tracing/spans.mdx +0 -4
  82. package/.docs/raw/reference/processors/language-detector.mdx +9 -2
  83. package/.docs/raw/reference/processors/message-history-processor.mdx +131 -0
  84. package/.docs/raw/reference/processors/moderation-processor.mdx +10 -3
  85. package/.docs/raw/reference/processors/pii-detector.mdx +10 -3
  86. package/.docs/raw/reference/processors/processor-interface.mdx +502 -0
  87. package/.docs/raw/reference/processors/prompt-injection-detector.mdx +9 -2
  88. package/.docs/raw/reference/processors/semantic-recall-processor.mdx +197 -0
  89. package/.docs/raw/reference/processors/system-prompt-scrubber.mdx +2 -2
  90. package/.docs/raw/reference/processors/tool-call-filter.mdx +125 -0
  91. package/.docs/raw/reference/processors/working-memory-processor.mdx +221 -0
  92. package/.docs/raw/reference/storage/cloudflare-d1.mdx +37 -0
  93. package/.docs/raw/reference/storage/convex.mdx +164 -0
  94. package/.docs/raw/reference/storage/lance.mdx +33 -0
  95. package/.docs/raw/reference/storage/libsql.mdx +37 -0
  96. package/.docs/raw/reference/storage/mongodb.mdx +39 -0
  97. package/.docs/raw/reference/storage/mssql.mdx +37 -0
  98. package/.docs/raw/reference/storage/postgresql.mdx +37 -0
  99. package/.docs/raw/reference/streaming/ChunkType.mdx +1 -1
  100. package/.docs/raw/reference/streaming/agents/stream.mdx +56 -1
  101. package/.docs/raw/reference/streaming/workflows/observeStream.mdx +7 -9
  102. package/.docs/raw/reference/streaming/workflows/{resumeStreamVNext.mdx → resumeStream.mdx} +51 -11
  103. package/.docs/raw/reference/streaming/workflows/stream.mdx +83 -24
  104. package/.docs/raw/reference/tools/mcp-client.mdx +74 -17
  105. package/.docs/raw/reference/vectors/convex.mdx +429 -0
  106. package/.docs/raw/reference/vectors/duckdb.mdx +462 -0
  107. package/.docs/raw/reference/vectors/elasticsearch.mdx +310 -0
  108. package/.docs/raw/reference/voice/google.mdx +159 -20
  109. package/.docs/raw/reference/workflows/run-methods/restart.mdx +142 -0
  110. package/.docs/raw/reference/workflows/run-methods/resume.mdx +44 -0
  111. package/.docs/raw/reference/workflows/run-methods/start.mdx +44 -0
  112. package/.docs/raw/reference/workflows/run.mdx +13 -5
  113. package/.docs/raw/reference/workflows/step.mdx +13 -0
  114. package/.docs/raw/reference/workflows/workflow.mdx +19 -0
  115. package/.docs/raw/server-db/mastra-server.mdx +30 -1
  116. package/.docs/raw/server-db/request-context.mdx +0 -1
  117. package/.docs/raw/server-db/storage.mdx +11 -0
  118. package/.docs/raw/streaming/overview.mdx +6 -6
  119. package/.docs/raw/streaming/tool-streaming.mdx +2 -2
  120. package/.docs/raw/streaming/workflow-streaming.mdx +5 -11
  121. package/.docs/raw/workflows/error-handling.mdx +1 -0
  122. package/.docs/raw/workflows/human-in-the-loop.mdx +4 -4
  123. package/.docs/raw/workflows/overview.mdx +56 -44
  124. package/.docs/raw/workflows/snapshots.mdx +1 -0
  125. package/.docs/raw/workflows/suspend-and-resume.mdx +85 -16
  126. package/.docs/raw/workflows/time-travel.mdx +313 -0
  127. package/.docs/raw/workflows/workflow-state.mdx +191 -0
  128. package/CHANGELOG.md +8 -0
  129. package/package.json +4 -4
  130. package/.docs/raw/agents/human-in-the-loop-with-tools.mdx +0 -91
  131. package/.docs/raw/reference/streaming/workflows/observeStreamVNext.mdx +0 -47
  132. package/.docs/raw/reference/streaming/workflows/streamVNext.mdx +0 -153
@@ -0,0 +1,150 @@
1
+ ---
2
+ title: "Reference: OtelBridge | Observability"
3
+ description: OpenTelemetry bridge for Tracing
4
+ ---
5
+
6
+ import PropertiesTable from "@site/src/components/PropertiesTable";
7
+
8
+ # OtelBridge
9
+
10
+ :::warning
11
+
12
+ The OpenTelemetry Bridge is currently **experimental**. APIs and configuration options may change in future releases.
13
+
14
+ :::
15
+
16
+ Enables bidirectional integration between Mastra tracing and OpenTelemetry infrastructure. Creates native OTEL spans for Mastra operations and inherits context from active OTEL spans.
17
+
18
+ ## Constructor
19
+
20
+ ```typescript
21
+ new OtelBridge()
22
+ ```
23
+
24
+ ## Methods
25
+
26
+ ### executeInContext
27
+
28
+ ```typescript
29
+ executeInContext<T>(spanId: string, fn: () => Promise<T>): Promise<T>
30
+ ```
31
+
32
+ Executes an async function within the OTEL context of a Mastra span. OTEL-instrumented code running inside the function will have correct parent relationships.
33
+
34
+ <PropertiesTable
35
+ props={[
36
+ {
37
+ name: "spanId",
38
+ type: "string",
39
+ description: "The ID of the Mastra span to use as context",
40
+ required: true,
41
+ },
42
+ {
43
+ name: "fn",
44
+ type: "() => Promise<T>",
45
+ description: "The async function to execute within the span context",
46
+ required: true,
47
+ },
48
+ ]}
49
+ />
50
+
51
+ **Returns:** `Promise<T>` - The result of the function execution.
52
+
53
+ ### executeInContextSync
54
+
55
+ ```typescript
56
+ executeInContextSync<T>(spanId: string, fn: () => T): T
57
+ ```
58
+
59
+ Executes a synchronous function within the OTEL context of a Mastra span.
60
+
61
+ <PropertiesTable
62
+ props={[
63
+ {
64
+ name: "spanId",
65
+ type: "string",
66
+ description: "The ID of the Mastra span to use as context",
67
+ required: true,
68
+ },
69
+ {
70
+ name: "fn",
71
+ type: "() => T",
72
+ description: "The synchronous function to execute within the span context",
73
+ required: true,
74
+ },
75
+ ]}
76
+ />
77
+
78
+ **Returns:** `T` - The result of the function execution.
79
+
80
+ ### shutdown
81
+
82
+ ```typescript
83
+ async shutdown(): Promise<void>
84
+ ```
85
+
86
+ Shuts down the bridge and cleans up resources. Ends any spans that were not properly closed.
87
+
88
+ ## Usage Examples
89
+
90
+ ### Basic Usage
91
+
92
+ ```typescript
93
+ import { Mastra } from "@mastra/core";
94
+ import { Observability } from "@mastra/observability";
95
+ import { OtelBridge } from "@mastra/otel-bridge";
96
+
97
+ const mastra = new Mastra({
98
+ observability: new Observability({
99
+ configs: {
100
+ default: {
101
+ serviceName: "my-service",
102
+ bridge: new OtelBridge(),
103
+ },
104
+ },
105
+ }),
106
+ agents: { myAgent },
107
+ });
108
+ ```
109
+
110
+ ### Combined with Exporters
111
+
112
+ The bridge can be used alongside exporters. The bridge handles OTEL context, while exporters send data to additional destinations:
113
+
114
+ ```typescript
115
+ import { Mastra } from "@mastra/core";
116
+ import { Observability, DefaultExporter } from "@mastra/observability";
117
+ import { OtelBridge } from "@mastra/otel-bridge";
118
+ import { LangfuseExporter } from "@mastra/langfuse";
119
+
120
+ const mastra = new Mastra({
121
+ observability: new Observability({
122
+ configs: {
123
+ default: {
124
+ serviceName: "my-service",
125
+ bridge: new OtelBridge(), // Handles OTEL context
126
+ exporters: [
127
+ new DefaultExporter(), // Studio access
128
+ new LangfuseExporter({
129
+ // Additional destination
130
+ publicKey: process.env.LANGFUSE_PUBLIC_KEY,
131
+ secretKey: process.env.LANGFUSE_SECRET_KEY,
132
+ }),
133
+ ],
134
+ },
135
+ },
136
+ }),
137
+ });
138
+ ```
139
+
140
+ ## OpenTelemetry Setup Requirements
141
+
142
+ The OtelBridge requires an active OpenTelemetry SDK to function. The bridge reads from OTEL's ambient context.
143
+
144
+ See the [OtelBridge Guide](/docs/v1/observability/tracing/bridges/otel#configuration) for complete setup instructions, including how to configure OTEL instrumentation and run your application.
145
+
146
+ ## Related
147
+
148
+ - [OtelBridge Guide](/docs/v1/observability/tracing/bridges/otel) - Setup guide with examples
149
+ - [Tracing Overview](/docs/v1/observability/tracing/overview) - General tracing concepts
150
+ - [OtelExporter Reference](/reference/v1/observability/tracing/exporters/otel) - OTEL exporter for sending traces
@@ -232,10 +232,6 @@ Shuts down all observability instances and clears the registry.
232
232
  - [Interfaces](/reference/v1/observability/tracing/interfaces) - Type definitions
233
233
  - [Spans Reference](/reference/v1/observability/tracing/spans) - Span lifecycle
234
234
 
235
- ### Examples
236
-
237
- - [Basic Tracing](/examples/v1/observability/basic-ai-tracing) - Getting started
238
-
239
235
  ### Exporters
240
236
 
241
237
  - [DefaultExporter](/reference/v1/observability/tracing/exporters/default-exporter) - Storage configuration
@@ -38,6 +38,10 @@ Inherits from `OtelExporterConfig` (excluding `provider`), which includes:
38
38
  - `logLevel?: LogLevel | 'debug' | 'info' | 'warn' | 'error'` - Log level (default: WARN)
39
39
  - `resourceAttributes?: Record<string, any>` - Custom resource attributes
40
40
 
41
+ ### Metadata passthrough
42
+
43
+ Non-reserved span attributes are serialized into the OpenInference `metadata` payload. Add them via `tracingOptions.metadata` (e.g., `companyId`, `tier`). Reserved fields such as `input`, `output`, `sessionId`, thread/user IDs, and OpenInference IDs are excluded automatically.
44
+
41
45
  <PropertiesTable
42
46
  props={[
43
47
  {
@@ -20,6 +20,7 @@ new LangSmithExporter(config: LangSmithExporterConfig)
20
20
  ```typescript
21
21
  interface LangSmithExporterConfig extends ClientConfig, BaseExporterConfig {
22
22
  client?: Client;
23
+ projectName?: string;
23
24
  }
24
25
  ```
25
26
 
@@ -32,7 +33,13 @@ Extends both `ClientConfig` (from LangSmith SDK) and `BaseExporterConfig`:
32
33
  {
33
34
  name: "apiKey",
34
35
  type: "string",
35
- description: "LangSmith API key",
36
+ description: "LangSmith API key. Defaults to LANGSMITH_API_KEY env var.",
37
+ required: false,
38
+ },
39
+ {
40
+ name: "projectName",
41
+ type: "string",
42
+ description: "The LangSmith project to send traces to. Overrides LANGCHAIN_PROJECT env var. Defaults to 'default'.",
36
43
  required: false,
37
44
  },
38
45
  {
@@ -99,11 +106,20 @@ import { LangSmithExporter } from "@mastra/langsmith";
99
106
 
100
107
  const exporter = new LangSmithExporter({
101
108
  apiKey: process.env.LANGSMITH_API_KEY,
109
+ projectName: "my-project", // Optional: specify which project to send traces to
102
110
  apiUrl: "https://api.smith.langchain.com",
103
111
  logLevel: "info",
104
112
  });
105
113
  ```
106
114
 
115
+ ## Environment Variables
116
+
117
+ | Variable | Description |
118
+ |----------|-------------|
119
+ | `LANGSMITH_API_KEY` | Your LangSmith API key |
120
+ | `LANGCHAIN_PROJECT` | Default project name for traces (used if `projectName` not specified) |
121
+ | `LANGSMITH_BASE_URL` | API URL for self-hosted instances |
122
+
107
123
  ## Span Type Mapping
108
124
 
109
125
  | Span Type | LangSmith Type |
@@ -367,3 +367,9 @@ The exporter preserves span hierarchy from Mastra's Tracing:
367
367
  - Uses `parentSpanId` directly from Mastra spans
368
368
  - Maintains correct nesting for agents, workflows, LLM calls, and tools
369
369
  - Exports complete traces with all relationships intact
370
+
371
+ ## Related
372
+
373
+ - [OtelExporter Guide](/docs/v1/observability/tracing/exporters/otel) - Setup guide with provider configurations
374
+ - [OtelBridge](/docs/v1/observability/tracing/bridges/otel) - For bidirectional OTEL context integration
375
+ - [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
  ]