@mastra/mcp-docs-server 1.1.35-alpha.13 → 1.1.35-alpha.17

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 (29) hide show
  1. package/.docs/course/03-agent-memory/18-advanced-configuration-semantic-recall.md +48 -4
  2. package/.docs/docs/agents/response-caching.md +148 -0
  3. package/.docs/docs/agents/using-tools.md +8 -0
  4. package/.docs/docs/memory/observational-memory.md +56 -12
  5. package/.docs/docs/memory/semantic-recall.md +68 -6
  6. package/.docs/docs/observability/tracing/exporters/arize.md +5 -5
  7. package/.docs/docs/observability/tracing/exporters/default.md +36 -1
  8. package/.docs/docs/observability/tracing/overview.md +1 -1
  9. package/.docs/docs/workflows/suspend-and-resume.md +28 -1
  10. package/.docs/models/gateways/openrouter.md +2 -1
  11. package/.docs/models/index.md +1 -1
  12. package/.docs/models/providers/llmgateway.md +7 -1
  13. package/.docs/models/providers/nebius.md +2 -1
  14. package/.docs/models/providers/opencode.md +1 -2
  15. package/.docs/models/providers/poe.md +4 -1
  16. package/.docs/reference/agents/agent.md +2 -0
  17. package/.docs/reference/client-js/responses.md +4 -0
  18. package/.docs/reference/configuration.md +4 -4
  19. package/.docs/reference/harness/harness-class.md +21 -8
  20. package/.docs/reference/index.md +2 -0
  21. package/.docs/reference/memory/observational-memory.md +11 -1
  22. package/.docs/reference/observability/tracing/exporters/arize.md +1 -1
  23. package/.docs/reference/observability/tracing/exporters/default-exporter.md +2 -0
  24. package/.docs/reference/observability/tracing/interfaces.md +36 -1
  25. package/.docs/reference/processors/response-cache.md +114 -0
  26. package/.docs/reference/tools/create-tool.md +46 -0
  27. package/.docs/reference/workflows/workflow-state-reader.md +113 -0
  28. package/CHANGELOG.md +15 -0
  29. package/package.json +3 -3
@@ -1,6 +1,6 @@
1
1
  # ![OpenCode Zen logo](https://models.dev/logos/opencode.svg)OpenCode Zen
2
2
 
3
- Access 39 OpenCode Zen models through Mastra's model router. Authentication is handled automatically using the `OPENCODE_API_KEY` environment variable.
3
+ Access 38 OpenCode Zen models through Mastra's model router. Authentication is handled automatically using the `OPENCODE_API_KEY` environment variable.
4
4
 
5
5
  Learn more in the [OpenCode Zen documentation](https://opencode.ai/docs/zen).
6
6
 
@@ -64,7 +64,6 @@ for await (const chunk of stream) {
64
64
  | `opencode/gpt-5.4-pro` | 1.1M | | | | | | $30 | $180 |
65
65
  | `opencode/gpt-5.5` | 1.1M | | | | | | $5 | $30 |
66
66
  | `opencode/gpt-5.5-pro` | 1.1M | | | | | | $30 | $180 |
67
- | `opencode/hy3-preview-free` | 256K | | | | | | — | — |
68
67
  | `opencode/kimi-k2.5` | 262K | | | | | | $0.60 | $3 |
69
68
  | `opencode/kimi-k2.6` | 262K | | | | | | $0.95 | $4 |
70
69
  | `opencode/minimax-m2.5` | 205K | | | | | | $0.30 | $1 |
@@ -1,6 +1,6 @@
1
1
  # ![Poe logo](https://models.dev/logos/poe.svg)Poe
2
2
 
3
- Access 121 Poe models through Mastra's model router. Authentication is handled automatically using the `POE_API_KEY` environment variable.
3
+ Access 124 Poe models through Mastra's model router. Authentication is handled automatically using the `POE_API_KEY` environment variable.
4
4
 
5
5
  Learn more in the [Poe documentation](https://creator.poe.com/docs/external-applications/openai-compatible-api).
6
6
 
@@ -51,6 +51,8 @@ for await (const chunk of stream) {
51
51
  | `poe/elevenlabs/elevenlabs-music` | 2K | | | | | | — | — |
52
52
  | `poe/elevenlabs/elevenlabs-v2.5-turbo` | 128K | | | | | | — | — |
53
53
  | `poe/elevenlabs/elevenlabs-v3` | 128K | | | | | | — | — |
54
+ | `poe/empiriolabs/deepseek-v4-flash-el` | 1.0M | | | | | | $0.14 | $0.28 |
55
+ | `poe/empiriolabs/deepseek-v4-pro-el` | 1.0M | | | | | | $2 | $3 |
54
56
  | `poe/fireworks-ai/kimi-k2.5-fw` | 262K | | | | | | — | — |
55
57
  | `poe/google/gemini-2.0-flash` | 990K | | | | | | $0.10 | $0.42 |
56
58
  | `poe/google/gemini-2.0-flash-lite` | 990K | | | | | | $0.05 | $0.21 |
@@ -87,6 +89,7 @@ for await (const chunk of stream) {
87
89
  | `poe/novita/glm-5` | 205K | | | | | | $1 | $3 |
88
90
  | `poe/novita/kimi-k2-thinking` | 256K | | | | | | — | — |
89
91
  | `poe/novita/kimi-k2.5` | 128K | | | | | | $0.60 | $3 |
92
+ | `poe/novita/kimi-k2.6` | 262K | | | | | | $0.96 | $4 |
90
93
  | `poe/novita/minimax-m2.1` | 205K | | | | | | — | — |
91
94
  | `poe/openai/dall-e-3` | 800 | | | | | | — | — |
92
95
  | `poe/openai/gpt-3.5-turbo` | 16K | | | | | | $0.45 | $1 |
@@ -110,6 +110,8 @@ export const agent = new Agent({
110
110
 
111
111
  **tools** (`ToolsInput | ({ requestContext: RequestContext }) => ToolsInput | Promise<ToolsInput>`): Tools that the agent can access. Can be provided statically or resolved dynamically.
112
112
 
113
+ **transform** (`ToolPayloadTransformPolicy`): Shared policy for transforming tool payloads before display streams or user-visible transcript messages receive them. Use per-tool \`transform\` on \`createTool()\` for tool-local rules.
114
+
113
115
  **workflows** (`Record<string, Workflow> | ({ requestContext: RequestContext }) => Record<string, Workflow> | Promise<Record<string, Workflow>>`): Workflows that the agent can execute. Can be static or dynamically resolved.
114
116
 
115
117
  **defaultOptions** (`AgentExecutionOptions | ({ requestContext: RequestContext }) => AgentExecutionOptions | Promise<AgentExecutionOptions>`): Default options used when calling \`stream()\` and \`generate()\`.
@@ -59,6 +59,8 @@ for await (const event of stream) {
59
59
  }
60
60
  ```
61
61
 
62
+ Streaming responses can also include tool events. Tool-call streams use `response.output_item.added`, `response.function_call_arguments.delta`, `response.function_call_arguments.done`, and `response.output_item.done` events. Tool results appear as `function_call_output` items with `<toolCallId>:output` IDs.
63
+
62
64
  **Returns:** `Promise<ResponsesStream>`.
63
65
 
64
66
  #### `retrieve(responseId, requestContext?)`
@@ -130,6 +132,8 @@ Use [`client.conversations`](https://mastra.ai/reference/client-js/conversations
130
132
 
131
133
  If the model calls a function, that activity appears in `response.output` as `function_call` and `function_call_output` items alongside the final assistant `message`.
132
134
 
135
+ When `stream: true`, function calls are also emitted as Responses stream events. Read `response.function_call_arguments.delta` events for partial argument chunks and prefer `response.function_call_arguments.done` for the finalized arguments payload and tool name. Read `response.output_item.done` events for completed `function_call` and `function_call_output` items. Tool output items use `<toolCallId>:output` IDs.
136
+
133
137
  ## Structured output
134
138
 
135
139
  Use `text.format` when you want JSON output.
@@ -175,20 +175,20 @@ Custom ID generator function for creating unique identifiers. Mastra passes opti
175
175
  > **Warning:** This is used internally by Mastra for creating IDs for workflow runs, agent conversations, and other resources. Most users won't need to configure this option.
176
176
 
177
177
  ```typescript
178
+ import { v4 as uuid } from '@lukeed/uuid'
178
179
  import { Mastra } from '@mastra/core'
179
- import { nanoid } from 'nanoid'
180
180
 
181
181
  export const mastra = new Mastra({
182
182
  idGenerator: context => {
183
183
  if (context?.idType === 'message' && context?.threadId) {
184
- return `msg-${context.threadId}-${nanoid(8)}`
184
+ return `msg-${context.threadId}-${uuid()}`
185
185
  }
186
186
 
187
187
  if (context?.idType === 'run' && context?.source && context?.entityId) {
188
- return `${context.source}-run-${context.entityId}-${nanoid(6)}`
188
+ return `${context.source}-run-${context.entityId}-${uuid()}`
189
189
  }
190
190
 
191
- return nanoid()
191
+ return uuid()
192
192
  },
193
193
  })
194
194
  ```
@@ -98,7 +98,7 @@ await harness.sendMessage({ content: 'Hello!' })
98
98
 
99
99
  **omConfig** (`HarnessOMConfig`): Default configuration for observational memory (observer/reflector model IDs and thresholds).
100
100
 
101
- **disableBuiltinTools** (`BuiltinToolId[]`): Built-in harness tool IDs to remove from the \`harnessBuiltIn\` toolset. Valid values are \`ask\_user\`, \`submit\_plan\`, \`task\_write\`, \`task\_check\`, and \`subagent\`.
101
+ **disableBuiltinTools** (`BuiltinToolId[]`): Built-in harness tool IDs to remove from the \`harnessBuiltIn\` toolset. Valid values are \`ask\_user\`, \`submit\_plan\`, \`task\_write\`, \`task\_update\`, \`task\_complete\`, \`task\_check\`, and \`subagent\`.
102
102
 
103
103
  **heartbeatHandlers** (`HeartbeatHandler[]`): Periodic background tasks started during \`init()\`. Use for gateway sync, cache refresh, and similar tasks.
104
104
 
@@ -162,6 +162,17 @@ Return the current `HarnessDisplayState` snapshot for UI rendering.
162
162
  const displayState = harness.getDisplayState()
163
163
  ```
164
164
 
165
+ #### `restoreDisplayTasks(tasks)`
166
+
167
+ Restore the task portion of `HarnessDisplayState` after a UI replays persisted task tool history. This emits `display_state_changed` without emitting a live `task_updated` event.
168
+
169
+ If later task tools should read the replayed tasks, persist the same task list with `setState({ tasks })` before calling `restoreDisplayTasks(tasks)`.
170
+
171
+ ```typescript
172
+ await harness.setState({ tasks: replayedTasks })
173
+ harness.restoreDisplayTasks(replayedTasks)
174
+ ```
175
+
165
176
  #### `setState(updates)`
166
177
 
167
178
  Update the harness state. Validates against `stateSchema` if provided, and emits a `state_changed` event with the new state and changed keys.
@@ -831,13 +842,15 @@ The harness emits events through registered listeners. The following table lists
831
842
 
832
843
  The harness provides built-in tools to agents in every mode:
833
844
 
834
- | Tool | Description |
835
- | ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
836
- | `ask_user` | Ask the user a question and wait for their response. Supports free text, single-select choices, and multi-select choices. |
837
- | `submit_plan` | Submit a plan for user review and approval. |
838
- | `task_write` | Create or update a structured task list for tracking progress. |
839
- | `task_check` | Check the completion status of the current task list. |
840
- | `subagent` | Spawn a focused subagent with constrained tools (only available when `subagents` is configured). Pass `forked: true` to inherit the parent conversation see [Forked subagents](#forked-subagents). |
845
+ | Tool | Description |
846
+ | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
847
+ | `ask_user` | Ask the user a question and wait for their response. Supports free text, single-select choices, and multi-select choices. |
848
+ | `submit_plan` | Submit a plan for user review and approval. |
849
+ | `task_write` | Create or replace a structured task list for tracking progress. Assigns task IDs when omitted and returns the structured task list snapshot. |
850
+ | `task_update` | Update one tracked task by ID and return the structured task list snapshot. |
851
+ | `task_complete` | Mark one tracked task completed by ID and return the structured task list snapshot. |
852
+ | `task_check` | Check the completion status of the current task list and return `tasks`, `summary`, `incompleteTasks`, and `isError` fields. |
853
+ | `subagent` | Spawn a focused subagent with constrained tools (only available when `subagents` is configured). Pass `forked: true` to inherit the parent conversation — see [Forked subagents](#forked-subagents). |
841
854
 
842
855
  ### `ask_user` selections
843
856
 
@@ -170,6 +170,7 @@ The Reference section provides documentation of Mastra's API, including paramete
170
170
  - [PromptInjectionDetector](https://mastra.ai/reference/processors/prompt-injection-detector)
171
171
  - [ProviderHistoryCompat](https://mastra.ai/reference/processors/provider-history-compat)
172
172
  - [RegexFilterProcessor](https://mastra.ai/reference/processors/regex-filter-processor)
173
+ - [ResponseCache](https://mastra.ai/reference/processors/response-cache)
173
174
  - [SemanticRecall](https://mastra.ai/reference/processors/semantic-recall-processor)
174
175
  - [SkillSearchProcessor](https://mastra.ai/reference/processors/skill-search-processor)
175
176
  - [StreamErrorRetryProcessor](https://mastra.ai/reference/processors/stream-error-retry-processor)
@@ -278,6 +279,7 @@ The Reference section provides documentation of Mastra's API, including paramete
278
279
  - [Run Class](https://mastra.ai/reference/workflows/run)
279
280
  - [Step Class](https://mastra.ai/reference/workflows/step)
280
281
  - [Workflow Class](https://mastra.ai/reference/workflows/workflow)
282
+ - [Workflow State Reader](https://mastra.ai/reference/workflows/workflow-state-reader)
281
283
  - [.branch()](https://mastra.ai/reference/workflows/workflow-methods/branch)
282
284
  - [.commit()](https://mastra.ai/reference/workflows/workflow-methods/commit)
283
285
  - [.createRun()](https://mastra.ai/reference/workflows/workflow-methods/create-run)
@@ -36,7 +36,9 @@ OM performs thresholding with fast local token estimation. Text uses `tokenx`, a
36
36
 
37
37
  **scope** (`'resource' | 'thread'`): Memory scope for observations. \`'thread'\` keeps observations per-thread. \`'resource'\` (experimental) shares observations across all threads for a resource, enabling cross-conversation memory. (Default: `'thread'`)
38
38
 
39
- **activateAfterIdle** (`number | string`): Time before buffered observations or buffered reflections are forced to activate after inactivity, even if their token thresholds have not been reached yet. Accepts milliseconds or duration strings like \`300\_000\`, \`"5m"\`, or \`"1hr"\`. When the gap between the current time and the last assistant message part timestamp exceeds this value, buffered observational memory activates before the next prompt. Useful for aligning with prompt cache TTLs.
39
+ **activateAfterIdle** (`number | string | false`): Time before buffered observations are forced to activate after inactivity, even before \`observation.messageTokens\` is reached. Accepts a numeric millisecond value such as \`300\_000\`, duration strings like \`"5m"\` or \`"1hr"\`, or \`false\` to disable inherited observation idle activation. Reflections do not inherit this setting. Use \`reflection.activateAfterIdle\` to opt reflections into idle activation.
40
+
41
+ **activateOnProviderChange** (`boolean`): Force buffered observations to activate when the actor provider or model changes. Reflections do not inherit this setting. Use \`reflection.activateOnProviderChange\` to opt reflections into provider-change activation. (Default: `false`)
40
42
 
41
43
  **shareTokenBudget** (`boolean`): Share the token budget between messages and observations. When enabled, the total budget is \`observation.messageTokens + reflection.observationTokens\`. Messages can use more space when observations are small, and vice versa. This maximizes context usage through flexible allocation. \`shareTokenBudget\` is not yet compatible with async buffering. You must set \`observation: { bufferTokens: false }\` when using this option (this is a temporary limitation). (Default: `false`)
42
44
 
@@ -66,6 +68,10 @@ OM performs thresholding with fast local token estimation. Text uses `tokenx`, a
66
68
 
67
69
  **observation.bufferActivation** (`number`): Controls how much of the message window to retain after activation. Accepts a ratio (0-1) or an absolute token count (≥ 1000). For example, \`0.8\` means: activate enough buffers to remove 80% of \`messageTokens\` and leave 20% as active message history. An absolute token count like \`4000\` targets a goal of keeping \~4k message tokens remaining after activation. Higher values remove more message history per activation when using a ratio. Higher values keep more message history when using a token count.
68
70
 
71
+ **observation.activateAfterIdle** (`number | string | false`): Time before buffered observations are forced to activate after inactivity. Accepts milliseconds, a duration string, or \`false\`. If unset, the top-level \`activateAfterIdle\` value is used for observations. Set \`false\` to disable the top-level idle setting for observations.
72
+
73
+ **observation.activateOnProviderChange** (`boolean`): Force buffered observations to activate when the actor provider or model changes. If unset, the top-level \`activateOnProviderChange\` value is used for observations.
74
+
69
75
  **observation.blockAfter** (`number`): Token threshold above which synchronous (blocking) observation is forced. Between \`messageTokens\` and \`blockAfter\`, only async buffering/activation is used. Above \`blockAfter\`, a synchronous observation runs as a last resort, while buffered activation still preserves a minimum remaining context (min(1000, retention floor)). Accepts a multiplier (1 < value < 2, multiplied by \`messageTokens\`) or an absolute token count (≥ 2, must be greater than \`messageTokens\`). Only relevant when \`bufferTokens\` is set. Defaults to \`1.2\` when async buffering is enabled.
70
76
 
71
77
  **observation.previousObserverTokens** (`number | false`): Optional token budget for the observer's previous-observations context. When set to a number, the observations passed to the Observer agent are tail-truncated to fit within this budget while keeping the newest observations and preserving highlighted 🔴 items when possible. When a buffered reflection is pending, the already-reflected observation lines are automatically replaced with the reflection summary before truncation. Set to \`0\` to omit previous observations entirely, or \`false\` to disable truncation explicitly.
@@ -86,6 +92,10 @@ OM performs thresholding with fast local token estimation. Text uses `tokenx`, a
86
92
 
87
93
  **reflection.bufferActivation** (`number`): Ratio (0-1) controlling when async reflection buffering starts. When observation tokens reach \`observationTokens \* bufferActivation\`, reflection runs in the background. On activation at the full threshold, the buffered reflection replaces the observations it covers, preserving any new observations appended after that range.
88
94
 
95
+ **reflection.activateAfterIdle** (`number | string | false`): Time before buffered reflections are forced to activate after inactivity. Accepts milliseconds, a duration string, or \`false\`. Reflections do not inherit top-level \`activateAfterIdle\`; set this explicitly to opt reflections into idle activation.
96
+
97
+ **reflection.activateOnProviderChange** (`boolean`): Force buffered reflections to activate when the actor provider or model changes. Reflections do not inherit top-level \`activateOnProviderChange\`; set this explicitly to opt reflections into provider-change activation.
98
+
89
99
  **reflection.blockAfter** (`number`): Token threshold above which synchronous (blocking) reflection is forced. Between \`observationTokens\` and \`blockAfter\`, only async buffering/activation is used. Above \`blockAfter\`, a synchronous reflection runs as a last resort. Accepts a multiplier (1 < value < 2, multiplied by \`observationTokens\`) or an absolute token count (≥ 2, must be greater than \`observationTokens\`). Only relevant when \`bufferActivation\` is set. Defaults to \`1.2\` when async reflection is enabled.
90
100
 
91
101
  ### Token estimate metadata cache
@@ -77,7 +77,7 @@ Flushes pending data and shuts down the client.
77
77
  ```typescript
78
78
  import { ArizeExporter } from '@mastra/arize'
79
79
 
80
- // For Phoenix: Set PHOENIX_ENDPOINT, PHOENIX_API_KEY, PHOENIX_PROJECT_NAME
80
+ // For Phoenix: Set PHOENIX_COLLECTOR_ENDPOINT, PHOENIX_API_KEY, PHOENIX_PROJECT_NAME
81
81
  // For Arize AX: Set ARIZE_SPACE_ID, ARIZE_API_KEY, ARIZE_PROJECT_NAME
82
82
  const exporter = new ArizeExporter()
83
83
  ```
@@ -128,6 +128,8 @@ Failed flushes are retried with exponential backoff:
128
128
  - Maximum attempts: `maxRetries`
129
129
  - Batch is dropped after all retries fail
130
130
 
131
+ When storage does not support a signal or retries are exhausted, `DefaultExporter` emits an `ObservabilityDropEvent` through `onDroppedEvent` handlers registered on exporters and bridges. The drop event includes the signal, reason, count, exporter name, storage name when known, and sanitized error details.
132
+
131
133
  ### Out-of-Order Handling
132
134
 
133
135
  For `batch-with-updates` strategy:
@@ -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,
@@ -171,6 +179,33 @@ interface ObservabilityExporter {
171
179
 
172
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 Cloud exporter behavior for these callbacks, see [CloudExporter](https://mastra.ai/reference/observability/tracing/exporters/cloud-exporter).
173
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.
208
+
174
209
  ### `SpanOutputProcessor`
175
210
 
176
211
  Interface for span output processors.
@@ -0,0 +1,114 @@
1
+ # ResponseCache
2
+
3
+ `ResponseCache` is an input processor that caches LLM responses on the request/response boundary inside the agentic loop. It hooks into `processLLMRequest` (cache lookup; short-circuits on hit) and `processLLMResponse` (cache write on completion).
4
+
5
+ The cache key is derived from the resolved `LanguageModelV2Prompt` Mastra is about to send to the model — i.e. _after_ memory has loaded and earlier input processors have transformed the prompt — so two users with different memory contexts produce different cache keys. Each step in an agentic tool loop is independently cached.
6
+
7
+ There is no agent-level option for response caching; register `ResponseCache` explicitly on `inputProcessors`. Per-call overrides flow through `RequestContext` via [`ResponseCache.context()`](#static-helpers) and [`ResponseCache.applyContext()`](#static-helpers).
8
+
9
+ ## Usage example
10
+
11
+ ```typescript
12
+ import { Agent } from '@mastra/core/agent'
13
+ import { InMemoryServerCache } from '@mastra/core/cache'
14
+ import { ResponseCache } from '@mastra/core/processors'
15
+
16
+ const cache = new InMemoryServerCache()
17
+
18
+ const agent = new Agent({
19
+ name: 'Search Agent',
20
+ instructions: 'You answer questions concisely.',
21
+ model: 'openai/gpt-5',
22
+ inputProcessors: [new ResponseCache({ cache, ttl: 600 })],
23
+ })
24
+
25
+ // First call hits the LLM and writes to the cache.
26
+ await agent.generate('What is the capital of France?')
27
+
28
+ // Second identical call replays the cached response.
29
+ await agent.generate('What is the capital of France?')
30
+
31
+ // Force a fresh call but still update the cache.
32
+ await agent.generate('What is the capital of France?', {
33
+ requestContext: ResponseCache.context({ bust: true }),
34
+ })
35
+ ```
36
+
37
+ See [Response caching](https://mastra.ai/docs/agents/response-caching) for the conceptual overview, scoping rules, and recommended deployment patterns.
38
+
39
+ ## Constructor parameters
40
+
41
+ **cache** (`MastraServerCache`): The cache backend. Required. Pass any \`MastraServerCache\` implementation — \`InMemoryServerCache\` for local development, \`RedisCache\` from \`@mastra/redis\` for production, or your own subclass for a custom backend.
42
+
43
+ **ttl** (`number`): Time-to-live (seconds) for entries written by this processor. Defaults to 300 seconds (5 minutes), matching OpenRouter's reference implementation. (Default: `300`)
44
+
45
+ **scope** (`string | null`): Tenant scope appended to the cache key. \`null\` opts out of scoping. When omitted, the processor falls back to the resource id resolved from the request context (\`MASTRA\_RESOURCE\_ID\_KEY\`) for automatic per-user isolation.
46
+
47
+ **key** (`string | (inputs: ResponseCacheKeyInputs) => string | Promise<string>`): Override the auto-derived cache key. Pass a string to pin a key, or a function that receives \`{ agentId, scope, model, prompt, stepNumber }\` and returns a key. If the function throws, the processor falls back to the deterministic hash so the call still benefits from caching.
48
+
49
+ **bust** (`boolean`): Force a cache miss on every call: skip the read but still write on completion. Useful for explicit refresh paths. (Default: `false`)
50
+
51
+ **agentId** (`string`): Logical id used in the cache key namespace. Defaults to \`'mastra-response-cache'\`. Set this to the owning agent's id when you want cache entries scoped per-agent. (Default: `'mastra-response-cache'`)
52
+
53
+ ## Static helpers
54
+
55
+ `ResponseCache` exposes two static helpers for setting per-call overrides on a `RequestContext`. The helpers keep the underlying context key a private implementation detail — prefer them over reading/writing the raw key.
56
+
57
+ ### `ResponseCache.context(options)`
58
+
59
+ Build a fresh `RequestContext` preloaded with per-call response cache overrides.
60
+
61
+ ```typescript
62
+ await agent.stream('hello', {
63
+ requestContext: ResponseCache.context({ key: 'custom', bust: true }),
64
+ })
65
+ ```
66
+
67
+ ### `ResponseCache.applyContext(requestContext, options)`
68
+
69
+ Merge per-call response cache overrides into an existing `RequestContext`. Returns the same context for chaining.
70
+
71
+ ```typescript
72
+ const ctx = new RequestContext()
73
+ ctx.set('caller-meta', { userId: 'u-123' })
74
+ ResponseCache.applyContext(ctx, { bust: true })
75
+ await agent.stream('hello', { requestContext: ctx })
76
+ ```
77
+
78
+ ## ResponseCacheContextOptions
79
+
80
+ The shape passed to `ResponseCache.context()` / `ResponseCache.applyContext()`.
81
+
82
+ **key** (`string | (inputs: ResponseCacheKeyInputs) => string | Promise<string>`): Overrides the auto-derived cache key for this request only.
83
+
84
+ **scope** (`string | null`): Overrides the tenant scope for this request only. \`null\` opts out of scoping.
85
+
86
+ **bust** (`boolean`): Skip the cache read but still write on completion.
87
+
88
+ `cache`, `ttl`, and `agentId` are intentionally not overridable per call — they are instance-level concerns that should not vary per request.
89
+
90
+ ## ResponseCacheKeyInputs
91
+
92
+ The argument passed to a `key` function (constructor or per-call). All fields contribute to the deterministic hash by default.
93
+
94
+ **agentId** (`string`): Logical processor id used to namespace the cache key.
95
+
96
+ **scope** (`string | null | undefined`): Resolved scope for this request, or \`null\` when scoping is disabled.
97
+
98
+ **model** (`{ provider?: string; modelId?: string; specVersion?: string }`): Provider/model identity. Different models produce different responses.
99
+
100
+ **prompt** (`LanguageModelV2Prompt`): The exact prompt the provider would receive, post memory load and post any prompt-modifying input processors.
101
+
102
+ **stepNumber** (`number`): 0-indexed step number within the agentic loop. Greater than zero for tool steps.
103
+
104
+ ## Helper exports
105
+
106
+ - `buildResponseCacheKey(inputs)` — the deterministic hash used by default. Re-export it to override individual fields while preserving the rest of the standard key shape.
107
+ - `DEFAULT_RESPONSE_CACHE_TTL_SECONDS` — the default `ttl` (`300`).
108
+ - `RESPONSE_CACHE_CONTEXT_KEY` — the `RequestContext` key the static helpers write to. Exposed for advanced cases (e.g. clearing the override mid-pipeline); prefer the helpers.
109
+
110
+ ## Related
111
+
112
+ - [Response caching](https://mastra.ai/docs/agents/response-caching)
113
+ - [Processors](https://mastra.ai/docs/agents/processors)
114
+ - [Processor interface](https://mastra.ai/reference/processors/processor-interface)
@@ -173,6 +173,50 @@ The tool still returns the full `execute` result to your application, while the
173
173
  - `type: 'json'`
174
174
  - `type: 'content'` with parts like `text`, `image-url`, `image-data`, `file-url`, `file-data`, `file-id`, `image-file-id`, or `custom`
175
175
 
176
+ ## Example with `transform`
177
+
178
+ Use `transform` when the tool should keep raw inputs or outputs for runtime behavior, but display streams or transcript messages should receive a smaller or safer shape.
179
+
180
+ ```typescript
181
+ import { createTool } from '@mastra/core/tools'
182
+ import { z } from 'zod'
183
+
184
+ export const customerTool = createTool({
185
+ id: 'lookup-customer',
186
+ description: 'Looks up a customer',
187
+ inputSchema: z.object({
188
+ customerId: z.string(),
189
+ internalPath: z.string(),
190
+ }),
191
+ outputSchema: z.object({
192
+ displayName: z.string(),
193
+ apiKey: z.string(),
194
+ debugScore: z.number(),
195
+ }),
196
+ execute: async () => {
197
+ return {
198
+ displayName: 'Acme',
199
+ apiKey: 'secret-value',
200
+ debugScore: 0.97,
201
+ }
202
+ },
203
+ transform: {
204
+ display: {
205
+ input: ({ input }) => ({ customerId: input?.customerId }),
206
+ output: ({ output }) => ({ displayName: output?.displayName }),
207
+ error: () => ({ message: 'Customer lookup failed' }),
208
+ },
209
+ transcript: {
210
+ input: ({ input }) => ({ customerId: input?.customerId }),
211
+ output: ({ output }) => ({ displayName: output?.displayName }),
212
+ error: () => ({ message: 'Customer lookup failed' }),
213
+ },
214
+ },
215
+ })
216
+ ```
217
+
218
+ The tool still receives the raw `inputSchema` value and returns the raw `execute` result. Mastra applies `display` transforms to streamed UI payloads and `transcript` transforms to user-visible transcript messages.
219
+
176
220
  ## Example with MCP annotations
177
221
 
178
222
  When exposing tools via MCP (Model Context Protocol), you can add annotations to describe tool behavior and customize how clients display the tool. These MCP-specific properties are grouped under the `mcp` property:
@@ -224,6 +268,8 @@ export const weatherTool = createTool({
224
268
 
225
269
  **toModelOutput** (`(output: TSchemaOut) => unknown`): Optional function that transforms the tool's \`execute\` output before it is sent back to the model. Use this to return \`text\`, \`json\`, or \`content\`-shaped outputs (including multimodal parts like images/files) to the model while still keeping the full raw output in your application code.
226
270
 
271
+ **transform** (`ToolPayloadTransform`): Optional target-aware transform for tool payloads before they leave runtime for display streams or user-visible transcript messages. Configure \`display\` and \`transcript\` transforms for phases such as \`input\`, \`inputDelta\`, \`output\`, \`error\`, \`approval\`, \`suspend\`, and \`resume\`.
272
+
227
273
  **suspendSchema** (`StandardJSONSchemaV1`): A Standard JSON Schema defining the structure of the payload passed to \`suspend()\`. This payload is returned to the client when the tool suspends execution.
228
274
 
229
275
  **resumeSchema** (`StandardJSONSchemaV1`): A Standard JSON Schema defining the expected structure of \`resumeData\` when the tool is resumed. Used by the agent to extract data from user messages when \`autoResumeSuspendedTools\` is enabled.
@@ -0,0 +1,113 @@
1
+ # Workflow state reader
2
+
3
+ Workflow state reader helpers inspect the public `WorkflowState` returned by `workflow.getWorkflowRunById()`. Use them to recover suspended runs, inspect resume labels, and read step payloads or outputs without parsing raw workflow snapshots.
4
+
5
+ ## Usage example
6
+
7
+ ```typescript
8
+ import { createWorkflowStateReader } from '@mastra/core/workflows'
9
+
10
+ const state = await workflow.getWorkflowRunById('run-123')
11
+
12
+ if (state) {
13
+ const reader = createWorkflowStateReader(state)
14
+ const suspendedStep = reader.getSuspendedStep()
15
+ const labels = reader.getResumeLabels()
16
+
17
+ console.log(reader.getStatus())
18
+ console.log(reader.getStepOutput('extract-data'))
19
+ console.log(suspendedStep?.path)
20
+ console.log(labels.approve)
21
+ }
22
+ ```
23
+
24
+ ## Functions
25
+
26
+ ### `createWorkflowStateReader(state)`
27
+
28
+ Creates a reader object with methods bound to one `WorkflowState`.
29
+
30
+ ```typescript
31
+ const reader = createWorkflowStateReader(state)
32
+ const suspendedStep = reader.getSuspendedStep()
33
+ ```
34
+
35
+ ### `getWorkflowStepOutput(state, stepId)`
36
+
37
+ Returns the output for a step ID, including nested workflow dot paths such as `parent.child`. For `foreach` steps, returns one entry per iteration; suspended iterations can have `undefined` output entries.
38
+
39
+ ```typescript
40
+ const output = getWorkflowStepOutput(state, 'extract-data')
41
+ ```
42
+
43
+ ### `getWorkflowStepPayload(state, stepId)`
44
+
45
+ Returns the payload that was passed to a step. For `foreach` steps, returns one entry per iteration.
46
+
47
+ ```typescript
48
+ const payload = getWorkflowStepPayload(state, 'extract-data')
49
+ ```
50
+
51
+ ### `getWorkflowSuspendedStep(state)`
52
+
53
+ Returns the first suspended step from the workflow state. When multiple steps are suspended, ordering follows the order stored in `suspendedPaths`.
54
+
55
+ ```typescript
56
+ const suspendedStep = getWorkflowSuspendedStep(state)
57
+ ```
58
+
59
+ ### `getWorkflowSuspendedSteps(state)`
60
+
61
+ Returns all suspended steps from the workflow state. Each result includes the top-level step ID, resume path, execution path, suspend payload, suspend output, and matching resume labels.
62
+
63
+ ```typescript
64
+ const suspendedSteps = getWorkflowSuspendedSteps(state)
65
+ ```
66
+
67
+ ### `getWorkflowResumeLabel(state, label)`
68
+
69
+ Returns a resume label by name.
70
+
71
+ ```typescript
72
+ const label = getWorkflowResumeLabel(state, 'approve')
73
+ ```
74
+
75
+ ### `getWorkflowResumeLabels(state)`
76
+
77
+ Returns all resume labels from the workflow state.
78
+
79
+ ```typescript
80
+ const labels = getWorkflowResumeLabels(state)
81
+ ```
82
+
83
+ ## Reader methods
84
+
85
+ `createWorkflowStateReader(state)` returns the following methods:
86
+
87
+ **getStatus** (`() => WorkflowRunStatus`): Returns the workflow run status.
88
+
89
+ **getResult** (`() => WorkflowState["result"]`): Returns the terminal workflow result when it exists.
90
+
91
+ **getError** (`() => WorkflowState["error"]`): Returns the terminal workflow error when it exists.
92
+
93
+ **getStepOutput** (`(stepId: string) => any | Array<any | undefined> | undefined`): Returns the output for a step ID or nested workflow dot path.
94
+
95
+ **getStepPayload** (`(stepId: string) => any | Array<any | undefined> | undefined`): Returns the payload for a step ID or nested workflow dot path.
96
+
97
+ **getSuspendedStep** (`() => { stepId: string; path: string[]; executionPath?: number[]; step?: NonNullable<WorkflowState["steps"]>[string]; payload?: any; suspendPayload?: any; suspendOutput?: any; resumeLabels: Record<string, { stepId: string; foreachIndex?: number }> } | undefined`): Returns the first suspended step.
98
+
99
+ **getSuspendedSteps** (`() => Array<{ stepId: string; path: string[]; executionPath?: number[]; step?: NonNullable<WorkflowState["steps"]>[string]; payload?: any; suspendPayload?: any; suspendOutput?: any; resumeLabels: Record<string, { stepId: string; foreachIndex?: number }> }>`): Returns all suspended steps.
100
+
101
+ **getResumeLabel** (`(label: string) => { stepId: string; foreachIndex?: number } | undefined`): Returns a resume label by name.
102
+
103
+ **getResumeLabels** (`() => Record<string, { stepId: string; foreachIndex?: number }>`): Returns all resume labels.
104
+
105
+ ## Notes
106
+
107
+ `requestContext` and `tracingContext` are only returned by `workflow.getWorkflowRunById()` when explicitly requested with `fields`.
108
+
109
+ ## Related
110
+
111
+ - [Suspend & resume](https://mastra.ai/docs/workflows/suspend-and-resume)
112
+ - [Snapshots](https://mastra.ai/docs/workflows/snapshots)
113
+ - [Workflow class](https://mastra.ai/reference/workflows/workflow)
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @mastra/mcp-docs-server
2
2
 
3
+ ## 1.1.35-alpha.16
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`7c275a8`](https://github.com/mastra-ai/mastra/commit/7c275a810595e1a6c41ccc39720531ab65734700), [`890b24c`](https://github.com/mastra-ai/mastra/commit/890b24cc7d32ed6aa4dfe253e54dc6bf4099f690), [`0f48ebf`](https://github.com/mastra-ai/mastra/commit/0f48ebfc7ac7897b2092a189f45751924cf56d1c), [`f180e49`](https://github.com/mastra-ai/mastra/commit/f180e4990e71b04c9a475b523584071712f0048f), [`9260e01`](https://github.com/mastra-ai/mastra/commit/9260e015276fb1b500f7878ee452b47476bf1583), [`2f6c54e`](https://github.com/mastra-ai/mastra/commit/2f6c54e17c041cac1def54baaa6b771647836414), [`e06a159`](https://github.com/mastra-ai/mastra/commit/e06a1598ca07a6c3778aefc2a2d288363c6294ff), [`db34bc6`](https://github.com/mastra-ai/mastra/commit/db34bc6fb36cf125bda0c46be4d3fdc774b70cc4)]:
8
+ - @mastra/core@1.33.0-alpha.8
9
+ - @mastra/mcp@1.7.0
10
+
11
+ ## 1.1.35-alpha.14
12
+
13
+ ### Patch Changes
14
+
15
+ - Updated dependencies [[`6742347`](https://github.com/mastra-ai/mastra/commit/6742347d71955d7639adc9ddf6ff8282de7ee3ba), [`7b0ad1f`](https://github.com/mastra-ai/mastra/commit/7b0ad1f5c53dc118c6da12ae82ae2587037dc2b8), [`62666c3`](https://github.com/mastra-ai/mastra/commit/62666c367eaeac3941ead454b1d38810cc855721), [`4af2160`](https://github.com/mastra-ai/mastra/commit/4af2160322f4718cac421930cce85641e9512389), [`136c959`](https://github.com/mastra-ai/mastra/commit/136c9592fb0eeb0cd212f28629d8a29b7557a2fc), [`4df7cc7`](https://github.com/mastra-ai/mastra/commit/4df7cc79342fd065fe7fdeef93c094db14b12bcd), [`aca3121`](https://github.com/mastra-ai/mastra/commit/aca31211233dac25459f140ea4fcfb3a5af64c18), [`9cdf38e`](https://github.com/mastra-ai/mastra/commit/9cdf38e58506e1109c8b38f97cd7770978a4218e), [`990851e`](https://github.com/mastra-ai/mastra/commit/990851edcb0e30be5c2c18b6532f1a876cc2d335), [`6068a6c`](https://github.com/mastra-ai/mastra/commit/6068a6c42950fad3ebfc92346417896ba60803d2), [`00106be`](https://github.com/mastra-ai/mastra/commit/00106bede59b81e5b0e9cd6aad8d3b5dbc336387), [`e2a079c`](https://github.com/mastra-ai/mastra/commit/e2a079cc3755b1895f7bd5dc36e9be81b11c7c22), [`534a456`](https://github.com/mastra-ai/mastra/commit/534a456a25e4df1e5407e7e632f4cb3b1fa14f9d), [`36bae07`](https://github.com/mastra-ai/mastra/commit/36bae07c0e70b1b3006f2fd20830e8883dcbd066)]:
16
+ - @mastra/core@1.33.0-alpha.7
17
+
3
18
  ## 1.1.35-alpha.12
4
19
 
5
20
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/mcp-docs-server",
3
- "version": "1.1.35-alpha.13",
3
+ "version": "1.1.35-alpha.17",
4
4
  "description": "MCP server for accessing Mastra.ai documentation, changelogs, and news.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -29,7 +29,7 @@
29
29
  "jsdom": "^26.1.0",
30
30
  "local-pkg": "^1.1.2",
31
31
  "zod": "^4.3.6",
32
- "@mastra/core": "1.33.0-alpha.6",
32
+ "@mastra/core": "1.33.0-alpha.8",
33
33
  "@mastra/mcp": "^1.7.0"
34
34
  },
35
35
  "devDependencies": {
@@ -48,7 +48,7 @@
48
48
  "vitest": "4.1.5",
49
49
  "@internal/lint": "0.0.92",
50
50
  "@internal/types-builder": "0.0.67",
51
- "@mastra/core": "1.33.0-alpha.6"
51
+ "@mastra/core": "1.33.0-alpha.8"
52
52
  },
53
53
  "homepage": "https://mastra.ai",
54
54
  "repository": {