@mastra/mcp-docs-server 1.1.45 → 1.1.46-alpha.0

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 (60) hide show
  1. package/.docs/docs/agents/code-mode.md +2 -0
  2. package/.docs/docs/agents/signal-providers.md +222 -0
  3. package/.docs/docs/agents/signals.md +63 -189
  4. package/.docs/docs/getting-started/build-with-ai.md +2 -2
  5. package/.docs/docs/mastra-platform/configuration.md +1 -1
  6. package/.docs/docs/mastra-platform/overview.md +1 -1
  7. package/.docs/docs/observability/config.md +139 -0
  8. package/.docs/docs/observability/{tracing → integrations}/bridges/datadog.md +7 -7
  9. package/.docs/docs/observability/{tracing → integrations}/bridges/otel.md +3 -3
  10. package/.docs/docs/observability/{tracing → integrations}/exporters/datadog.md +1 -1
  11. package/.docs/docs/observability/{tracing → integrations}/exporters/mastra-platform.md +1 -1
  12. package/.docs/docs/observability/{tracing → integrations}/exporters/mastra-storage.md +1 -1
  13. package/.docs/docs/observability/{tracing → integrations}/exporters/otel.md +4 -4
  14. package/.docs/docs/observability/{tracing → integrations}/exporters/posthog.md +16 -0
  15. package/.docs/docs/observability/integrations/overview.md +45 -0
  16. package/.docs/docs/observability/metrics/overview.md +1 -1
  17. package/.docs/docs/observability/metrics/querying.md +18 -0
  18. package/.docs/docs/observability/overview.md +8 -4
  19. package/.docs/docs/observability/storage.md +79 -0
  20. package/.docs/docs/observability/tracing/overview.md +98 -390
  21. package/.docs/guides/guide/signal-provider.md +217 -0
  22. package/.docs/guides/migrations/upgrade-to-v1/tracing.md +11 -11
  23. package/.docs/reference/agents/agent.md +150 -2
  24. package/.docs/reference/client-js/agents.md +4 -0
  25. package/.docs/reference/core/mastra-class.md +28 -0
  26. package/.docs/reference/harness/harness-class.md +1 -1
  27. package/.docs/reference/index.md +3 -0
  28. package/.docs/reference/observability/tracing/bridges/datadog.md +2 -2
  29. package/.docs/reference/observability/tracing/bridges/otel.md +2 -2
  30. package/.docs/reference/observability/tracing/configuration.md +1 -1
  31. package/.docs/reference/observability/tracing/exporters/arize.md +1 -1
  32. package/.docs/reference/observability/tracing/exporters/arthur.md +1 -1
  33. package/.docs/reference/observability/tracing/exporters/cloud-exporter.md +1 -1
  34. package/.docs/reference/observability/tracing/exporters/console-exporter.md +1 -1
  35. package/.docs/reference/observability/tracing/exporters/default-exporter.md +1 -1
  36. package/.docs/reference/observability/tracing/exporters/mastra-platform-exporter.md +1 -1
  37. package/.docs/reference/observability/tracing/exporters/mastra-storage-exporter.md +1 -1
  38. package/.docs/reference/observability/tracing/exporters/otel.md +2 -2
  39. package/.docs/reference/observability/tracing/span-filtering.md +1 -1
  40. package/.docs/reference/pubsub/base.md +24 -0
  41. package/.docs/reference/pubsub/caching-pubsub.md +6 -0
  42. package/.docs/reference/pubsub/event-emitter.md +36 -1
  43. package/.docs/reference/signals/create-notification-inbox-tool.md +67 -0
  44. package/.docs/reference/signals/signal-provider.md +406 -0
  45. package/.docs/reference/signals/webhook-signal-provider.md +137 -0
  46. package/.docs/reference/storage/clickhouse.md +3 -3
  47. package/.docs/reference/storage/composite.md +1 -1
  48. package/.docs/reference/storage/duckdb.md +1 -1
  49. package/.docs/reference/storage/libsql.md +1 -1
  50. package/.docs/reference/storage/postgresql.md +1 -1
  51. package/CHANGELOG.md +8 -0
  52. package/package.json +7 -7
  53. /package/.docs/docs/observability/{tracing → integrations}/exporters/arize.md +0 -0
  54. /package/.docs/docs/observability/{tracing → integrations}/exporters/arthur.md +0 -0
  55. /package/.docs/docs/observability/{tracing → integrations}/exporters/braintrust.md +0 -0
  56. /package/.docs/docs/observability/{tracing → integrations}/exporters/laminar.md +0 -0
  57. /package/.docs/docs/observability/{tracing → integrations}/exporters/langfuse.md +0 -0
  58. /package/.docs/docs/observability/{tracing → integrations}/exporters/langsmith.md +0 -0
  59. /package/.docs/docs/observability/{tracing → integrations}/exporters/sentry.md +0 -0
  60. /package/.docs/docs/observability/{tracing → integrations}/processors/sensitive-data-filter.md +0 -0
@@ -0,0 +1,217 @@
1
+ # Building a signal provider
2
+
3
+ In this guide, you'll build a signal provider that polls an external service on an interval and pushes a notification into an agent thread whenever a watched resource changes. You'll learn how to extend the `SignalProvider` base class, track subscriptions, emit notifications from a poll loop, and register the provider on an agent.
4
+
5
+ The example watches build pipelines in a fake CI service, but the pattern applies to any pull-based source: an issue tracker, a status API, a queue, or your own backend.
6
+
7
+ > **Alpha:** Signal providers are in alpha. Breaking changes may occur without a major version bump until the API is stable.
8
+
9
+ ## Prerequisites
10
+
11
+ - Node.js `v22.13.0` or later installed
12
+ - An API key from a supported [Model Provider](https://mastra.ai/models)
13
+ - An existing Mastra project. Follow the [installation guide](https://mastra.ai/guides/getting-started/quickstart) if needed.
14
+
15
+ This guide also assumes you understand [signals](https://mastra.ai/docs/agents/signals) at a high level. For the full API surface, see the [`SignalProvider` reference](https://mastra.ai/reference/signals/signal-provider).
16
+
17
+ ## Add notification storage
18
+
19
+ A signal provider pushes [notification signals](https://mastra.ai/docs/agents/signals) into threads, and notifications require a storage adapter that supports the notifications domain. Configure storage on your Mastra instance.
20
+
21
+ ```typescript
22
+ import { Mastra } from '@mastra/core'
23
+ import { LibSQLStore } from '@mastra/libsql'
24
+
25
+ export const mastra = new Mastra({
26
+ storage: new LibSQLStore({
27
+ url: 'file:./mastra.db',
28
+ }),
29
+ })
30
+ ```
31
+
32
+ LibSQL, PostgreSQL, and MongoDB all support notification records. Without notification storage, the provider's `notify()` calls throw at runtime.
33
+
34
+ ## Create the external service client
35
+
36
+ Real providers call an external API. To keep this guide self-contained, create a small fake CI client that returns a build status for a pipeline. Swap this for your real API client later.
37
+
38
+ ```typescript
39
+ export type BuildStatus = {
40
+ id: string
41
+ pipeline: string
42
+ status: 'passed' | 'failed' | 'running'
43
+ }
44
+
45
+ // Returns a random status so you can see notifications fire while testing.
46
+ export async function fetchBuildStatus(pipeline: string): Promise<BuildStatus> {
47
+ const states: BuildStatus['status'][] = ['passed', 'failed', 'running']
48
+ const status = states[Math.floor(Math.random() * states.length)]!
49
+ return { id: `build_${Date.now()}`, pipeline, status }
50
+ }
51
+ ```
52
+
53
+ This client returns a random status each call. When you wire in a real API, only this file changes.
54
+
55
+ ## Build the signal provider
56
+
57
+ Extend `SignalProvider`, implement the abstract `id` field, set a `pollInterval`, and override `poll()`. The base class calls `poll()` on the interval with every active subscription. Emit a notification only for the builds you care about.
58
+
59
+ ```typescript
60
+ import { SignalProvider } from '@mastra/core/signals'
61
+ import type { SignalProviderTarget, SignalSubscription } from '@mastra/core/signals'
62
+ import { fetchBuildStatus } from './ci-client'
63
+
64
+ export class CiSignals extends SignalProvider<'ci-signals'> {
65
+ readonly id = 'ci-signals' as const
66
+ readonly pollInterval = 10_000 // poll every 10 seconds
67
+
68
+ // Public API so callers can subscribe a thread to a pipeline.
69
+ watch(target: SignalProviderTarget, pipeline: string): SignalSubscription {
70
+ return this.subscribe(target, pipeline)
71
+ }
72
+
73
+ unwatch(target: SignalProviderTarget, pipeline: string): boolean {
74
+ return this.unsubscribe(target, pipeline)
75
+ }
76
+
77
+ async poll(subscriptions: SignalSubscription[]): Promise<void> {
78
+ for (const sub of subscriptions) {
79
+ const build = await fetchBuildStatus(sub.externalResourceId)
80
+ if (build.status !== 'failed') continue
81
+
82
+ await this.notify(
83
+ {
84
+ source: this.id,
85
+ kind: 'ci-status',
86
+ priority: 'high',
87
+ summary: `Build failed for ${sub.externalResourceId}`,
88
+ payload: build,
89
+ dedupeKey: `${this.id}:${sub.externalResourceId}:${build.id}`,
90
+ },
91
+ { resourceId: sub.resourceId, threadId: sub.threadId },
92
+ )
93
+ }
94
+ }
95
+ }
96
+ ```
97
+
98
+ A few things to note:
99
+
100
+ - `subscribe()` and `unsubscribe()` are protected on the base class. Wrap them in your own public methods (`watch` / `unwatch`) so callers can manage subscriptions.
101
+ - `externalResourceId` is any provider-specific string. Here it's the pipeline name; a GitHub provider might use `"github:owner/repo#123"`.
102
+ - `notify()` forwards a notification signal to the connected agent's thread. It throws if the provider was never registered on an agent.
103
+ - `dedupeKey` prevents storing the same failure twice.
104
+
105
+ ## Register the provider on an agent
106
+
107
+ Pass the provider to the agent through `signals`. The agent connects it and starts the poll loop automatically.
108
+
109
+ ```typescript
110
+ import { Agent } from '@mastra/core/agent'
111
+ import { CiSignals } from '../signals/ci-signals'
112
+
113
+ export const ciSignals = new CiSignals()
114
+
115
+ export const devAgent = new Agent({
116
+ id: 'dev-agent',
117
+ name: 'Dev Agent',
118
+ instructions: 'Help the user triage CI build failures.',
119
+ model: 'openai/gpt-5.5',
120
+ signals: [ciSignals],
121
+ })
122
+ ```
123
+
124
+ Register the agent with Mastra and add the storage from the first step.
125
+
126
+ ```typescript
127
+ import { Mastra } from '@mastra/core'
128
+ import { LibSQLStore } from '@mastra/libsql'
129
+ import { devAgent } from './agents/dev-agent'
130
+
131
+ export const mastra = new Mastra({
132
+ agents: { devAgent },
133
+ storage: new LibSQLStore({
134
+ url: 'file:./mastra.db',
135
+ }),
136
+ })
137
+ ```
138
+
139
+ ## Subscribe a thread
140
+
141
+ A provider only polls resources that a thread is watching. Subscribe a thread to a pipeline so `poll()` has something to check.
142
+
143
+ ```typescript
144
+ import { ciSignals } from './agents/dev-agent'
145
+
146
+ ciSignals.watch({ resourceId: 'user_123', threadId: 'thread_456' }, 'acme/app:main')
147
+ ```
148
+
149
+ Run this once after the agent is registered, for example from a setup script or an API route. The subscription lives in the provider's in-memory registry, so re-subscribe after a restart.
150
+
151
+ ## Test the signal provider
152
+
153
+ Start the dev server:
154
+
155
+ **npm**:
156
+
157
+ ```bash
158
+ npm run dev
159
+ ```
160
+
161
+ **pnpm**:
162
+
163
+ ```bash
164
+ pnpm run dev
165
+ ```
166
+
167
+ **Yarn**:
168
+
169
+ ```bash
170
+ yarn dev
171
+ ```
172
+
173
+ **Bun**:
174
+
175
+ ```bash
176
+ bun run dev
177
+ ```
178
+
179
+ Make sure a thread is subscribed, then watch the logs. The fake client returns a random status each poll, so within a few cycles you'll see a failed build trigger a notification for the subscribed thread.
180
+
181
+ To see the agent react to the notification, subscribe to the thread and stream it:
182
+
183
+ ```typescript
184
+ const subscription = await devAgent.subscribeToThread({
185
+ resourceId: 'user_123',
186
+ threadId: 'thread_456',
187
+ })
188
+
189
+ for await (const chunk of subscription.stream) {
190
+ console.log(chunk)
191
+ }
192
+ ```
193
+
194
+ When a build fails, the model receives the notification as context:
195
+
196
+ ```xml
197
+ <notification source="ci-signals" type="ci-status" priority="high" status="delivered">Build failed for acme/app:main</notification>
198
+ ```
199
+
200
+ Output is non-deterministic because the fake client randomizes status and the model phrases its reply freely, so the exact wording will vary.
201
+
202
+ ## Next steps
203
+
204
+ You can extend this signal provider to:
205
+
206
+ - Replace `fetchBuildStatus()` with a real API client.
207
+ - Persist subscriptions so they survive a restart, then rehydrate them in [`start()`](https://mastra.ai/reference/signals/signal-provider).
208
+ - Add a [webhook](https://mastra.ai/docs/agents/signal-providers) entry point with [`handleWebhook()`](https://mastra.ai/reference/signals/signal-provider) for push-based sources.
209
+ - Expose `subscribe` and `unsubscribe` tools with [`getTools()`](https://mastra.ai/reference/signals/signal-provider) so the agent can manage its own subscriptions.
210
+ - Use [`dedupeKey` and `coalesceKey`](https://mastra.ai/reference/agents/agent) when notifications need deduplication or batching.
211
+
212
+ Learn more:
213
+
214
+ - [Building signal providers](https://mastra.ai/docs/agents/signal-providers)
215
+ - [Signals](https://mastra.ai/docs/agents/signals)
216
+ - [`SignalProvider` reference](https://mastra.ai/reference/signals/signal-provider)
217
+ - [`WebhookSignalProvider` reference](https://mastra.ai/reference/signals/webhook-signal-provider)
@@ -127,7 +127,7 @@ Key changes:
127
127
  3. Use explicit `configs:` with `MastraStorageExporter`, `MastraPlatformExporter`, and `SensitiveDataFilter`
128
128
  4. Export types change from string literals (`'otlp'`) to exporter class instances (`new OtelExporter()`)
129
129
 
130
- See the [exporters documentation](https://mastra.ai/docs/observability/tracing/overview) for all available exporters.
130
+ See the [exporters documentation](https://mastra.ai/docs/observability/integrations/overview) for all available exporters.
131
131
 
132
132
  ### From AI Tracing
133
133
 
@@ -292,7 +292,7 @@ To migrate, follow the "From OTEL-based Telemetry" section above. For detailed c
292
292
 
293
293
  The automatic detection of instrumentation files in `/mastra` (with `.ts`, `.js`, or `.mjs` extensions) has been removed. Custom instrumentation is no longer supported through separate files.
294
294
 
295
- To migrate, use the built-in exporter system or implement custom exporters using the `ObservabilityExporter` interface. See the [exporters documentation](https://mastra.ai/docs/observability/tracing/overview) for details.
295
+ To migrate, use the built-in exporter system or implement custom exporters using the `ObservabilityExporter` interface. See the [exporters documentation](https://mastra.ai/docs/observability/integrations/overview) for details.
296
296
 
297
297
  ### `instrumentation.mjs` files
298
298
 
@@ -352,14 +352,14 @@ No separate instrumentation files or special startup flags required.
352
352
 
353
353
  If you were using OTEL-based telemetry with specific providers in 0.x, here's how to configure them in v1:
354
354
 
355
- | Provider | Exporter | Guide | Reference |
356
- | --------------------------------------------------------- | ----------------- | -------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
357
- | Arize AX, Arize Phoenix | **Arize** | [Guide](https://mastra.ai/docs/observability/tracing/exporters/arize) | [Reference](https://mastra.ai/reference/observability/tracing/exporters/arize) |
358
- | Braintrust | **Braintrust** | [Guide](https://mastra.ai/docs/observability/tracing/exporters/braintrust) | [Reference](https://mastra.ai/reference/observability/tracing/exporters/braintrust) |
359
- | Langfuse | **Langfuse** | [Guide](https://mastra.ai/docs/observability/tracing/exporters/langfuse) | [Reference](https://mastra.ai/reference/observability/tracing/exporters/langfuse) |
360
- | LangSmith | **LangSmith** | [Guide](https://mastra.ai/docs/observability/tracing/exporters/langsmith) | [Reference](https://mastra.ai/reference/observability/tracing/exporters/langsmith) |
361
- | Dash0, Laminar, New Relic, SigNoz, Traceloop, Custom OTEL | **OpenTelemetry** | [Guide](https://mastra.ai/docs/observability/tracing/exporters/otel) | [Reference](https://mastra.ai/reference/observability/tracing/exporters/otel) |
362
- | LangWatch | \<coming soon> | - | - |
355
+ | Provider | Exporter | Guide | Reference |
356
+ | --------------------------------------------------------- | ----------------- | ------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
357
+ | Arize AX, Arize Phoenix | **Arize** | [Guide](https://mastra.ai/docs/observability/integrations/exporters/arize) | [Reference](https://mastra.ai/reference/observability/tracing/exporters/arize) |
358
+ | Braintrust | **Braintrust** | [Guide](https://mastra.ai/docs/observability/integrations/exporters/braintrust) | [Reference](https://mastra.ai/reference/observability/tracing/exporters/braintrust) |
359
+ | Langfuse | **Langfuse** | [Guide](https://mastra.ai/docs/observability/integrations/exporters/langfuse) | [Reference](https://mastra.ai/reference/observability/tracing/exporters/langfuse) |
360
+ | LangSmith | **LangSmith** | [Guide](https://mastra.ai/docs/observability/integrations/exporters/langsmith) | [Reference](https://mastra.ai/reference/observability/tracing/exporters/langsmith) |
361
+ | Dash0, Laminar, New Relic, SigNoz, Traceloop, Custom OTEL | **OpenTelemetry** | [Guide](https://mastra.ai/docs/observability/integrations/exporters/otel) | [Reference](https://mastra.ai/reference/observability/tracing/exporters/otel) |
362
+ | LangWatch | \<coming soon> | - | - |
363
363
 
364
364
  ### Installation
365
365
 
@@ -415,4 +415,4 @@ yarn add @mastra/otel-exporter@latest
415
415
  bun add @mastra/otel-exporter@latest
416
416
  ```
417
417
 
418
- Plus the required protocol package for your provider (see [OTEL guide](https://mastra.ai/docs/observability/tracing/exporters/otel)).
418
+ Plus the required protocol package for your provider (see [OTEL guide](https://mastra.ai/docs/observability/integrations/exporters/otel)).
@@ -141,6 +141,35 @@ The model receives this as:
141
141
  <user name="Devin" from="slack">Can we simplify the API surface?</user>
142
142
  ```
143
143
 
144
+ Use `ifActive.attributes` and `ifIdle.attributes` when the message should carry different context depending on whether the thread is currently running:
145
+
146
+ ```typescript
147
+ agent.sendMessage(
148
+ {
149
+ contents: 'Also cover the edge cases.',
150
+ attributes: { source: 'chat' },
151
+ },
152
+ {
153
+ resourceId: 'user-123',
154
+ threadId: 'thread-abc',
155
+ ifActive: { attributes: { delivery: 'while-active' } },
156
+ ifIdle: { attributes: { delivery: 'new-message' } },
157
+ },
158
+ )
159
+ ```
160
+
161
+ When the thread is active, the model sees:
162
+
163
+ ```xml
164
+ <user source="chat" delivery="while-active">Also cover the edge cases.</user>
165
+ ```
166
+
167
+ When the thread is idle, the model sees:
168
+
169
+ ```xml
170
+ <user source="chat" delivery="new-message">Also cover the edge cases.</user>
171
+ ```
172
+
144
173
  The UI sees the message contents and can also read `attributes` and `metadata` off the signal message for custom rendering (e.g. showing user names, avatars, or platform badges).
145
174
 
146
175
  ### `sendMessage(message, options)`
@@ -149,18 +178,43 @@ Sends a user message to an active run or memory thread. Use this when the active
149
178
 
150
179
  **message** (`string | Array<TextPart | FilePart> | { contents: string | Array<TextPart | FilePart>; attributes?: Record<string, JSONValue>; metadata?: Record<string, unknown>; providerOptions?: ProviderMetadata }`): User-authored input. Bare strings and parts without attributes are sent to the model as normal user input. When \`attributes\` are present, Mastra renders the message as a \`\<user>\` XML element with the attributes included.
151
180
 
181
+ **options** (`object`): Targeting and delivery behavior for the message.
182
+
152
183
  **options.runId** (`string`): Run ID to target directly. Use this when you already know the active run ID.
153
184
 
154
185
  **options.resourceId** (`string`): Resource ID for the memory thread. Required with \`threadId\` for thread-targeted messages.
155
186
 
156
187
  **options.threadId** (`string`): Thread ID to target. Required with \`resourceId\` for thread-targeted messages.
157
188
 
189
+ **options.ifActive** (`object`): Controls what happens when the target thread is active.
190
+
158
191
  **options.ifActive.behavior** (`'deliver' | 'persist' | 'discard'`): Controls what happens when the target thread is active. Defaults to \`deliver\`.
159
192
 
193
+ **options.ifActive.attributes** (`Record<string, string | number | boolean>`): Attributes merged into the message when Mastra accepts it while the target thread is active.
194
+
195
+ **options.ifIdle** (`object`): Controls what happens when the target thread is idle.
196
+
160
197
  **options.ifIdle.behavior** (`'wake' | 'persist' | 'discard'`): Controls what happens when the target thread is idle. Defaults to \`wake\`.
161
198
 
162
199
  **options.ifIdle.streamOptions** (`AgentExecutionOptions`): Options for the stream that starts when \`ifIdle.behavior\` is \`wake\`. Mastra uses the top-level \`resourceId\` and \`threadId\` for memory context.
163
200
 
201
+ **options.ifIdle.attributes** (`Record<string, string | number | boolean>`): Attributes merged into the message when Mastra accepts it while the target thread is idle.
202
+
203
+ Set `ifIdle.behavior` to `wake` and pass `ifIdle.streamOptions` when an idle thread should start a new stream with custom execution options:
204
+
205
+ ```typescript
206
+ agent.sendMessage('Continue with the next step.', {
207
+ resourceId: 'user-123',
208
+ threadId: 'thread-abc',
209
+ ifIdle: {
210
+ behavior: 'wake',
211
+ streamOptions: {
212
+ maxSteps: 3,
213
+ },
214
+ },
215
+ })
216
+ ```
217
+
164
218
  Returns `{ accepted: true, runId: string, signal: CreatedAgentSignal, persisted?: Promise<void> }`. `persisted` is only present for `persist` behavior and resolves when Mastra finishes writing the message to memory.
165
219
 
166
220
  ### `queueMessage(message, options)`
@@ -182,20 +236,78 @@ Sends a signal to an active run or memory thread.
182
236
 
183
237
  **signal** (`{ type: 'user' | 'state' | 'reactive' | 'notification' | 'user-message' | 'system-reminder'; tagName?: string; contents: string | Array<TextPart | FilePart>; attributes?: Record<string, JSONValue>; metadata?: Record<string, unknown>; providerOptions?: ProviderMetadata }`): Signal context to send to the thread. \`type\` is the semantic signal category. \`tagName\` controls the XML tag the model sees. For example, \`{ type: 'notification', tagName: 'github-review' }\` renders as \`\<github-review>...\</github-review>\`. Legacy \`user-message\` and \`system-reminder\` payloads are still accepted and normalized. Unknown \`type\` values are rejected; use \`tagName\` for custom XML tags.
184
238
 
239
+ **options** (`object`): Targeting and delivery behavior for the signal.
240
+
185
241
  **options.runId** (`string`): Run ID to target directly. Use this when you already know the active run ID.
186
242
 
187
243
  **options.resourceId** (`string`): Resource ID for the memory thread. Required with \`threadId\` for thread-targeted signals.
188
244
 
189
245
  **options.threadId** (`string`): Thread ID to target. Required with \`resourceId\` for thread-targeted signals.
190
246
 
247
+ **options.ifActive** (`object`): Controls what happens when the target thread is active.
248
+
191
249
  **options.ifActive.behavior** (`'deliver' | 'persist' | 'discard'`): Controls what happens when the target thread is active. Defaults to \`deliver\`.
192
250
 
251
+ **options.ifActive.attributes** (`Record<string, string | number | boolean>`): Attributes merged into the signal when Mastra accepts it while the target thread is active.
252
+
253
+ **options.ifIdle** (`object`): Controls what happens when the target thread is idle.
254
+
193
255
  **options.ifIdle.behavior** (`'wake' | 'persist' | 'discard'`): Controls what happens when the target thread is idle. Defaults to \`wake\`.
194
256
 
195
257
  **options.ifIdle.streamOptions** (`AgentExecutionOptions`): Options for the stream that starts when \`ifIdle.behavior\` is \`wake\`. Mastra uses the top-level \`resourceId\` and \`threadId\` for memory context.
196
258
 
259
+ **options.ifIdle.attributes** (`Record<string, string | number | boolean>`): Attributes merged into the signal when Mastra accepts it while the target thread is idle.
260
+
197
261
  Returns `{ accepted: true, runId: string, signal: CreatedAgentSignal, persisted?: Promise<void> }`. `persisted` is only present for `persist` behavior and resolves when Mastra finishes writing the signal to memory.
198
262
 
263
+ ### `sendStateSignal(state, options)`
264
+
265
+ Sends named, thread-scoped state context to an active run or memory thread. Use this when an external producer owns durable context that changes over time, such as browser state, editor state, or watcher output.
266
+
267
+ ```typescript
268
+ const result = await agent.sendStateSignal(
269
+ {
270
+ id: 'browser',
271
+ mode: 'snapshot',
272
+ cacheKey: 'browser:https://example.com:3-tabs',
273
+ contents: 'Browser is open on https://example.com with 3 tabs.',
274
+ value: {
275
+ activeUrl: 'https://example.com',
276
+ tabCount: 3,
277
+ open: true,
278
+ },
279
+ },
280
+ {
281
+ resourceId: 'user-123',
282
+ threadId: 'thread-abc',
283
+ },
284
+ )
285
+ ```
286
+
287
+ **state** (`object`): State signal to send to the thread.
288
+
289
+ **state.id** (`string`): State lane name, such as \`browser\` or \`editor\`.
290
+
291
+ **state.cacheKey** (`string`): Producer-owned key Mastra uses to skip duplicate state for the same lane and mode.
292
+
293
+ **state.contents** (`string | Array<TextPart | FilePart>`): LLM-facing representation of the state.
294
+
295
+ **state.mode** (`'snapshot' | 'delta'`): Whether the state is an authoritative snapshot or a change event. Defaults to \`snapshot\`.
296
+
297
+ **state.value** (`unknown`): Structured snapshot value for \`mode: 'snapshot'\`.
298
+
299
+ **state.delta** (`unknown`): Structured change value for \`mode: 'delta'\`.
300
+
301
+ **state.attributes** (`Record<string, string | number | boolean>`): Attributes rendered on the state signal tag.
302
+
303
+ **state.metadata** (`Record<string, unknown>`): Application metadata stored with the state signal.
304
+
305
+ **state.tagName** (`string`): XML tag name shown to the model. Defaults to \`state\`.
306
+
307
+ **options** (`object`): Targeting and delivery behavior for the state signal. Accepts the same options as \`sendSignal()\`.
308
+
309
+ Returns `{ accepted: true, runId: string, signal: CreatedAgentSignal, persisted?: Promise<void>, skipped?: false }` when Mastra accepts new state. Returns `{ accepted: true, skipped: true, reason: 'unchanged' }` when the same `cacheKey` and mode are already current for the state lane.
310
+
199
311
  ### `sendNotificationSignal(notification, options)`
200
312
 
201
313
  Creates or coalesces a notification inbox record, resolves the notification delivery policy, and sends a notification signal when the decision is immediate.
@@ -216,6 +328,8 @@ const result = await agent.sendNotificationSignal(
216
328
  )
217
329
  ```
218
330
 
331
+ **notification** (`object`): Notification inbox record to create or coalesce.
332
+
219
333
  **notification.source** (`string`): External system that produced the notification, such as \`github\`, \`slack\`, or \`email\`.
220
334
 
221
335
  **notification.kind** (`string`): Notification kind within the source, such as \`ci-status\`, \`mention\`, or \`direct-message\`.
@@ -234,20 +348,52 @@ const result = await agent.sendNotificationSignal(
234
348
 
235
349
  **notification.metadata** (`Record<string, unknown>`): Application metadata stored on the inbox record.
236
350
 
351
+ **options** (`object`): Target thread and wake-up behavior for the notification.
352
+
237
353
  **options.resourceId** (`string`): Resource ID for the notification inbox and target memory thread.
238
354
 
239
355
  **options.threadId** (`string`): Thread ID for the notification inbox and target memory thread.
240
356
 
357
+ **options.ifIdle** (`object`): Controls what happens when the target thread is idle.
358
+
241
359
  **options.ifIdle.streamOptions** (`AgentExecutionOptions`): Options for the stream that starts when an immediate notification wakes an idle thread.
242
360
 
243
361
  Returns `{ accepted: true, record: NotificationRecord, decision: NotificationDeliveryDecision, runId?: string, signal?: CreatedAgentSignal, persisted?: Promise<void> }`. `record` is the stored inbox record. `decision` is the delivery-policy result. `signal` and `runId` are present when ingress emits a signal immediately, including the immediate summary emitted for active high-priority notifications. `persisted` is present when the emitted signal is persisted without waking an idle thread.
244
362
 
245
363
  Default delivery is priority-aware. `urgent` notifications deliver immediately. `high` notifications deliver immediately when the thread is idle; when the thread is active, Mastra emits a summary immediately and keeps `deliverAt` for later full delivery when the thread is idle. `medium` notifications deliver immediately when idle and batch into summaries when active. `low` notifications batch into summaries in both active and idle threads; idle low-priority summaries reach subscribers without waking the model loop. For the full flow, visit [Signals](https://mastra.ai/docs/agents/signals).
246
364
 
365
+ Configure `notifications.deliveryPolicy` on the agent when some notifications should wait for a different dispatch window or summary rollup:
366
+
367
+ ```typescript
368
+ export const supportAgent = new Agent({
369
+ id: 'support-agent',
370
+ name: 'Support Agent',
371
+ instructions: 'Help the user triage updates.',
372
+ model: 'openai/gpt-5.5',
373
+ notifications: {
374
+ deliveryPolicy: {
375
+ priorities: {
376
+ urgent: 'deliver',
377
+ },
378
+ decide: ({ record }) => {
379
+ if (record.priority === 'low') {
380
+ return {
381
+ action: 'summarize',
382
+ summaryAt: new Date(Date.now() + 30 * 60 * 1000),
383
+ }
384
+ }
385
+ },
386
+ },
387
+ },
388
+ })
389
+ ```
390
+
247
391
  ### `subscribeToThread(options)`
248
392
 
249
393
  Subscribes to raw stream chunks for a memory thread. Use this before calling `sendMessage()`, `queueMessage()`, or `sendSignal()` when you need to render stream output, observe signal echoes, or abort the active run.
250
394
 
395
+ **options** (`object`): Thread subscription target.
396
+
251
397
  **options.resourceId** (`string`): Resource ID for the memory thread.
252
398
 
253
399
  **options.threadId** (`string`): Thread ID to subscribe to.
@@ -282,8 +428,6 @@ Returns an `AgentThreadSubscription` object with these members:
282
428
 
283
429
  **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.
284
430
 
285
- **notifications** (`{ deliveryPolicy?: NotificationDeliveryPolicyConfig }`): Notification delivery configuration for \`sendNotificationSignal()\`. \`deliveryPolicy\` can define \`decide\`, \`sources\`, \`priorities\`, or \`default\` rules that return \`deliver\`, \`queue\`, \`defer\`, \`summarize\`, \`persist\`, or \`discard\` decisions.
286
-
287
431
  **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.
288
432
 
289
433
  **defaultOptions** (`AgentExecutionOptions | ({ requestContext: RequestContext }) => AgentExecutionOptions | Promise<AgentExecutionOptions>`): Default options used when calling \`stream()\` and \`generate()\`.
@@ -298,6 +442,10 @@ Returns an `AgentThreadSubscription` object with these members:
298
442
 
299
443
  **memory** (`MastraMemory | ({ requestContext: RequestContext }) => MastraMemory | Promise<MastraMemory>`): Memory module used for storing and retrieving stateful context.
300
444
 
445
+ **notifications** (`object`): Notification delivery configuration for durable notification signals.
446
+
447
+ **notifications.deliveryPolicy** (`NotificationDeliveryPolicyConfig`): Controls how notification records are delivered. Configure a default decision, per-priority decisions, per-source decisions, or a custom \`decide()\` function.
448
+
301
449
  **voice** (`CompositeVoice`): Voice settings for speech input and output.
302
450
 
303
451
  **inputProcessors** (`(Processor | ProcessorWorkflow)[] | ({ requestContext: RequestContext }) => (Processor | ProcessorWorkflow)[] | Promise<(Processor | ProcessorWorkflow)[]>`): Input processors that can modify or validate messages before they are processed by the agent. Can be individual Processor objects or workflows created with \`createWorkflow()\` using ProcessorStepSchema.
@@ -245,10 +245,14 @@ Returns `{ accepted: true, runId: string }`.
245
245
 
246
246
  **ifActive.behavior** (`'deliver' | 'persist' | 'discard'`): Controls what happens when the target thread is active. Defaults to \`deliver\`.
247
247
 
248
+ **ifActive.attributes** (`Record<string, string | number | boolean>`): Attributes merged into the signal when Mastra accepts it while the target thread is active.
249
+
248
250
  **ifIdle.behavior** (`'wake' | 'persist' | 'discard'`): Controls what happens when the target thread is idle. Defaults to \`wake\`.
249
251
 
250
252
  **ifIdle.streamOptions** (`Omit<AgentExecutionOptions, 'messages'>`): Options for the stream that starts when \`ifIdle.behavior\` is \`wake\`.
251
253
 
254
+ **ifIdle.attributes** (`Record<string, string | number | boolean>`): Attributes merged into the signal when Mastra accepts it while the target thread is idle.
255
+
252
256
  ### `subscribeToThread()`
253
257
 
254
258
  Subscribe to raw stream chunks for a memory thread. Use this to render output from a thread that may be started or continued by `sendMessage()`, `queueMessage()`, `sendSignal()`, or server-side notification dispatch.
@@ -27,6 +27,24 @@ export const mastra = new Mastra({
27
27
  })
28
28
  ```
29
29
 
30
+ Enable scheduled notification dispatch when deferred notification records and notification summaries should be delivered automatically through the workflow scheduler:
31
+
32
+ ```typescript
33
+ export const mastra = new Mastra({
34
+ agents: { supportAgent },
35
+ storage,
36
+ notifications: {
37
+ dispatch: {
38
+ enabled: true,
39
+ cron: '*/1 * * * *',
40
+ batchSize: 100,
41
+ },
42
+ },
43
+ })
44
+ ```
45
+
46
+ `notifications.dispatch.enabled` registers an internal workflow with the default cron `*/1 * * * *`. The dispatcher reads due notification records from storage, groups summaries by `agentId`, `resourceId`, and `threadId`, and emits signals through the agent thread runtime. It isn't a user-facing entrypoint.
47
+
30
48
  ## Constructor parameters
31
49
 
32
50
  Visit the [Configuration reference](https://mastra.ai/reference/configuration) for detailed documentation on all available configuration options.
@@ -67,6 +85,16 @@ Visit the [Configuration reference](https://mastra.ai/reference/configuration) f
67
85
 
68
86
  **memory** (`Record<string, MastraMemory>`): Memory instances to register. These can be referenced by stored agents and resolved at runtime. Structured as a key-value pair, with keys being the registry key and values being memory instances. (Default: `{}`)
69
87
 
88
+ **notifications** (`object`): Runtime configuration for notification signal dispatch.
89
+
90
+ **notifications.dispatch** (`NotificationDispatchConfig`): Scheduled dispatch configuration for deferred notifications and notification summaries. Dispatch is enabled by default.
91
+
92
+ **notifications.dispatch.enabled** (`boolean`): Set to \`false\` to opt out of automatic scheduled notification dispatch.
93
+
94
+ **notifications.dispatch.cron** (`string`): Cron schedule used by the internal notification dispatcher workflow.
95
+
96
+ **notifications.dispatch.batchSize** (`number`): Maximum number of due notification records to process per dispatch run.
97
+
70
98
  **versions** (`VersionOverrides`): Global version overrides for sub-agent delegation. When a supervisor agent delegates to a sub-agent, these overrides determine which stored version of that sub-agent to use instead of the code-defined default. Requires the editor package to be configured. See \[Sub-agent versioning]\(/docs/editor/overview#sub-agent-versioning) for details.
71
99
 
72
100
  **versions.agents** (`Record<string, VersionSelector>`): A map of agent IDs to their version selectors. Each selector can target a specific version by ID or by publication status.
@@ -2,7 +2,7 @@
2
2
 
3
3
  **Added in:** `@mastra/core@1.5.0`
4
4
 
5
- > **Warning:** The `Harness` class is in alpha stage and subject to change. It won't follow semantic versioning guarantees until it graduates from experimental status. Use with caution and expect breaking changes in minor versions.
5
+ > **Alpha:** The `Harness` class is in alpha stage and subject to change. It won't follow semantic versioning guarantees until it graduates from experimental status. Use with caution and expect breaking changes in minor versions.
6
6
  >
7
7
  > [Mastra Code](https://code.mastra.ai/) is the flagship implementation of the `Harness` class, showcasing how it can be used to build a powerful terminal-based coding agent with multi-model support, persistent conversations, and built-in tools.
8
8
 
@@ -220,6 +220,9 @@ The Reference section provides documentation of Mastra's API, including paramete
220
220
  - [NestJS Adapter](https://mastra.ai/reference/server/nestjs-adapter)
221
221
  - [registerApiRoute()](https://mastra.ai/reference/server/register-api-route)
222
222
  - [Server Routes](https://mastra.ai/reference/server/routes)
223
+ - [createNotificationInboxTool()](https://mastra.ai/reference/signals/create-notification-inbox-tool)
224
+ - [SignalProvider](https://mastra.ai/reference/signals/signal-provider)
225
+ - [WebhookSignalProvider](https://mastra.ai/reference/signals/webhook-signal-provider)
223
226
  - [Overview](https://mastra.ai/reference/storage/overview)
224
227
  - [Aurora DSQL Storage](https://mastra.ai/reference/storage/dsql)
225
228
  - [ClickHouse Storage](https://mastra.ai/reference/storage/clickhouse)
@@ -155,7 +155,7 @@ const mastra = new Mastra({
155
155
 
156
156
  The DatadogBridge requires `dd-trace` to be initialized before any other imports so its auto-instrumentation can patch HTTP, database, and framework libraries at load time.
157
157
 
158
- See the [DatadogBridge Guide](https://mastra.ai/docs/observability/tracing/bridges/datadog) for complete setup instructions, including dd-trace initialization, bundler externals, and agent configuration.
158
+ See the [DatadogBridge Guide](https://mastra.ai/docs/observability/integrations/bridges/datadog) for complete setup instructions, including dd-trace initialization, bundler externals, and agent configuration.
159
159
 
160
160
  ## Span mapping
161
161
 
@@ -206,6 +206,6 @@ The bridge reads configuration from these environment variables:
206
206
 
207
207
  ## Related
208
208
 
209
- - [DatadogBridge Guide](https://mastra.ai/docs/observability/tracing/bridges/datadog) - Setup guide with examples
209
+ - [DatadogBridge Guide](https://mastra.ai/docs/observability/integrations/bridges/datadog) - Setup guide with examples
210
210
  - [Tracing Overview](https://mastra.ai/docs/observability/tracing/overview) - General tracing concepts
211
211
  - [DatadogExporter Reference](https://mastra.ai/reference/observability/tracing/exporters/datadog) - LLM Observability only, no `dd-trace` APM
@@ -118,7 +118,7 @@ const mastra = new Mastra({
118
118
 
119
119
  The OtelBridge requires an active OpenTelemetry SDK to function. The bridge reads from OTEL's ambient context.
120
120
 
121
- See the [OtelBridge Guide](https://mastra.ai/docs/observability/tracing/bridges/otel) for complete setup instructions, including how to configure OTEL instrumentation and run your application.
121
+ See the [OtelBridge Guide](https://mastra.ai/docs/observability/integrations/bridges/otel) for complete setup instructions, including how to configure OTEL instrumentation and run your application.
122
122
 
123
123
  ## Tags support
124
124
 
@@ -148,6 +148,6 @@ This format ensures compatibility with all OTEL-compatible backends and collecto
148
148
 
149
149
  ## Related
150
150
 
151
- - [OtelBridge Guide](https://mastra.ai/docs/observability/tracing/bridges/otel): Setup guide with examples
151
+ - [OtelBridge Guide](https://mastra.ai/docs/observability/integrations/bridges/otel): Setup guide with examples
152
152
  - [Tracing Overview](https://mastra.ai/docs/observability/tracing/overview): General tracing concepts
153
153
  - [OtelExporter Reference](https://mastra.ai/reference/observability/tracing/exporters/otel): OTEL exporter for sending traces
@@ -194,7 +194,7 @@ Shuts down all observability instances and clears the registry.
194
194
 
195
195
  - [Tracing Overview](https://mastra.ai/docs/observability/tracing/overview): Concepts and usage guide
196
196
  - [Sampling Strategies](https://mastra.ai/docs/observability/tracing/overview): Sampling configuration details
197
- - [Multi-Config Setup](https://mastra.ai/docs/observability/tracing/overview): Using multiple configurations
197
+ - [Multi-Config Setup](https://mastra.ai/docs/observability/config): Using multiple configurations
198
198
 
199
199
  ### Reference
200
200
 
@@ -136,6 +136,6 @@ Tags are stored using the OpenInference `tag.tags` attribute:
136
136
 
137
137
  ## Related
138
138
 
139
- - [ArizeExporter Documentation](https://mastra.ai/docs/observability/tracing/exporters/arize)
139
+ - [ArizeExporter Documentation](https://mastra.ai/docs/observability/integrations/exporters/arize)
140
140
  - [Phoenix Documentation](https://docs.arize.com/phoenix)
141
141
  - [Arize AX Documentation](https://docs.arize.com/)
@@ -117,6 +117,6 @@ Tags are stored using the OpenInference `tag.tags` attribute:
117
117
 
118
118
  ## Related
119
119
 
120
- - [ArthurExporter Documentation](https://mastra.ai/docs/observability/tracing/exporters/arthur)
120
+ - [ArthurExporter Documentation](https://mastra.ai/docs/observability/integrations/exporters/arthur)
121
121
  - [Arthur Engine documentation](https://docs.arthur.ai/)
122
122
  - [Arthur Engine repository](https://github.com/arthur-ai/arthur-engine)