@mastra/mcp-docs-server 1.3.5-alpha.1 → 1.3.5-alpha.12

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 (96) hide show
  1. package/.docs/docs/agents/code-mode.md +0 -2
  2. package/.docs/docs/agents/processors.md +8 -0
  3. package/.docs/docs/agents/tools.md +17 -0
  4. package/.docs/docs/channels.md +5 -1
  5. package/.docs/docs/develop.md +1 -3
  6. package/.docs/docs/guides/context-engineering.md +0 -2
  7. package/.docs/docs/harness/agent-controller.md +0 -2
  8. package/.docs/docs/harness/durable-agents.md +2 -0
  9. package/.docs/docs/harness/goals.md +1 -3
  10. package/.docs/docs/harness/schedules.md +0 -2
  11. package/.docs/docs/harness/signal-providers.md +1 -3
  12. package/.docs/docs/harness/signals.md +15 -3
  13. package/.docs/docs/mastra-platform/environments.md +1 -1
  14. package/.docs/docs/mastra-platform/observability.md +1 -1
  15. package/.docs/docs/memory/observational-memory.md +3 -1
  16. package/.docs/docs/memory/semantic-recall.md +35 -1
  17. package/.docs/docs/storage.md +1 -0
  18. package/.docs/docs/workflows/error-handling.md +2 -0
  19. package/.docs/docs/workflows/scheduled-workflows.md +2 -2
  20. package/.docs/integrations/databases/clickhouse-managed-postgres.md +82 -0
  21. package/.docs/integrations.md +1 -0
  22. package/.docs/models/environment-variables.md +1 -0
  23. package/.docs/models/gateways/merge-gateway.md +3 -1
  24. package/.docs/models/gateways/neon.md +2 -1
  25. package/.docs/models/gateways/netlify.md +3 -2
  26. package/.docs/models/gateways/openrouter.md +2 -3
  27. package/.docs/models/gateways/vercel.md +1 -1
  28. package/.docs/models/index.md +2 -1
  29. package/.docs/models/providers/aiand.md +17 -15
  30. package/.docs/models/providers/blueclaw.md +8 -9
  31. package/.docs/models/providers/coralbricks.md +6 -4
  32. package/.docs/models/providers/cortecs.md +5 -11
  33. package/.docs/models/providers/crossmodel.md +2 -1
  34. package/.docs/models/providers/deepinfra.md +57 -60
  35. package/.docs/models/providers/deepseek.md +1 -1
  36. package/.docs/models/providers/edenai.md +6 -3
  37. package/.docs/models/providers/engy.md +84 -0
  38. package/.docs/models/providers/kilo.md +15 -16
  39. package/.docs/models/providers/llmgateway-providers.md +12 -3
  40. package/.docs/models/providers/llmgateway.md +2 -2
  41. package/.docs/models/providers/nano-gpt.md +15 -5
  42. package/.docs/models/providers/opencode.md +2 -1
  43. package/.docs/models/providers/privatemode-ai.md +5 -5
  44. package/.docs/models/providers/requesty.md +2 -1
  45. package/.docs/models/providers/subconscious.md +8 -8
  46. package/.docs/models/providers/synthetic.md +2 -1
  47. package/.docs/models/providers/togetherai.md +21 -28
  48. package/.docs/models/providers/umans-ai-coding-plan.md +2 -1
  49. package/.docs/models/providers/umans-ai.md +2 -1
  50. package/.docs/models/providers/xai.md +3 -2
  51. package/.docs/models/providers.md +1 -0
  52. package/.docs/reference/agent-controller/agent-controller-class.md +2 -2
  53. package/.docs/reference/agent-controller/session.md +8 -2
  54. package/.docs/reference/agents/channels.md +2 -1
  55. package/.docs/reference/agents/durable-agent.md +12 -7
  56. package/.docs/reference/agents/generate.md +2 -0
  57. package/.docs/reference/cli/mastra.md +43 -5
  58. package/.docs/reference/client-js/agents.md +1 -1
  59. package/.docs/reference/client-js/observability.md +28 -0
  60. package/.docs/reference/code-sdk/acp-server.md +19 -2
  61. package/.docs/reference/code-sdk/mount-agent-controller.md +0 -2
  62. package/.docs/reference/configuration.md +1 -1
  63. package/.docs/reference/editor/mastra-editor.md +28 -0
  64. package/.docs/reference/editor/prompt-blocks.md +41 -0
  65. package/.docs/reference/editor/tool-provider.md +19 -0
  66. package/.docs/reference/file-based-agents/config.md +0 -2
  67. package/.docs/reference/file-based-agents/instructions.md +0 -2
  68. package/.docs/reference/file-based-agents/logger.md +0 -2
  69. package/.docs/reference/file-based-agents/memory.md +0 -2
  70. package/.docs/reference/file-based-agents/observability.md +0 -2
  71. package/.docs/reference/file-based-agents/processors.md +0 -2
  72. package/.docs/reference/file-based-agents/schedules.md +2 -4
  73. package/.docs/reference/file-based-agents/scorers.md +0 -2
  74. package/.docs/reference/file-based-agents/server.md +0 -2
  75. package/.docs/reference/file-based-agents/skills.md +0 -2
  76. package/.docs/reference/file-based-agents/storage.md +0 -2
  77. package/.docs/reference/file-based-agents/studio.md +0 -2
  78. package/.docs/reference/file-based-agents/subagents.md +0 -2
  79. package/.docs/reference/file-based-agents/tools.md +0 -2
  80. package/.docs/reference/file-based-agents/workflows.md +0 -2
  81. package/.docs/reference/file-based-agents/workspace.md +0 -2
  82. package/.docs/reference/memory/observational-memory.md +2 -2
  83. package/.docs/reference/observability/tracing/interfaces.md +62 -2
  84. package/.docs/reference/observability/tracing/trace-query.md +113 -2
  85. package/.docs/reference/schedules/overview.md +3 -5
  86. package/.docs/reference/server/elysia-adapter.md +18 -0
  87. package/.docs/reference/signals/create-notification-inbox-tool.md +0 -2
  88. package/.docs/reference/signals/signal-provider.md +1 -3
  89. package/.docs/reference/signals/task-signal-provider.md +1 -1
  90. package/.docs/reference/signals/webhook-signal-provider.md +1 -3
  91. package/.docs/reference/streaming/ChunkType.md +2 -0
  92. package/.docs/reference/tools/create-code-mode.md +0 -2
  93. package/.docs/reference/tools/create-tool.md +2 -0
  94. package/.docs/reference/tools/mcp-client.md +17 -0
  95. package/.docs/reference/tools/mcp-server.md +7 -1
  96. package/package.json +5 -5
@@ -4,8 +4,6 @@
4
4
 
5
5
  # Session
6
6
 
7
- > **Beta:** Breaking changes may occur without a major version bump until the API is stable.
8
-
9
7
  A `Session` is the isolated runtime for one resource and optional scope. It owns its event bus, thread binding, state, mode and model selections, run control, approvals, suspensions, follow-ups, and display state. The [`AgentController`](https://mastra.ai/reference/agent-controller/agent-controller-class) supplies shared agents, configuration, storage, workspaces, and services.
10
8
 
11
9
  Create sessions through `controller.createSession()`. Direct construction and controller wiring methods aren't application APIs.
@@ -351,6 +349,14 @@ Return the active thread ID, or `null` when no thread is bound.
351
349
  const threadId = session.thread.getId()
352
350
  ```
353
351
 
352
+ ### `session.thread.ensureId({ requestContext? })`
353
+
354
+ Return the active thread ID, creating and binding a new thread when none is bound. Concurrent calls share one thread. Use it with sessions created with `createInitialThread: false`.
355
+
356
+ ```typescript
357
+ const threadId = await session.thread.ensureId()
358
+ ```
359
+
354
360
  ### `session.thread.list(options?)`
355
361
 
356
362
  List threads from storage. By default only threads for the current resource are returned, and transient forked subagent threads are hidden.
@@ -202,7 +202,8 @@ Override built-in event handlers. Each handler can be:
202
202
 
203
203
  - **Omitted**: uses the default Mastra handler (routes the message through the agent and posts the response)
204
204
  - **`false`**: disables the handler entirely
205
- - **A function** `(thread, message, defaultHandler) => Promise<void>`: wraps or replaces the default
205
+ - **A function** `(thread, message, defaultHandler, ctx) => Promise<void>`: wraps or replaces the default
206
+ - When a `chatOptions.concurrency` strategy batches messages from several senders into one dispatch, the function is called once per sender's turn, each with its own `ctx`; `ctx.skipped` holds that turn's earlier batched messages
206
207
 
207
208
  ```typescript
208
209
  import { Agent } from '@mastra/core/agent'
@@ -179,17 +179,22 @@ Returns: [`Promise<DurableAgentStreamResult>`](#durableagentstreamresult)
179
179
 
180
180
  #### `observe(runId, options?)`
181
181
 
182
- Reconnects to an existing run, replaying cached events before delivering live ones. Use this after a network disconnection. Pass `offset` to start replay from a known position.
182
+ Reconnects to an existing run. Use this after a network disconnection. For the supported general reconnect flow, omit `offset` to replay all available cached events before receiving live events.
183
183
 
184
184
  ```typescript
185
- const { output, cleanup } = await durableAgent.observe(runId, {
186
- offset: 0,
185
+ const { output } = await durableAgent.observe(runId, {
187
186
  onChunk: chunk => console.log(chunk),
188
187
  })
189
188
 
190
189
  await output.text
191
190
  ```
192
191
 
192
+ The `offset` option is an inclusive, zero-based PubSub event index. It counts every cached event published to the run topic, including lifecycle events, so it isn't a chunk count. Public stream chunks and callbacks don't expose the PubSub index. Only pass an offset when another integration already tracks the transport position.
193
+
194
+ A non-zero offset can skip earlier events. Aggregated values are built only from chunks delivered to that observer. If the offset skips earlier text deltas, `output.text` is partial and structured output may be incomplete or fail validation or parsing.
195
+
196
+ When the PubSub transport supports numeric offsets, an offset beyond the highest retained index replays nothing and also skips live events with lower indexes. The observer receives events only when the published index reaches the requested offset. If the index counter restarts below that offset, the observer can wait indefinitely. On a transport without numeric offset support, providing an offset starts with new live events and doesn't replay cached events. Replay is limited to events still available in the configured cache. Events can't be replayed when caching is disabled, `shouldCache` excludes the run topic, a cache write fails, or retained events have been cleared.
197
+
193
198
  By default `observe()` waits indefinitely for events. If the process running the run stops unexpectedly, the run stops producing events but never emits a completion event, so the observed stream would wait forever. Pass `idleTimeoutMs` to end the stream after a bounded period of silence. Before timing out, `observe()` can consult an optional `isAlive` check. Return `true` while work continues, such as during a long-running tool call or a pause for human input. A `false` result ends the stream with an error, as does omitting `isAlive`. A transient throw from `isAlive` is treated as "still alive", so a momentary check failure never ends a live stream.
194
199
 
195
200
  ```typescript
@@ -235,7 +240,7 @@ interface PrepareResult {
235
240
 
236
241
  #### `abortRunStream(runId)`
237
242
 
238
- Stops a run by ID from any process that shares the agent's [PubSub](https://mastra.ai/docs/server/pubsub). Only the `runId` from `stream()` or `prepare()` is needed, so a later request can stop a run it didn't start. The run ends the same way as `abort()` on the stream result: the `finish` event carries reason `abort`, `onAbort` fires, and `observe()` consumers see the stream end.
243
+ Stops a run by ID from any process that shares the agent's [PubSub](https://mastra.ai/docs/server/pubsub). Only the `runId` from `stream()` or `prepare()` is needed, so a later request can stop a run it didn't start. The run ends the same way as `abort()` on the stream result: the stream emits an `abort` chunk, `onAbort` fires, and `observe()` consumers see the stream end.
239
244
 
240
245
  ```typescript
241
246
  const { runId } = await durableAgent.stream('Summarize the document')
@@ -426,7 +431,7 @@ Returns: [`Promise<DurableAgentStreamResult>`](#durableagentstreamresult)
426
431
 
427
432
  **onStepFinish** (`(result: AgentStepFinishEventData) => void | Promise<void>`): Called when a step in the agentic loop finishes.
428
433
 
429
- **onFinish** (`(result: AgentFinishEventData) => void | Promise<void>`): Called when the run finishes.
434
+ **onFinish** (`(result: AgentFinishEventData) => void | Promise<void>`): Called when the run completes successfully. Aborted runs call onAbort; failed runs call onError.
430
435
 
431
436
  **onError** (`(error: Error) => void | Promise<void>`): Called when the run errors.
432
437
 
@@ -434,9 +439,9 @@ Returns: [`Promise<DurableAgentStreamResult>`](#durableagentstreamresult)
434
439
 
435
440
  **onAbort** (`AgentExecutionOptions['onAbort']`): Called when the run is aborted via abortSignal, result.abort(), abortRunStream(), or abortThreadStream(). Receives the steps completed before the abort and, in text, the assistant text streamed so far.
436
441
 
437
- **onIterationComplete** (`AgentExecutionOptions['onIterationComplete']`): Called after every agentic-loop iteration with the latest messageList, finishReason, and isFinal flag. Observation-only on durable agents: returning continue: false or feedback does not influence the loop.
442
+ **onIterationComplete** (`AgentExecutionOptions['onIterationComplete']`): Called after every agentic-loop iteration with the latest messageList, finishReason, and isFinal flag. Return continue: true to request another iteration or continue: false to stop. Feedback is added as a synthetic assistant message when the loop runs another iteration. If the model has stopped, feedback alone or continue: false with feedback does not start another iteration. When the loop was already going to continue, continue: false with feedback runs one final feedback-guided iteration before stopping.
438
443
 
439
- `resume()` and `observe()` accept the same lifecycle callbacks (`onChunk`, `onStepFinish`, `onFinish`, `onError`, `onSuspended`). `observe()` also accepts an `offset` to control where replay starts.
444
+ `resume()`, `observe()`, and `recover()` accept the same lifecycle callbacks (`onChunk`, `onStepFinish`, `onFinish`, `onError`, `onAbort`, `onSuspended`). `observe()` also accepts an `offset` to control where replay starts.
440
445
 
441
446
  ## DurableAgentStreamResult
442
447
 
@@ -444,6 +444,8 @@ const response = await agent.generate([
444
444
  console.log(response.text)
445
445
  ```
446
446
 
447
+ The `image` value, or `data` for a `type: 'file'` part, should be an absolute URL, a data URL, or base64 content. The model can't see an attachment given as a relative path such as `/api/images/foo.png`, so resolve it to an absolute URL before sending. The agent replaces it with a placeholder and logs a warning. It does the same for inline content that can't be decoded or isn't the image or PDF its media type says, and for any attachment it can't download, instead of failing. See [attachment download failures](https://mastra.ai/docs/agents/processors).
448
+
447
449
  ### Using `maxSteps`
448
450
 
449
451
  The `maxSteps` parameter controls the maximum number of sequential LLM calls an agent can make. Each step generates a response and executes any tool calls before processing the result. Limiting steps helps prevent infinite loops and reduce latency. It also controls token usage for agents that use tools. The default is 5, but can be increased:
@@ -428,7 +428,7 @@ mastra deploy --env staging --yes
428
428
 
429
429
  Manages environments on Mastra platform. Environments are deploy targets (for example `production`, `staging`, `preview-42`) that belong to a project. The current organization is resolved from stored credentials.
430
430
 
431
- Every subcommand resolves its project in a fixed order. It first checks the `MASTRA_PROJECT_ID` environment variable and the `--project <name|slug|id>` flag. It then reads the `.mastra-project.json` file written by [`mastra deploy`](#mastra-deploy) in the current directory. Run from your project directory and you never need to name the project.
431
+ Every subcommand resolves its project in a fixed order. It first checks the `--project <name|slug|id>` flag, then the `MASTRA_PROJECT_ID` environment variable. It then reads the `.mastra-project.json` file written by [`mastra deploy`](#mastra-deploy) in the current directory. Run from your project directory and you never need to name the project.
432
432
 
433
433
  ### `mastra env list`
434
434
 
@@ -790,7 +790,7 @@ Organization ID. Can also be set via the `MASTRA_ORG_ID` environment variable.
790
790
 
791
791
  #### `--project`
792
792
 
793
- Project ID or slug when `MASTRA_PROJECT_ID` isn't set. Slugs are resolved against projects in the current organization.
793
+ Project ID or slug. Takes precedence over `MASTRA_PROJECT_ID`. Slugs are resolved against projects in the current organization.
794
794
 
795
795
  #### `-c, --config`
796
796
 
@@ -858,7 +858,7 @@ The file defaults to `.env` when no argument is given. All values are double-quo
858
858
 
859
859
  #### `--project`
860
860
 
861
- Project ID or slug. Overrides the linked project when `MASTRA_PROJECT_ID` isn't set.
861
+ Project ID or slug. Takes precedence over `MASTRA_PROJECT_ID` and the linked project.
862
862
 
863
863
  #### CI usage
864
864
 
@@ -913,6 +913,44 @@ Revokes an API token.
913
913
  mastra auth tokens revoke <token-id>
914
914
  ```
915
915
 
916
+ ## `mastra connect`
917
+
918
+ Manages provider connections for the linked platform project, so agents using `@mastra/connect` pick up provider toolsets without leaving the terminal.
919
+
920
+ The target project resolves from the `--project` flag, the `MASTRA_PROJECT_ID` environment variable, or the `.mastra-project.json` written by `mastra deploy`, in that order. All subcommands accept `--project <name|slug|id>`.
921
+
922
+ ### `mastra connect list`
923
+
924
+ Lists the available providers. Providers already connected to the project are shown in green, and unconnected providers are shown in grey.
925
+
926
+ ```bash
927
+ mastra connect list
928
+ ```
929
+
930
+ ### `mastra connect add`
931
+
932
+ Connects a provider to the project. When the organization already has connections for the provider that aren't attached to the project, the command lists them and lets you attach an existing connection or create a new one. With no existing connections it goes straight to the provider's auth flow.
933
+
934
+ OAuth providers open the provider's consent screen in your browser, while API key and Basic auth providers prompt for credentials in the terminal. Providers with other auth types open a hosted connect page. The command waits until the connection becomes active before exiting.
935
+
936
+ Once a new connection is active, the command offers to set a display name so you can tell connections to the same provider apart. It lists the provider's existing connections, suggests a name that doesn't collide with them, and asks for confirmation if the chosen name duplicates another connection's name. Leave the field blank to skip naming.
937
+
938
+ ```bash
939
+ mastra connect add <provider>
940
+ ```
941
+
942
+ Pass `--yes` to skip all prompts. This always creates a new connection without a display name, even when existing connections could be reused.
943
+
944
+ ### `mastra connect remove`
945
+
946
+ Unlinks a provider's connection from the project. The organization-level connection is kept and can be re-attached later.
947
+
948
+ ```bash
949
+ mastra connect remove <provider>
950
+ ```
951
+
952
+ When a provider has multiple connections, the command prompts for which one to remove. Pass `--yes` to skip confirmation. Without a terminal, or with `--yes`, removing several connections at once requires `--all`, and `--connection <id>` removes a single one.
953
+
916
954
  ## `mastra lint`
917
955
 
918
956
  The `mastra lint` command validates the structure and code of your Mastra project.
@@ -1100,7 +1138,7 @@ See [Import existing traces](https://mastra.ai/docs/mastra-platform/observabilit
1100
1138
 
1101
1139
  #### `--project <name|slug|id>`
1102
1140
 
1103
- Selects the destination Mastra Platform project. `MASTRA_PROJECT_ID` takes precedence when set. Without either value, the command uses the project linked in `.mastra-project.json`.
1141
+ Selects the destination Mastra Platform project. Takes precedence over `MASTRA_PROJECT_ID`. Without either value, the command uses the project linked in `.mastra-project.json`.
1104
1142
 
1105
1143
  #### `--from <date>`
1106
1144
 
@@ -1136,7 +1174,7 @@ The command loads `.env` and `.env.local` from the current directory.
1136
1174
  | `MASTRA_API_TOKEN` | For headless authentication | Mastra Platform API token. Without it, the command uses credentials from `mastra auth login`. |
1137
1175
  | `MASTRA_ORG_ID` | With `MASTRA_API_TOKEN` | Organization that owns the destination project. |
1138
1176
  | `MASTRA_PLATFORM_ACCESS_TOKEN` | For upload and read-back with interactive login | Mastra Platform access token for the destination. Not required for `--dry-run` or when `MASTRA_API_TOKEN` is set. |
1139
- | `MASTRA_PROJECT_ID` | When no project is otherwise linked | Destination project ID. Takes precedence over `--project`. |
1177
+ | `MASTRA_PROJECT_ID` | When no project is otherwise linked | Destination project ID. The `--project` flag takes precedence over it. |
1140
1178
 
1141
1179
  ### Examples
1142
1180
 
@@ -1040,7 +1040,7 @@ console.log(diff.changes) // Fields that changed between versions
1040
1040
  In the React SDK, pass an `agentVersionId` through `requestContext` when using the `useChat` hook:
1041
1041
 
1042
1042
  ```typescript
1043
- import { useChat } from '@mastra/react'
1043
+ import { useChat } from '@mastra/react/chat'
1044
1044
 
1045
1045
  function Chat() {
1046
1046
  const { messages, input, handleInputChange, handleSubmit } = useChat({
@@ -217,6 +217,34 @@ The API limits predicate depth, nodes, related clauses, set members, literal byt
217
217
 
218
218
  See [Advanced trace queries](https://mastra.ai/reference/observability/tracing/trace-query) for the complete limits, request fields, predicates, thread qualification semantics, cursor pagination, response shapes, and errors.
219
219
 
220
+ ## Querying spans
221
+
222
+ `querySpans()` returns one row per matching completed span across traces. Use it to list the spans themselves. `queryTraces()` with a `spans.some` predicate returns the traces that contain a matching span instead. Every query requires an ISO timestamp range of at most 31 days.
223
+
224
+ ```typescript
225
+ const result = await mastraClient.querySpans({
226
+ timeRange: {
227
+ from: '2026-10-01T00:00:00.000Z',
228
+ to: '2026-10-02T00:00:00.000Z',
229
+ },
230
+ where: {
231
+ op: 'eq',
232
+ left: { path: 'spanType' },
233
+ right: { literal: 'tool_call' },
234
+ },
235
+ orderBy: [{ field: 'startedAt', direction: 'desc' }],
236
+ page: { limit: 50 },
237
+ })
238
+
239
+ // { spans: [{ traceId, spanId, name, spanType, status, durationMs, cost, ... }], page: { next } }
240
+ ```
241
+
242
+ Pass `result.page.next` back as `page.after` with the same time range, filter, and ordering to load the next page. Each row contains identifiers, display fields, input and output previews, and the span's model cost. Use `getSpan()` to load the full span.
243
+
244
+ Span queries are optional for observability stores. Check `capabilities.spanQuery` from `getObservabilityCapabilities()` before calling `querySpans()`, and treat a missing value as unsupported. Unsupported servers reject with `501 SPAN_QUERY_UNSUPPORTED`.
245
+
246
+ See [Query individual spans](https://mastra.ai/reference/observability/tracing/trace-query) for filters, ordering, cursors, cost states, limits, and errors.
247
+
220
248
  ## Deleting traces
221
249
 
222
250
  Delete traces and their associated spans, metrics, logs, scores, and feedback:
@@ -25,10 +25,27 @@ A client that accepts command and argument fields can use:
25
25
  }
26
26
  ```
27
27
 
28
- Configure provider authentication in Mastra Code before starting the client, or supply API keys in the server process's environment. ACP sessions don't load project `.env` files into the shared process environment. The server doesn't offer interactive ACP authentication.
29
-
30
28
  After initialization, the client calls `session/new` with an absolute `cwd` and an `mcpServers` array. The response includes the session ID and configuration choices. Send that ID with subsequent prompts and configuration requests.
31
29
 
30
+ ## Authentication
31
+
32
+ `session/new` returns an `auth_required` error when no model provider is configured, so clients can offer the methods from the `initialize` response:
33
+
34
+ | Method ID | Type | Behavior |
35
+ | ------------------ | -------- | ---------------------------------------------------------------------------------------------- |
36
+ | `openai-codex` | Agent | Opens the browser to sign in with a ChatGPT Plus or Pro subscription. |
37
+ | `kimi-for-coding` | Agent | Opens the browser to approve a Kimi For Coding device sign-in. |
38
+ | `xai` | Agent | Opens the browser to approve an xAI device sign-in. |
39
+ | `anthropic` | Terminal | Runs `mastracode login --provider anthropic` to sign in with a Claude Pro or Max subscription. |
40
+ | `github-copilot` | Terminal | Runs `mastracode login --provider github-copilot` to sign in with GitHub Copilot. |
41
+ | `mastracode-login` | Terminal | Runs `mastracode login` to choose any provider or save an API key. |
42
+
43
+ Terminal methods are offered only to clients that advertise terminal authentication.
44
+
45
+ For agent methods, `authenticate` runs the sign-in inside the server process and returns after the credentials are saved. If a provider needs typed input, such as a code to paste, the request fails and asks you to run `mastracode login` in a terminal.
46
+
47
+ API keys in the server process's environment also count as a configured provider. ACP sessions don't load project `.env` files into the shared process environment. New sessions pick up saved credentials without restarting the server. When the default model's provider isn't configured, a new session starts on the default model of a provider that is, such as `anthropic/claude-fable-5` after an Anthropic sign-in.
48
+
32
49
  ## `acpMain(options?)`
33
50
 
34
51
  To start the same server from an SDK entry point:
@@ -4,8 +4,6 @@
4
4
 
5
5
  # mountAgentControllerOnMastra()
6
6
 
7
- > **Beta:** Breaking changes may occur without a major version bump until the API is stable.
8
-
9
7
  The `mountAgentControllerOnMastra()` function builds the Mastra Code agent controller (the coding agent behind [Mastra Code](https://code.mastra.ai), with its modes, tools, memory, and thread management) and registers it on a server-owned [Mastra](https://mastra.ai/reference/core/mastra-class) instance. Use it to serve the Mastra Code agent to your own UI (web app, editor, bot): each client creates or resumes its own isolated session through the returned [`AgentController`](https://mastra.ai/reference/agent-controller/agent-controller-class).
10
8
 
11
9
  To construct the `Mastra` instance yourself (for example in a deployable entry file), use `prepareAgentControllerMount()` from the same package, which returns the constructor args plus a `finalize()` callback.
@@ -244,7 +244,7 @@ export const mastra = new Mastra({
244
244
 
245
245
  **Type:** `Record<string, MastraMemory>`
246
246
 
247
- A registry of memory instances that can be referenced by agents. Memory gives agents coherence across interactions by retaining relevant information from past conversations. Mastra supports message history for recent messages and working memory for persistent user-specific details. Semantic recall retrieves older messages based on relevance.
247
+ A registry of memory instances that can be referenced by agents, including stored agents that use `{ type: 'id', memoryId: '<key>' }`. Memory gives agents coherence across interactions by retaining relevant information from past conversations. Mastra supports message history for recent messages and working memory for persistent user-specific details. Semantic recall retrieves older messages based on relevance.
248
248
 
249
249
  Visit the [Memory documentation](https://mastra.ai/docs/memory/overview) to learn more.
250
250
 
@@ -192,6 +192,34 @@ await editor.agent.create({
192
192
  })
193
193
  ```
194
194
 
195
+ ### Stored agent memory
196
+
197
+ The `memory` field of a stored agent accepts one of these shapes:
198
+
199
+ - `{ type: 'id', memoryId: string }`: Uses a memory instance registered on the Mastra instance. The editor looks up `memoryId` as a registry key first, then as the memory instance's `id`. The agent uses that exact instance, including its storage, processors, and working memory settings.
200
+ - `{ type: 'inline', config: SerializedMemoryConfig }`: Builds a new memory instance from a serializable config.
201
+ - `SerializedMemoryConfig`: The untagged inline config. Existing stored agents use this shape and keep working.
202
+
203
+ Reference a registered memory instance so many stored agents share one configuration:
204
+
205
+ ```typescript
206
+ import { mastra } from '../mastra'
207
+
208
+ const editor = mastra.getEditor()!
209
+
210
+ await editor.agent.create({
211
+ id: 'support-agent',
212
+ name: 'Support agent',
213
+ instructions: 'You are a friendly support agent for Acme.',
214
+ model: { provider: 'openai', name: 'gpt-5' },
215
+ memory: { type: 'id', memoryId: 'supportMemory' },
216
+ })
217
+ ```
218
+
219
+ The reference is resolved when the editor loads the agent. If no registered memory matches `memoryId`, the agent loads without memory and the editor logs a warning that names the missing key. The stored reference isn't changed. In conditional memory, a variant whose reference isn't registered is skipped. If you register memory with `mastra.addMemory()` after an agent has loaded, call `editor.agent.clearCache(id)` so the next load picks it up. Renaming or removing a key in the Mastra `memory` config detaches memory from every stored agent that references it, so keep keys stable across deployments.
220
+
221
+ `editor.agent.clone()` stores a reference when the source agent uses a registered memory instance, and an inline config otherwise.
222
+
195
223
  ## Methods
196
224
 
197
225
  ### Provider access
@@ -92,6 +92,47 @@ Dot paths are supported. An empty group evaluates to `true`, and an unknown oper
92
92
 
93
93
  Blocks without conditions are always included.
94
94
 
95
+ A `prompt_block_ref` can also have its own `rules`. They apply only to that reference in that agent, so you can reuse one stored block under different conditions. If the stored block has rules too, both must pass.
96
+
97
+ ### Runtime slot with a fallback
98
+
99
+ Combine an inline `prompt_block` and a conditional `prompt_block_ref` to insert a value from request context and fall back to a shared stored block when the value is missing:
100
+
101
+ ```typescript
102
+ await editor.agent.update({
103
+ id: 'support-agent',
104
+ instructions: [
105
+ { type: 'text', content: 'Follow the platform safety policy.' },
106
+ {
107
+ type: 'prompt_block',
108
+ content: '{{userPrompt}}',
109
+ rules: {
110
+ operator: 'AND',
111
+ conditions: [
112
+ { field: 'userPrompt', operator: 'exists' },
113
+ { field: 'userPrompt', operator: 'not_equals', value: '' },
114
+ ],
115
+ },
116
+ },
117
+ {
118
+ type: 'prompt_block_ref',
119
+ id: 'default-user-prompt',
120
+ rules: {
121
+ operator: 'OR',
122
+ conditions: [
123
+ { field: 'userPrompt', operator: 'not_exists' },
124
+ { field: 'userPrompt', operator: 'equals', value: '' },
125
+ ],
126
+ },
127
+ },
128
+ ],
129
+ })
130
+ ```
131
+
132
+ When the request context contains a non-empty `userPrompt`, the agent receives that value. Otherwise, it receives the published `default-user-prompt` block. The stored block doesn't need to know about `userPrompt`.
133
+
134
+ > **Note:** The `exists` operator treats an empty string as present. The extra `''` conditions make an empty `userPrompt` use the fallback too.
135
+
95
136
  ## Programmatic API
96
137
 
97
138
  Access prompt blocks through `mastra.getEditor().prompt`. See the [`prompt` namespace](https://mastra.ai/reference/editor/mastra-editor) for complete method signatures.
@@ -81,6 +81,8 @@ const editor = new MastraEditor({
81
81
 
82
82
  **userIdResolver** (`ComposioUserIdResolver`): Server-side resolver that derives the effective Composio userId from authenticated context fields. Used for invoker and caller-supplied execution. The exact connected account always comes from the stored connection pin.
83
83
 
84
+ **sharedConnections** (`{ acl?: ComposioSharedAccountAcl }`): Opt in to Composio SHARED connected accounts. When set, connections authorized with scope: 'shared' are created as Composio SHARED accounts. acl accepts allowAllUsers, allowedUserIds, and notAllowedUserIds. Omit acl to keep Composio's deny-by-default access.
85
+
84
86
  ### Tool slugs
85
87
 
86
88
  Composio tools use uppercase slug format: `GITHUB_CREATE_ISSUE`, `SLACK_SEND_MESSAGE`.
@@ -125,6 +127,23 @@ export const mastra = new Mastra({ editor })
125
127
 
126
128
  Configure the agent with an invoker connection pinned to `ca_alice_salesforce`. When Bob invokes the agent, Mastra sends `bob` as the Composio user and the pinned account ID as the exact connected account. The Memory resource stays `project_123`. Composio then checks whether the account's ACL permits Bob to execute it.
127
129
 
130
+ ### Create shared accounts
131
+
132
+ Set `sharedConnections` to create Composio [SHARED accounts](https://docs.composio.dev/docs/shared-connections) for connections authorized with `scope: 'shared'`:
133
+
134
+ ```typescript
135
+ new ComposioToolProvider({
136
+ apiKey: process.env.COMPOSIO_API_KEY!,
137
+ sharedConnections: {
138
+ acl: { allowAllUsers: true, notAllowedUserIds: ['contractor_1'] },
139
+ },
140
+ })
141
+ ```
142
+
143
+ Without `sharedConnections`, shared-scope connections are Composio PRIVATE accounts under the `shared` user. Composio doesn't support SHARED accounts for toolkits that require custom connection fields, so authorization fails for those toolkits instead of creating a PRIVATE account.
144
+
145
+ `listConnections()` returns the requested users' PRIVATE and SHARED accounts, plus SHARED accounts owned by other users whose ACL grants access to one of the requested users. You can pin these accounts like any other connected account.
146
+
128
147
  ### Map application users to Composio users
129
148
 
130
149
  Use `userIdResolver` when your Composio user IDs differ from the IDs returned by Mastra authentication, or when your application must authorize the stored account pin before execution.
@@ -4,8 +4,6 @@
4
4
 
5
5
  # config.ts
6
6
 
7
- > **Beta:** Breaking changes may occur without a major version bump until the API is stable.
8
-
9
7
  An agent's `config.ts` sets its model and runtime options. Use it for options that belong to the [`Agent`](https://mastra.ai/reference/agents/agent) itself, while sibling files provide instructions, tools, skills, et cetera.
10
8
 
11
9
  ## What belongs in `config.ts`
@@ -4,8 +4,6 @@
4
4
 
5
5
  # Instructions
6
6
 
7
- > **Beta:** Breaking changes may occur without a major version bump until the API is stable.
8
-
9
7
  An agent's instructions hold its always-on system prompt: the model reads it on every turn. Use them to define the agent's identity, tone, role, and standing rules.
10
8
 
11
9
  Write them in one of two files at the agent root. Use `instructions.md` when the prompt is fixed text. Use `instructions.ts` when the prompt needs code, for example when it's built from shared constants or resolved per request.
@@ -4,8 +4,6 @@
4
4
 
5
5
  # Logger
6
6
 
7
- > **Beta:** Breaking changes may occur without a major version bump until the API is stable.
8
-
9
7
  Mastra sets the project's [logger](https://mastra.ai/docs/observability/logging) from a `logger.ts` file directly under `src/mastra/`. The file default-exports a logger, which replaces the built-in `ConsoleLogger` used across agents, workflows, and other components.
10
8
 
11
9
  Use this page for the file-based convention. For log levels, transports, and provider details, see [logging](https://mastra.ai/docs/observability/logging).
@@ -4,8 +4,6 @@
4
4
 
5
5
  # Memory
6
6
 
7
- > **Beta:** Breaking changes may occur without a major version bump until the API is stable.
8
-
9
7
  A file-based agent gets [memory](https://mastra.ai/docs/memory/overview) from a `memory.ts` file that default-exports a [`Memory`](https://mastra.ai/reference/memory/memory-class) instance. Use this page for the file-based convention; use the memory docs for message history, semantic recall, storage, and processors.
10
8
 
11
9
  Without `memory.ts` or `config.memory`, the agent has no memory by default. Each `generate()` or `stream()` call starts without remembered conversation state unless you pass the prior context yourself.
@@ -4,8 +4,6 @@
4
4
 
5
5
  # Observability
6
6
 
7
- > **Beta:** Breaking changes may occur without a major version bump until the API is stable.
8
-
9
7
  Mastra configures [observability](https://mastra.ai/docs/observability/overview) from an `observability.ts` file directly under `src/mastra/`. The file default-exports an `Observability` instance that sets up tracing, logging, metrics, and feedback for the project.
10
8
 
11
9
  Use this page for the file-based convention. For the signal model, exporters, storage, and multi-config setup, see the [observability overview](https://mastra.ai/docs/observability/overview) and [observability configuration](https://mastra.ai/docs/observability/overview).
@@ -4,8 +4,6 @@
4
4
 
5
5
  # Processors
6
6
 
7
- > **Beta:** Breaking changes may occur without a major version bump until the API is stable.
8
-
9
7
  A file-based agent discovers [processors](https://mastra.ai/docs/agents/processors) from its `processors/` directory. Use this page for the file-based convention; use the processors guide for built-in processors, custom processors, streaming behavior, and advanced patterns.
10
8
 
11
9
  Files under `processors/input/` run before messages reach the model. Files under `processors/output/` run after the model responds. Each file default-exports one [`Processor`](https://mastra.ai/reference/processors/processor-interface), and the filename becomes its discovery key.
@@ -4,8 +4,6 @@
4
4
 
5
5
  # Schedules
6
6
 
7
- > **Beta:** Breaking changes may occur without a major version bump until the API is stable.
8
-
9
7
  A file-based agent discovers **schedules** from its `schedules/` directory. Each file declares one recurring task: a cron expression plus what the agent should do when it fires. Mastra registers them into schedule storage at startup. A scheduled agent needs no runtime registration code.
10
8
 
11
9
  Use this page for the file-based convention. To create schedules at runtime instead, see [Schedules](https://mastra.ai/reference/schedules/overview).
@@ -118,7 +116,7 @@ Frontmatter accepts every option below except `handler`, which needs a function
118
116
 
119
117
  ## Options
120
118
 
121
- **cron** (`string`): Standard five-field cron expression. Required. The scheduler evaluates schedules on a tick loop, so the effective granularity is one minute. Sub-minute fields are not supported.
119
+ **cron** (`string`): A 5-, 6-, or 7-part cron expression. Required.
122
120
 
123
121
  **prompt** (`string`): Message the agent runs on each fire. Set this or handler, not both.
124
122
 
@@ -144,7 +142,7 @@ Frontmatter accepts every option below except `handler`, which needs a function
144
142
 
145
143
  **ifIdle** (`ScheduleIfIdle`): What to do when the target thread is idle: wake, persist, or discard. Threaded schedules only.
146
144
 
147
- **status** (`'active' | 'paused'`): Status the row is created with. Applies on first create only, because the sync never patches status so that pausing through the API survives a redeploy. Changing this value in code later has no effect on an existing schedule. (Default: `'active'`)
145
+ **status** (`'active' | 'paused'`): Status the row is created with. Applies on first create, because a redeploy that leaves the cadence unchanged never patches status, so pausing through the API survives it. Changing this value in code later has no effect on an existing schedule. A cadence with no future occurrence is registered as completed, and a later cadence edit that can fire reactivates a completed row. (Default: `'active'`)
148
146
 
149
147
  **metadata** (`Record<string, unknown>`): Arbitrary JSON-safe data stored alongside the schedule row.
150
148
 
@@ -4,8 +4,6 @@
4
4
 
5
5
  # Scorers
6
6
 
7
- > **Beta:** Breaking changes may occur without a major version bump until the API is stable.
8
-
9
7
  A file-based agent discovers [scorers](https://mastra.ai/docs/evals/overview) from its `scorers/` directory. Use this page for the file-based convention; use the scorers guide for built-in scorers, custom scorers, and sampling.
10
8
 
11
9
  Each file under `scorers/` default-exports one scorer, and the filename becomes its key. The default export is either a [`MastraScorer`](https://mastra.ai/reference/evals/create-scorer) or a `{ scorer, sampling }` entry.
@@ -4,8 +4,6 @@
4
4
 
5
5
  # Server
6
6
 
7
- > **Beta:** Breaking changes may occur without a major version bump until the API is stable.
8
-
9
7
  Mastra configures its HTTP [server](https://mastra.ai/docs/server/overview) from a `server.ts` file directly under `src/mastra/`. The server exposes agents, workflows, and other registered primitives as REST endpoints, and the file default-exports the same `ServerConfig` shape you'd pass to [`new Mastra()`](https://mastra.ai/reference/core/mastra-class).
10
8
 
11
9
  Use this page for the file-based convention. For server features, middleware, custom routes, generated API docs, and deployment behavior, see [Server overview](https://mastra.ai/docs/server/overview).
@@ -4,8 +4,6 @@
4
4
 
5
5
  # Skills
6
6
 
7
- > **Beta:** Breaking changes may occur without a major version bump until the API is stable.
8
-
9
7
  A file-based agent discovers skills from its `skills/` directory and bundles them at build time. Skills are reusable procedures or reference material that the agent can load when relevant, instead of putting every detail into the always-on prompt.
10
8
 
11
9
  Use this page for the file-based convention. For code-defined skills, see [Agent skills](https://mastra.ai/docs/skills). For the `SKILL.md` package format, see [Workspace skills](https://mastra.ai/docs/sandbox/skills).
@@ -4,8 +4,6 @@
4
4
 
5
5
  # Storage
6
6
 
7
- > **Beta:** Breaking changes may occur without a major version bump until the API is stable.
8
-
9
7
  Mastra sets the project's default [storage](https://mastra.ai/docs/storage) from a `storage.ts` file directly under `src/mastra/`. The file default-exports a store, which replaces the built-in in-memory store used for memory, workflows, observability, and other storage domains.
10
8
 
11
9
  Use this page for the file-based convention. For backend choice, storage domains, retention, and provider details, see [storage overview](https://mastra.ai/docs/storage).
@@ -4,8 +4,6 @@
4
4
 
5
5
  # Studio
6
6
 
7
- > **Beta:** Breaking changes may occur without a major version bump until the API is stable.
8
-
9
7
  Mastra configures [Studio](https://mastra.ai/docs/studio/overview) from a `studio.ts` file directly under `src/mastra/`. The file default-exports a `StudioConfig` object for Studio authentication and authorization: who can access Studio, and what authenticated users can do.
10
8
 
11
9
  Use this page for the file-based convention. For auth providers, role-based access control (RBAC), and fine-grained authorization (FGA), see [Studio auth](https://mastra.ai/docs/studio/auth).
@@ -4,8 +4,6 @@
4
4
 
5
5
  # Subagents
6
6
 
7
- > **Beta:** Breaking changes may occur without a major version bump until the API is stable.
8
-
9
7
  A file-based agent can declare **subagents**, specialist child agents it delegates to. The parent model sees each subagent as a delegation tool named after the subagent directory and calls that tool to hand off a task. The subagent's result returns to the parent conversation.
10
8
 
11
9
  Use this page for the file-based convention. For broader delegation patterns, hooks, memory isolation, tool approval propagation, and scoring, see [Supervisor agents](https://mastra.ai/docs/subagents).
@@ -4,8 +4,6 @@
4
4
 
5
5
  # Tools
6
6
 
7
- > **Beta:** Breaking changes may occur without a major version bump until the API is stable.
8
-
9
7
  A file-based agent discovers tools from `.ts` and `.js` files directly under its `tools/` directory. Each discovered file is imported at build time, the file must default-export a [`createTool()`](https://mastra.ai/reference/tools/create-tool) result, and the filename without its extension becomes the tool key the model can call.
10
8
 
11
9
  Use this page for the file-based convention. For tool schemas, execution options, output shaping, and approval options, see the [`createTool()` reference](https://mastra.ai/reference/tools/create-tool).
@@ -4,8 +4,6 @@
4
4
 
5
5
  # Workflows
6
6
 
7
- > **Beta:** Breaking changes may occur without a major version bump until the API is stable.
8
-
9
7
  Mastra discovers project-level workflows from `.ts` and `.js` files under `src/mastra/workflows/`. This convention isn't scoped to one agent: every file with a default export becomes a registered workflow, and the filename becomes the workflow key.
10
8
 
11
9
  Use this page for the file-based convention. For steps, schemas, control flow, streaming, state, and workflow execution, see [Workflows overview](https://mastra.ai/docs/workflows/overview).
@@ -4,8 +4,6 @@
4
4
 
5
5
  # Workspace
6
6
 
7
- > **Beta:** Breaking changes may occur without a major version bump until the API is stable.
8
-
9
7
  A [workspace](https://mastra.ai/docs/sandbox/overview) assembles capabilities such as filesystem access and command execution. The configured backends determine which tools are available. File-based agents get a default workspace automatically when discovered through `mastra dev` or `mastra build`. This default includes filesystem access and command execution, so agents can read and write files and run shell commands without extra configuration.
10
8
 
11
9
  Use this page for the file-based convention. For workspace providers, tools, search, lifecycle, and sandbox details, see [Sandbox](https://mastra.ai/docs/sandbox/overview).
@@ -95,7 +95,7 @@ OM performs thresholding with fast local token estimation. Text uses `tokenx`, a
95
95
 
96
96
  **observation.activateOnProviderChange** (`boolean`): Force buffered observations to activate when the actor provider or model changes. If unset, the top-level activateOnProviderChange value is used for observations. Currently only applied when using the standalone ObservationalMemory class; new Memory(...) applies the top-level activateOnProviderChange only.
97
97
 
98
- **observation.blockAfter** (`number`): Safety net for when background buffering can't keep up. Values from 1 up to (but not including) 100 are multipliers of messageTokens: 1.2 resolves to 120% of the threshold (36k tokens with the default 30k). Values of 100 or more are absolute token counts and must be greater than messageTokens. Above this point, activation uses the smallest set of buffered chunks that reaches the retention target, even when that overshoots the target by more than the usual safeguard allows. It never activates more chunks than are needed to reach the retention target, so it removes only slightly more history than a normal activation. It changes the result only when the retention floor is above roughly 20,000 tokens; with the default bufferActivation (a 6k floor) it has no observable effect. Activation usually keeps a minimum remaining context (the smaller of 1000 tokens or the retention floor), but a single buffered chunk that covers the whole pending window still activates and can leave less. Crossing blockAfter does not trigger a blocking observation. A synchronous (blocking) observation runs when the messageTokens threshold is reached and buffered activation did not happen. Only relevant when bufferTokens is set. Defaults to 1.2 when async buffering is enabled.
98
+ **observation.blockAfter** (`number`): Safety net for when background buffering can't keep up. Values from 1 up to (but not including) 100 are multipliers of messageTokens: 1.2 resolves to 120% of the threshold (36k tokens with the default 30k). Values of 100 or more are absolute token counts and must be greater than messageTokens. Above this point, activation uses the smallest set of buffered chunks that reaches the retention target, even when that overshoots the target by more than the usual safeguard allows. It never activates more chunks than are needed to reach the retention target, so it removes only slightly more history than a normal activation. It changes the result only when the retention floor is above roughly 20,000 tokens; with the default bufferActivation (a 6k floor) it has no observable effect. Activation usually keeps a minimum remaining context (the smaller of 1000 tokens or the retention floor), but a single buffered chunk that covers the whole pending window still activates and can leave less. Crossing blockAfter does not trigger a blocking observation. A synchronous (blocking) observation runs when the messageTokens threshold is reached and activating buffered chunks doesn't bring pending tokens back under it, for example when a large tool result arrives after buffering has stopped. All remaining buffered chunks are activated first, so the synchronous observation only covers messages no chunk has observed. Only relevant when bufferTokens is set. Defaults to 1.2 when async buffering is enabled.
99
99
 
100
100
  **observation.previousObserverTokens** (`number | false`): Optional token budget for the observer's previous-observations context. When set to a number, the observations passed to the Observer agent are tail-truncated to fit within this budget while keeping the newest observations and preserving highlighted 🔴 items when possible. When a buffered reflection is pending, the already-reflected observation lines are automatically replaced with the reflection summary before truncation. Set to 0 to omit previous observations entirely, or false to disable truncation explicitly.
101
101
 
@@ -367,7 +367,7 @@ export const agent = new Agent({
367
367
 
368
368
  Async buffering is **enabled by default**. It pre-computes observations in the background as the conversation grows: when the `messageTokens` threshold is reached, buffered observations activate instantly with no blocking LLM call.
369
369
 
370
- The lifecycle follows **buffer → activate → remove messages → repeat**. Background Observer calls run at `bufferTokens` intervals and produce chunks of observations. At the threshold, activation moves observations into the log and removes raw messages from context. Above `blockAfter`, activation may overshoot the retention target instead of activating fewer chunks. A synchronous observation runs if the threshold is reached without activating a buffered chunk.
370
+ The lifecycle follows **buffer → activate → remove messages → repeat**. Background Observer calls run at `bufferTokens` intervals and produce chunks of observations. At the threshold, activation moves observations into the log and removes raw messages from context. Above `blockAfter`, activation may overshoot the retention target instead of activating fewer chunks. A synchronous observation runs if pending tokens are still at or above the threshold after all buffered chunks have been activated.
371
371
 
372
372
  Default settings:
373
373