@mastra/mcp-docs-server 1.2.2 → 1.2.3-alpha.11

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 (49) hide show
  1. package/.docs/docs/{harness → agent-controller}/modes.md +19 -19
  2. package/.docs/docs/agent-controller/overview.md +128 -0
  3. package/.docs/docs/agent-controller/session.md +143 -0
  4. package/.docs/docs/{harness → agent-controller}/subagents.md +12 -12
  5. package/.docs/docs/agent-controller/threads-and-state.md +141 -0
  6. package/.docs/docs/{harness → agent-controller}/tool-approvals.md +23 -23
  7. package/.docs/docs/agents/agent-approval.md +38 -0
  8. package/.docs/docs/agents/channels.md +47 -0
  9. package/.docs/docs/agents/heartbeats.md +211 -0
  10. package/.docs/docs/agents/signals.md +25 -1
  11. package/.docs/docs/observability/metrics/overview.md +2 -2
  12. package/.docs/models/gateways/openrouter.md +1 -2
  13. package/.docs/models/gateways/vercel.md +3 -1
  14. package/.docs/models/index.md +1 -1
  15. package/.docs/models/providers/anthropic.md +4 -5
  16. package/.docs/models/providers/chutes.md +17 -43
  17. package/.docs/models/providers/deepinfra.md +3 -2
  18. package/.docs/models/providers/friendli.md +1 -3
  19. package/.docs/models/providers/gmicloud.md +18 -15
  20. package/.docs/models/providers/huggingface.md +2 -1
  21. package/.docs/models/providers/inceptron.md +10 -8
  22. package/.docs/models/providers/llmgateway.md +3 -6
  23. package/.docs/models/providers/neuralwatt.md +9 -5
  24. package/.docs/models/providers/novita-ai.md +1 -1
  25. package/.docs/models/providers/nvidia.md +2 -1
  26. package/.docs/models/providers/siliconflow-cn.md +50 -78
  27. package/.docs/models/providers/siliconflow.md +52 -73
  28. package/.docs/models/providers/stepfun.md +1 -1
  29. package/.docs/models/providers/subconscious.md +71 -0
  30. package/.docs/models/providers/synthetic.md +8 -6
  31. package/.docs/models/providers/tinfoil.md +77 -0
  32. package/.docs/models/providers/xiaomi.md +2 -2
  33. package/.docs/models/providers.md +2 -0
  34. package/.docs/reference/{harness/harness-class.md → agent-controller/agent-controller-class.md} +106 -106
  35. package/.docs/reference/{harness → agent-controller}/session.md +97 -91
  36. package/.docs/reference/agents/channels.md +3 -1
  37. package/.docs/reference/agents/listSuspendedRuns.md +91 -0
  38. package/.docs/reference/channels/channel-provider.md +65 -0
  39. package/.docs/reference/channels/slack-provider.md +226 -0
  40. package/.docs/reference/client-js/agents.md +21 -0
  41. package/.docs/reference/index.md +6 -2
  42. package/.docs/reference/observability/metrics/automatic-metrics.md +2 -2
  43. package/.docs/reference/pubsub/lease-provider.md +131 -0
  44. package/.docs/reference/pubsub/redis-streams.md +10 -2
  45. package/CHANGELOG.md +42 -0
  46. package/package.json +4 -4
  47. package/.docs/docs/harness/overview.md +0 -128
  48. package/.docs/docs/harness/session.md +0 -143
  49. package/.docs/docs/harness/threads-and-state.md +0 -141
@@ -1,6 +1,6 @@
1
1
  # Tool approvals and permissions
2
2
 
3
- The Harness provides a permission system that controls which tools require user approval before execution. You can configure policies at the category level or per-tool, and grant session-wide exceptions for trusted tools. This gives agents with access to destructive or sensitive tools — file writes, command execution, API calls — a human-in-the-loop checkpoint before those tools run.
3
+ The AgentController provides a permission system that controls which tools require user approval before execution. You can configure policies at the category level or per-tool, and grant session-wide exceptions for trusted tools. This gives agents with access to destructive or sensitive tools — file writes, command execution, API calls — a human-in-the-loop checkpoint before those tools run.
4
4
 
5
5
  ## Permission policies
6
6
 
@@ -16,18 +16,18 @@ Set policies per-category or per-tool. Per-tool policies take precedence over ca
16
16
 
17
17
  ```typescript
18
18
  // Category-level: all execute tools require approval
19
- await harness.session.permissions.setForCategory({ category: 'execute', policy: 'ask' })
19
+ await agentController.session.permissions.setForCategory({ category: 'execute', policy: 'ask' })
20
20
 
21
21
  // Tool-level: this specific tool is always blocked
22
- await harness.session.permissions.setForTool({ toolName: 'dangerous_tool', policy: 'deny' })
22
+ await agentController.session.permissions.setForTool({ toolName: 'dangerous_tool', policy: 'deny' })
23
23
  ```
24
24
 
25
25
  ### Tool categories
26
26
 
27
- The `toolCategoryResolver` maps tool names to categories. Pass it to the Harness constructor:
27
+ The `toolCategoryResolver` maps tool names to categories. Pass it to the AgentController constructor:
28
28
 
29
29
  ```typescript
30
- const harness = new Harness({
30
+ const agentController = new AgentController({
31
31
  id: 'my-agent',
32
32
  toolCategoryResolver: toolName => {
33
33
  if (toolName.includes('write') || toolName.includes('delete')) return 'edit'
@@ -41,13 +41,13 @@ Built-in categories are `read`, `edit`, `execute`, `mcp`, and `other`.
41
41
 
42
42
  ## Responding to approval requests
43
43
 
44
- When a tool's policy is `ask`, the Harness emits a `tool_approval_required` event. Your UI should display a prompt and call `session.respondToToolApproval()`:
44
+ When a tool's policy is `ask`, the AgentController emits a `tool_approval_required` event. Your UI should display a prompt and call `session.respondToToolApproval()`:
45
45
 
46
46
  ```typescript
47
- harness.subscribe(event => {
47
+ agentController.subscribe(event => {
48
48
  if (event.type === 'tool_approval_required') {
49
49
  // Show approval UI...
50
- harness.session.respondToToolApproval({ decision: 'approve' })
50
+ agentController.session.respondToToolApproval({ decision: 'approve' })
51
51
  }
52
52
  })
53
53
  ```
@@ -55,22 +55,22 @@ harness.subscribe(event => {
55
55
  The `decision` field accepts `'approve'`, `'decline'`, or `'always_allow_category'`. When `always_allow_category` is used, the tool's category is granted for the rest of the session. Future tools in the same category are auto-approved.
56
56
 
57
57
  ```typescript
58
- harness.session.respondToToolApproval({ decision: 'always_allow_category' })
58
+ agentController.session.respondToToolApproval({ decision: 'always_allow_category' })
59
59
  ```
60
60
 
61
61
  ## Session grants
62
62
 
63
- The Harness owns permission _policy_ (which categories require approval); the [`Session`](https://mastra.ai/docs/harness/session) owns the _grants_ a user makes during a conversation. Grant a category or tool for the rest of the session so it runs without further prompting:
63
+ The AgentController owns permission _policy_ (which categories require approval); the [`Session`](https://mastra.ai/docs/agent-controller/session) owns the _grants_ a user makes during a conversation. Grant a category or tool for the rest of the session so it runs without further prompting:
64
64
 
65
65
  ```typescript
66
66
  // Grant all edit tools for this session
67
- harness.session.grantCategory('edit')
67
+ agentController.session.grantCategory('edit')
68
68
 
69
69
  // Grant a specific tool
70
- harness.session.grantTool('mastra_workspace_execute_command')
70
+ agentController.session.grantTool('mastra_workspace_execute_command')
71
71
 
72
72
  // Check current grants
73
- const grants = harness.session.getGrants()
73
+ const grants = agentController.session.getGrants()
74
74
  // { categories: ['edit'], tools: ['mastra_workspace_execute_command'] }
75
75
  ```
76
76
 
@@ -79,11 +79,11 @@ const grants = harness.session.getGrants()
79
79
  Interactive built-in tools (`ask_user`, `submit_plan`) use the native tool-suspension primitive instead of the approval flow. They emit a `tool_suspended` event with `toolCallId`, `toolName`, and `suspendPayload`. Resume with `respondToToolSuspension()`:
80
80
 
81
81
  ```typescript
82
- harness.subscribe(event => {
82
+ agentController.subscribe(event => {
83
83
  if (event.type === 'tool_suspended' && event.toolName === 'ask_user') {
84
84
  const { question } = event.suspendPayload as { question: string }
85
85
  // Show question to user, then resume:
86
- harness.respondToToolSuspension({
86
+ agentController.respondToToolSuspension({
87
87
  toolCallId: event.toolCallId,
88
88
  resumeData: 'User response here',
89
89
  })
@@ -97,13 +97,13 @@ The `submit_plan` tool suspends via the same mechanism. Resume with an `action`
97
97
 
98
98
  ```typescript
99
99
  // Approve the plan
100
- harness.respondToToolSuspension({
100
+ agentController.respondToToolSuspension({
101
101
  toolCallId: event.toolCallId,
102
102
  resumeData: { action: 'approved' },
103
103
  })
104
104
 
105
105
  // Reject with feedback
106
- harness.respondToToolSuspension({
106
+ agentController.respondToToolSuspension({
107
107
  toolCallId: event.toolCallId,
108
108
  resumeData: { action: 'rejected', feedback: 'Needs more detail' },
109
109
  })
@@ -111,7 +111,7 @@ harness.respondToToolSuspension({
111
111
 
112
112
  ## Built-in tools
113
113
 
114
- The Harness provides these built-in tools to agents in every mode:
114
+ The AgentController provides these built-in tools to agents in every mode:
115
115
 
116
116
  | Tool | Description |
117
117
  | --------------- | ------------------------------------------------------------------- |
@@ -126,7 +126,7 @@ The Harness provides these built-in tools to agents in every mode:
126
126
  Disable specific built-in tools with `disableBuiltinTools`:
127
127
 
128
128
  ```typescript
129
- const harness = new Harness({
129
+ const agentController = new AgentController({
130
130
  id: 'no-plans',
131
131
  disableBuiltinTools: ['submit_plan'],
132
132
  })
@@ -134,8 +134,8 @@ const harness = new Harness({
134
134
 
135
135
  ## Related
136
136
 
137
- - [Harness overview](https://mastra.ai/docs/harness/overview)
138
- - [Session](https://mastra.ai/docs/harness/session)
139
- - [Subagents](https://mastra.ai/docs/harness/subagents)
137
+ - [AgentController overview](https://mastra.ai/docs/agent-controller/overview)
138
+ - [Session](https://mastra.ai/docs/agent-controller/session)
139
+ - [Subagents](https://mastra.ai/docs/agent-controller/subagents)
140
140
  - [Agent approval](https://mastra.ai/docs/agents/agent-approval)
141
- - [API reference](https://mastra.ai/reference/harness/harness-class)
141
+ - [API reference](https://mastra.ai/reference/agent-controller/agent-controller-class)
@@ -357,6 +357,44 @@ For automatic tool resumption to work:
357
357
 
358
358
  Both approaches work with the same tool definitions. Automatic resumption triggers only when suspended tools exist in the message history and the user sends a new message on the same thread.
359
359
 
360
+ ## Resuming after a restart
361
+
362
+ The examples above hold on to `stream.runId` between suspension and approval. That works while the process stays alive, but in production the approval often arrives later — after a page refresh, a server restart, or on a different server instance behind a load balancer.
363
+
364
+ Use [`listSuspendedRuns()`](https://mastra.ai/reference/agents/listSuspendedRuns) to rediscover the pending run for a conversation from storage:
365
+
366
+ ```typescript
367
+ // In the request handler that receives the user's decision
368
+ const { runs } = await agent.listSuspendedRuns({
369
+ threadId: 'thread-123',
370
+ resourceId: 'user-456',
371
+ })
372
+
373
+ const run = runs[0]
374
+ const toolCall = run?.toolCalls[0]
375
+
376
+ if (run && toolCall) {
377
+ let stream
378
+ if (toolCall.requiresApproval) {
379
+ // Suspended by requireApproval — approve or decline the tool call
380
+ stream = await agent.approveToolCall({ runId: run.runId, toolCallId: toolCall.toolCallId })
381
+ } else {
382
+ // Suspended by suspend() — resume with the data the tool asked for
383
+ console.log('Tool asked:', toolCall.suspendPayload)
384
+ stream = await agent.resumeStream({ name: 'San Francisco' }, { runId: run.runId })
385
+ }
386
+ for await (const chunk of stream.textStream) process.stdout.write(chunk)
387
+ }
388
+ ```
389
+
390
+ Each returned run includes the suspended tool calls (`toolCallId`, `toolName`, `args`, and `requiresApproval`). Approval suspensions (`requiresApproval: true`) are answered with `approveToolCall()` / `declineToolCall()`, while `suspend()`-based suspensions carry their `suspendPayload` and expect `resumeStream()` with resume data — so you can rebuild the right UI for either flow without keeping any state in memory.
391
+
392
+ `sendToolApproval()` uses the same storage-backed discovery automatically: when no active run is found in memory for the thread, it looks up the suspended run in storage before failing. If several suspended runs match the thread, pass a `toolCallId` to disambiguate.
393
+
394
+ The same discovery is available over HTTP as `GET /agents/:agentId/suspended-runs` and in the client SDK as [`agent.listSuspendedRuns()`](https://mastra.ai/reference/client-js/agents), so browser-based approval UIs can rediscover pending runs directly.
395
+
396
+ > **Note:** Suspended runs only survive restarts when your Mastra instance is configured with a persistent [storage provider](https://mastra.ai/docs/memory/storage). The default in-memory store loses snapshots when the process exits.
397
+
360
398
  ## Tool approval: Supervisor agents
361
399
 
362
400
  A [supervisor agent](https://mastra.ai/docs/agents/supervisor-agents) coordinates multiple subagents using `.stream()` or `.generate()`. When a subagent calls a tool that requires approval, the request propagates up through the delegation chain and surfaces at the supervisor level:
@@ -164,6 +164,53 @@ By default, only images are sent inline (`inlineMedia: ['image/*']`). Unsupporte
164
164
 
165
165
  > **Note:** See [Channels reference](https://mastra.ai/reference/agents/channels) for all `inlineMedia` patterns and [inlineLinks reference](https://mastra.ai/reference/agents/channels) for domain matching, HEAD detection, and forced mime types.
166
166
 
167
+ ## Serverless deployment
168
+
169
+ On serverless platforms like Vercel, each request runs in a separate, short-lived instance. Channels need two things to work reliably in that environment: a way to keep the function alive while the agent responds, and a shared pub/sub so instances can coordinate.
170
+
171
+ ### Keep the function alive with `waitUntil`
172
+
173
+ A channel webhook returns a `200` response right away, then the agent runs in the background to post its reply. On most serverless platforms the function is frozen as soon as it responds, which kills the run before the agent answers. Pass a `waitUntil` function so the platform keeps the instance alive until the run finishes.
174
+
175
+ On Vercel, pass `waitUntil` from `@vercel/functions`:
176
+
177
+ ```typescript
178
+ import { waitUntil } from '@vercel/functions'
179
+
180
+ export const agent = new Agent({
181
+ // ...
182
+ channels: {
183
+ adapters: {
184
+ slack: createSlackAdapter(),
185
+ },
186
+ waitUntil,
187
+ },
188
+ })
189
+ ```
190
+
191
+ Vercel and AWS Lambda require `waitUntil`, since they freeze the function as soon as the response is sent. Cloudflare Workers and Netlify Functions are detected automatically from the request context, so they don't need it. For runtimes where `waitUntil` lives on the request context but isn't detected automatically, use `resolveWaitUntil`. See the [Channels reference](https://mastra.ai/reference/agents/channels) for details.
192
+
193
+ ### Coordinate instances with a shared pub/sub
194
+
195
+ Channels route messages through the agent's signal pipeline, and each run acquires a lease on its thread so a single run owns the conversation at a time. The default in-memory pub/sub can't cross instance boundaries, so on serverless a follow-up message can land on a different instance than the one running the agent. Without a shared pub/sub, that instance can't reach the active run and starts its own, leaving the original run untouched and the thread processed twice.
196
+
197
+ Configure a shared pub/sub backed by Redis Streams on the `Mastra` instance so leases and signals coordinate across instances:
198
+
199
+ ```typescript
200
+ import { Mastra } from '@mastra/core'
201
+ import { RedisStreamsPubSub } from '@mastra/redis-streams'
202
+
203
+ export const mastra = new Mastra({
204
+ agents: { agent },
205
+ pubsub: new RedisStreamsPubSub({
206
+ url: process.env.REDIS_URL,
207
+ keyPrefix: 'mastra:my-app',
208
+ }),
209
+ })
210
+ ```
211
+
212
+ Vercel's one-click Redis integration and Upstash Redis both work well. For more on when a distributed pub/sub is needed, see the [PubSub guide](https://mastra.ai/docs/server/pubsub) and the [`RedisStreamsPubSub` reference](https://mastra.ai/reference/pubsub/redis-streams).
213
+
167
214
  ## Related
168
215
 
169
216
  - [Guide: Building a Slack assistant](https://mastra.ai/guides/guide/slack-assistant)
@@ -0,0 +1,211 @@
1
+ # Heartbeats
2
+
3
+ **Added in:** `@mastra/core@1.46.0`
4
+
5
+ > **Beta:** This feature is in alpha. Breaking changes may occur without a major version bump until the API is stable.
6
+
7
+ A heartbeat runs an agent on a cron schedule. On each fire, Mastra sends a prompt to the agent, either as a [signal](https://mastra.ai/docs/agents/signals) into a thread or as a threadless `agent.generate()` run. Use heartbeats for recurring agent work such as daily summaries, periodic checks, or scheduled nudges into a conversation.
8
+
9
+ Heartbeats are persisted, so they survive restarts and redeploys. Manage them at runtime through `mastra.heartbeats`, the canonical create, read, update, and delete (CRUD) surface.
10
+
11
+ ## Prerequisites
12
+
13
+ Heartbeats require a [storage](https://mastra.ai/docs/memory/storage) adapter that implements the schedules domain, for example `@mastra/libsql`. Without one, `mastra.heartbeats.create()` throws.
14
+
15
+ ## Quickstart
16
+
17
+ The following heartbeat runs the `pinger` agent every hour. It has no thread, so each fire is an isolated `agent.generate()` run.
18
+
19
+ ```typescript
20
+ import { Mastra } from '@mastra/core'
21
+ import { Agent } from '@mastra/core/agent'
22
+ import { LibSQLStore } from '@mastra/libsql'
23
+
24
+ const pinger = new Agent({
25
+ id: 'pinger',
26
+ name: 'Pinger',
27
+ instructions: 'Report the current system status in one sentence.',
28
+ model: 'openai/gpt-5.5',
29
+ })
30
+
31
+ const mastra = new Mastra({
32
+ agents: { pinger },
33
+ storage: new LibSQLStore({ url: 'file:./mastra.db' }),
34
+ })
35
+
36
+ await mastra.heartbeats.create({
37
+ agentId: 'pinger',
38
+ cron: '0 * * * *',
39
+ prompt: 'Give me a status update.',
40
+ })
41
+ ```
42
+
43
+ Mastra starts the scheduler the first time a heartbeat is created, then fires the agent on the cron you specify.
44
+
45
+ ## Cadence
46
+
47
+ Heartbeats fire on a cron expression. The `cron` field accepts a standard 5-, 6-, or 7-part cron expression, and it's validated when you create or update the heartbeat.
48
+
49
+ Croner nicknames also work, for example `@hourly`, `@daily`, `@weekly`, `@monthly`, and `@midnight`. For day-and-time combinations, write the cron field directly:
50
+
51
+ ```typescript
52
+ // Every weekday at 9am
53
+ await mastra.heartbeats.create({
54
+ agentId: 'pinger',
55
+ cron: '0 9 * * 1-5',
56
+ prompt: 'Start-of-day check.',
57
+ })
58
+ ```
59
+
60
+ Set `timezone` to an IANA timezone, for example `America/New_York`, so fire times don't depend on the host's locale. When omitted, the cron resolves against the host's local timezone.
61
+
62
+ For more readable cron construction, you can use a userland builder such as [`cron-time-generator`](https://www.npmjs.com/package/cron-time-generator) and pass its output to `cron`.
63
+
64
+ ## Threadless and threaded heartbeats
65
+
66
+ A heartbeat fires in one of two modes, decided by whether you pass a `threadId`.
67
+
68
+ ### Threadless
69
+
70
+ Without a `threadId`, each fire is an isolated `agent.generate()` run. Nothing is written to a conversation thread. This is the simplest mode and suits status checks, reports, and other work that doesn't need conversation context.
71
+
72
+ ### Threaded
73
+
74
+ With a `threadId`, the heartbeat sends a [signal](https://mastra.ai/docs/agents/signals) into that thread, so the prompt joins the agent's conversation. Threaded heartbeats require a `resourceId` alongside the `threadId`.
75
+
76
+ ```typescript
77
+ await mastra.heartbeats.create({
78
+ agentId: 'pinger',
79
+ cron: '0 9 * * *',
80
+ prompt: 'Summarize anything new since yesterday.',
81
+ threadId: 'thread-123',
82
+ resourceId: 'user-456',
83
+ })
84
+ ```
85
+
86
+ Threaded heartbeats accept extra fields that control how the signal behaves. They mirror the options [`agent.sendSignal`](https://mastra.ai/docs/agents/signals) accepts and stay JSON-serializable so they persist with the schedule.
87
+
88
+ - `signalType`: the [signal type](https://mastra.ai/docs/agents/signals) to send, for example `notification` or `system-reminder`. Defaults to `notification`.
89
+ - `tagName`: the XML tag the signal renders as. Defaults to `heartbeat`, so a fire surfaces to the agent as `<heartbeat>…</heartbeat>`.
90
+ - `attributes`: values rendered onto the signal's XML tag.
91
+ - `ifActive`: behavior when the thread is already streaming, as `{ behavior, attributes }`. `behavior` is one of `deliver`, `persist`, or `discard`.
92
+ - `ifIdle`: behavior when the thread is idle, as `{ behavior, attributes, streamOptions }`. `behavior` is one of `wake`, `persist`, or `discard`. `streamOptions.requestContext` is applied to the woken run.
93
+
94
+ These fields require a `threadId`. Passing them on a threadless heartbeat throws.
95
+
96
+ ```typescript
97
+ await mastra.heartbeats.create({
98
+ agentId: 'pinger',
99
+ cron: '0 9 * * *',
100
+ prompt: 'Summarize anything new since yesterday.',
101
+ threadId: 'thread-123',
102
+ resourceId: 'user-456',
103
+ tagName: 'check-in', // renders as <check-in>…</check-in>
104
+ attributes: { source: 'cron' },
105
+ ifActive: { behavior: 'discard' }, // skip if the thread is mid-stream
106
+ ifIdle: {
107
+ behavior: 'wake', // wake the agent if the thread is idle
108
+ streamOptions: { requestContext: { locale: 'en-US' } },
109
+ },
110
+ })
111
+ ```
112
+
113
+ `providerOptions` are merged into the signal payload on every fire and apply to both threaded and threadless heartbeats.
114
+
115
+ ## Managing heartbeats
116
+
117
+ Use `mastra.heartbeats` for all heartbeat operations. To scope to a single agent, pass `agentId` to `create` or `list`.
118
+
119
+ ```typescript
120
+ // Create
121
+ const hb = await mastra.heartbeats.create({
122
+ agentId: 'pinger',
123
+ cron: '0 * * * *',
124
+ prompt: 'Status check.',
125
+ })
126
+
127
+ // Read
128
+ await mastra.heartbeats.get(hb.id)
129
+ await mastra.heartbeats.list({ agentId: 'pinger' })
130
+
131
+ // Update — changing cron or timezone recomputes the next fire time
132
+ await mastra.heartbeats.update(hb.id, { cron: '*/30 * * * *' })
133
+
134
+ // Pause and resume
135
+ await mastra.heartbeats.pause(hb.id)
136
+ await mastra.heartbeats.resume(hb.id)
137
+
138
+ // Fire once now, off-schedule
139
+ await mastra.heartbeats.run(hb.id)
140
+
141
+ // Delete
142
+ await mastra.heartbeats.delete(hb.id)
143
+ ```
144
+
145
+ A few rules worth knowing:
146
+
147
+ - `pause` and `resume` are durable and idempotent. A paused heartbeat survives restarts, and `resume` recomputes the next fire time from now rather than firing backlogged runs.
148
+ - `run` fires the heartbeat once immediately without affecting its schedule.
149
+ - `list` filters by `agentId`, `threadId`, `resourceId`, and `name`.
150
+
151
+ ### Custom IDs
152
+
153
+ By default `create` generates a random `hb_<uuid>` id. Pass `id` to choose a stable one, for example when you want a predictable handle to look up, update, or delete later:
154
+
155
+ ```typescript
156
+ await mastra.heartbeats.create({
157
+ id: 'nightly-summary',
158
+ agentId: 'pinger',
159
+ cron: '0 9 * * *',
160
+ prompt: 'Summarize anything new since yesterday.',
161
+ })
162
+ // stored as `hb_nightly-summary`
163
+ ```
164
+
165
+ The id is normalized to `hb_<slug>`: the `hb_` prefix is added if missing and the rest is slugified. Creating a heartbeat with an id that already exists throws, so use `update` to change an existing one.
166
+
167
+ ### From the client
168
+
169
+ The same operations are available from `@mastra/client-js` over the server routes, so you can manage heartbeats from a separate process or a UI.
170
+
171
+ ## Lifecycle hooks
172
+
173
+ Hooks let you run code at key points in a heartbeat's lifecycle, for example to compute fire-time parameters or react to the outcome. Configure them on the `Mastra` constructor under `heartbeat`. The hooks are a single flat bundle that runs for every agent's heartbeats; each hook context carries the firing `agentId`, so branch on it when you need per-agent behavior. Hooks live at the `Mastra` level so they apply to both code-defined and stored agents.
174
+
175
+ ```typescript
176
+ const mastra = new Mastra({
177
+ agents: { pinger },
178
+ storage: new LibSQLStore({ url: 'file:./mastra.db' }),
179
+ heartbeat: {
180
+ prepare: async ({ agentId, heartbeat, trigger }) => {
181
+ // Return overrides, null to skip this fire, or undefined for defaults
182
+ return { prompt: `Status as of ${trigger.firedAt.toISOString()}` }
183
+ },
184
+ onFinish: async ({ agentId, outcome, runId }) => {
185
+ // Runs on any non-error, non-abort outcome
186
+ },
187
+ onError: async ({ agentId, phase, error }) => {
188
+ // Runs when prepare, the signal, or the agent run threw
189
+ },
190
+ onAbort: async ({ agentId, runId }) => {
191
+ // Runs when the run was aborted mid-stream
192
+ },
193
+ },
194
+ })
195
+ ```
196
+
197
+ The hooks are:
198
+
199
+ - `prepare`: runs before the fire. Return an object to override fire-time parameters such as `prompt` or `threadId`, `null` to skip the fire, or `undefined` to use the stored defaults.
200
+ - `onFinish`: runs once per trigger that reached a non-error, non-abort terminal state.
201
+ - `onError`: runs when `prepare`, the signal, or the agent run threw.
202
+ - `onAbort`: runs when the run was aborted mid-stream.
203
+
204
+ Every hook context includes `agentId` (the agent the heartbeat fired for) alongside `heartbeat` and `trigger`.
205
+
206
+ Hook exceptions are caught and logged. They never re-route the worker or trigger another hook.
207
+
208
+ ## Related
209
+
210
+ - [Signals](https://mastra.ai/docs/agents/signals): the delivery mechanism behind threaded heartbeats.
211
+ - [Scheduled workflows](https://mastra.ai/docs/workflows/scheduled-workflows): run a workflow, rather than an agent, on a cron schedule.
@@ -322,6 +322,29 @@ Use `createNotificationInboxTool()` to give agents one tool for inbox actions in
322
322
 
323
323
  `sendNotificationSignal()` requires a storage domain with `notifications` support. Use `sendSignal({ type: 'notification' })` only for lower-level notification-shaped context that should bypass inbox storage.
324
324
 
325
+ ## Distributed and serverless deployments
326
+
327
+ Signals coordinate runs through a pub/sub backend. When a signal arrives on a backend that implements `LeaseProvider`, Mastra acquires a lease on the target thread so a single process owns the conversation at a time, then either wakes the agent or routes the input into the running loop. Backends without leasing fall back to a no-op that always grants ownership, which is fine in a single process but not across instances.
328
+
329
+ The default in-memory pub/sub can't cross instance boundaries. On serverless platforms like Vercel, or any multi-instance deployment, a follow-up signal can land on a different instance than the one running the agent. Without a shared pub/sub, that instance can't reach the active run and starts its own, leaving the original run untouched and the thread processed twice.
330
+
331
+ Configure a shared pub/sub backed by Redis Streams on the `Mastra` instance so leases and signals coordinate across instances:
332
+
333
+ ```typescript
334
+ import { Mastra } from '@mastra/core'
335
+ import { RedisStreamsPubSub } from '@mastra/redis-streams'
336
+
337
+ export const mastra = new Mastra({
338
+ agents: { agent },
339
+ pubsub: new RedisStreamsPubSub({
340
+ url: process.env.REDIS_URL,
341
+ keyPrefix: 'mastra:my-app',
342
+ }),
343
+ })
344
+ ```
345
+
346
+ `RedisStreamsPubSub` implements both the event delivery contract and distributed leasing, so a single backend handles cross-instance signal delivery and lease ownership. Vercel's one-click Redis integration and Upstash Redis both work well. For more on when a distributed pub/sub is needed, see the [PubSub guide](https://mastra.ai/docs/server/pubsub) and the [`RedisStreamsPubSub` reference](https://mastra.ai/reference/pubsub/redis-streams).
347
+
325
348
  ## Compatibility and APIs
326
349
 
327
350
  ### Compatibility
@@ -404,4 +427,5 @@ Use heartbeats together with client-side reconnect logic. Heartbeats reduce idle
404
427
  - [`client.getAgent().sendSignal()`](https://mastra.ai/reference/client-js/agents)
405
428
  - [Server agent routes](https://mastra.ai/reference/server/routes)
406
429
  - [`client.getAgent().subscribeToThread()`](https://mastra.ai/reference/client-js/agents)
407
- - [`client.getAgent().sendToolApproval()`](https://mastra.ai/reference/client-js/agents)
430
+ - [`client.getAgent().sendToolApproval()`](https://mastra.ai/reference/client-js/agents)
431
+ - [`RedisStreamsPubSub`](https://mastra.ai/reference/pubsub/redis-streams)
@@ -8,9 +8,9 @@ Three categories of metrics are emitted automatically:
8
8
  - **Token usage metrics**: Input and output token counts broken down by type (text, cache, audio, image, reasoning).
9
9
  - **Cost estimation**: Estimated cost per model call based on an embedded pricing registry.
10
10
 
11
- > **Note:** Metrics require an OLAP-capable store for observability. Relational databases like PostgreSQL, LibSQL, etc. aren't supported for metrics. In-memory storage resets on restart.
11
+ > **Note:** Metrics require an analytics-capable store for observability. Most relational databases (LibSQL, MSSQL) aren't supported for metrics. In-memory storage resets on restart.
12
12
  >
13
- > For local development, use [DuckDB](https://duckdb.org/) through `@mastra/duckdb`. For production, use [ClickHouse](https://clickhouse.com/) through `@mastra/clickhouse`.
13
+ > For local development, use [DuckDB](https://duckdb.org/) through `@mastra/duckdb`. For production, use [ClickHouse](https://clickhouse.com/) through `@mastra/clickhouse`. `PostgresStoreVNext` with the observability domain enabled also supports metrics, but always provide a time range to avoid full partition scans.
14
14
  >
15
15
  > Google Cloud Spanner supports metrics, but it's not recommended for heavy metrics workloads. The Spanner adapter disables metrics by default because metrics are write-heavy and scan-heavy. Set `disableMetrics: false` only for light workloads, or route metrics to an OLAP store.
16
16
 
@@ -1,6 +1,6 @@
1
1
  # ![OpenRouter logo](https://models.dev/logos/openrouter.svg)OpenRouter
2
2
 
3
- OpenRouter aggregates models from multiple providers with enhanced features like rate limiting and failover. Access 337 models through Mastra's model router.
3
+ OpenRouter aggregates models from multiple providers with enhanced features like rate limiting and failover. Access 336 models through Mastra's model router.
4
4
 
5
5
  Learn more in the [OpenRouter documentation](https://openrouter.ai/models).
6
6
 
@@ -61,7 +61,6 @@ ANTHROPIC_API_KEY=ant-...
61
61
  | `anthropic/claude-opus-4.1` |
62
62
  | `anthropic/claude-opus-4.5` |
63
63
  | `anthropic/claude-opus-4.6` |
64
- | `anthropic/claude-opus-4.6-fast` |
65
64
  | `anthropic/claude-opus-4.7` |
66
65
  | `anthropic/claude-opus-4.7-fast` |
67
66
  | `anthropic/claude-opus-4.8` |
@@ -1,6 +1,6 @@
1
1
  # ![Vercel logo](https://models.dev/logos/vercel.svg)Vercel
2
2
 
3
- Vercel aggregates models from multiple providers with enhanced features like rate limiting and failover. Access 292 models through Mastra's model router.
3
+ Vercel aggregates models from multiple providers with enhanced features like rate limiting and failover. Access 294 models through Mastra's model router.
4
4
 
5
5
  Learn more in the [Vercel documentation](https://ai-sdk.dev/providers/ai-sdk-providers).
6
6
 
@@ -72,6 +72,7 @@ ANTHROPIC_API_KEY=ant-...
72
72
  | `amazon/nova-micro` |
73
73
  | `amazon/nova-pro` |
74
74
  | `amazon/titan-embed-text-v2` |
75
+ | `anthropic/claude-3.5-haiku` |
75
76
  | `anthropic/claude-haiku-4.5` |
76
77
  | `anthropic/claude-opus-4` |
77
78
  | `anthropic/claude-opus-4.1` |
@@ -267,6 +268,7 @@ ANTHROPIC_API_KEY=ant-...
267
268
  | `perplexity/sonar-pro` |
268
269
  | `perplexity/sonar-reasoning-pro` |
269
270
  | `prodia/flux-fast-schnell` |
271
+ | `quiverai/arrow-1.1` |
270
272
  | `recraft/recraft-v2` |
271
273
  | `recraft/recraft-v3` |
272
274
  | `recraft/recraft-v4` |
@@ -1,6 +1,6 @@
1
1
  # Model Providers
2
2
 
3
- Mastra provides a unified interface for working with LLMs across multiple providers, giving you access to 4540 models from 133 providers through a single API.
3
+ Mastra provides a unified interface for working with LLMs across multiple providers, giving you access to 4482 models from 135 providers through a single API.
4
4
 
5
5
  ## Features
6
6
 
@@ -1,6 +1,6 @@
1
1
  # ![Anthropic logo](https://models.dev/logos/anthropic.svg)Anthropic
2
2
 
3
- Access 18 Anthropic models through Mastra's model router. Authentication is handled automatically using the `ANTHROPIC_API_KEY` environment variable.
3
+ Access 17 Anthropic models through Mastra's model router. Authentication is handled automatically using the `ANTHROPIC_API_KEY` environment variable.
4
4
 
5
5
  Learn more in the [Anthropic documentation](https://docs.anthropic.com/en/docs/about-claude/models).
6
6
 
@@ -15,7 +15,7 @@ const agent = new Agent({
15
15
  id: "my-agent",
16
16
  name: "My Agent",
17
17
  instructions: "You are a helpful assistant",
18
- model: "anthropic/claude-3-5-haiku-latest"
18
+ model: "anthropic/claude-fable-5"
19
19
  });
20
20
 
21
21
  // Generate a response
@@ -32,7 +32,6 @@ for await (const chunk of stream) {
32
32
 
33
33
  | Model | Context | Tools | Reasoning | Image | Audio | Video | Input $/1M | Output $/1M |
34
34
  | -------------------------------------- | ------- | ----- | --------- | ----- | ----- | ----- | ---------- | ----------- |
35
- | `anthropic/claude-3-5-haiku-latest` | 200K | | | | | | $0.80 | $4 |
36
35
  | `anthropic/claude-fable-5` | 1.0M | | | | | | $10 | $50 |
37
36
  | `anthropic/claude-haiku-4-5` | 200K | | | | | | $1 | $5 |
38
37
  | `anthropic/claude-haiku-4-5-20251001` | 200K | | | | | | $1 | $5 |
@@ -60,7 +59,7 @@ const agent = new Agent({
60
59
  id: "custom-agent",
61
60
  name: "custom-agent",
62
61
  model: {
63
- id: "anthropic/claude-3-5-haiku-latest",
62
+ id: "anthropic/claude-fable-5",
64
63
  apiKey: process.env.ANTHROPIC_API_KEY,
65
64
  headers: {
66
65
  "X-Custom-Header": "value"
@@ -79,7 +78,7 @@ const agent = new Agent({
79
78
  const useAdvanced = requestContext.task === "complex";
80
79
  return useAdvanced
81
80
  ? "anthropic/claude-sonnet-4-6"
82
- : "anthropic/claude-3-5-haiku-latest";
81
+ : "anthropic/claude-fable-5";
83
82
  }
84
83
  });
85
84
  ```