@mastra/mcp-docs-server 1.3.6-alpha.14 → 1.3.6-alpha.16

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.
@@ -143,7 +143,7 @@ To add your own endpoints, see [Custom API Routes](https://mastra.ai/docs/server
143
143
 
144
144
  ## Graceful shutdown and rolling deploys
145
145
 
146
- By default, the generated server handles `SIGINT` and `SIGTERM`. It stops accepting connections, waits up to [`server.drainTimeout`](https://mastra.ai/reference/configuration) for active requests and streams, then runs `mastra.shutdown()`. Shutdown gives in-flight workflow runs (including durable agent runs) the same drain window to finish before workers and pub/sub subscriptions are torn down. The drain timeout defaults to 5 seconds. A second signal terminates the process immediately. See [`server.handleShutdownSignals`](https://mastra.ai/reference/configuration) if you need to manage signals yourself.
146
+ By default, the generated server handles `SIGINT` and `SIGTERM`. It stops accepting connections, waits up to [`server.drainTimeout`](https://mastra.ai/reference/configuration) for active requests and streams, then runs `mastra.shutdown()`. Shutdown gives in-flight workflow runs (including durable agent runs) the same drain window to finish before workers and pub/sub subscriptions are torn down. A durable agent run still executing after the window stops and releases its claim on the run, so the next boot can recover it right away. The drain timeout defaults to 5 seconds. A second signal terminates the process immediately. See [`server.handleShutdownSignals`](https://mastra.ai/reference/configuration) if you need to manage signals yourself.
147
147
 
148
148
  Increase `drainTimeout` when your hosting platform's termination grace period can accommodate longer turns. The HTTP drain and the workflow drain run one after the other, so keep enough time for both plus shutdown cleanup.
149
149
 
@@ -163,7 +163,7 @@ export const mastra = new Mastra({
163
163
  })
164
164
  ```
165
165
 
166
- A plain `agent.stream()` call can't resume after its server process exits. If a stream ends without its expected terminal event, treat the turn as interrupted and let the client retry or reconcile it. Use [durable agents](https://mastra.ai/docs/harness/durable-agents) when turns must survive process replacement. [Crash recovery](https://mastra.ai/docs/harness/durable-agents) requires shared persistent run storage and idempotent tools. Replaying missed events after a restart also requires a shared persistent cache such as Redis because the default event cache is in-memory. Multi-replica recovery doesn't yet use a distributed lease.
166
+ A plain `agent.stream()` call can't resume after its server process exits. If a stream ends without its expected terminal event, treat the turn as interrupted and let the client retry or reconcile it. Use [durable agents](https://mastra.ai/docs/harness/durable-agents) when turns must survive process replacement. [Crash recovery](https://mastra.ai/docs/harness/durable-agents) requires shared persistent run storage and idempotent tools. Replaying missed events after a restart also requires a shared persistent cache such as Redis because the default event cache is in-memory. Recovering from multiple replicas requires a storage adapter that supports run fencing or a PubSub backend whose lease every replica shares. See [multi-instance deployments](https://mastra.ai/docs/harness/durable-agents).
167
167
 
168
168
  ## Troubleshooting
169
169
 
@@ -276,9 +276,9 @@ await durableAgent.resume(runId, { approved: true })
276
276
 
277
277
  Durable agents can checkpoint each run's state to storage while it executes. If the server process crashes mid-run, the run remains in `running` status in storage with no automatic retry, and on the next server start you can re-drive these orphaned runs so they pick up where they left off. For orderly shutdowns such as rolling deploys, the generated server can also drain in-flight turns before exiting. See [graceful shutdown and rolling deploys](https://mastra.ai/docs/deployment/mastra-server).
278
278
 
279
- Under the default persistence policy, these `running` checkpoints are only written when crash recovery is enabled. With `recovery.durableAgents: 'off'` (the default), durable agents persist snapshots only for `pending`, `paused`, and `suspended` runs (the artifacts human-in-the-loop resume depends on) and skip the per-step `running` writes entirely. A custom `shouldPersistSnapshot` predicate can keep `running` checkpoints even with recovery off. See [snapshot persistence](#snapshot-persistence) for the full policy and how to override it.
279
+ Under the default persistence policy, these `running` checkpoints are written when crash recovery is enabled. With `recovery.durableAgents: 'off'` (the default), durable agents persist snapshots for `pending`, `paused`, and `suspended` runs (the artifacts human-in-the-loop resume depends on) and skip the per-step `running` writes until `mastra.shutdown()` starts. A custom `shouldPersistSnapshot` predicate replaces the default policy: one that includes `running` writes those checkpoints at every step, and one that excludes `running` writes none, including during shutdown. See [snapshot persistence](#snapshot-persistence) for the full policy and how to override it.
280
280
 
281
- Durable agent runs are excluded from the generic boot-time restart of active workflow runs. The only automatic recovery path for durable agent runs is `recovery.durableAgents: 'auto'`, which holds a recovery lease and registers thread runtimes before re-driving each run.
281
+ Durable agent runs are excluded from the generic boot-time restart of active workflow runs. The only automatic recovery path for durable agent runs is `recovery.durableAgents: 'auto'`, which claims each orphaned run and registers its thread runtimes before re-driving it. See [run ownership](#run-ownership).
282
282
 
283
283
  > **Warning:** Automatic and manual recovery re-run the agentic loop from the last persisted snapshot, which can reissue LLM calls (with real cost) and re-execute tool calls. A sub-agent delegation is one generated `agent-<name>` tool call, and recovery doesn't checkpoint the LLM or tool calls inside that delegation independently. If recovery replays the delegation step, the entire sub-agent run starts again and can repeat inner LLM calls and already-completed tool side effects. Make tools, including tools used by sub-agents, idempotent, or deduplicate their external side effects.
284
284
 
@@ -287,7 +287,10 @@ Durable agent runs are excluded from the generic boot-time restart of active wor
287
287
  The `shouldPersistSnapshot` option on `createDurableAgent()` (also accepted in the agent-level `durable` config) controls which workflow snapshots a durable agent writes. The default policy:
288
288
 
289
289
  - Always persists `pending`, `paused`, and `suspended` snapshots. These are what `resume()` and tool approval read, so human-in-the-loop flows work without configuration.
290
- - Persists `running` checkpoints only when `recovery.durableAgents` is `'auto'`. These per-step writes exist solely to make in-flight runs recoverable after a crash, so they're skipped when nothing consumes them.
290
+ - Persists `running` checkpoints at every step when `recovery.durableAgents` is `'auto'`. These per-step writes exist solely to make in-flight runs recoverable after a crash, so with recovery off they're skipped until shutdown.
291
+ - Persists a `running` checkpoint at each step boundary a run reaches after `mastra.shutdown()` starts, even with recovery off. A run that reaches a step boundary before the drain window ends can then be resumed later with `recover()` or `recoverActiveRuns()`. A run blocked in a single LLM or tool call for the whole drain gets no shutdown checkpoint.
292
+
293
+ When the agent is configured with a fixed memory instance (`memory: new Memory(...)`), a `running` checkpoint doesn't repeat messages memory already stores. Messages recalled from memory and messages the run saved itself (for example with `savePerStep: true`) are stored as small references to their memory rows instead of their full contents, as long as they still match the stored row (a message changed after saving stays inline). This applies to every copy of the conversation a checkpoint holds, including the run input and step results. A long run's checkpoints grow much more slowly as a result. Agents that resolve memory with a function keep the full transcript in each checkpoint, because the memory a resumed run resolves may differ.
291
294
 
292
295
  To keep crash-recovery checkpoints without enabling automatic recovery (for example, when you call `recoverActiveRuns()` yourself behind a leader election), pass a predicate that includes `running`:
293
296
 
@@ -305,7 +308,7 @@ Evented agents always persist the full snapshot set: the evented engine coordina
305
308
 
306
309
  ### Automatic recovery
307
310
 
308
- Set `recovery.durableAgents` to `'auto'` in the Mastra config. The deployer calls `recoverAllDurableAgents()` on boot, right after restarting active workflow runs:
311
+ Set `recovery.durableAgents` to `'auto'` in the Mastra config. The deployer calls `recoverAllDurableAgents()` on boot, alongside the workflow run restarts (the two run concurrently):
309
312
 
310
313
  ```typescript
311
314
  export const mastra = new Mastra({
@@ -317,27 +320,60 @@ export const mastra = new Mastra({
317
320
 
318
321
  On startup, this discovers every registered durable agent with runs stuck in `running` status and re-drives them from the last persisted snapshot.
319
322
 
323
+ Recovery doesn't take over a run that another execution still drives. It skips the run and checks it again once that execution's claim could have lapsed. A run whose process crashed shortly before the restart is still recovered, without another call.
324
+
320
325
  ### Manual recovery
321
326
 
322
- If you need finer control, such as gating recovery behind a leader election or running it on a schedule, call the methods directly:
327
+ If you need finer control, such as running recovery on a schedule, call the methods directly:
323
328
 
324
329
  ```typescript
325
330
  // Recover all durable agents
326
331
  const result = await mastra.recoverAllDurableAgents()
327
- console.log(`Recovered ${result.recovered} runs (${result.succeeded} ok, ${result.failed} failed)`)
332
+ console.log(
333
+ `Recovered ${result.recovered} runs (${result.succeeded} ok, ${result.failed} failed, ${result.skipped} still live)`,
334
+ )
328
335
 
329
336
  // Recover a specific agent
330
- const agentResult = await durableAgent.recoverActiveRuns()
337
+ const { recovered } = await durableAgent.recoverActiveRuns()
338
+ for (const run of recovered) {
339
+ if (run.status === 'skipped') console.log(`${run.runId} is still live: ${run.reason}`)
340
+ }
331
341
 
332
342
  // Recover a single known run
333
343
  await durableAgent.recoverActiveRuns({ runId: 'run-abc-123' })
334
344
  ```
335
345
 
336
- Manual recovery reads the same `running` checkpoints as automatic recovery. If `recovery.durableAgents` is `'off'` and you haven't set a custom `shouldPersistSnapshot` that includes `running`, in-flight runs are never checkpointed, so `listActiveRuns()` and `recoverActiveRuns()` find nothing after a crash. See [snapshot persistence](#snapshot-persistence).
346
+ `recoverAllDurableAgents()` returns counts and re-checks skipped runs itself. `recoverActiveRuns()` returns each run's outcome as `success`, `failed`, or `skipped`, and doesn't re-check skipped runs. A run skipped because another process drives it carries `retryAt`, the time after which its claim lapses unless renewed.
347
+
348
+ Manual recovery reads the same `running` checkpoints as automatic recovery. For a `DurableAgent` using the default snapshot policy with `recovery.durableAgents` set to `'off'`, in-flight runs are only checkpointed at step boundaries reached after `mastra.shutdown()` starts. A run that crashes before then, or doesn't reach a step boundary during the drain, has no checkpoint, so `listActiveRuns()` and `recoverActiveRuns()` don't find it. See [snapshot persistence](#snapshot-persistence).
349
+
350
+ To take over a run that's still live, such as one held by a hung execution, call `recover()` with `force: true`:
351
+
352
+ ```typescript
353
+ const { output } = await durableAgent.recover('run-abc-123', { force: true })
354
+ ```
355
+
356
+ The execution that held the run loses it and stops, and streams for the run drop the events it still publishes. Without `force`, `recover()` throws `DURABLE_AGENT_RUN_ACTIVE` for a live run. Even with `force`, `recover()` refuses a run that the same process is executing.
357
+
358
+ ### Run ownership
359
+
360
+ Every `stream()`, `generate()`, `resume()`, and `recover()` call claims the run before it executes and renews the claim every 10 seconds. A claim lapses 30 seconds after its last renewal, so a run whose process crashed becomes recoverable within 30 seconds. Until then, recovery treats the run as live, and a `stream()` or `resume()` call for that run waits up to 5 seconds for the claim, then throws `DURABLE_AGENT_EXECUTION_CONFLICT`. `mastra.shutdown()` stops the runs still executing after its drain window without further writes and releases their claims. The next boot then recovers them without waiting for the claims to lapse.
361
+
362
+ Enforcement of the claim depends on the workflows store. When the store supports run fencing, the claim is a record in that store, and each write is checked against the claim in the same operation. Once another execution claims the run, writes from the execution that lost it are rejected. That execution's message, thread, and working memory writes are rejected only if the memory store supports run fencing too, so they still land when the agent's `Memory` uses a storage adapter without it. These storage adapters support run fencing:
363
+
364
+ - `InMemoryStore` from `@mastra/core/storage`
365
+ - `@mastra/pg`
366
+ - `@mastra/libsql` and `@mastra/turso`
367
+
368
+ Stores that support run fencing keep one claim record per run, plus one memory fence record per run with memory. Stores with retention support prune them with the `workflows.runOwnership` and `memory.runFences` [retention keys](https://mastra.ai/reference/storage/retention). A run's first generation comes from the store's clock, so a run that reuses a `runId` after its records were pruned still outranks the fences and stream events of its earlier executions.
369
+
370
+ With any other workflows store, the claim is a lease on the [PubSub](https://mastra.ai/docs/server/pubsub) backend. The lease keeps two executions from claiming the run at once, but writes from an execution that lost the run aren't rejected. A run taken over while its previous execution was still live can end with that execution's output. When an execution loses its lease and no other execution has taken the run, the run stays held for up to 15 more seconds. Until then, `recover()` without `force` throws `DURABLE_AGENT_RUN_ACTIVE` with `retryAt` set to when the hold is sure to have ended. Mastra logs a warning when it recovers runs against a workflows or memory store without run fencing.
371
+
372
+ A lease only coordinates the processes that share it. `EventEmitterPubSub`, the default, covers one process. `UnixSocketPubSub` covers the processes on one host. `RedisStreamsPubSub` and `ValkeyStreamsPubSub` cover every instance connected to the same server. `GoogleCloudPubSub` doesn't provide leases, so with a store that lacks run fencing every claim succeeds, and recovery can take over a run that's still live.
337
373
 
338
374
  ### Multi-instance deployments
339
375
 
340
- Mastra doesn't provide a distributed lease or lock yet. In multi-replica deployments, every replica that starts with `recovery.durableAgents: 'auto'` will race to recover the same runs. For now, either gate recovery behind your own leader election or run it from a single replica.
376
+ Every replica can start with `recovery.durableAgents: 'auto'`. Replicas that boot together race to recover the same orphaned runs, but only one claim succeeds per run and the other replicas skip it. This requires a claim that every replica shares: a workflows store that supports run fencing, or a PubSub backend whose lease every replica shares. Without either, gate recovery behind your own leader election or run it from a single replica.
341
377
 
342
378
  ## Related
343
379
 
@@ -74,6 +74,8 @@ Use a distributed backend when you run more than one instance or host, and every
74
74
 
75
75
  For example, sending a signal to an agent run requires the signal event to cross the process boundary to the instance that owns the run. With the in-process default, that instance never receives the event.
76
76
 
77
+ [Durable agent](https://mastra.ai/docs/harness/durable-agents) crash recovery also depends on the backend when the storage adapter doesn't support run fencing. Recovery then uses the backend's leases to tell whether another instance still drives a run. `RedisStreamsPubSub` provides leases across hosts. `GoogleCloudPubSub` doesn't.
78
+
77
79
  Both backends below deliver across processes and hosts and persist events for redelivery.
78
80
 
79
81
  The following example uses [Redis Streams](https://redis.io/docs/latest/develop/data-types/streams/):
@@ -490,6 +490,8 @@ Use `restartAllActiveWorkflowRuns()` to restart all active workflow runs of a wo
490
490
  workflow.restartAllActiveWorkflowRuns()
491
491
  ```
492
492
 
493
+ Runs restart concurrently, up to `recovery.workflowConcurrency` at a time (default `5`). Set it to `1` in the Mastra config if your runs share side effects that must not run in parallel.
494
+
493
495
  To exclude a workflow from automatic boot-time restarts triggered by `Mastra.restartAllActiveWorkflowRuns()`, set `autoRestartActiveRuns: false` in the workflow's `options`. This is useful for workflows with side effects that must not be re-driven by a blanket restart. Durable agent workflows set this automatically because their recovery is owned by the opt-in `recovery.durableAgents: 'auto'` path.
494
496
 
495
497
  ### Restarting an active workflow run with `restart()`
@@ -120,11 +120,13 @@ const handle = await sandbox.processes.spawn('node server.js', {
120
120
  })
121
121
 
122
122
  // Interact with the process
123
+ await handle.sendStdin('hello\n')
124
+ await handle.closeStdin()
123
125
  console.log(handle.stdout)
124
126
  await handle.kill()
125
127
  ```
126
128
 
127
- > **Note:** Blaxel sandboxes don't support stdin. Calling `handle.sendStdin()` throws an error.
129
+ Spawned processes have a writable stdin by default. Pass `stdinMode: 'ignore'` to start a process with stdin closed so commands that read stdin get EOF immediately.
128
130
 
129
131
  See [`SandboxProcessManager` reference](https://mastra.ai/reference/workspace/process-manager) for the full API.
130
132
 
@@ -361,6 +361,21 @@ Failure handling is designed so a broken template never wedges a session:
361
361
  - A failed build falls back to the default mountable template; the session's runtime cold clone into `$HOME` keeps working.
362
362
  - E2B keeps a failed build's ref visible to `Template.exists`, so a broken ref could otherwise be reused forever. When creating a sandbox from a named ref fails, the cached resolution is dropped and creation retries down the fallback ladder.
363
363
 
364
+ If a sandbox without the template's toolchain is worse than a failed start, set `fallbackTemplate: false` on the resolved spec. A failed build, or a ref that can't create a sandbox, then rejects `start()` with the original error instead of falling back:
365
+
366
+ ```typescript
367
+ const repoTemplate = createRepoTemplate({
368
+ getRepositoryAccess: async () => ({ cloneUrl: 'https://github.com/acme/app.git' }),
369
+ setupCommand: 'pnpm install',
370
+ })!
371
+
372
+ const sandbox = new E2BSandbox({
373
+ template: {
374
+ resolveSpec: async () => ({ ...(await repoTemplate.resolveSpec()), fallbackTemplate: false }),
375
+ },
376
+ })
377
+ ```
378
+
364
379
  Private repositories build warm templates when `getRepositoryAccess` returns an `authorization` alongside the clone URL — a fresh, short-lived credential (such as a GitHub App installation token) minted per template resolution. The credential authenticates the head lookup and the build's clone through an in-shell `http.extraheader` — it enters the template definition's environment (visible to build steps but not persisted into runtime sandbox environments) and never touches the image filesystem, so no captured layer can contain it. It's set as `GH_TOKEN`, the same variable a session installs before running setup, so a command that shells out to `gh` or authenticated https behaves the same in the build as it does in a session.
365
380
 
366
381
  Only pass short-lived credentials — the value stays in the template definition until the next rebuild, so its expiry is what bounds the exposure. Note that the cloned repository contents become part of a team-visible template image. When the access call returns no credential the clone is tokenless: public repositories build fine, and a private repository's build degrades to the fallback, where the session's own runtime setup (with runtime-injected auth) does the clone.
@@ -4,7 +4,7 @@
4
4
 
5
5
  # Model Providers
6
6
 
7
- Mastra provides a unified interface for working with LLMs across multiple providers, giving you access to 7797 models from 214 providers through a single API.
7
+ Mastra provides a unified interface for working with LLMs across multiple providers, giving you access to 7804 models from 214 providers through a single API.
8
8
 
9
9
  ## Features
10
10
 
@@ -4,7 +4,7 @@
4
4
 
5
5
  # ![302.AI logo](https://models.dev/logos/302ai.svg)302.AI
6
6
 
7
- Access 122 302.AI models through Mastra's model router. Authentication is handled automatically using the `302AI_API_KEY` environment variable.
7
+ Access 124 302.AI models through Mastra's model router. Authentication is handled automatically using the `302AI_API_KEY` environment variable.
8
8
 
9
9
  Learn more in the [302.AI documentation](https://doc.302.ai).
10
10
 
@@ -42,6 +42,7 @@ for await (const chunk of stream) {
42
42
  | `302ai/claude-fable-5-1` | 1.0M | | | | | | $10 | $50 |
43
43
  | `302ai/claude-haiku-4-5` | 200K | | | | | | $1 | $5 |
44
44
  | `302ai/claude-haiku-4-5-20251001` | 200K | | | | | | $1 | $5 |
45
+ | `302ai/claude-haiku-5-5` | 1.0M | | | | | | $0.10 | $0.50 |
45
46
  | `302ai/claude-opus-4-1-20250805` | 200K | | | | | | $15 | $75 |
46
47
  | `302ai/claude-opus-4-1-20250805-thinking` | 200K | | | | | | $15 | $75 |
47
48
  | `302ai/claude-opus-4-5-20251101` | 200K | | | | | | $5 | $25 |
@@ -121,6 +122,7 @@ for await (const chunk of stream) {
121
122
  | `302ai/gpt-6-astra` | 1.1M | | | | | | $10 | $50 |
122
123
  | `302ai/gpt-6-luna` | 1.1M | | | | | | $0.10 | $0.50 |
123
124
  | `302ai/gpt-6-sol` | 1.1M | | | | | | $2 | $10 |
125
+ | `302ai/gpt-6.1-sol` | 1.1M | | | | | | $2 | $10 |
124
126
  | `302ai/grok-4-1-fast-reasoning` | 2.0M | | | | | | $0.20 | $0.50 |
125
127
  | `302ai/grok-4-fast-non-reasoning` | 2.0M | | | | | | $0.20 | $0.50 |
126
128
  | `302ai/grok-4-fast-reasoning` | 2.0M | | | | | | $0.20 | $0.50 |