@mastra/mcp-docs-server 1.1.35-alpha.3 → 1.1.35-alpha.30

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 (120) hide show
  1. package/.docs/course/03-agent-memory/18-advanced-configuration-semantic-recall.md +48 -4
  2. package/.docs/docs/agents/background-tasks.md +62 -2
  3. package/.docs/docs/agents/processors.md +35 -3
  4. package/.docs/docs/agents/response-caching.md +148 -0
  5. package/.docs/docs/agents/signals.md +151 -0
  6. package/.docs/docs/agents/using-tools.md +8 -0
  7. package/.docs/docs/browser/agent-browser.md +15 -0
  8. package/.docs/docs/browser/stagehand.md +25 -1
  9. package/.docs/docs/editor/tools.md +1 -1
  10. package/.docs/docs/index.md +2 -2
  11. package/.docs/docs/mastra-platform/configuration.md +1 -1
  12. package/.docs/docs/mastra-platform/overview.md +1 -1
  13. package/.docs/docs/memory/observational-memory.md +63 -14
  14. package/.docs/docs/memory/overview.md +2 -1
  15. package/.docs/docs/memory/semantic-recall.md +68 -6
  16. package/.docs/docs/observability/logging.md +2 -2
  17. package/.docs/docs/observability/metrics/overview.md +4 -4
  18. package/.docs/docs/observability/overview.md +6 -6
  19. package/.docs/docs/observability/tracing/bridges/otel.md +25 -0
  20. package/.docs/docs/observability/tracing/exporters/arize.md +5 -5
  21. package/.docs/docs/observability/tracing/exporters/braintrust.md +37 -0
  22. package/.docs/docs/observability/tracing/exporters/langfuse.md +21 -0
  23. package/.docs/docs/observability/tracing/exporters/{cloud.md → mastra-platform.md} +28 -26
  24. package/.docs/docs/observability/tracing/exporters/{default.md → mastra-storage.md} +56 -19
  25. package/.docs/docs/observability/tracing/exporters/otel.md +79 -2
  26. package/.docs/docs/observability/tracing/overview.md +30 -29
  27. package/.docs/docs/observability/tracing/processors/sensitive-data-filter.md +6 -6
  28. package/.docs/docs/server/mastra-server.md +30 -19
  29. package/.docs/docs/studio/observability.md +4 -4
  30. package/.docs/docs/studio/overview.md +6 -0
  31. package/.docs/docs/voice/overview.md +84 -0
  32. package/.docs/docs/workflows/suspend-and-resume.md +28 -1
  33. package/.docs/guides/deployment/inngest.md +23 -0
  34. package/.docs/guides/guide/web-search.md +7 -7
  35. package/.docs/guides/migrations/mastra-cloud.md +6 -6
  36. package/.docs/guides/migrations/upgrade-to-v1/tracing.md +19 -17
  37. package/.docs/models/gateways/azure-openai.md +94 -23
  38. package/.docs/models/gateways/netlify.md +2 -1
  39. package/.docs/models/gateways/openrouter.md +4 -1
  40. package/.docs/models/gateways/vercel.md +2 -1
  41. package/.docs/models/index.md +1 -1
  42. package/.docs/models/providers/chutes.md +23 -54
  43. package/.docs/models/providers/databricks.md +96 -0
  44. package/.docs/models/providers/deepseek.md +3 -1
  45. package/.docs/models/providers/digitalocean.md +9 -2
  46. package/.docs/models/providers/firepass.md +71 -0
  47. package/.docs/models/providers/google.md +3 -2
  48. package/.docs/models/providers/kilo.md +5 -3
  49. package/.docs/models/providers/kiro.md +110 -0
  50. package/.docs/models/providers/llmgateway.md +8 -2
  51. package/.docs/models/providers/nebius.md +37 -55
  52. package/.docs/models/providers/novita-ai.md +5 -5
  53. package/.docs/models/providers/nvidia.md +59 -49
  54. package/.docs/models/providers/ollama-cloud.md +1 -1
  55. package/.docs/models/providers/openai.md +2 -0
  56. package/.docs/models/providers/opencode-go.md +2 -4
  57. package/.docs/models/providers/opencode.md +44 -43
  58. package/.docs/models/providers/poe.md +4 -1
  59. package/.docs/models/providers/qiniu-ai.md +2 -2
  60. package/.docs/models/providers/sarvam.md +72 -0
  61. package/.docs/models/providers/wafer.ai.md +2 -1
  62. package/.docs/models/providers/xiaomi-token-plan-ams.md +6 -5
  63. package/.docs/models/providers/xiaomi-token-plan-cn.md +6 -5
  64. package/.docs/models/providers/xiaomi-token-plan-sgp.md +6 -5
  65. package/.docs/models/providers/xiaomi.md +2 -2
  66. package/.docs/models/providers/zenmux.md +1 -1
  67. package/.docs/models/providers.md +3 -0
  68. package/.docs/reference/agents/agent.md +85 -0
  69. package/.docs/reference/browser/agent-browser.md +37 -11
  70. package/.docs/reference/browser/stagehand-browser.md +35 -9
  71. package/.docs/reference/cli/mastra.md +497 -1
  72. package/.docs/reference/client-js/agents.md +115 -1
  73. package/.docs/reference/client-js/responses.md +4 -0
  74. package/.docs/reference/configuration.md +6 -6
  75. package/.docs/reference/editor/tool-provider.md +3 -3
  76. package/.docs/reference/harness/harness-class.md +23 -8
  77. package/.docs/reference/index.md +6 -0
  78. package/.docs/reference/memory/observational-memory.md +11 -1
  79. package/.docs/reference/observability/metrics/automatic-metrics.md +2 -4
  80. package/.docs/reference/observability/tracing/bridges/datadog.md +2 -2
  81. package/.docs/reference/observability/tracing/bridges/otel.md +26 -4
  82. package/.docs/reference/observability/tracing/configuration.md +6 -3
  83. package/.docs/reference/observability/tracing/exporters/arize.md +1 -1
  84. package/.docs/reference/observability/tracing/exporters/braintrust.md +2 -0
  85. package/.docs/reference/observability/tracing/exporters/cloud-exporter.md +3 -1
  86. package/.docs/reference/observability/tracing/exporters/console-exporter.md +2 -2
  87. package/.docs/reference/observability/tracing/exporters/default-exporter.md +7 -1
  88. package/.docs/reference/observability/tracing/exporters/mastra-platform-exporter.md +263 -0
  89. package/.docs/reference/observability/tracing/exporters/mastra-storage-exporter.md +194 -0
  90. package/.docs/reference/observability/tracing/exporters/otel.md +12 -8
  91. package/.docs/reference/observability/tracing/instances.md +2 -2
  92. package/.docs/reference/observability/tracing/interfaces.md +37 -2
  93. package/.docs/reference/observability/tracing/processors/sensitive-data-filter.md +22 -0
  94. package/.docs/reference/observability/tracing/span-filtering.md +2 -2
  95. package/.docs/reference/processors/prefill-error-handler.md +3 -3
  96. package/.docs/reference/processors/processor-interface.md +74 -12
  97. package/.docs/reference/processors/provider-history-compat.md +132 -0
  98. package/.docs/reference/processors/response-cache.md +114 -0
  99. package/.docs/reference/processors/tool-call-filter.md +28 -0
  100. package/.docs/reference/storage/clickhouse.md +8 -8
  101. package/.docs/reference/storage/cloudflare-d1.md +1 -1
  102. package/.docs/reference/storage/cloudflare.md +1 -1
  103. package/.docs/reference/storage/composite.md +1 -1
  104. package/.docs/reference/storage/convex.md +1 -1
  105. package/.docs/reference/storage/dsql.md +428 -0
  106. package/.docs/reference/storage/duckdb.md +3 -3
  107. package/.docs/reference/storage/dynamodb.md +1 -1
  108. package/.docs/reference/storage/lance.md +1 -1
  109. package/.docs/reference/storage/libsql.md +1 -1
  110. package/.docs/reference/storage/postgresql.md +1 -1
  111. package/.docs/reference/storage/upstash.md +1 -1
  112. package/.docs/reference/streaming/ChunkType.md +44 -0
  113. package/.docs/reference/streaming/agents/stream.md +18 -2
  114. package/.docs/reference/tools/brightdata.md +167 -0
  115. package/.docs/reference/tools/create-tool.md +46 -0
  116. package/.docs/reference/tools/mcp-client.md +47 -0
  117. package/.docs/reference/voice/inworld.md +133 -0
  118. package/.docs/reference/workflows/workflow-state-reader.md +113 -0
  119. package/CHANGELOG.md +120 -0
  120. package/package.json +4 -4
@@ -0,0 +1,194 @@
1
+ # MastraStorageExporter
2
+
3
+ Persists traces to Mastra's configured storage with automatic batching and retry logic.
4
+
5
+ > **Note:** `MastraStorageExporter` was previously called `DefaultExporter`. The original `DefaultExporter` class is still exported from `@mastra/observability` so existing imports keep working, but it is deprecated and will be removed in a future major version. New code should use `MastraStorageExporter`.
6
+
7
+ ## Constructor
8
+
9
+ ```typescript
10
+ new MastraStorageExporter(config?: MastraStorageExporterConfig)
11
+ ```
12
+
13
+ ## `MastraStorageExporterConfig`
14
+
15
+ ```typescript
16
+ interface MastraStorageExporterConfig extends BaseExporterConfig {
17
+ /** Maximum number of spans per batch. Default: 1000 */
18
+ maxBatchSize?: number
19
+
20
+ /** Maximum total buffer size before emergency flush. Default: 10000 */
21
+ maxBufferSize?: number
22
+
23
+ /** Maximum time to wait before flushing batch in milliseconds. Default: 5000 */
24
+ maxBatchWaitMs?: number
25
+
26
+ /** Maximum number of retry attempts. Default: 4 */
27
+ maxRetries?: number
28
+
29
+ /** Base retry delay in milliseconds (uses exponential backoff). Default: 500 */
30
+ retryDelayMs?: number
31
+
32
+ /** Tracing storage strategy or 'auto' for automatic selection. Default: 'auto' */
33
+ strategy?: TracingStorageStrategy | 'auto'
34
+ }
35
+ ```
36
+
37
+ Extends `BaseExporterConfig`, which includes:
38
+
39
+ - `logger?: IMastraLogger` - Logger instance
40
+ - `logLevel?: LogLevel | 'debug' | 'info' | 'warn' | 'error'` - Log level (default: INFO)
41
+
42
+ ## `TracingStorageStrategy`
43
+
44
+ ```typescript
45
+ type TracingStorageStrategy = 'realtime' | 'batch-with-updates' | 'insert-only'
46
+ ```
47
+
48
+ ### Strategy Behaviors
49
+
50
+ - **realtime**: Immediately persists each event to storage
51
+ - **batch-with-updates**: Batches creates and updates separately, applies in order
52
+ - **insert-only**: Only processes SPAN\_ENDED events, ignores updates
53
+
54
+ ## Properties
55
+
56
+ ```typescript
57
+ readonly name = 'mastra-storage-exporter';
58
+ ```
59
+
60
+ The deprecated `DefaultExporter` class continues to use `'mastra-default-observability-exporter'` as its `name` for backward compatibility.
61
+
62
+ ## Methods
63
+
64
+ ### init
65
+
66
+ ```typescript
67
+ init(options: InitExporterOptions): void
68
+ ```
69
+
70
+ Initializes the exporter after dependencies are ready. Resolves tracing strategy based on storage capabilities.
71
+
72
+ ### `exportTracingEvent`
73
+
74
+ ```typescript
75
+ async exportTracingEvent(event: TracingEvent): Promise<void>
76
+ ```
77
+
78
+ Processes a tracing event according to the resolved strategy.
79
+
80
+ ### flush
81
+
82
+ ```typescript
83
+ async flush(): Promise<void>
84
+ ```
85
+
86
+ Force flushes any buffered events to storage without shutting down the exporter. Useful in serverless environments where you need to ensure spans are exported before the runtime terminates.
87
+
88
+ ### shutdown
89
+
90
+ ```typescript
91
+ async shutdown(): Promise<void>
92
+ ```
93
+
94
+ Flushes remaining buffered events and performs cleanup.
95
+
96
+ ## Automatic strategy selection
97
+
98
+ When `strategy: 'auto'` (default), the exporter queries the storage adapter for its capabilities:
99
+
100
+ ```typescript
101
+ interface TracingStrategy {
102
+ /** Strategies supported by this adapter */
103
+ supported: TracingStorageStrategy[]
104
+
105
+ /** Preferred strategy for optimal performance */
106
+ preferred: TracingStorageStrategy
107
+ }
108
+ ```
109
+
110
+ The exporter will:
111
+
112
+ 1. Use the storage adapter's preferred strategy if available
113
+ 2. Fall back to the first supported strategy if preferred isn't available
114
+ 3. Log a warning if a user-specified strategy isn't supported
115
+
116
+ ## Batching behavior
117
+
118
+ ### Flush Triggers
119
+
120
+ The buffer flushes when any of these conditions are met:
121
+
122
+ - Buffer size reaches `maxBatchSize`
123
+ - Time since first buffered event exceeds `maxBatchWaitMs`
124
+ - Buffer size reaches `maxBufferSize` (emergency flush)
125
+ - `shutdown()` is called
126
+
127
+ ### Retry Logic
128
+
129
+ Failed flushes are retried with exponential backoff:
130
+
131
+ - Retry delay: `retryDelayMs * 2^attempt`
132
+ - Maximum attempts: `maxRetries`
133
+ - Batch is dropped after all retries fail
134
+
135
+ ### Out-of-Order Handling
136
+
137
+ For `batch-with-updates` strategy:
138
+
139
+ - Tracks which spans have been created
140
+ - Rejects updates/ends for spans not yet created
141
+ - Logs warnings for out-of-order events
142
+ - Maintains sequence numbers for ordered updates
143
+
144
+ ## Usage
145
+
146
+ ```typescript
147
+ import { MastraStorageExporter } from '@mastra/observability'
148
+
149
+ // Default configuration
150
+ const exporter = new MastraStorageExporter()
151
+
152
+ // Custom batching configuration
153
+ const customExporter = new MastraStorageExporter({
154
+ maxBatchSize: 500,
155
+ maxBatchWaitMs: 2000,
156
+ strategy: 'batch-with-updates',
157
+ logLevel: 'debug',
158
+ })
159
+ ```
160
+
161
+ ## Migrating from `DefaultExporter`
162
+
163
+ The two classes share the same constructor signature and behavior. To migrate, replace the import and constructor:
164
+
165
+ ```typescript
166
+ // Before
167
+ import { DefaultExporter } from '@mastra/observability'
168
+ const exporter = new DefaultExporter()
169
+
170
+ // After
171
+ import { MastraStorageExporter } from '@mastra/observability'
172
+ const exporter = new MastraStorageExporter()
173
+ ```
174
+
175
+ The original `DefaultExporter` is preserved unchanged so dashboards or alert rules that match the previous `mastra-default-observability-exporter` exporter name keep working until you migrate.
176
+
177
+ ## See also
178
+
179
+ ### Documentation
180
+
181
+ - [Tracing Overview](https://mastra.ai/docs/observability/tracing/overview): Complete guide
182
+ - [Exporters](https://mastra.ai/docs/observability/tracing/overview): Exporter concepts
183
+
184
+ ### Other Exporters
185
+
186
+ - [MastraPlatformExporter](https://mastra.ai/reference/observability/tracing/exporters/mastra-platform-exporter): Mastra platform
187
+ - [ConsoleExporter](https://mastra.ai/reference/observability/tracing/exporters/console-exporter): Debug output
188
+ - [Langfuse](https://mastra.ai/reference/observability/tracing/exporters/langfuse): Langfuse integration
189
+ - [Braintrust](https://mastra.ai/reference/observability/tracing/exporters/braintrust): Braintrust integration
190
+
191
+ ### Reference
192
+
193
+ - [Configuration](https://mastra.ai/reference/observability/tracing/configuration): Configuration options
194
+ - [Interfaces](https://mastra.ai/reference/observability/tracing/interfaces): Type definitions
@@ -1,6 +1,6 @@
1
1
  # OtelExporter
2
2
 
3
- Sends Tracing data to any OpenTelemetry-compatible observability platform using standardized GenAI semantic conventions.
3
+ Sends traces and logs to any OpenTelemetry-compatible observability platform. Traces use the standardized GenAI semantic conventions; logs carry their original severity and message body and are correlated to traces via both the OTEL log record's native trace context and `mastra.traceId` / `mastra.spanId` attributes.
4
4
 
5
5
  ## Constructor
6
6
 
@@ -13,6 +13,10 @@ new OtelExporter(config: OtelExporterConfig)
13
13
  ```typescript
14
14
  interface OtelExporterConfig {
15
15
  provider?: ProviderConfig
16
+ signals?: {
17
+ traces?: boolean
18
+ logs?: boolean
19
+ }
16
20
  timeout?: number
17
21
  batchSize?: number
18
22
  logLevel?: 'debug' | 'info' | 'warn' | 'error'
@@ -157,14 +161,14 @@ const exporter = new OtelExporter({
157
161
 
158
162
  ## Protocol requirements
159
163
 
160
- Different providers require different OTEL exporter packages:
164
+ Different providers require different OTEL exporter packages. Trace and log export are independent: install only the trace package if you only need traces, or install both the trace and log packages for the chosen protocol if you also want log export. Zipkin does not support OTLP logs.
161
165
 
162
- | Protocol | Required Package | Providers |
163
- | ------------- | ------------------------------------------ | -------------------------- |
164
- | gRPC | `@opentelemetry/exporter-trace-otlp-grpc` | Dash0 |
165
- | HTTP/Protobuf | `@opentelemetry/exporter-trace-otlp-proto` | SigNoz, New Relic, Laminar |
166
- | HTTP/JSON | `@opentelemetry/exporter-trace-otlp-http` | Traceloop, Custom |
167
- | Zipkin | `@opentelemetry/exporter-zipkin` | Zipkin collectors |
166
+ | Protocol | Trace package | Log package |
167
+ | ------------- | ------------------------------------------------------------- | ------------------------------------------------------------ |
168
+ | gRPC | `@opentelemetry/exporter-trace-otlp-grpc` (+ `@grpc/grpc-js`) | `@opentelemetry/exporter-logs-otlp-grpc` (+ `@grpc/grpc-js`) |
169
+ | HTTP/Protobuf | `@opentelemetry/exporter-trace-otlp-proto` | `@opentelemetry/exporter-logs-otlp-proto` |
170
+ | HTTP/JSON | `@opentelemetry/exporter-trace-otlp-http` | `@opentelemetry/exporter-logs-otlp-http` |
171
+ | Zipkin | `@opentelemetry/exporter-zipkin` | not supported |
168
172
 
169
173
  ## Tags support
170
174
 
@@ -102,6 +102,6 @@ class CustomObservabilityInstance extends BaseObservabilityInstance {
102
102
 
103
103
  ### Exporters
104
104
 
105
- - [DefaultExporter](https://mastra.ai/reference/observability/tracing/exporters/default-exporter): Storage persistence
106
- - [CloudExporter](https://mastra.ai/reference/observability/tracing/exporters/cloud-exporter): Mastra platform integration
105
+ - [MastraStorageExporter](https://mastra.ai/reference/observability/tracing/exporters/mastra-storage-exporter): Storage persistence
106
+ - [MastraPlatformExporter](https://mastra.ai/reference/observability/tracing/exporters/mastra-platform-exporter): Mastra platform integration
107
107
  - [ConsoleExporter](https://mastra.ai/reference/observability/tracing/exporters/console-exporter): Debug output
@@ -141,10 +141,18 @@ interface ObservabilityExporter {
141
141
  /** Handle feedback events */
142
142
  onFeedbackEvent?(event: FeedbackEvent): void | Promise<void>
143
143
 
144
+ /** Handle exporter pipeline droppedEvent */
145
+ onDroppedEvent?(event: ObservabilityDropEvent): void | Promise<void>
146
+
144
147
  /** Export tracing events */
145
148
  exportTracingEvent(event: TracingEvent): Promise<void>
146
149
 
147
- /** Add score to a trace (optional) */
150
+ /**
151
+ * @deprecated Implement `onScoreEvent` instead. Eval scores now flow through the
152
+ * unified observability bus as `ScoreEvent`s. This method is preserved on the
153
+ * interface for backwards compatibility with existing exporters; new exporters
154
+ * should not implement it.
155
+ */
148
156
  addScoreToTrace?({
149
157
  traceId,
150
158
  spanId,
@@ -169,7 +177,34 @@ interface ObservabilityExporter {
169
177
  }
170
178
  ```
171
179
 
172
- Event callback payloads use observability event bus envelopes: `TracingEvent` carries span lifecycle events with `exportedSpan`, `LogEvent` wraps `ExportedLog` in `log`, `MetricEvent` wraps `ExportedMetric` in `metric`, `ScoreEvent` wraps `ExportedScore` in `score`, and `FeedbackEvent` wraps `ExportedFeedback` in `feedback`. For Cloud exporter behavior for these callbacks, see [CloudExporter](https://mastra.ai/reference/observability/tracing/exporters/cloud-exporter).
180
+ Event callback payloads use observability event bus envelopes: `TracingEvent` carries span lifecycle events with `exportedSpan`, `LogEvent` wraps `ExportedLog` in `log`, `MetricEvent` wraps `ExportedMetric` in `metric`, `ScoreEvent` wraps `ExportedScore` in `score`, and `FeedbackEvent` wraps `ExportedFeedback` in `feedback`. For Mastra Platform exporter behavior for these callbacks, see [MastraPlatformExporter](https://mastra.ai/reference/observability/tracing/exporters/mastra-platform-exporter).
181
+
182
+ ### `ObservabilityDropEvent`
183
+
184
+ Structured event emitted when the exporter pipeline drops observability events.
185
+
186
+ ```typescript
187
+ type ObservabilityDropSignal = 'tracing' | 'log' | 'metric' | 'score' | 'feedback'
188
+
189
+ type ObservabilityDropReason = 'unsupported-storage' | 'retry-exhausted'
190
+
191
+ interface ObservabilityDropEvent {
192
+ type: 'drop'
193
+ signal: ObservabilityDropSignal
194
+ reason: ObservabilityDropReason
195
+ count: number
196
+ timestamp: Date
197
+ exporterName: string
198
+ storageName?: string
199
+ error?: {
200
+ id?: string
201
+ domain?: string
202
+ message: string
203
+ }
204
+ }
205
+ ```
206
+
207
+ Use `onDroppedEvent` on a custom exporter or bridge to forward these events to external metrics or alerting systems.
173
208
 
174
209
  ### `SpanOutputProcessor`
175
210
 
@@ -2,6 +2,28 @@
2
2
 
3
3
  A SpanOutputProcessor that redacts sensitive information from span fields.
4
4
 
5
+ ## Auto-applied by default
6
+
7
+ `Observability` automatically appends a `SensitiveDataFilter` to every configured instance's `spanOutputProcessors` so secrets are redacted before they reach exporters such as the Mastra cloud exporter. The filter runs last (after any user-provided processors) so that sensitive data introduced or surfaced by upstream processors is still redacted. You do not need to add it manually unless you want to customize its options.
8
+
9
+ To opt out or customize the auto-applied filter, use the `sensitiveDataFilter` option on the [`Observability` registry config](https://mastra.ai/reference/observability/tracing/configuration):
10
+
11
+ ```typescript
12
+ import { Observability } from '@mastra/observability'
13
+
14
+ new Observability({
15
+ configs: {
16
+ /* ... */
17
+ },
18
+ // disable the auto-applied filter
19
+ sensitiveDataFilter: false,
20
+ // or customize it
21
+ // sensitiveDataFilter: { sensitiveFields: ['mySecret'], redactionStyle: 'partial' },
22
+ })
23
+ ```
24
+
25
+ If a config already includes a `SensitiveDataFilter` in `spanOutputProcessors`, the auto-applied filter is skipped to avoid double redaction. Pre-instantiated `ObservabilityInstance` values are not modified — add a `SensitiveDataFilter` to their processors yourself if needed.
26
+
5
27
  ## Constructor
6
28
 
7
29
  ```typescript
@@ -11,7 +11,7 @@ The following example demonstrates how to combine `excludeSpanTypes` and `spanFi
11
11
  ```ts
12
12
  import { Mastra } from '@mastra/core'
13
13
  import { SpanType } from '@mastra/core/observability'
14
- import { Observability, DefaultExporter } from '@mastra/observability'
14
+ import { Observability, MastraStorageExporter } from '@mastra/observability'
15
15
  import { LangfuseExporter } from '@mastra/langfuse'
16
16
 
17
17
  export const mastra = new Mastra({
@@ -19,7 +19,7 @@ export const mastra = new Mastra({
19
19
  configs: {
20
20
  default: {
21
21
  serviceName: 'my-app',
22
- exporters: [new DefaultExporter(), new LangfuseExporter()],
22
+ exporters: [new MastraStorageExporter(), new LangfuseExporter()],
23
23
  excludeSpanTypes: [SpanType.MODEL_CHUNK, SpanType.MODEL_STEP],
24
24
  spanFilter: span => {
25
25
  if (span.type === SpanType.TOOL_CALL && span.attributes?.success) {
@@ -2,7 +2,7 @@
2
2
 
3
3
  The `PrefillErrorHandler` is an **error processor** that handles assistant-response prefill errors. This error occurs when a conversation ends with an assistant message and the model rejects the request because it interprets it as prefilling the assistant response.
4
4
 
5
- When the error is detected, the processor appends a hidden `<system-reminder>continue</system-reminder>` user message to the conversation and signals a retry. The reminder is persisted with `metadata.systemReminder = { type: 'anthropic-prefill-processor-retry' }`, which keeps it available for retry reconstruction and raw history while standard UI-facing message conversions hide it.
5
+ When the error is detected, the processor sends a hidden `system-reminder` signal with `continue` as its contents and signals a retry. The reminder is persisted as signal metadata, which keeps it available for retry reconstruction and raw history while standard UI-facing message conversions hide it.
6
6
 
7
7
  Add this processor to `errorProcessors` when you want Mastra to recover from assistant prefill rejections (for example Anthropic's "assistant message prefill" and Qwen/llama.cpp's "assistant response prefill is incompatible with `enable_thinking`" errors).
8
8
 
@@ -10,7 +10,7 @@ Add this processor to `errorProcessors` when you want Mastra to recover from ass
10
10
 
11
11
  1. The LLM API call fails with a known assistant-prefill rejection message
12
12
  2. `PrefillErrorHandler` checks that this is the first retry attempt
13
- 3. It appends a hidden `<system-reminder>continue</system-reminder>` user message to the `messageList`
13
+ 3. It sends a hidden `system-reminder` signal with `continue` as its contents
14
14
  4. It returns `{ retry: true }` to signal the LLM call should be retried with the modified messages
15
15
 
16
16
  The processor now reacts to the API rejection itself instead of re-checking whether the conversation currently ends with an assistant message. This makes it resilient to cases where the provider rejects the request for prefill semantics even if the trailing message shape has already been transformed upstream.
@@ -62,7 +62,7 @@ The `PrefillErrorHandler` takes no constructor parameters.
62
62
 
63
63
  **name** (`'Prefill Error Handler'`): Processor display name.
64
64
 
65
- **processAPIError** (`(args: ProcessAPIErrorArgs) => ProcessAPIErrorResult | void`): Handles known assistant-prefill errors by appending a hidden system reminder continue message and signaling retry. Only triggers on the first retry attempt.
65
+ **processAPIError** (`(args: ProcessAPIErrorArgs) => ProcessAPIErrorResult | void`): Handles known assistant-prefill errors by sending a hidden system reminder signal and signaling retry. Only triggers on the first retry attempt.
66
66
 
67
67
  ## Related
68
68
 
@@ -4,7 +4,7 @@ The `Processor` interface defines the contract for all processors in Mastra. Pro
4
4
 
5
5
  ## When processor methods run
6
6
 
7
- The six processor methods run at different points in the agent execution lifecycle:
7
+ The seven processor methods run at different points in the agent execution lifecycle:
8
8
 
9
9
  ```text
10
10
  ┌─────────────────────────────────────────────────────────────────┐
@@ -26,6 +26,11 @@ The six processor methods run at different points in the agent execution lifecyc
26
26
  │ │ └──────────┬──────────┘ │ │
27
27
  │ │ │ │ │
28
28
  │ │ ▼ │ │
29
+ │ │ ┌─────────────────────┐ │ │
30
+ │ │ │ processLLMRequest │ ← Runs before provider call │ │
31
+ │ │ └──────────┬──────────┘ │ │
32
+ │ │ │ │ │
33
+ │ │ ▼ │ │
29
34
  │ │ LLM Execution ──── API Error? ──┐ │ │
30
35
  │ │ │ │ │ │
31
36
  │ │ │ ┌───────────────────┐ │ │
@@ -59,14 +64,15 @@ The six processor methods run at different points in the agent execution lifecyc
59
64
  └─────────────────────────────────────────────────────────────────┘
60
65
  ```
61
66
 
62
- | Method | When it runs | Use case |
63
- | --------------------- | ------------------------------------------------------ | ----------------------------------------------------------------------------- |
64
- | `processInput` | Once at the start, before the agentic loop | Validate/transform initial user input, add context |
65
- | `processInputStep` | At each step of the agentic loop, before each LLM call | Transform messages between steps, handle tool results |
66
- | `processAPIError` | When an LLM API call fails | Inspect API rejections, optionally mutate state/messages, and request a retry |
67
- | `processOutputStream` | On each streaming chunk during LLM response | Filter/modify streaming content, detect patterns in real-time |
68
- | `processOutputStep` | After each LLM response, before tool execution | Validate output quality, implement guardrails with retry |
69
- | `processOutputResult` | Once after generation completes | Post-process final response, log results |
67
+ | Method | When it runs | Use case |
68
+ | --------------------- | ------------------------------------------------------ | -------------------------------------------------------------------------------------------- |
69
+ | `processInput` | Once at the start, before the agentic loop | Validate/transform initial user input, add context |
70
+ | `processInputStep` | At each step of the agentic loop, before each LLM call | Transform messages between steps, handle tool results |
71
+ | `processLLMRequest` | After LLM request conversion, before the provider call | Rewrite the outbound `LanguageModelV2Prompt` for the current call without persisting changes |
72
+ | `processAPIError` | When an LLM API call fails | Inspect API rejections, optionally mutate state/messages, and request a retry |
73
+ | `processOutputStream` | On each streaming chunk during LLM response | Filter/modify streaming content, detect patterns in real-time |
74
+ | `processOutputStep` | After each LLM response, before tool execution | Validate output quality, implement guardrails with retry |
75
+ | `processOutputResult` | Once after generation completes | Post-process final response, log results |
70
76
 
71
77
  ## Interface definition
72
78
 
@@ -97,6 +103,10 @@ interface Processor<TId extends string = string, TTripwireMetadata = unknown> {
97
103
  | void
98
104
  | undefined
99
105
 
106
+ processLLMRequest?(
107
+ args: ProcessLLMRequestArgs<TTripwireMetadata>,
108
+ ): Promise<ProcessLLMRequestResult> | ProcessLLMRequestResult
109
+
100
110
  processAPIError?(
101
111
  args: ProcessAPIErrorArgs<TTripwireMetadata>,
102
112
  ): Promise<ProcessAPIErrorResult | void> | ProcessAPIErrorResult | void
@@ -243,9 +253,10 @@ processInputStep?<TTripwireMetadata = unknown>(
243
253
  1. `processInput` (once at start)
244
254
  2. `processInputStep` from inputProcessors (at each step, before LLM call)
245
255
  3. `prepareStep` callback (runs as part of the processInputStep pipeline, after inputProcessors)
246
- 4. LLM execution
247
- 5. Tool execution (if needed)
248
- 6. Repeat from step 2 if tools were called
256
+ 4. `processLLMRequest` from inputProcessors (after prompt conversion, before the provider call)
257
+ 5. LLM execution
258
+ 6. Tool execution (if needed)
259
+ 7. Repeat from step 2 if tools were called
249
260
 
250
261
  #### `ProcessInputStepArgs`
251
262
 
@@ -339,6 +350,57 @@ System messages are **reset to their original values** at the start of each step
339
350
 
340
351
  ***
341
352
 
353
+ ### `processLLMRequest`
354
+
355
+ Processes the final LLM request after Mastra converts the `MessageList` into `LanguageModelV2Prompt` and before the provider call. Use this method for transient, model-aware rewrites that should affect only the current outbound request.
356
+
357
+ Returned prompt changes are forwarded to the model for the current call only. They are not persisted back to `MessageList`, memory, UI history, or later provider calls.
358
+
359
+ ```typescript
360
+ processLLMRequest?(
361
+ args: ProcessLLMRequestArgs,
362
+ ): Promise<ProcessLLMRequestResult> | ProcessLLMRequestResult;
363
+ ```
364
+
365
+ #### `ProcessLLMRequestArgs`
366
+
367
+ **prompt** (`LanguageModelV2Prompt`): The LLM request prompt that will be sent to the provider for this call.
368
+
369
+ **model** (`MastraLanguageModel`): The resolved model that will receive the prompt. Use this to scope provider-specific rewrites.
370
+
371
+ **stepNumber** (`number`): Current step number (0-indexed). Step 0 is the initial LLM call.
372
+
373
+ **steps** (`StepResult[]`): Results from previous steps, including text, toolCalls, and toolResults.
374
+
375
+ **state** (`Record<string, unknown>`): Per-processor state that persists across all method calls within this request.
376
+
377
+ **abort** (`(reason?: string, options?: { retry?: boolean; metadata?: unknown }) => never`): Function to abort processing. Throws a TripWire error that stops execution and emits a \`tripwire\` chunk.
378
+
379
+ **retryCount** (`number`): Current retry attempt count from \`ProcessorContext\`. Starts at \`0\`; use to cap processor-triggered retries.
380
+
381
+ **requestContext** (`RequestContext`): Request-scoped context with execution metadata.
382
+
383
+ **tracingContext** (`TracingContext`): Tracing context for observability.
384
+
385
+ **writer** (`ProcessorStreamWriter`): Stream writer for emitting custom data chunks during streaming. Use \`writer.custom()\` to send transient UI signals.
386
+
387
+ **abortSignal** (`AbortSignal`): Signal for cancelling the operation.
388
+
389
+ #### Return value
390
+
391
+ `processLLMRequest` returns `ProcessLLMRequestResult`, which is `{ prompt?: LanguageModelV2Prompt } | undefined | void`.
392
+
393
+ - Return `{ prompt }` to replace the outbound prompt for the current provider call.
394
+ - Return `undefined` or `void` to forward the original prompt unchanged.
395
+
396
+ #### Use cases
397
+
398
+ - Removing or reshaping provider-specific prompt parts before a model call
399
+ - Normalizing roles or content to match a provider's input requirements
400
+ - Adapting tool result formats when switching providers mid-loop
401
+
402
+ ***
403
+
342
404
  ### `processAPIError`
343
405
 
344
406
  Handles LLM API rejection errors before they surface as final errors. This runs when the API call fails with a non-retryable error (such as a 400 or 422 status code). Unlike `processOutputStep` which runs after successful responses, this runs when the API rejects the request.
@@ -0,0 +1,132 @@
1
+ # ProviderHistoryCompat
2
+
3
+ The `ProviderHistoryCompat` processor handles provider-specific history incompatibilities. It can rewrite the outbound language model prompt before a provider call, or react to API errors and retry with repaired message history.
4
+
5
+ Use it when an agent may switch between model providers, reuse message history across providers, or call a provider that rejects fields emitted by another provider.
6
+
7
+ ## Usage example
8
+
9
+ Add `ProviderHistoryCompat` to `inputProcessors` when you want all built-in compatibility rules available for an agent:
10
+
11
+ ```typescript
12
+ import { Agent } from '@mastra/core/agent'
13
+ import { ProviderHistoryCompat } from '@mastra/core/processors'
14
+
15
+ export const agent = new Agent({
16
+ name: 'my-agent',
17
+ instructions: 'You are a helpful assistant.',
18
+ model: 'anthropic/claude-sonnet-4-5',
19
+ inputProcessors: [new ProviderHistoryCompat()],
20
+ })
21
+ ```
22
+
23
+ Mastra agents don't add this processor automatically. Add it explicitly when you need provider history compatibility rules, reactive API error recovery, custom rules, or predictable processor ordering.
24
+
25
+ ## Constructor parameters
26
+
27
+ **opts** (`{ additionalRules?: CompatRule[] }`): Configuration options for provider history compatibility rules.
28
+
29
+ **opts.additionalRules** (`CompatRule[]`): Custom compatibility rules to run after the built-in rules. Rules can rewrite the outbound prompt or repair persisted messages after matching an API error.
30
+
31
+ ## Properties
32
+
33
+ **id** (`'provider-history-compat'`): Processor identifier.
34
+
35
+ **name** (`'Provider History Compat'`): Processor display name.
36
+
37
+ **processLLMRequest** (`(args: ProcessLLMRequestArgs) => ProcessLLMRequestResult`): Runs preemptive compatibility rules against the converted LanguageModelV2Prompt immediately before the provider call. Returned prompt changes are transient and are not persisted to memory or message history.
38
+
39
+ **processAPIError** (`(args: ProcessAPIErrorArgs) => Promise<ProcessAPIErrorResult | void>`): Runs reactive compatibility rules when a provider rejects the request. Matching rules can mutate the message list and return retry: true on the first retry attempt.
40
+
41
+ ## Built-in rules
42
+
43
+ `ProviderHistoryCompat` includes these built-in compatibility rules:
44
+
45
+ | Rule | Provider | Timing | Behavior |
46
+ | ------------------------------------------- | --------- | --------------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
47
+ | `anthropic-tool-id-format` | Anthropic | Reactive API error recovery | Rewrites tool call IDs that contain characters outside `[a-zA-Z0-9_-]` and retries the request. |
48
+ | `cerebras-strip-reasoning-content` | Cerebras | Preemptive prompt rewrite | Removes assistant `reasoning` parts from the outbound prompt so they're not serialized as unsupported `reasoning_content` fields. |
49
+ | `anthropic-strip-foreign-reasoning-content` | Anthropic | Preemptive prompt rewrite | Removes non-Anthropic assistant `reasoning` parts from the outbound prompt. Anthropic-native thinking history is preserved. |
50
+
51
+ Preemptive rules run through `processLLMRequest` after Mastra converts messages to the model prompt format and before the prompt is sent to the provider. These rewrites affect only the current provider call.
52
+
53
+ Reactive rules run through `processAPIError` after a provider rejection. They can update the persisted `messageList` and request a retry.
54
+
55
+ ## `CompatRule`
56
+
57
+ A `CompatRule` defines one provider history compatibility fix:
58
+
59
+ ```typescript
60
+ import type { CompatRule } from '@mastra/core/processors'
61
+
62
+ const removeUnsupportedPromptParts: CompatRule = {
63
+ name: 'remove-unsupported-prompt-parts',
64
+ applyToPrompt({ prompt, model }) {
65
+ // Return a modified LanguageModelV2Prompt, or undefined to leave it unchanged.
66
+ return undefined
67
+ },
68
+ }
69
+ ```
70
+
71
+ **name** (`string`): Human-readable rule identifier for logs and debugging.
72
+
73
+ **errorPatterns** (`RegExp[]`): Patterns matched against provider API error messages and response bodies. Required for reactive rules that implement fix.
74
+
75
+ **fix** (`(messages: MastraDBMessage[]) => boolean`): Reactive fix that mutates persisted database messages after a matching API error. Return true when the rule changed messages and the request should retry.
76
+
77
+ **applyToPrompt** (`(args: { prompt: LanguageModelV2Prompt; model: unknown }) => LanguageModelV2Prompt | undefined`): Preemptive fix that rewrites the outbound prompt for the current provider call. Return undefined when no prompt change is needed.
78
+
79
+ ## Custom rules
80
+
81
+ Pass custom rules through `additionalRules`. Custom rules run after the built-in rules:
82
+
83
+ ```typescript
84
+ import { Agent } from '@mastra/core/agent'
85
+ import { ProviderHistoryCompat, type CompatRule } from '@mastra/core/processors'
86
+
87
+ const stripUnsupportedAssistantMetadata: CompatRule = {
88
+ name: 'strip-unsupported-assistant-metadata',
89
+ applyToPrompt({ prompt, model }) {
90
+ if (typeof model !== 'string' || !model.startsWith('example-provider/')) {
91
+ return undefined
92
+ }
93
+
94
+ let changed = false
95
+ const nextPrompt = prompt.map(message => {
96
+ if (message.role !== 'assistant' || typeof message.content === 'string') {
97
+ return message
98
+ }
99
+
100
+ const nextContent = message.content.map(part => {
101
+ if (!('providerOptions' in part)) return part
102
+ changed = true
103
+ const { providerOptions: _providerOptions, ...rest } = part
104
+ return rest
105
+ })
106
+
107
+ return { ...message, content: nextContent }
108
+ })
109
+
110
+ return changed ? nextPrompt : undefined
111
+ },
112
+ }
113
+
114
+ export const agent = new Agent({
115
+ name: 'custom-provider-agent',
116
+ instructions: 'You are a helpful assistant.',
117
+ model: 'example-provider/model',
118
+ inputProcessors: [
119
+ new ProviderHistoryCompat({
120
+ additionalRules: [stripUnsupportedAssistantMetadata],
121
+ }),
122
+ ],
123
+ })
124
+ ```
125
+
126
+ Use `applyToPrompt` for provider-specific rewrites that shouldn't be saved to memory. Use `fix` with `errorPatterns` when the provider rejects persisted message history and the repaired history should be reused on future turns.
127
+
128
+ ## Related
129
+
130
+ - [Processor interface](https://mastra.ai/reference/processors/processor-interface)
131
+ - [Processors](https://mastra.ai/docs/agents/processors)
132
+ - [PrefillErrorHandler](https://mastra.ai/reference/processors/prefill-error-handler)