@mastra/mcp-docs-server 1.3.2 → 1.3.3-alpha.1

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 (51) hide show
  1. package/.docs/docs/agents/human-in-the-loop.md +2 -4
  2. package/.docs/docs/agents/processors.md +58 -4
  3. package/.docs/docs/connections/mcp.md +2 -0
  4. package/.docs/docs/deployment/workers.md +3 -1
  5. package/.docs/docs/guides/authentication-identity.md +4 -2
  6. package/.docs/docs/guides/mcp-authentication-authorization.md +136 -0
  7. package/.docs/docs/index.md +1 -1
  8. package/.docs/docs/server/server-adapters.md +54 -11
  9. package/.docs/docs/workflows/control-flow.md +2 -4
  10. package/.docs/docs/workflows/scheduled-workflows.md +5 -1
  11. package/.docs/models/environment-variables.md +1 -1
  12. package/.docs/models/gateways/merge-gateway.md +2 -1
  13. package/.docs/models/gateways/openrouter.md +2 -1
  14. package/.docs/models/gateways/vercel.md +4 -1
  15. package/.docs/models/index.md +2 -2
  16. package/.docs/models/providers/baseten.md +2 -1
  17. package/.docs/models/providers/cortecs.md +3 -2
  18. package/.docs/models/providers/deepinfra.md +0 -4
  19. package/.docs/models/providers/edenai.md +3 -2
  20. package/.docs/models/providers/kilo.md +14 -12
  21. package/.docs/models/providers/llmgateway-providers.md +2 -9
  22. package/.docs/models/providers/llmgateway.md +2 -1
  23. package/.docs/models/providers/nano-gpt.md +3 -1
  24. package/.docs/models/providers/opencode.md +2 -1
  25. package/.docs/models/providers/requesty.md +3 -1
  26. package/.docs/models/providers/tempr.md +23 -4
  27. package/.docs/models/providers.md +1 -1
  28. package/.docs/reference/agent-controller/agent-controller-class.md +2 -0
  29. package/.docs/reference/classifier/classifier.md +49 -22
  30. package/.docs/reference/client-js/observability.md +1 -1
  31. package/.docs/reference/coding-agent/create-coding-agent.md +2 -2
  32. package/.docs/reference/configuration.md +2 -4
  33. package/.docs/reference/evals/create-classifier-scorer.md +2 -4
  34. package/.docs/reference/evals/create-scorer.md +1 -1
  35. package/.docs/reference/memory/observational-memory.md +3 -1
  36. package/.docs/reference/observability/tracing/spans.md +1 -1
  37. package/.docs/reference/processors/classifier-processor.md +8 -10
  38. package/.docs/reference/processors/model-selection-processor.md +8 -10
  39. package/.docs/reference/processors/prefill-error-handler.md +2 -2
  40. package/.docs/reference/processors/processor-interface.md +2 -2
  41. package/.docs/reference/processors/provider-history-compat.md +37 -17
  42. package/.docs/reference/processors/stream-error-retry-processor.md +9 -4
  43. package/.docs/reference/server/elysia-adapter.md +2 -0
  44. package/.docs/reference/server/express-adapter.md +1 -1
  45. package/.docs/reference/server/fastify-adapter.md +2 -0
  46. package/.docs/reference/server/hono-adapter.md +2 -0
  47. package/.docs/reference/server/koa-adapter.md +2 -0
  48. package/.docs/reference/server/nestjs-adapter.md +48 -0
  49. package/.docs/reference/tools/mcp-server.md +25 -10
  50. package/.docs/reference/workflows/step.md +2 -4
  51. package/package.json +5 -5
@@ -12,14 +12,12 @@ Abort reasons are always the string supplied by the caller. Provider-generated t
12
12
 
13
13
  ```typescript
14
14
  import { Classifier } from '@mastra/core/classifier'
15
- import { createTypeSafeAi } from '@ai-sdk/typesafe-ai'
15
+ import { typeSafeAi } from '@ai-sdk/typesafe-ai'
16
16
  import { ClassifierProcessor } from '@mastra/core/processors'
17
17
 
18
18
  const safety = new Classifier({
19
19
  id: 'safety',
20
- model: createTypeSafeAi({ apiKey: process.env.TYPESAFE_AI_API_KEY }).evaluationModel(
21
- 'jev-latest',
22
- ),
20
+ model: typeSafeAi.evaluationModel('jev-latest'),
23
21
  questions: {
24
22
  unsafe: {
25
23
  type: 'boolean',
@@ -95,12 +93,12 @@ Messages with no text content are passed through without calling the classifier.
95
93
  ```typescript
96
94
  import { Agent } from '@mastra/core/agent'
97
95
  import { Classifier } from '@mastra/core/classifier'
98
- import { createTypeSafeAi } from '@ai-sdk/typesafe-ai'
96
+ import { typeSafeAi } from '@ai-sdk/typesafe-ai'
99
97
  import { ClassifierProcessor } from '@mastra/core/processors'
100
98
 
101
99
  const topic = new Classifier({
102
100
  id: 'topic',
103
- model: createTypeSafeAi({/* ... */}).evaluationModel('jev-latest'),
101
+ model: typeSafeAi.evaluationModel('jev-latest'),
104
102
  questions: {
105
103
  topic: {
106
104
  type: 'choice',
@@ -137,12 +135,12 @@ export const agent = new Agent({
137
135
  ```typescript
138
136
  import { Agent } from '@mastra/core/agent'
139
137
  import { Classifier } from '@mastra/core/classifier'
140
- import { createTypeSafeAi } from '@ai-sdk/typesafe-ai'
138
+ import { typeSafeAi } from '@ai-sdk/typesafe-ai'
141
139
  import { ClassifierProcessor } from '@mastra/core/processors'
142
140
 
143
141
  const quality = new Classifier({
144
142
  id: 'quality',
145
- model: createTypeSafeAi({/* ... */}).evaluationModel('jev-latest'),
143
+ model: typeSafeAi.evaluationModel('jev-latest'),
146
144
  questions: {
147
145
  quality: {
148
146
  type: 'score',
@@ -175,13 +173,13 @@ Register the classifier on the `Mastra` instance and reference it by key or ID.
175
173
  ```typescript
176
174
  import { Mastra } from '@mastra/core'
177
175
  import { Classifier } from '@mastra/core/classifier'
178
- import { createTypeSafeAi } from '@ai-sdk/typesafe-ai'
176
+ import { typeSafeAi } from '@ai-sdk/typesafe-ai'
179
177
 
180
178
  export const mastra = new Mastra({
181
179
  classifiers: {
182
180
  safety: new Classifier({
183
181
  id: 'safety',
184
- model: createTypeSafeAi({/* ... */}).evaluationModel('jev-latest'),
182
+ model: typeSafeAi.evaluationModel('jev-latest'),
185
183
  questions: {/* ... */},
186
184
  }),
187
185
  },
@@ -13,7 +13,7 @@ Describe each model alongside the kind of request it should handle. The processo
13
13
  ```typescript
14
14
  import { Agent } from '@mastra/core/agent'
15
15
  import { ModelSelectionProcessor } from '@mastra/core/processors'
16
- import { createTypeSafeAi } from '@ai-sdk/typesafe-ai'
16
+ import { typeSafeAi } from '@ai-sdk/typesafe-ai'
17
17
 
18
18
  export const agent = new Agent({
19
19
  name: 'support-agent',
@@ -21,9 +21,7 @@ export const agent = new Agent({
21
21
  model: 'openai/gpt-5.6-sol',
22
22
  inputProcessors: [
23
23
  new ModelSelectionProcessor({
24
- model: createTypeSafeAi({ apiKey: process.env.TYPESAFE_AI_API_KEY }).evaluationModel(
25
- 'jev-latest',
26
- ),
24
+ model: typeSafeAi.evaluationModel('jev-latest'),
27
25
  choices: [
28
26
  {
29
27
  model: 'openai/gpt-5-mini',
@@ -81,13 +79,13 @@ By default the decision applies to every step of the run. Set `scope: 'first-ste
81
79
 
82
80
  ```typescript
83
81
  import { ModelSelectionProcessor } from '@mastra/core/processors'
84
- import { createTypeSafeAi } from '@ai-sdk/typesafe-ai'
82
+ import { typeSafeAi } from '@ai-sdk/typesafe-ai'
85
83
  import { PinoLogger } from '@mastra/loggers'
86
84
 
87
85
  const logger = new PinoLogger({ name: 'model-selection' })
88
86
 
89
87
  new ModelSelectionProcessor({
90
- model: createTypeSafeAi({/* ... */}).evaluationModel('jev-latest'),
88
+ model: typeSafeAi.evaluationModel('jev-latest'),
91
89
  choices: [
92
90
  { model: 'openai/gpt-5-mini', criteria: 'Simple lookups' },
93
91
  { model: 'openai/gpt-5.6-sol', criteria: 'Multi-step reasoning' },
@@ -114,11 +112,11 @@ Pass `classifier` instead of `choices` to route on a [Classifier](https://mastra
114
112
 
115
113
  ```typescript
116
114
  import { Classifier } from '@mastra/core/classifier'
117
- import { createTypeSafeAi } from '@ai-sdk/typesafe-ai'
115
+ import { typeSafeAi } from '@ai-sdk/typesafe-ai'
118
116
 
119
117
  const triage = new Classifier({
120
118
  id: 'triage',
121
- model: createTypeSafeAi({/* ... */}).evaluationModel('jev-latest'),
119
+ model: typeSafeAi.evaluationModel('jev-latest'),
122
120
  questions: {
123
121
  complexity: {
124
122
  type: 'choice',
@@ -155,12 +153,12 @@ Choice criteria are mutually exclusive, which is the wrong shape when routing de
155
153
 
156
154
  ```typescript
157
155
  import { Classifier } from '@mastra/core/classifier'
158
- import { createTypeSafeAi } from '@ai-sdk/typesafe-ai'
156
+ import { typeSafeAi } from '@ai-sdk/typesafe-ai'
159
157
  import { ModelSelectionProcessor } from '@mastra/core/processors'
160
158
 
161
159
  const triage = new Classifier({
162
160
  id: 'triage',
163
- model: createTypeSafeAi({/* ... */}).evaluationModel('jev-latest'),
161
+ model: typeSafeAi.evaluationModel('jev-latest'),
164
162
  questions: {
165
163
  complexity: {
166
164
  type: 'choice',
@@ -8,7 +8,7 @@ The `PrefillErrorHandler` is an **error processor** that handles assistant-respo
8
8
 
9
9
  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.
10
10
 
11
- 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).
11
+ Mastra adds this processor to every agent's `errorProcessors` by default, after `ProviderHistoryCompat` and before `StreamErrorRetryProcessor`. It only acts on the first retry attempt, so it needs no configuration. Supply your own instance to tune it. Anything already in your list is kept and the default is only added when its `id` is absent.
12
12
 
13
13
  ## How it works
14
14
 
@@ -21,7 +21,7 @@ The processor now reacts to the API rejection itself instead of re-checking whet
21
21
 
22
22
  ## Usage example
23
23
 
24
- Add `PrefillErrorHandler` to `errorProcessors` for any agent that should retry assistant-prefill failures:
24
+ To tune or explicitly scope prefill recovery, supply your own instance. The default `PrefillErrorHandler` isn't added when you do:
25
25
 
26
26
  ```typescript
27
27
  import { Agent } from '@mastra/core/agent'
@@ -170,7 +170,7 @@ Use `messages` when you only need to read, map over, or lightly edit fields on t
170
170
 
171
171
  When memory is enabled, only what ends up in `messageList` after all processors finish is persisted to storage. Both return styles are equivalent for persistence:
172
172
 
173
- - When you mutate `messageList` directly (or return the same `MessageList` instance), recorded mutations are applied in place, so the saved conversation reflects your changes.
173
+ - When you mutate `messageList` directly (or return the same `MessageList` instance), recorded mutations are applied in place. The saved conversation reflects your changes.
174
174
  - When you return a `MastraDBMessage[]` or `{ messages, systemMessages }`, Mastra reconciles the returned array against `messageList` for the current stage, removing missing messages and replacing system messages.
175
175
 
176
176
  Returning a different `MessageList` instance is an error. Always mutate the one passed to your processor.
@@ -1034,7 +1034,7 @@ abort('Blocked content detected', { retry: false, metadata: { category: 'pii' }
1034
1034
  ```
1035
1035
 
1036
1036
  - `reason`: A human-readable explanation. Appears as `tripwire.payload.reason`.
1037
- - `retry`: When `true`, the agent retries the same step with `reason` fed back as feedback. Retries only run when `maxProcessorRetries` is set on the agent or call; otherwise the request aborts. When `errorProcessors` are configured, `maxProcessorRetries` defaults to `10` for that call.
1037
+ - `retry`: When `true`, the agent retries the same step with `reason` fed back as feedback. Retries only run when `maxProcessorRetries` is set on the agent or call; otherwise the request aborts. The safety cap of `3` that applies when no cap is set covers only error-processor retries from `processAPIError`. It doesn't give abort retries a budget.
1038
1038
  - `metadata`: Optional structured data attached to the `tripwire` chunk for downstream consumers.
1039
1039
 
1040
1040
  The emitted `tripwire` chunk has the shape:
@@ -10,7 +10,7 @@ Use it when an agent may switch between model providers or reuse message history
10
10
 
11
11
  ## Usage example
12
12
 
13
- Add `ProviderHistoryCompat` to both lists when you want all built-in compatibility rules available for an agent. `inputProcessors` drives the preemptive rewrites, `errorProcessors` drives the reactive recovery:
13
+ Mastra adds this processor to every agent's `errorProcessors` by default when your list doesn't already contain that `id`. Among the added defaults it comes first. Its outbound prompt rules run before the other defaults, including the retry processor's blind resend. Supply your own instance to add custom rules or position it yourself:
14
14
 
15
15
  ```typescript
16
16
  import { Agent } from '@mastra/core/agent'
@@ -21,19 +21,18 @@ export const agent = new Agent({
21
21
  name: 'my-agent',
22
22
  instructions: 'You are a helpful assistant.',
23
23
  model: 'anthropic/claude-sonnet-4-5',
24
- inputProcessors: [new ProviderHistoryCompat()],
25
- errorProcessors: [new ProviderHistoryCompat()],
24
+ errorProcessors: [new ProviderHistoryCompat({ additionalRules: [/* ... */] })],
26
25
  })
27
26
  ```
28
27
 
29
- 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.
28
+ A supplied `ProviderHistoryCompat` is used instead of the default. The default is only added when no processor in your list carries that `id`. Place an instance in `inputProcessors` when you want the prompt-rewriting rules to run in the input lane instead.
30
29
 
31
30
  The placement decides which half of the processor works:
32
31
 
33
- - **Reactive rules need `errorProcessors`.** On the standard loop, `processAPIError` runs from any of the three lists, so an input-processor registration does repair the message list, but the retry it asks for is only honored when the agent has a retry budget, and that budget is left `undefined` unless the agent configures `errorProcessors` or sets `maxProcessorRetries` explicitly. Registered only as an input processor and without an explicit `maxProcessorRetries`, a reactive rule repairs the history and the request still fails. On the durable path the API-error pass additionally requires a non-empty `errorProcessors` list. If that list is empty, an input-processor registration can't trigger reactive recovery there at all, even with `maxProcessorRetries` set.
34
- - **Preemptive rules need `inputProcessors`.** `processLLMRequest` runs over the input processors only, so prompt rewrites don't happen from the error list.
32
+ - **Reactive rules need `errorProcessors`.** On the standard loop, `processAPIError` runs from any of the three lists, so an input-processor registration does repair the message list, but the retry it asks for is only honored when the agent has a retry budget. With the default error processors in place the resolved list is non-empty, so a safety cap of `3` applies. The budget is left `undefined` only when the caller runs with no error processors at all (`errorProcessorDefaults: false` with none configured) and doesn't set `maxProcessorRetries` explicitly. Registered only as an input processor in that no-budget state, a reactive rule repairs the history and the request still fails. On the durable path the API-error pass additionally requires a non-empty `errorProcessors` list. If that list is empty, an input-processor registration can't trigger reactive recovery there at all, even with `maxProcessorRetries` set.
33
+ - **Preemptive rules run from either list.** `processLLMRequest` runs over the input processors and over the resolved error processors, so a `ProviderHistoryCompat` in `errorProcessors` gets its prompt rewrites as well as its reactive recovery. An instance registered in `inputProcessors` runs once, in its input position.
35
34
 
36
- An agent that wants both registers the processor in both lists, as the example above does. Double registration can't cause a double retry: the runner stops at the first processor that asks for one, and each reactive rule bails once `retryCount` is above zero, so a repaired turn is attempted exactly once more.
35
+ Registering in `errorProcessors` alone, as the example above does, covers both halves. Double registration can't cause a double retry: the runner stops at the first processor that asks for one, and each reactive rule bails once `retryCount` is above zero, so a repaired turn is attempted exactly once more.
37
36
 
38
37
  ## Constructor parameters
39
38
 
@@ -55,19 +54,21 @@ An agent that wants both registers the processor in both lists, as the example a
55
54
 
56
55
  `ProviderHistoryCompat` includes these built-in compatibility rules:
57
56
 
58
- | Rule | Provider | Timing | Behavior |
59
- | ------------------------------------------- | -------------------------------- | --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
60
- | `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. |
61
- | `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. |
62
- | `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. |
63
- | `anthropic-strip-foreign-signed-reasoning` | Anthropic-compatible | Preemptive prompt rewrite | Drops signed thinking from the outbound prompt when its origin turn was stamped with a different provider (for example Kimi For Coding ↔ `anthropic/claude-sonnet-4-6`), since the receiving provider can't verify another provider's signature. Turns emptied of all content by the drop are removed from the prompt. Unstamped history is left untouched. |
64
- | `azure-system-reminder-transform` | Azure OpenAI | Preemptive prompt rewrite | Renames `<system-reminder>` wrappers in user text and system instructions to `<memory-context>` for the outbound request. Stored history remains unchanged. |
65
- | `openai-orphan-item-id` | OpenAI, Azure OpenAI (Responses) | Reactive API error recovery | Recovers history that OpenAI rejects with `Item 'msg_…' of type 'message' was provided without its required 'reasoning' item`. Drops the Responses `itemId` from every item-bearing part of an assistant message that carries one but has no `reasoning` part, so the message replays by value instead of as an unsatisfiable `item_reference`, and retries. The repair is applied to the in-memory list for the current turn. |
57
+ | Rule | Provider | Timing | Behavior |
58
+ | ------------------------------------------- | -------------------------------- | --------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
59
+ | `anthropic-tool-id-format` | Anthropic | Preemptive prompt rewrite | Rewrites tool call IDs that contain characters outside `[a-zA-Z0-9_-]` in the outbound prompt, on both the call and its result. A sanitized ID that would collide with one already in the prompt gets a `_2`, `_3`, … suffix. The provider's rejection never fires, and persisted history keeps the original IDs. A reactive fallback covers providers the preemptive check doesn't recognize, such as Vertex-hosted Claude. |
60
+ | `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. |
61
+ | `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. |
62
+ | `anthropic-strip-foreign-signed-reasoning` | Anthropic-compatible | Preemptive prompt rewrite | Drops signed thinking from the outbound prompt when its origin turn was stamped with a different provider (for example Kimi For Coding ↔ `anthropic/claude-sonnet-4-6`), since the receiving provider can't verify another provider's signature. Turns emptied of all content by the drop are removed from the prompt. Unstamped history is left untouched. |
63
+ | `azure-system-reminder-transform` | Azure OpenAI | Preemptive prompt rewrite | Renames `<system-reminder>` wrappers in user text and system instructions to `<memory-context>` for the outbound request. Stored history remains unchanged. |
64
+ | `openai-orphan-item-id` | OpenAI, Azure OpenAI (Responses) | Reactive API error recovery | Recovers history that OpenAI rejects with `Item 'msg_…' of type 'message' was provided without its required 'reasoning' item`. Drops the Responses `itemId` from every item-bearing part of an assistant message that carries one but has no `reasoning` part, and retries. The message then replays by value instead of as an unsatisfiable `item_reference`. The repair is applied to the in-memory list for the current turn. |
66
65
 
67
- 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.
66
+ 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. Persisted history is never changed, so the IDs and content in memory and in the Studio stay exactly as written.
68
67
 
69
68
  Reactive rules run through `processAPIError` after a provider rejection. They can update the persisted `messageList` and request a retry.
70
69
 
70
+ `anthropic-tool-id-format` implements both. Its preemptive hook normally prevents the rejection from happening at all, which leaves the reactive hook dormant. See [Tool call ID repair is prompt-scoped](#tool-call-id-repair-is-prompt-scoped) below.
71
+
71
72
  ## `CompatRule`
72
73
 
73
74
  A `CompatRule` defines one provider history compatibility fix:
@@ -140,7 +141,26 @@ export const agent = new Agent({
140
141
  })
141
142
  ```
142
143
 
143
- 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.
144
+ Use `applyToPrompt` for provider-specific rewrites that shouldn't be saved to memory. This is what new rules should normally reach for, and it's the hook the built-in rules use. Use `fix` with `errorPatterns` only when the repaired history must persist and be reused on future turns, and when the provider can't be stopped from rejecting the request up front.
145
+
146
+ ## Tool call ID repair is prompt-scoped
147
+
148
+ Anthropic enforces `^[a-zA-Z0-9_-]+$` on `tool_use.id`. A tool call whose ID came from another provider, containing `.` or `:`, is rejected. The rule sanitizes those IDs in the outbound request:
149
+
150
+ ```typescript
151
+ // What the provider receives
152
+ tool_use.id: 'call_abc_1'
153
+ // What stays in memory, in the returned messages, and in the Studio
154
+ toolCallId: 'call.abc:1'
155
+ ```
156
+
157
+ Both the `tool-call` and its paired `tool-result` are rewritten from the same map, so call/result pairing survives the rewrite. Replacement IDs are assigned in encounter order and never collide with an ID the prompt already carries: if `a.b` sanitizes to `a_b` and the prompt already has an `a_b`, the rewritten ID becomes `a_b_2`.
158
+
159
+ Because nothing is persisted, a caller that reuses the same message list in a later turn sees the original IDs again, and the repair runs again on that request.
160
+
161
+ ### Reactive fallback
162
+
163
+ The rule's `errorPatterns` and `fix` hooks repair the same rejection after the provider raises it. The preemptive rewrite only runs when `isMaybeAnthropic(model)` matches. The reactive path stays the fallback for Claude served through a provider the check doesn't recognize, such as Vertex-hosted Claude, and the only repair once a call has already been rejected. A rule can use both hooks together, and `fix` on the `CompatRule` interface itself isn't deprecated: custom rules legitimately use it.
144
164
 
145
165
  ## Related
146
166
 
@@ -6,11 +6,11 @@
6
6
 
7
7
  `StreamErrorRetryProcessor` is an **error processor** that retries transient LLM API and stream failures. It includes built-in matching for OpenAI Responses stream errors and supports additional matchers for other provider-specific error shapes.
8
8
 
9
- The processor isn't enabled by default in core. Add it to `errorProcessors` for agents that need bounded retry handling.
9
+ Mastra adds this processor to every agent's `errorProcessors` by default, last, after the `ProviderHistoryCompat` and `PrefillErrorHandler` defaults, so the processors that repair a request get their chance before this one retries it unchanged. The default instance uses `maxRetries: 2` with a connection-reset matcher alongside the built-in matching, and it doesn't retry unknown errors or replay bad-request (HTTP 400) responses the repair processors couldn't fix. Supply your own instance in `errorProcessors` to change its policy. Because a default is only added when its `id` is missing from your list, your instance is used and the default isn't added alongside it.
10
10
 
11
11
  ## Usage example
12
12
 
13
- Add `StreamErrorRetryProcessor` to `errorProcessors`:
13
+ Configure `StreamErrorRetryProcessor`. Supplying the same `id` means the default isn't added:
14
14
 
15
15
  ```typescript
16
16
  import { Agent } from '@mastra/core/agent'
@@ -21,10 +21,15 @@ export const agent = new Agent({
21
21
  name: 'openai-agent',
22
22
  instructions: 'You are a helpful assistant.',
23
23
  model: 'openai/gpt-5',
24
- errorProcessors: [new StreamErrorRetryProcessor()],
24
+ errorProcessors: [new StreamErrorRetryProcessor({ maxRetries: 5 })],
25
+ maxProcessorRetries: 5,
25
26
  })
26
27
  ```
27
28
 
29
+ Set `maxProcessorRetries` alongside a `maxRetries` above `3`, because the agent stops error-processor retries at `3` when it's unset. See [Retry limits](#retry-limits).
30
+
31
+ To run only the processors you configure, with none of the defaults merged in, set `errorProcessorDefaults: false`. Without an `errorProcessors` list, the agent then runs no error processors. An empty `errorProcessors` list still gets the defaults. Supplying your own processor for all three default ids replaces every default with your own implementation.
32
+
28
33
  ## How it works
29
34
 
30
35
  The processor checks the error and its cause chain for:
@@ -39,7 +44,7 @@ When `delayMs` is set, the processor waits before signaling a retry. This is use
39
44
 
40
45
  ### Retry limits
41
46
 
42
- `maxRetries` defaults to `1` and limits this processor's retry requests. The agent also limits processor retries with `maxProcessorRetries`. When error processors are configured without an agent limit, the runtime cap is `10`.
47
+ `maxRetries` defaults to `1` and limits this processor's retry requests. The agent also limits processor retries with `maxProcessorRetries`. When error processors are configured without an agent limit, the runtime cap is `3`.
43
48
 
44
49
  Set both values explicitly to the same bounded value when you need a single retry budget. Keep model `maxRetries` at `0` for that call to avoid multiplying provider attempts.
45
50
 
@@ -53,6 +53,8 @@ app.listen(3000)
53
53
  console.log('Server running on http://localhost:3000')
54
54
  ```
55
55
 
56
+ `init()` doesn't start Mastra's background workers. To run [scheduled workflows](https://mastra.ai/docs/workflows/scheduled-workflows), agent schedules, or event listeners, call `await mastra.startWorkers()` after the server starts listening. See [Start background workers](https://mastra.ai/docs/server/server-adapters).
57
+
56
58
  ## Constructor parameters
57
59
 
58
60
  **app** (`Elysia`): Elysia app instance
@@ -52,7 +52,7 @@ app.listen(4111, () => {
52
52
  })
53
53
  ```
54
54
 
55
- > **Note:** Express requires `express.json()` middleware for JSON body parsing. Add it before creating the `MastraServer`.
55
+ Express requires `express.json()` middleware for JSON body parsing. Add it before creating the `MastraServer`. `init()` doesn't start Mastra's background workers. To run [scheduled workflows](https://mastra.ai/docs/workflows/scheduled-workflows), agent schedules, or event listeners, call `await mastra.startWorkers()` after the server starts listening. See [Start background workers](https://mastra.ai/docs/server/server-adapters).
56
56
 
57
57
  ## Constructor parameters
58
58
 
@@ -55,6 +55,8 @@ app.listen({ port: 3000 }, (err, address) => {
55
55
  })
56
56
  ```
57
57
 
58
+ `init()` doesn't start Mastra's background workers. To run [scheduled workflows](https://mastra.ai/docs/workflows/scheduled-workflows), agent schedules, or event listeners, call `await mastra.startWorkers()` after the server starts listening. See [Start background workers](https://mastra.ai/docs/server/server-adapters).
59
+
58
60
  ## Constructor parameters
59
61
 
60
62
  **app** (`FastifyInstance`): Fastify app instance
@@ -49,6 +49,8 @@ await server.init()
49
49
  export default app
50
50
  ```
51
51
 
52
+ `init()` doesn't start Mastra's background workers. To run [scheduled workflows](https://mastra.ai/docs/workflows/scheduled-workflows), agent schedules, or event listeners, call `await mastra.startWorkers()` after the server starts listening. See [Start background workers](https://mastra.ai/docs/server/server-adapters).
53
+
52
54
  ## Constructor parameters
53
55
 
54
56
  **app** (`Hono`): Hono app instance
@@ -54,6 +54,8 @@ app.listen(3000, () => {
54
54
  })
55
55
  ```
56
56
 
57
+ `init()` doesn't start Mastra's background workers. To run [scheduled workflows](https://mastra.ai/docs/workflows/scheduled-workflows), agent schedules, or event listeners, call `await mastra.startWorkers()` after the server starts listening. See [Start background workers](https://mastra.ai/docs/server/server-adapters).
58
+
57
59
  ## Constructor parameters
58
60
 
59
61
  **app** (`Koa`): Koa app instance
@@ -149,6 +149,54 @@ export class WorkflowService {
149
149
  }
150
150
  ```
151
151
 
152
+ ## Start background workers
153
+
154
+ `MastraModule` doesn't start Mastra's background workers. Without them, [scheduled workflows](https://mastra.ai/docs/workflows/scheduled-workflows), agent schedules, and event listeners never run. Call `mastra.startWorkers()` after the app starts listening:
155
+
156
+ ```typescript
157
+ import { NestFactory } from '@nestjs/core'
158
+ import { MASTRA } from '@mastra/nestjs'
159
+ import type { Mastra } from '@mastra/core/mastra'
160
+ import { AppModule } from './app.module'
161
+
162
+ async function bootstrap() {
163
+ const app = await NestFactory.create(AppModule)
164
+ app.enableShutdownHooks()
165
+ await app.listen(3000)
166
+
167
+ try {
168
+ await app.get<Mastra>(MASTRA).startWorkers()
169
+ } catch (error) {
170
+ console.error('Failed to start background workers', error)
171
+ await app.close()
172
+ process.exit(1)
173
+ }
174
+ }
175
+
176
+ bootstrap()
177
+ ```
178
+
179
+ The module's shutdown handling drains in-flight requests but doesn't stop Mastra. To stop workers and drain in-flight workflow runs, call `mastra.shutdown()` from a shutdown hook. The drain is bounded by `drainTimeout` (default 5 seconds), and runs that don't settle within it are abandoned with a warning:
180
+
181
+ ```typescript
182
+ import { Inject, Injectable, type OnApplicationShutdown } from '@nestjs/common'
183
+ import { MASTRA } from '@mastra/nestjs'
184
+ import type { Mastra } from '@mastra/core/mastra'
185
+
186
+ @Injectable()
187
+ export class MastraLifecycleService implements OnApplicationShutdown {
188
+ constructor(@Inject(MASTRA) private readonly mastra: Mastra) {}
189
+
190
+ async onApplicationShutdown() {
191
+ await this.mastra.shutdown()
192
+ }
193
+ }
194
+ ```
195
+
196
+ Add `MastraLifecycleService` to the `providers` of a module that imports `MastraModule`. Shutdown hooks only run when `app.enableShutdownHooks()` is called.
197
+
198
+ See [Start background workers](https://mastra.ai/docs/server/server-adapters) for more details.
199
+
152
200
  ## MCP routes
153
201
 
154
202
  MCP endpoints are exposed under the API prefix:
@@ -154,37 +154,48 @@ The same request also populates `context.requestContext`, the trusted applicatio
154
154
  const authInfo = context.mcp?.extra.authInfo ?? context.requestContext?.get('authInfo')
155
155
  ```
156
156
 
157
- #### Example: Tool that reads the caller's token
157
+ #### Example: Tool that uses caller identity with a separate credential
158
158
 
159
159
  ```typescript
160
160
  import { createTool } from '@mastra/core/tools'
161
161
  import { z } from 'zod'
162
162
 
163
+ import { apiCredentials } from '../lib/api-credentials'
164
+
163
165
  const fetchUserData = createTool({
164
166
  id: 'fetchUserData',
165
- description: 'Fetches user data using authentication from MCP context',
167
+ description: 'Fetches data for the authenticated MCP caller',
166
168
  inputSchema: z.object({
167
- userId: z.string().describe('The ID of the user to fetch'),
169
+ resourceId: z.string().describe('The ID of the record to fetch'),
168
170
  }),
169
171
  execute: async (inputData, context) => {
170
172
  const authInfo = context.mcp?.extra.authInfo ?? context.requestContext?.get('authInfo')
173
+ const user = authInfo?.extra?.user as { id?: string } | undefined
171
174
 
172
- if (!authInfo?.token) {
175
+ if (!user?.id) {
173
176
  throw new Error('Authentication required')
174
177
  }
175
178
 
176
- const response = await fetch(`https://api.example.com/users/${inputData.userId}`, {
177
- headers: {
178
- Authorization: `Bearer ${authInfo.token}`,
179
+ // Resolve the owner from trusted context, not from model input
180
+ const credential = await apiCredentials.getForUser(user.id)
181
+
182
+ const response = await fetch(
183
+ `https://api.example.com/users/${encodeURIComponent(user.id)}/records/${encodeURIComponent(inputData.resourceId)}`,
184
+ {
185
+ headers: {
186
+ Authorization: `Bearer ${credential.token}`,
187
+ },
188
+ signal: context.mcp?.extra.signal,
179
189
  },
180
- signal: context.mcp?.extra.signal,
181
- })
190
+ )
182
191
 
183
192
  return response.json()
184
193
  },
185
194
  })
186
195
  ```
187
196
 
197
+ Use `authInfo` for caller identity, then select a credential intended for the service the tool calls. The model supplies business input such as `resourceId`, while trusted code selects the credential. An MCP access token is for your MCP server, so it must not be forwarded to another API. See [Access upstream services safely](https://mastra.ai/docs/guides/mcp-authentication-authorization).
198
+
188
199
  #### Where `authInfo` comes from
189
200
 
190
201
  When an MCP server is served by a Mastra server, `extra.authInfo` is populated from the principal resolved by `server.auth`. Nothing extra is required:
@@ -1113,8 +1124,12 @@ execute: async (inputData, context) => {
1113
1124
  console.log('User ID:', authInfo.extra.sub)
1114
1125
  console.log('Email:', authInfo.extra.email)
1115
1126
 
1127
+ // Use a credential intended for the API being called, not the MCP token.
1128
+ // See https://mastra.ai/docs/guides/mcp-authentication-authorization#access-upstream-services-safely
1129
+ const credential = await apiCredentials.getForUser(authInfo.extra.sub as string)
1130
+
1116
1131
  const response = await fetch('/api/data', {
1117
- headers: { Authorization: `Bearer ${authInfo.token}` },
1132
+ headers: { Authorization: `Bearer ${credential.token}` },
1118
1133
  signal: context.mcp?.extra.signal,
1119
1134
  })
1120
1135
 
@@ -155,14 +155,12 @@ Pass a [`Classifier`](https://mastra.ai/reference/classifier/classifier) with co
155
155
 
156
156
  ```typescript
157
157
  import { Classifier } from '@mastra/core/classifier'
158
- import { createTypeSafeAi } from '@ai-sdk/typesafe-ai'
158
+ import { typeSafeAi } from '@ai-sdk/typesafe-ai'
159
159
  import { createStep } from '@mastra/core/workflows'
160
160
 
161
161
  const router = new Classifier({
162
162
  id: 'ticket-router',
163
- model: createTypeSafeAi({ apiKey: process.env.TYPESAFE_AI_API_KEY }).evaluationModel(
164
- 'jev-latest',
165
- ),
163
+ model: typeSafeAi.evaluationModel('jev-latest'),
166
164
  questions: {
167
165
  route: {
168
166
  type: 'choice',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/mcp-docs-server",
3
- "version": "1.3.2",
3
+ "version": "1.3.3-alpha.1",
4
4
  "description": "MCP server for accessing Mastra.ai documentation, changelogs, and news.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -26,8 +26,8 @@
26
26
  "@mastra/mcp-legacy": "npm:@mastra/mcp@^1.18.0",
27
27
  "local-pkg": "^1.1.2",
28
28
  "zod": "^4.6.4",
29
- "@mastra/core": "1.72.0",
30
- "@mastra/mcp": "^2.1.1"
29
+ "@mastra/mcp": "^2.1.2-alpha.0",
30
+ "@mastra/core": "1.73.0-alpha.0"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@hono/node-server": "^2.0.0",
@@ -43,9 +43,9 @@
43
43
  "tsx": "^4.23.1",
44
44
  "typescript": "^7.0.2",
45
45
  "vitest": "4.1.11",
46
+ "@internal/types-builder": "0.0.113",
46
47
  "@internal/lint": "0.0.138",
47
- "@mastra/core": "1.72.0",
48
- "@internal/types-builder": "0.0.113"
48
+ "@mastra/core": "1.73.0-alpha.0"
49
49
  },
50
50
  "homepage": "https://mastra.ai",
51
51
  "repository": {