@mastra/mcp-docs-server 1.2.14-alpha.1 → 1.2.14-alpha.4

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 (127) hide show
  1. package/.docs/docs/agents/a2a.md +1 -1
  2. package/.docs/docs/agents/acp.md +1 -1
  3. package/.docs/docs/agents/agent-approval.md +1 -1
  4. package/.docs/docs/agents/networks.md +2 -2
  5. package/.docs/docs/agents/overview.md +2 -2
  6. package/.docs/docs/agents/processors.md +25 -1
  7. package/.docs/docs/agents/using-tools.md +2 -2
  8. package/.docs/docs/capabilities/channels/overview.md +1 -1
  9. package/.docs/docs/{agents/supervisor-agents.md → capabilities/subagents.md} +58 -58
  10. package/.docs/docs/deployment/sandbox.md +95 -1
  11. package/.docs/docs/getting-started/develop.md +2 -0
  12. package/.docs/docs/harness/agent-controller.md +370 -0
  13. package/.docs/docs/long-running-agents/background-tasks.md +1 -1
  14. package/.docs/docs/long-running-agents/goals.md +3 -3
  15. package/.docs/docs/mcp/overview.md +222 -281
  16. package/.docs/docs/memory/overview.md +2 -2
  17. package/.docs/docs/observability/integrations/exporters/confident-ai.md +140 -0
  18. package/.docs/docs/observability/integrations/overview.md +1 -1
  19. package/.docs/docs/observability/overview.md +122 -8
  20. package/.docs/docs/observability/tracing/overview.md +2 -2
  21. package/.docs/docs/server/mastra-client.md +1 -1
  22. package/.docs/docs/server/server-adapters.md +2 -0
  23. package/.docs/docs/storage/overview.md +2 -2
  24. package/.docs/docs/workflows/agents-and-tools.md +29 -0
  25. package/.docs/docs/workflows/stored-workflows.md +146 -0
  26. package/.docs/guides/build-your-ui/copilotkit/channels.md +49 -39
  27. package/.docs/guides/concepts/multi-agent-systems.md +7 -7
  28. package/.docs/guides/guide/coding-agent.md +2 -2
  29. package/.docs/guides/guide/research-coordinator.md +1 -1
  30. package/.docs/guides/migrations/network-to-supervisor.md +1 -1
  31. package/.docs/models/environment-variables.md +1 -1
  32. package/.docs/models/gateways/neon.md +71 -0
  33. package/.docs/models/gateways/netlify.md +6 -6
  34. package/.docs/models/gateways/openrouter.md +6 -6
  35. package/.docs/models/gateways/vercel.md +6 -6
  36. package/.docs/models/gateways.md +1 -0
  37. package/.docs/models/index.md +96 -97
  38. package/.docs/models/providers/alibaba-cn.md +23 -25
  39. package/.docs/models/providers/alibaba-token-plan-cn.md +24 -24
  40. package/.docs/models/providers/alibaba-token-plan.md +23 -25
  41. package/.docs/models/providers/alibaba.md +23 -25
  42. package/.docs/models/providers/ambient.md +23 -25
  43. package/.docs/models/providers/baseten.md +23 -25
  44. package/.docs/models/providers/chutes.md +23 -25
  45. package/.docs/models/providers/cortecs.md +23 -25
  46. package/.docs/models/providers/crof.md +23 -25
  47. package/.docs/models/providers/crossmodel.md +23 -25
  48. package/.docs/models/providers/deepinfra.md +22 -24
  49. package/.docs/models/providers/digitalocean.md +32 -34
  50. package/.docs/models/providers/empiriolabs.md +23 -25
  51. package/.docs/models/providers/fireworks-ai.md +24 -24
  52. package/.docs/models/providers/greenpt.md +23 -25
  53. package/.docs/models/providers/groq.md +23 -25
  54. package/.docs/models/providers/huggingface.md +23 -25
  55. package/.docs/models/providers/hyper.md +23 -25
  56. package/.docs/models/providers/impossibl.md +23 -25
  57. package/.docs/models/providers/infomaniak.md +24 -24
  58. package/.docs/models/providers/kilo.md +24 -26
  59. package/.docs/models/providers/llmgateway.md +24 -26
  60. package/.docs/models/providers/mistral.md +23 -25
  61. package/.docs/models/providers/modal.md +23 -25
  62. package/.docs/models/providers/modelis.md +23 -25
  63. package/.docs/models/providers/nano-gpt.md +23 -25
  64. package/.docs/models/providers/neuralwatt.md +23 -25
  65. package/.docs/models/providers/ofox.md +23 -25
  66. package/.docs/models/providers/ollama-cloud.md +23 -25
  67. package/.docs/models/providers/opencode-go.md +23 -25
  68. package/.docs/models/providers/opencode.md +25 -26
  69. package/.docs/models/providers/pioneer.md +23 -25
  70. package/.docs/models/providers/requesty.md +23 -25
  71. package/.docs/models/providers/routing-run.md +23 -25
  72. package/.docs/models/providers/scx.md +23 -25
  73. package/.docs/models/providers/tensorx.md +23 -25
  74. package/.docs/models/providers/togetherai.md +22 -24
  75. package/.docs/models/providers/umans-ai-coding-plan.md +24 -24
  76. package/.docs/models/providers/umans-ai.md +23 -25
  77. package/.docs/models/providers/wandb.md +23 -25
  78. package/.docs/models/providers/xai.md +26 -28
  79. package/.docs/models/providers/zai-coding-plan.md +23 -25
  80. package/.docs/models/providers/zhipuai-coding-plan.md +23 -25
  81. package/.docs/models/providers.md +0 -1
  82. package/.docs/reference/acp/acp-agent.md +1 -1
  83. package/.docs/reference/agent-controller/agent-controller-class.md +195 -506
  84. package/.docs/reference/agent-controller/session.md +274 -111
  85. package/.docs/reference/agents/network.md +1 -1
  86. package/.docs/reference/ai-sdk/handle-network-stream.md +1 -1
  87. package/.docs/reference/ai-sdk/network-route.md +1 -1
  88. package/.docs/reference/cli/create-mastra.md +1 -1
  89. package/.docs/reference/client-js/workflows.md +92 -0
  90. package/.docs/reference/core/addStoredWorkflow.md +62 -0
  91. package/.docs/reference/core/addStoredWorkflows.md +40 -0
  92. package/.docs/reference/editor/versioning.md +1 -1
  93. package/.docs/reference/evals/rubric.md +1 -1
  94. package/.docs/reference/file-based-agents/observability.md +2 -2
  95. package/.docs/reference/file-based-agents/storage.md +1 -1
  96. package/.docs/reference/file-based-agents/subagents.md +1 -1
  97. package/.docs/reference/file-based-agents/tools.md +1 -1
  98. package/.docs/reference/index.md +5 -0
  99. package/.docs/reference/observability/tracing/configuration.md +1 -1
  100. package/.docs/reference/observability/tracing/exporters/confident-ai.md +138 -0
  101. package/.docs/reference/observability/tracing/interfaces.md +29 -0
  102. package/.docs/reference/processors/processor-interface.md +121 -10
  103. package/.docs/reference/server/routes.md +13 -0
  104. package/.docs/reference/signals/signal-provider.md +2 -0
  105. package/.docs/reference/storage/overview.md +9 -8
  106. package/.docs/reference/streaming/workflows/observeStream.md +1 -1
  107. package/.docs/reference/streaming/workflows/resumeStream.md +1 -1
  108. package/.docs/reference/streaming/workflows/stream.md +1 -1
  109. package/.docs/reference/tools/mcp-server.md +1 -1
  110. package/.docs/reference/tools/submit-plan-tool.md +1 -1
  111. package/.docs/reference/workflows/stored-workflow-definition.md +292 -0
  112. package/.docs/reference/workflows/workflow-methods/agent.md +62 -0
  113. package/.docs/reference/workflows/workflow-methods/tool.md +43 -0
  114. package/.docs/reference/workspace/railway-sandbox.md +5 -5
  115. package/CHANGELOG.md +14 -0
  116. package/package.json +4 -4
  117. package/.docs/docs/agent-controller/channels.md +0 -111
  118. package/.docs/docs/agent-controller/modes.md +0 -147
  119. package/.docs/docs/agent-controller/overview.md +0 -136
  120. package/.docs/docs/agent-controller/session.md +0 -161
  121. package/.docs/docs/agent-controller/subagents.md +0 -110
  122. package/.docs/docs/agent-controller/threads-and-state.md +0 -148
  123. package/.docs/docs/agent-controller/tool-approvals.md +0 -147
  124. package/.docs/docs/mcp/mcp-apps.md +0 -306
  125. package/.docs/docs/observability/config.md +0 -140
  126. package/.docs/docs/observability/storage.md +0 -81
  127. package/.docs/models/providers/neon.md +0 -109
@@ -0,0 +1,43 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
3
+ # Workflow\.tool()
4
+
5
+ The `.tool()` method adds a tool as a declarative step. The tool's own input and output schemas apply, so the previous step's output must satisfy the tool's input schema. Use `.map()` to transform the data if they don't match.
6
+
7
+ Unlike wrapping a tool with `createStep()`, `.tool()` records a declarative entry in the workflow graph. This makes the workflow portable: the same graph can be serialized and persisted as a [stored workflow](https://mastra.ai/docs/workflows/stored-workflows).
8
+
9
+ ## Usage example
10
+
11
+ ```typescript
12
+ workflow.tool(testTool).commit();
13
+ ```
14
+
15
+ ## Parameters
16
+
17
+ **toolOrId** (`Tool | string`): A tool instance, or the ID of a tool registered on the Mastra instance. When passing an ID, the tool is resolved from the registry at execution time.
18
+
19
+ **options** (`{ retries?: number, scorers?: DynamicArgument<MastraScorers>, metadata?: StepMetadata }`): Step-level retry count, scorers, and metadata for the tool step.
20
+
21
+ **stepOptions** (`{ id?: string }`): The step's call-site ID within the workflow. Defaults to the tool's ID. Set this when the same tool appears more than once in one workflow.
22
+
23
+ ## Returns
24
+
25
+ **workflow** (`Workflow`): The workflow instance for method chaining
26
+
27
+ ## Referencing a tool by ID
28
+
29
+ Pass a string to reference a registered tool without importing it. The tool must be registered on the Mastra instance when the workflow runs:
30
+
31
+ ```typescript
32
+ workflow.tool("lookup-customer", { retries: 2 }).commit();
33
+ ```
34
+
35
+ ## Persisting tool steps
36
+
37
+ Workflows built with `.tool()` serialize to the same declarative entries that [stored workflows](https://mastra.ai/docs/workflows/stored-workflows) use. Only `retries` and `metadata` round-trip through storage. A function-valued `scorers` option throws an error when the workflow is stored.
38
+
39
+ ## Related
40
+
41
+ - [Agents and Tools](https://mastra.ai/docs/workflows/agents-and-tools)
42
+ - [Stored workflows](https://mastra.ai/docs/workflows/stored-workflows)
43
+ - [Workflow.agent()](https://mastra.ai/reference/workflows/workflow-methods/agent)
@@ -143,14 +143,14 @@ const sandbox = new RailwaySandbox({
143
143
 
144
144
  Use one stable checkpoint name for each independent filesystem. Don't share a checkpoint name across unrelated sessions or projects.
145
145
 
146
- ### Derived sandbox checkpoints
146
+ ### Cloned sandbox checkpoints
147
147
 
148
- Use `derive({ checkpointName })` when a configured `RailwaySandbox` acts as the template for a sandbox fleet:
148
+ Use `clone({ checkpointName })` when a configured `RailwaySandbox` acts as the template for a sandbox fleet:
149
149
 
150
150
  ```typescript
151
151
  const template = new RailwaySandbox({ idleTimeoutMinutes: 30 })
152
152
 
153
- const sessionSandbox = template.derive({
153
+ const sessionSandbox = template.clone({
154
154
  id: 'session-42',
155
155
  checkpointName: 'project-session-42',
156
156
  })
@@ -158,7 +158,7 @@ const sessionSandbox = template.derive({
158
158
  await sessionSandbox.start()
159
159
  ```
160
160
 
161
- A derived sandbox uses the checkpoint passed to `derive()`. If no override is passed, it inherits the template sandbox's `checkpointName`.
161
+ A cloned sandbox uses the checkpoint passed to `clone()`. If no override is passed, it inherits the template sandbox's `checkpointName`.
162
162
 
163
163
  ### Streaming output
164
164
 
@@ -226,7 +226,7 @@ const result = await sandbox.executeCommand('cat', ['/tmp/state.txt'])
226
226
 
227
227
  **fork** (`(options?) => Promise<RailwaySandbox>`): Clone this running sandbox into a new, independent RailwaySandbox. The returned sandbox is already started and reattached to the forked Railway sandbox. Accepts optional id, idleTimeoutMinutes, networkIsolation, and env overrides. Throws SandboxNotReadyError if this sandbox has not been started.
228
228
 
229
- **derive** (`(options?) => RailwaySandbox`): Construct an unstarted sibling sandbox that inherits credentials and defaults. Accepts optional id, sandboxId, env, idleTimeoutMinutes, and checkpointName overrides. The derived sandbox uses options.checkpointName when set, otherwise it inherits the template checkpointName.
229
+ **clone** (`(options?) => RailwaySandbox`): Construct an unstarted sibling sandbox that inherits credentials and defaults. Accepts optional id, sandboxId, env, idleTimeoutMinutes, and checkpointName overrides. The cloned sandbox uses options.checkpointName when set, otherwise it inherits the template checkpointName.
230
230
 
231
231
  ## Background processes
232
232
 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @mastra/mcp-docs-server
2
2
 
3
+ ## 1.2.14-alpha.4
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`810c7e7`](https://github.com/mastra-ai/mastra/commit/810c7e74929989d8b8b5db52cd3af22cd0998af4), [`f9f9884`](https://github.com/mastra-ai/mastra/commit/f9f98848ee194dc71a787a709ec430b065cdc41b), [`e0904dc`](https://github.com/mastra-ai/mastra/commit/e0904dc538792e54e1806b70172e5900ac49bff4), [`64d6781`](https://github.com/mastra-ai/mastra/commit/64d67814bccddd314f7e09643243821e57cb87b6), [`c848e65`](https://github.com/mastra-ai/mastra/commit/c848e655a64ff10331a8ceafafe7f18e70a0f092), [`0494489`](https://github.com/mastra-ai/mastra/commit/049448906e4c3d2d615bbe865b073a0d890ddb7c), [`8d1aeb8`](https://github.com/mastra-ai/mastra/commit/8d1aeb8acf7c20c4bb8e4d8e4bdc6569c83ac561), [`83065bf`](https://github.com/mastra-ai/mastra/commit/83065bfee9e47c3c6f09132a9034501f6cfb69cf), [`01b162f`](https://github.com/mastra-ai/mastra/commit/01b162fe435295881aa7ea55f1759407ad5175ad)]:
8
+ - @mastra/core@1.57.0-alpha.2
9
+
10
+ ## 1.2.14-alpha.2
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies [[`89200ba`](https://github.com/mastra-ai/mastra/commit/89200bafa05444bb7949b363ce7b743e29867561), [`c950138`](https://github.com/mastra-ai/mastra/commit/c950138e72e4f317a40187e3800588731ab790ce), [`063c8b2`](https://github.com/mastra-ai/mastra/commit/063c8b2eb14e4e5ca021779bc33e8c3c031c8604), [`f4e964c`](https://github.com/mastra-ai/mastra/commit/f4e964cad57057301d6bed5c55bcdd730175b941), [`1f7bbd7`](https://github.com/mastra-ai/mastra/commit/1f7bbd7785a8d230aad02454ecabeb4a0b2cc96f), [`e47ff36`](https://github.com/mastra-ai/mastra/commit/e47ff36945720f4ee4caa09f6e83514d7d188608), [`fb9a6ac`](https://github.com/mastra-ai/mastra/commit/fb9a6ac11c9560518742ece60b49d6b062845fd3), [`aa2cec8`](https://github.com/mastra-ai/mastra/commit/aa2cec8501f634d51c2f3ebfb3dd3aa7af8d2ca2), [`2adf8eb`](https://github.com/mastra-ai/mastra/commit/2adf8eb4a70ed2b6cff2dd39281496ea0e025fac), [`8264611`](https://github.com/mastra-ai/mastra/commit/8264611510e421b818bc7395dc2ae4d9c2d518b2), [`44fc98b`](https://github.com/mastra-ai/mastra/commit/44fc98b9d1242aa87a3ab44bdce9e9f12c44d8c9), [`0f2ef41`](https://github.com/mastra-ai/mastra/commit/0f2ef4118da022e4f30dac4e9856cc3a8c97671c)]:
15
+ - @mastra/core@1.57.0-alpha.1
16
+
3
17
  ## 1.2.14-alpha.0
4
18
 
5
19
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/mcp-docs-server",
3
- "version": "1.2.14-alpha.1",
3
+ "version": "1.2.14-alpha.4",
4
4
  "description": "MCP server for accessing Mastra.ai documentation, changelogs, and news.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -29,7 +29,7 @@
29
29
  "local-pkg": "^1.1.2",
30
30
  "zod": "^4.4.3",
31
31
  "@mastra/mcp": "^1.15.1",
32
- "@mastra/core": "1.56.1-alpha.0"
32
+ "@mastra/core": "1.57.0-alpha.2"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@hono/node-server": "^1.19.14",
@@ -45,9 +45,9 @@
45
45
  "tsx": "^4.23.1",
46
46
  "typescript": "^6.0.3",
47
47
  "vitest": "4.1.10",
48
- "@internal/types-builder": "0.0.95",
49
48
  "@internal/lint": "0.0.120",
50
- "@mastra/core": "1.56.1-alpha.0"
49
+ "@internal/types-builder": "0.0.95",
50
+ "@mastra/core": "1.57.0-alpha.2"
51
51
  },
52
52
  "homepage": "https://mastra.ai",
53
53
  "repository": {
@@ -1,111 +0,0 @@
1
- > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
-
3
- # Channels
4
-
5
- Channels connect an AgentController to messaging platforms like Slack, Discord, and Telegram, so a controller-backed session runs inside a chat thread. Inbound platform messages route into a controller [`Session`](https://mastra.ai/docs/agent-controller/session), and the agent's output renders back to the platform with native streaming. The response can also include tool approval cards and typing status.
6
-
7
- AgentController channels use the same channel layer as [agent channels](https://mastra.ai/docs/capabilities/channels/overview). The adapters and configuration shape are shared. Both channel types also use the same rendering pipeline.
8
-
9
- Message routing differs by channel type. Agent channels route messages straight into the agent loop. With AgentController channels, messages enter a durable session that tracks the active mode, model, permission grants, and state across the whole conversation.
10
-
11
- ## Configure a controller
12
-
13
- Pass a `channels` configuration to the AgentController constructor. It accepts the same shape as the [`Agent` channels option](https://mastra.ai/docs/capabilities/channels/overview):
14
-
15
- ```typescript
16
- import { Agent } from '@mastra/core/agent'
17
- import { AgentController } from '@mastra/core/agent-controller'
18
- import { createSlackAdapter } from '@chat-adapter/slack'
19
- import { LibSQLStore } from '@mastra/libsql'
20
-
21
- const agent = new Agent({
22
- id: 'assistant',
23
- name: 'assistant',
24
- instructions: 'Help the user plan and complete tasks.',
25
- model: 'anthropic/claude-sonnet-4-6',
26
- })
27
-
28
- export const agentController = new AgentController({
29
- id: 'my-agent-controller',
30
- agent,
31
- storage: new LibSQLStore({ url: 'file:./data.db' }),
32
- modes: [
33
- {
34
- id: 'plan',
35
- name: 'Plan',
36
- metadata: { default: true },
37
- instructions: 'Reason about changes before making them.',
38
- },
39
- { id: 'build', name: 'Build', instructions: 'Implement the approved plan.' },
40
- ],
41
- channels: {
42
- adapters: {
43
- slack: createSlackAdapter(),
44
- },
45
- },
46
- })
47
- ```
48
-
49
- Register the controller on the Mastra instance. Mastra registers the webhook routes and initializes the channel layer:
50
-
51
- ```typescript
52
- import { Mastra } from '@mastra/core'
53
- import { LibSQLStore } from '@mastra/libsql'
54
- import { agentController } from './agent-controller'
55
-
56
- export const mastra = new Mastra({
57
- agentControllers: { agentController },
58
- storage: new LibSQLStore({
59
- url: process.env.DATABASE_URL,
60
- }),
61
- })
62
- ```
63
-
64
- ## Webhook routes
65
-
66
- Controller channel webhooks follow the same pattern as agent channels, under an `agent-controllers` path:
67
-
68
- ```text
69
- /api/agent-controllers/<CONTROLLER_ID>/channels/<PLATFORM>/webhook
70
- ```
71
-
72
- For example, a Slack adapter on a controller with the `my-agent-controller` ID uses:
73
-
74
- ```text
75
- /api/agent-controllers/my-agent-controller/channels/slack/webhook
76
- ```
77
-
78
- Point the platform's webhook, event, or interactions URL to this path. See [Webhook routes](https://mastra.ai/docs/capabilities/channels/overview) for local tunneling and platform setup.
79
-
80
- ## One session per chat thread
81
-
82
- Each chat thread maps to one durable controller session. The first message in a Slack or Discord thread creates a Mastra thread and a controller session keyed to it. Every later message in that chat thread reuses both. The session carries the active mode, model, permission grants, and state for the life of the conversation, as with a session driven from a terminal or web UI.
83
-
84
- By default the session key derives from the platform and the external thread ID (`channel:slack:<THREAD_ID>`). Pass `resolveResourceId` in the channels configuration to control the mapping yourself.
85
-
86
- Avoid mapping multiple active chat threads to one session. A session works on one Mastra thread at a time, and a message arriving from a different chat thread rebinds the session to that thread, which cancels any run still in flight on the previous one.
87
-
88
- ## Tool approvals
89
-
90
- Tools that require approval render as interactive cards with Approve and Deny buttons, the same as [agent channel tool approvals](https://mastra.ai/docs/capabilities/channels/overview). The controller run pauses at the session's approval gate until a user acts on the card, then resumes and streams the continuation back to the thread.
91
-
92
- These behaviors follow from routing approvals through the session:
93
-
94
- - A new message in the thread while an approval is pending declines that approval, the same as sending a new message in a terminal session. The new message supersedes the pending ask.
95
- - On adapters that can't render approval buttons (`toolDisplay: 'text'`), tools run without approval prompts so runs can't stall on a card nobody can act on.
96
-
97
- See [Tool approvals and permissions](https://mastra.ai/docs/agent-controller/tool-approvals) for policies, categories, and session grants.
98
-
99
- ## Limits
100
-
101
- - Adapters can be constructed manually with the same configuration. The managed connect flow (`mastra.channels.slack.connect(...)`) also supports controller-owned installations: call it with an options object (`connect({ id, name })`) to connect a controller that has no registered agent. Adapters without controller support must still be constructed manually.
102
- - Controller sessions are in-memory objects, so channels-backed controllers need a long-lived server. Serverless deployment isn't supported for controller channels. Agent channels support it as described in [Serverless deployment](https://mastra.ai/docs/capabilities/channels/overview).
103
- - Pending tool approvals don't survive a server restart. An approval card acted on after a restart is ignored as stale.
104
- - Mode switching from chat (for example, a `/mode` slash command) isn't available yet.
105
-
106
- ## Related
107
-
108
- - [Channels overview](https://mastra.ai/docs/capabilities/channels/overview)
109
- - [Session](https://mastra.ai/docs/agent-controller/session)
110
- - [Tool approvals and permissions](https://mastra.ai/docs/agent-controller/tool-approvals)
111
- - [Channels reference](https://mastra.ai/reference/agents/channels)
@@ -1,147 +0,0 @@
1
- > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
-
3
- # Modes
4
-
5
- Modes define the different behaviors an AgentController can run. Each mode layers its own instructions and tool overrides on top of a shared backing agent, so the same agent can act as a planner in one mode and an executor in another. The AgentController keeps exactly one mode active at a time and carries the thread and state across switches, plus handles the transition between them.
6
-
7
- Every AgentController needs at least one mode, the `modes` array is required, and the AgentController throws at construction if it's empty. A single-purpose AgentController still defines one mode. Multiple modes are how you give a session more than one behavior to switch between.
8
-
9
- A mode supplies three things that change how the agent behaves:
10
-
11
- - **Instructions**: layered on top of the backing agent's own instructions while the mode is active.
12
- - **Tools**: either replacing or adding to the backing agent's tools (see [Mode tool overrides](#mode-tool-overrides)).
13
- - **Model**: an optional `defaultModelId` to bootstrap model selection when the session enters the mode.
14
-
15
- Because every mode shares the same backing agent, thread, and state, switching modes changes how the agent behaves without losing conversation context.
16
-
17
- ## Quickstart
18
-
19
- Import the `AgentController` class and create a new instance with your agent and modes:
20
-
21
- ```typescript
22
- import { AgentController } from '@mastra/core/agent-controller'
23
- import { myAgent } from './agents'
24
-
25
- const agentController = new AgentController({
26
- id: 'multi-mode',
27
- agent: myAgent,
28
- modes: [
29
- {
30
- id: 'plan',
31
- name: 'Plan',
32
- metadata: { default: true },
33
- instructions: 'Reason about the task before making changes.',
34
- },
35
- { id: 'build', name: 'Build', instructions: 'Implement the approved plan.' },
36
- ],
37
- })
38
-
39
- await agentController.init()
40
- ```
41
-
42
- ## Defining modes
43
-
44
- Each mode requires an `id`. When a top-level `agent` is provided, modes layer instructions and tool overrides on the shared agent. Each mode can also specify a `defaultModelId` to bootstrap model selection:
45
-
46
- ```typescript
47
- import { AgentController } from '@mastra/core/agent-controller'
48
-
49
- const agentController = new AgentController({
50
- id: 'multi-mode',
51
- agent: myAgent,
52
- modes: [
53
- {
54
- id: 'plan',
55
- name: 'Plan',
56
- metadata: { default: true },
57
- defaultModelId: 'anthropic/claude-sonnet-4-6',
58
- instructions: 'Reason about the task before making changes.',
59
- },
60
- {
61
- id: 'build',
62
- name: 'Build',
63
- defaultModelId: 'anthropic/claude-sonnet-4-6',
64
- instructions: 'Implement the approved plan.',
65
- },
66
- ],
67
- })
68
- ```
69
-
70
- ### Mode tool overrides
71
-
72
- Modes support two strategies for tool configuration. Use `tools` to replace the backing agent's tools entirely, or `additionalTools` to layer extra tools on top:
73
-
74
- ```typescript
75
- // Replace — agent sees only these tools in plan mode
76
- const planMode = { id: 'plan', tools: { planTool } }
77
-
78
- // Augment — agent keeps its own tools plus these
79
- const buildMode = { id: 'build', additionalTools: { deployTool } }
80
- ```
81
-
82
- You can't set both `tools` and `additionalTools` on the same mode.
83
-
84
- ### Restricting tool visibility
85
-
86
- `tools` and `additionalTools` control which tools are **added** to a mode's run, they don't hide the backing agent's own tools. To restrict which of those tools the model can actually see and call, set `availableTools`:
87
-
88
- ```typescript
89
- const reviewMode = {
90
- id: 'review',
91
- name: 'Review',
92
- // Only these tools are visible to the model in this mode.
93
- availableTools: ['view', 'find_files', 'search_content'],
94
- }
95
- ```
96
-
97
- `availableTools` is a per-mode visibility allowlist that matches each tool by its final exposed name:
98
-
99
- - **`undefined`** (default): no mode-level restriction: every tool is visible.
100
- - **`[]`**: no tools are available for this mode.
101
- - A denied tool stays hidden even when the list includes it. Per-tool and per-category `deny` rules in your permission config always take precedence.
102
-
103
- Workspace tools use the same list as every other tool, reference them by their exposed names (`view`, `write_file`, `find_files`, etc.). Visibility is enforced at LLM-call time, so the model never sees, and can't attempt to call, a tool outside the allowlist.
104
-
105
- ### Mode transitions
106
-
107
- A mode can declare a `transitionsTo` target. When the `submit_plan` built-in tool runs in that mode, the AgentController transitions to the target mode on approval:
108
-
109
- ```typescript
110
- const planMode = {
111
- id: 'plan',
112
- name: 'Plan',
113
- transitionsTo: 'build',
114
- instructions: 'Reason about the task and submit a plan.',
115
- }
116
- ```
117
-
118
- On plan approval, the AgentController automatically switches to `build` mode. On rejection, the agent remains in `plan` mode to revise.
119
-
120
- ## Switching modes
121
-
122
- The active mode lives on the Session, so call `agentController.session.mode.switch()` to change it. The switch aborts any in-progress generation and saves the current model to the outgoing mode, plus emits a `mode_changed` event. It then resolves the incoming mode's model and, when one resolves, applies it and emits a `model_changed` event:
123
-
124
- ```typescript
125
- await agentController.session.mode.switch({ modeId: 'build' })
126
- ```
127
-
128
- ## Querying modes
129
-
130
- The AgentController exposes the full mode catalog, while the Session tracks which mode is active. Use `agentController.listModes()` to read every configured mode, `agentController.session.mode.get()` for the active mode ID, and `agentController.session.mode.resolve()` for the active mode's full definition:
131
-
132
- ```typescript
133
- // List all configured modes
134
- const modes = agentController.listModes()
135
-
136
- // Get the current mode ID
137
- const modeId = agentController.session.mode.get()
138
-
139
- // Get the full mode object
140
- const mode = agentController.session.mode.resolve()
141
- ```
142
-
143
- ## Related
144
-
145
- - [AgentController overview](https://mastra.ai/docs/agent-controller/overview)
146
- - [Threads and state](https://mastra.ai/docs/agent-controller/threads-and-state)
147
- - [API reference](https://mastra.ai/reference/agent-controller/agent-controller-class)
@@ -1,136 +0,0 @@
1
- > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
-
3
- # AgentController overview
4
-
5
- > **Beta:** The `AgentController` feature is in beta stage and subject to breaking changes in minor versions until it graduates from its beta status.
6
-
7
- The AgentController is a session controller for building interactive agent applications.
8
-
9
- It handles the runtime concerns between your UI and the agent loop. These include conversation threads, mode switches, and persistent state. It also gates tool execution with approvals and coordinates subagents. You can focus on what your agent does rather than how to wire it together.
10
-
11
- An AgentController exposes a [`Session`](https://mastra.ai/docs/agent-controller/session), the per-conversation runtime state that tracks the active mode, model, thread binding, permission grants, follow-up queue, and token usage. The AgentController is the shared host. The Session is the conversation running inside it. In a multi-user host, the same AgentController can back many Sessions at once.
12
-
13
- [Mastra Code](https://code.mastra.ai/) is the flagship AgentController implementation. It's a terminal-based coding agent with multi-model support, persistent conversations, and plan-then-execute workflows.
14
-
15
- ## What you can build
16
-
17
- The AgentController gives you the runtime pieces to release interactive agent applications. Each outcome below maps to a capability you can use today:
18
-
19
- - **Resume a conversation exactly where the user left off.** Persistent [threads and state](https://mastra.ai/docs/agent-controller/threads-and-state) reload the active mode, model, and progress across restarts, so a coding agent or assistant picks up mid-task instead of starting over.
20
- - **Gate destructive actions behind human approval.** [Tool approvals and permission policies](https://mastra.ai/docs/agent-controller/tool-approvals) let you require confirmation for risky operations like file writes or deployments, while trusted tools run automatically.
21
- - **Move a task through distinct phases without losing context.** [Modes](https://mastra.ai/docs/agent-controller/modes) switch the agent's instructions, tools, and model on the same thread, so you can build a plan-then-execute coding agent or a research-then-draft assistant.
22
- - **Let users pick the right model for each step.** Per-mode [model management](https://mastra.ai/reference/agent-controller/agent-controller-class) switches models at runtime and tracks usage, which powers copilot UIs where users trade speed for capability.
23
- - **Delegate focused work to child agents.** [Subagents](https://mastra.ai/docs/agent-controller/subagents) run subtasks with constrained tools and can fork the parent conversation, so a research mode can spin off web search or code review without polluting the main thread.
24
- - **Drive a live UI from agent activity.** The [event system](https://mastra.ai/docs/agent-controller/session) emits typed events and coalesced display snapshots, so your TUI or web app reflects message updates, mode changes, and pending approvals in real time.
25
- - **Run long-lived autonomous agents.** Structured task lists, interval handlers, and observational memory keep background task runners on track and let them learn across threads.
26
-
27
- ## When to use the AgentController
28
-
29
- Use the AgentController when your application needs:
30
-
31
- - Multiple agent modes that share one conversation thread (e.g., plan → build → review)
32
- - A control layer between your UI and the agent loop (model switching, state persistence, thread management)
33
- - Tool approval flows and permission policies for human-in-the-loop gating
34
- - Subagent orchestration to delegate focused subtasks with constrained tools
35
- - Session continuity with persistent threads, state, and observational memory across restarts
36
-
37
- You could assemble all of this yourself on top of the [Agent class](https://mastra.ai/docs/agents/overview), which exposes the full agent loop, tools, and memory. The AgentController provides opinionated defaults for an ongoing session where the agent acts as a collaborator rather than a one-shot endpoint. Reach for the Agent class directly when you want full control or a request-response call. Reach for the AgentController when you want the collaborative-session model without building the runtime around it.
38
-
39
- ## Key capabilities
40
-
41
- - **Session**: Per-conversation state: active thread, mode, model, grants, follow-ups, token usage, and the display snapshot: accessed through `agentController.session`. See [Session](https://mastra.ai/docs/agent-controller/session).
42
- - **Modes**: Define distinct agent personalities (instructions, tools, model) and switch between them without losing conversation context. See [Modes](https://mastra.ai/docs/agent-controller/modes).
43
- - **Threads and state**: Persist conversations and structured state across sessions, users, and mode switches. See [Threads and state](https://mastra.ai/docs/agent-controller/threads-and-state).
44
- - **Subagents**: Spawn focused child agents with constrained tools for subtasks, optionally forking the parent conversation. See [Subagents](https://mastra.ai/docs/agent-controller/subagents).
45
- - **Tool approvals and permissions**: Configure which tools require user confirmation and grant session-wide exceptions, plus handle interactive tool suspension. See [Tool approvals](https://mastra.ai/docs/agent-controller/tool-approvals).
46
- - **Model management**: Switch models per-mode at runtime, track usage, and resolve gateway-backed models through Mastra's [model router](https://mastra.ai/models).
47
- - **Follow-ups and steering**: Queue messages while the agent is running, or inject mid-stream instructions to redirect the agent. Built on [signals](https://mastra.ai/docs/long-running-agents/signals).
48
- - **Event system**: Subscribe to typed events (message updates, mode changes, tool approvals) or coalesced `AgentControllerDisplayState` snapshots to drive your UI. See [Events](https://mastra.ai/reference/agent-controller/agent-controller-class).
49
- - **Observational memory**: Automatic summarization and reflection across threads for long-running agent sessions. See [Observational memory](https://mastra.ai/docs/memory/observational-memory).
50
-
51
- ## Quickstart
52
-
53
- Import the `AgentController` class and create a new instance with an agent, storage backend, and modes:
54
-
55
- ```typescript
56
- import { Agent } from '@mastra/core/agent'
57
- import { AgentController } from '@mastra/core/agent-controller'
58
- import { LibSQLStore } from '@mastra/libsql'
59
-
60
- const agent = new Agent({
61
- id: 'assistant',
62
- name: 'assistant',
63
- instructions: 'Help the user plan and complete tasks.',
64
- model: 'openai/gpt-5.6-sol',
65
- })
66
-
67
- const agentController = new AgentController({
68
- id: 'my-agent',
69
- agent,
70
- storage: new LibSQLStore({ id: 'agent-storage', url: 'file:./data.db' }),
71
- modes: [
72
- {
73
- id: 'plan',
74
- name: 'Plan',
75
- metadata: { default: true },
76
- instructions: 'Reason about changes before making them.',
77
- },
78
- { id: 'build', name: 'Build', instructions: 'Implement the approved plan.' },
79
- ],
80
- })
81
-
82
- agentController.subscribe(event => {
83
- if (event.type === 'message_update') {
84
- console.log(event.message)
85
- }
86
- })
87
-
88
- await agentController.init()
89
- await agentController.selectOrCreateThread()
90
- await agentController.sendMessage({ content: 'Hello!' })
91
- ```
92
-
93
- Visit the [AgentController reference](https://mastra.ai/reference/agent-controller/agent-controller-class) for the full constructor parameters and method signatures.
94
-
95
- ## Architecture
96
-
97
- The AgentController sits between your application layer and the underlying agent loop:
98
-
99
- ```text
100
- ┌───────────────────────────────────────┐
101
- │ Your App (TUI/Web/API) │
102
- └───────────────────────────────────────┘
103
- │ commands ▲ events
104
- ▼ │
105
- ┌───────────────────────────────────────┐
106
- │ AgentController │
107
- │ Config · storage · threads │
108
- │ permissions · subagents · events │
109
- │ │
110
- │ ┌─────────────────────────────────┐ │
111
- │ │ agentController.session │ │
112
- │ │ identity · thread · mode │ │
113
- │ │ model · run · grants │ │
114
- │ │ display state │ │
115
- │ └─────────────────────────────────┘ │
116
- └───────────────────────────────────────┘
117
-
118
-
119
- ┌───────────────────────────────────────┐
120
- │ Agent + Memory + Tools │
121
- └───────────────────────────────────────┘
122
- ```
123
-
124
- Your app sends commands, send a message, switch mode, approve a tool call, and receives typed events such as `message_update` and `tool_approval_required`.
125
-
126
- The AgentController manages the lifecycle internally. It persists threads and routes requests to the correct mode agent. It also enforces permissions and emits events as state changes.
127
-
128
- ## Next steps
129
-
130
- - [Session](https://mastra.ai/docs/agent-controller/session): The per-conversation state on an AgentController
131
- - [Modes](https://mastra.ai/docs/agent-controller/modes): Define and switch between agent personalities
132
- - [Threads and state](https://mastra.ai/docs/agent-controller/threads-and-state): Manage persistent conversations
133
- - [Subagents](https://mastra.ai/docs/agent-controller/subagents): Delegate focused subtasks
134
- - [Tool approvals and permissions](https://mastra.ai/docs/agent-controller/tool-approvals): Human-in-the-loop gating
135
- - [API reference](https://mastra.ai/reference/agent-controller/agent-controller-class): Full constructor and method docs
136
- - 📹 [Mastra AgentController harness workshop](https://www.youtube.com/watch?v=tV1pSleP-LM)