@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
@@ -1,161 +0,0 @@
1
- > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
-
3
- # Session
4
-
5
- A [`Session`](https://mastra.ai/reference/agent-controller/session) holds the live state of an AgentController. It identifies the user and active thread, along with the selected mode and model. It also stores permission grants, queued follow-ups, token usage, application state, and the display snapshot.
6
-
7
- You reach it through `agentController.session`.
8
-
9
- ## What the Session tracks
10
-
11
- The Session is the live state of a single user's interaction with the AgentController.
12
-
13
- It answers who owns the session and which thread is bound. It also identifies the selected mode and model while tracking approvals, queued or running work, application state, and the snapshot to render.
14
-
15
- A session has one active thread at a time but can list, switch between, and clone many threads over its lifetime. Anything that describes the current state lives here. The AgentController owns the shared infrastructure every session runs on.
16
-
17
- Each session has its own identity and state. One AgentController can therefore serve many users at once, with a separate `resourceId` and Session preventing mode, grant, or active-thread data from leaking between users.
18
-
19
- Calling `createSession` with the same `resourceId` returns the existing session (get-or-create), so a resource always resumes its own session.
20
-
21
- The rest of this page walks through the Session's state. Each part is a focused sub-object on `agentController.session`:
22
-
23
- - **Who and where**: [Identity](#identity) sets the stable session `id`, `ownerId`, and resource the session belongs to, and [Thread](#thread) tracks the currently bound thread.
24
- - **How the agent behaves**: [Mode and model](#mode-and-model) controls which agent profile and model are active, and [Permission grants](#permission-grants) records what the user has approved to run without prompting.
25
- - **What's happening right now**: [Run state](#run-state) reflects the in-flight generation, and [Follow-ups](#follow-ups) holds messages queued to send when it finishes.
26
- - **What you store and render**: [State](#state) holds your application's structured data, and [Display state](#display-state) is the single snapshot your UI renders from.
27
-
28
- The AgentController performs actions that change this state, switching threads, modes, or models, because those operations coordinate shared infrastructure and emit events. The Session is where you read the result. The sections below note this split where it matters.
29
-
30
- ## Identity
31
-
32
- `session.identity` holds three stable identifiers for the conversation: a session `id`, an `ownerId`, and the resource ID. Threads are scoped to a resource ID, so this is what groups a conversation's threads together:
33
-
34
- ```typescript
35
- const sessionId = agentController.session.identity.getId()
36
- const ownerId = agentController.session.identity.getOwnerId()
37
- const resourceId = agentController.session.identity.getResourceId()
38
- const threadId = agentController.session.thread.getId()
39
- ```
40
-
41
- The session `id` and `ownerId` are stable for the life of the session, they don't change when the resource ID is switched. They mirror the `id` and `ownerId` fields on `SessionRecord` in storage, so storage layers can key sessions by a stable identifier rather than the mutable resource ID.
42
-
43
- The resource ID is set when creating a session via [`agentController.createSession()`](https://mastra.ai/reference/agent-controller/agent-controller-class) and defaults to the agentController `id`. See [Resource IDs](https://mastra.ai/docs/agent-controller/threads-and-state) for how it scopes threads.
44
-
45
- ## Thread
46
-
47
- `session.thread` owns the active thread binding and read access to threads and messages. The AgentController performs lifecycle transitions; the Session reads the result:
48
-
49
- ```typescript
50
- // Lifecycle transitions live on the AgentController
51
- await agentController.switchThread({ threadId: 'thread-abc123' })
52
-
53
- // Reads live on the Session
54
- const threads = await agentController.session.thread.list()
55
- const messages = await agentController.session.thread.listActiveMessages()
56
- ```
57
-
58
- See [Threads and state](https://mastra.ai/docs/agent-controller/threads-and-state) for the full lifecycle.
59
-
60
- ## Mode and model
61
-
62
- The AgentController defines the available modes in `config.modes`. The Session tracks which mode and model are _currently_ selected:
63
-
64
- ```typescript
65
- // Switch mode (aborts the run, emits events)
66
- await agentController.session.mode.switch({ modeId: 'build' })
67
-
68
- // Read the current selection (Session state)
69
- const modeId = agentController.session.mode.get()
70
- const mode = agentController.session.mode.resolve()
71
- const modelId = agentController.session.model.get()
72
- ```
73
-
74
- See [Modes](https://mastra.ai/docs/agent-controller/modes) for how modes carry their own model.
75
-
76
- ## Permission grants
77
-
78
- The AgentController owns permission _policy_, which categories or tools require approval. The Session owns the _grants_ a user makes during the conversation. A grant lets a tool run for the rest of the session without prompting again:
79
-
80
- ```typescript
81
- // Grant a category or tool for the rest of the session
82
- agentController.session.grantCategory('edit')
83
- agentController.session.grantTool('mastra_workspace_execute_command')
84
-
85
- // Inspect current grants
86
- const grants = agentController.session.getGrants()
87
- ```
88
-
89
- Grants are intentionally in-memory and reset when the session restarts. See [Tool approvals](https://mastra.ai/docs/agent-controller/tool-approvals) for the approval flow.
90
-
91
- ## Run state
92
-
93
- `session.run` tracks the in-flight generation: whether a run is active, its run and trace IDs, and the abort signal. Use it to reflect run status in your UI:
94
-
95
- ```typescript
96
- if (agentController.session.run.isRunning()) {
97
- // show a stop button
98
- }
99
-
100
- // Abort the active run (AgentController orchestration clears related state)
101
- agentController.abort()
102
- ```
103
-
104
- ## Follow-ups
105
-
106
- A user may want to add to the conversation while the agent is still working. Instead of dropping or interrupting those messages, the Session queues them on `session.followUps` and sends them when the current run finishes:
107
-
108
- ```typescript
109
- const queued = agentController.session.followUps.count()
110
- ```
111
-
112
- Queue a follow-up with `agentController.followUp({ content })`. To redirect the agent mid-run instead of waiting, use `agentController.steer({ content })`. Both build on [signals](https://mastra.ai/docs/long-running-agents/signals).
113
-
114
- ## State
115
-
116
- `session.state` holds the conversation's application state, structured values that agents and the UI share, such as model preferences, feature flags, or progress.
117
-
118
- The AgentController defines the shape with a `stateSchema`. The Session owns the live snapshot and validates updates against that schema. Every write emits `state_changed`:
119
-
120
- ```typescript
121
- const state = agentController.session.state.get()
122
- await agentController.session.state.set({ theme: 'light' })
123
- ```
124
-
125
- See [Threads and state](https://mastra.ai/docs/agent-controller/threads-and-state) for defining a schema.
126
-
127
- ## Display state
128
-
129
- A conversation emits fine-grained events for streamed tokens and tool activity. Other events cover pending approvals, task updates, and token usage.
130
-
131
- Subscribing to each event type and reassembling the current picture yourself is tedious and error-prone.
132
-
133
- `session.displayState` does that work for you.
134
-
135
- It's a reducer-maintained snapshot.
136
-
137
- The Session keeps one `AgentControllerDisplayState` object and folds every agentController event into it as it happens, so the snapshot always reflects the latest state.
138
-
139
- It captures everything a UI needs to render. The snapshot shows whether the agent is running, what it's streaming, and which tools or subagents are active. It also includes pending approvals, the current task list, token usage, and queued follow-ups.
140
-
141
- Because it's a single object, you can drive an entire UI from one place: read the current snapshot with `get()`, and re-render whenever the AgentController emits `display_state_changed` (fired after every other event):
142
-
143
- ```typescript
144
- const snapshot = agentController.session.displayState.get()
145
-
146
- // Re-render from the snapshot on every change
147
- agentController.subscribe(event => {
148
- if (event.type === 'display_state_changed') {
149
- render(agentController.session.displayState.get())
150
- }
151
- })
152
- ```
153
-
154
- This is the recommended pattern for most UIs. Subscribe to individual typed events only when you need to react to a specific transition rather than re-render the whole view. Visit the [Session reference](https://mastra.ai/reference/agent-controller/session) for the full list of sub-objects and method signatures.
155
-
156
- ## Related
157
-
158
- - [AgentController overview](https://mastra.ai/docs/agent-controller/overview)
159
- - [Threads and state](https://mastra.ai/docs/agent-controller/threads-and-state)
160
- - [Tool approvals](https://mastra.ai/docs/agent-controller/tool-approvals)
161
- - [Session reference](https://mastra.ai/reference/agent-controller/session)
@@ -1,110 +0,0 @@
1
- > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
-
3
- # Subagents
4
-
5
- Subagents let a parent agent delegate focused tasks to child agents with constrained tools and instructions. The AgentController auto-generates a `subagent` built-in tool that the parent model can call to spawn any configured subagent type. Reach for a subagent when a task needs a different toolset or instruction set than the parent agent, when you want to isolate a subtask's messages from the parent thread, or when the parent should delegate to a cheaper or faster model for specific work.
6
-
7
- ## Quickstart
8
-
9
- Define subagent types in the AgentController constructor:
10
-
11
- ```typescript
12
- import { Agent } from '@mastra/core/agent'
13
- import { AgentController } from '@mastra/core/agent-controller'
14
-
15
- const agent = new Agent({
16
- id: 'assistant',
17
- name: 'assistant',
18
- instructions: 'Use subagents when a focused task needs a narrower toolset.',
19
- model: 'openai/gpt-5.6-sol',
20
- })
21
-
22
- const agentController = new AgentController({
23
- id: 'with-subagents',
24
- agent,
25
- modes: [{ id: 'default', name: 'Default', metadata: { default: true } }],
26
- subagents: [
27
- {
28
- id: 'explore',
29
- name: 'Explore',
30
- description: 'Reads files and gathers context without making changes.',
31
- instructions: 'You are a read-only exploration agent.',
32
- allowedWorkspaceTools: ['read_file', 'list_directory', 'grep_search'],
33
- defaultModelId: 'anthropic/claude-haiku-4-5',
34
- maxSteps: 30,
35
- },
36
- {
37
- id: 'execute',
38
- name: 'Execute',
39
- description: 'Makes changes to files and runs commands.',
40
- instructions: 'You are an execution agent.',
41
- allowedWorkspaceTools: ['read_file', 'write_file', 'execute_command'],
42
- defaultModelId: 'anthropic/claude-sonnet-4-6',
43
- },
44
- ],
45
- })
46
- ```
47
-
48
- The parent agent can then call the auto-generated `subagent` tool with a `task` description and optional `agentType`.
49
-
50
- When you define a subagent, give its `description` and `instructions` a clear, narrow scope. The `description` is what the parent model reads to decide _when_ to delegate, so state the single job the subagent is for and, by implication, what it's not for, "Reads files and gathers context without making changes" tells the parent to reach for it during exploration and to handle edits elsewhere. The `instructions` then keep the child agent inside that job. A subagent scoped to one task with a focused toolset stays predictable and is easier for the parent to route to. A broadly described subagent invites the parent to over-delegate and blurs the boundary between types. Pair the narrow scope with `allowedWorkspaceTools` so the subagent can only do what its description promises.
51
-
52
- For the full list of subagent configuration options, see [`AgentController` reference](https://mastra.ai/reference/agent-controller/agent-controller-class).
53
-
54
- ## Forked subagents
55
-
56
- A default subagent starts with a fresh context: it can't see the parent conversation, so you pass everything it needs in the `task` description. That's the right model for self-contained work, but it has two costs. The subagent has no access to what's already happened, and it builds a brand-new request prefix, a different system prompt and tool schemas, so it can't reuse the parent's prompt cache.
57
-
58
- **Forked subagents** solve both. Instead of a fresh agent, a fork clones the parent thread and runs the parent agent itself, so it sees the full conversation history and keeps the same system prompt and tool schemas as the parent. The identical prefix means the model's prompt cache still hits, which makes context-heavy delegation cheaper and faster.
59
-
60
- Use a fork when the subtask depends on the conversation so far, prior messages, earlier tool results, or the parent's tool environment, and you want to run it without paying to rebuild that context. Use a default subagent when the task is self-contained and benefits from a narrower toolset or a tighter system prompt, or alternatively a cheaper model.
61
-
62
- Enable forked mode per-type:
63
-
64
- ```typescript
65
- const collaborator = {
66
- id: 'collaborator',
67
- name: 'Collaborator',
68
- description: 'Continues the conversation in a fork.',
69
- forked: true,
70
- }
71
- ```
72
-
73
- Or per-invocation via the `subagent` tool's `forked` input parameter, which overrides the type's default.
74
-
75
- ### Forked mode semantics
76
-
77
- Because a fork reuses the parent agent to keep the prompt prefix stable, the subagent's own definition is mostly set aside:
78
-
79
- - Memory must be configured on the AgentController, since forking clones the parent thread.
80
-
81
- Without it, the fork call returns an error.
82
-
83
- - The fork runs with the parent agent's instructions, tools, and model. The subagent definition's own `instructions`, `tools`, and `defaultModelId` are ignored, and a per-invocation `modelId` is ignored too.
84
- - Only the subagent definition's `description` still matters: it's what the parent model reads to decide when to delegate.
85
- - Fork threads are tagged with `metadata.forkedSubagent === true` and hidden from `session.thread.list()` by default.
86
- - Recursive forks are blocked at runtime: the inherited `subagent` tool is disabled inside a fork to prevent infinite nesting.
87
-
88
- ## Subagent model management
89
-
90
- Set a global or per-type subagent model at runtime:
91
-
92
- ```typescript
93
- // Global subagent model
94
- await agentController.session.subagents.model.set({ modelId: 'anthropic/claude-sonnet-4-6' })
95
-
96
- // Per-type override
97
- await agentController.session.subagents.model.set({
98
- modelId: 'anthropic/claude-haiku-4-5',
99
- agentType: 'explore',
100
- })
101
-
102
- // Read current model
103
- const modelId = agentController.session.subagents.model.get({ agentType: 'explore' })
104
- ```
105
-
106
- ## Related
107
-
108
- - [AgentController overview](https://mastra.ai/docs/agent-controller/overview)
109
- - [Tool approvals and permissions](https://mastra.ai/docs/agent-controller/tool-approvals)
110
- - [API reference](https://mastra.ai/reference/agent-controller/agent-controller-class)
@@ -1,148 +0,0 @@
1
- > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
-
3
- # Threads and state
4
-
5
- Threads and state are how an AgentController conversation survives beyond a single exchange. A **thread** is the persistent record of a conversation, its messages and metadata, saved to storage so a user can close the app and resume the same conversation later, or switch between several conversations. **State** is structured data attached to the conversation, values like model preferences, feature flags, or progress, that agents and your UI read and write as the conversation runs.
6
-
7
- The thread and state work together: the thread is the message history, and state is the shared scratchpad alongside it.
8
-
9
- Both persist across mode switches, model changes, and restarts, so nothing is lost when a user switches from plan mode to build mode or reopens the app the next day.
10
-
11
- Thread _lifecycle_ transitions, create, switch, clone, delete, live on the AgentController because they coordinate the shared thread lock and emit events. The active thread binding and thread/message _reads_ live on the [`Session`](https://mastra.ai/docs/agent-controller/session) as `agentController.session.thread`.
12
-
13
- ## Threads
14
-
15
- A thread holds one conversation's full message history. The AgentController binds the Session to one active thread at a time. Messages you send and the agent's replies are appended to that thread and saved to storage. Threads let users resume a past conversation or keep several conversations side by side, or alternatively branch one into alternatives.
16
-
17
- ### Creating and selecting threads
18
-
19
- On startup, call `selectOrCreateThread()` to resume the most recent thread or create a new one:
20
-
21
- ```typescript
22
- await agentController.init()
23
- const thread = await agentController.selectOrCreateThread()
24
- ```
25
-
26
- Create a thread explicitly with a title:
27
-
28
- ```typescript
29
- const thread = await agentController.createThread({ title: 'New conversation' })
30
- ```
31
-
32
- ### Switching threads
33
-
34
- Switch to an existing thread.
35
-
36
- The agentController aborts any in-progress generation and acquires a lock on the new thread, plus emits a `thread_changed` event:
37
-
38
- ```typescript
39
- await agentController.switchThread({ threadId: 'thread-abc123' })
40
- ```
41
-
42
- ### Listing threads
43
-
44
- List threads for the current resource. Forked subagent threads are hidden by default:
45
-
46
- ```typescript
47
- const threads = await agentController.session.thread.list()
48
-
49
- // Include all resources
50
- const allThreads = await agentController.session.thread.list({ allResources: true })
51
- ```
52
-
53
- ### Cloning threads
54
-
55
- Clone a thread to create a branch of the conversation. The agentController copies all messages and switches to the clone:
56
-
57
- ```typescript
58
- const cloned = await agentController.cloneThread({ title: 'Alternative approach' })
59
- ```
60
-
61
- ### Thread locking
62
-
63
- Pass a `threadLock` to the AgentController constructor to prevent concurrent access from multiple processes. The lock is acquired before any thread operation and released on switch or delete:
64
-
65
- ```typescript
66
- const agentController = new AgentController({
67
- id: 'my-agent',
68
- threadLock: {
69
- acquire: async threadId => {
70
- /* acquire lock or throw */
71
- },
72
- release: async threadId => {
73
- /* release lock */
74
- },
75
- },
76
- })
77
- ```
78
-
79
- ## State
80
-
81
- Where a thread stores the conversation's messages, state stores structured values that describe the conversation but aren't messages, model preferences, feature flags, UI settings, or progress markers. Agents can read and update state during a run, and your UI can react to changes, so state is how the agent and the interface stay in sync on shared facts. You define its shape with a schema, and every update is validated against that schema before it's applied.
82
-
83
- ### Defining a state schema
84
-
85
- Pass a `stateSchema` (Standard JSON Schema) to validate state and extract defaults:
86
-
87
- ```typescript
88
- import { Agent } from '@mastra/core/agent'
89
- import { AgentController } from '@mastra/core/agent-controller'
90
- import { z } from 'zod'
91
-
92
- const agent = new Agent({
93
- id: 'assistant',
94
- name: 'assistant',
95
- instructions: 'Help the user manage a stateful session.',
96
- model: 'openai/gpt-5.6-sol',
97
- })
98
-
99
- const agentController = new AgentController({
100
- id: 'stateful-agent',
101
- agent,
102
- modes: [{ id: 'default', name: 'Default', metadata: { default: true } }],
103
- stateSchema: z.object({
104
- currentModelId: z.string().optional(),
105
- theme: z.enum(['light', 'dark']).default('dark'),
106
- }),
107
- })
108
- ```
109
-
110
- ### Reading and writing state
111
-
112
- State is owned by the [`Session`](https://mastra.ai/docs/agent-controller/session) as `agentController.session.state`:
113
-
114
- ```typescript
115
- // Read the current state snapshot
116
- const state = agentController.session.state.get()
117
-
118
- // Update state — validates against schema and emits state_changed
119
- await agentController.session.state.set({ theme: 'light' })
120
- ```
121
-
122
- State changes emit a `state_changed` event with the new state and the set of changed keys.
123
-
124
- ## Resource IDs
125
-
126
- Threads are scoped to a resource ID, which groups a conversation's threads by project, user, or workspace. Set it on the AgentController constructor; it defaults to the agentController `id` when omitted:
127
-
128
- ```typescript
129
- const agentController = new AgentController({
130
- id: 'my-agent',
131
- resourceId: 'project-xyz',
132
- })
133
- ```
134
-
135
- The resource ID is part of a conversation's identity, so you read it from the Session:
136
-
137
- ```typescript
138
- const resourceId = agentController.session.identity.getResourceId()
139
- ```
140
-
141
- The session also has a stable `id` and `ownerId` (read with `session.identity.getId()` and `session.identity.getOwnerId()`). Unlike the resource ID, these don't change when you switch resources, see [Session identity](https://mastra.ai/docs/agent-controller/session) for details.
142
-
143
- ## Related
144
-
145
- - [AgentController overview](https://mastra.ai/docs/agent-controller/overview)
146
- - [Session](https://mastra.ai/docs/agent-controller/session)
147
- - [Modes](https://mastra.ai/docs/agent-controller/modes)
148
- - [API reference](https://mastra.ai/reference/agent-controller/agent-controller-class)
@@ -1,147 +0,0 @@
1
- > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
-
3
- # Tool approvals and permissions
4
-
5
- The AgentController provides a permission system that controls which tools require user approval before execution.
6
-
7
- You can configure policies at the category level or per-tool, and grant session-wide exceptions for trusted tools.
8
-
9
- This gives agents with access to destructive or sensitive tools, file writes, command execution, API calls, a human-in-the-loop checkpoint before those tools run.
10
-
11
- ## Permission policies
12
-
13
- Policies control tool behavior:
14
-
15
- - `allow`: The tool runs without prompting
16
- - `ask`: The tool pauses and emits a `tool_approval_required` event; the user must approve or decline
17
- - `deny`: The tool is blocked from execution
18
-
19
- ### Setting policies
20
-
21
- Set policies per-category or per-tool. Per-tool policies take precedence over category policies:
22
-
23
- ```typescript
24
- // Category-level: all execute tools require approval
25
- await agentController.session.permissions.setForCategory({ category: 'execute', policy: 'ask' })
26
-
27
- // Tool-level: this specific tool is always blocked
28
- await agentController.session.permissions.setForTool({ toolName: 'dangerous_tool', policy: 'deny' })
29
- ```
30
-
31
- ### Tool categories
32
-
33
- The `toolCategoryResolver` maps tool names to categories. Pass it to the AgentController constructor:
34
-
35
- ```typescript
36
- const agentController = new AgentController({
37
- id: 'my-agent',
38
- toolCategoryResolver: toolName => {
39
- if (toolName.includes('write') || toolName.includes('delete')) return 'edit'
40
- if (toolName.includes('execute')) return 'execute'
41
- return 'read'
42
- },
43
- })
44
- ```
45
-
46
- Built-in categories are `read`, `edit`, `execute`, `mcp`, and `other`.
47
-
48
- ## Responding to approval requests
49
-
50
- When a tool's policy is `ask`, the AgentController emits a `tool_approval_required` event. Your UI should display a prompt and call `session.respondToToolApproval()`:
51
-
52
- ```typescript
53
- agentController.subscribe(event => {
54
- if (event.type === 'tool_approval_required') {
55
- // Show approval UI...
56
- agentController.session.respondToToolApproval({ decision: 'approve' })
57
- }
58
- })
59
- ```
60
-
61
- The `decision` field accepts `'approve'`, `'decline'`, or `'always_allow_category'`. When `always_allow_category` is used, the tool's category is granted for the rest of the session. Future tools in the same category are auto-approved.
62
-
63
- ```typescript
64
- agentController.session.respondToToolApproval({ decision: 'always_allow_category' })
65
- ```
66
-
67
- ## Session grants
68
-
69
- The AgentController owns permission _policy_ (which categories require approval). The [`Session`](https://mastra.ai/docs/agent-controller/session) owns the _grants_ a user makes during a conversation. Grant a category or tool for the rest of the session so it runs without further prompting:
70
-
71
- ```typescript
72
- // Grant all edit tools for this session
73
- agentController.session.grantCategory('edit')
74
-
75
- // Grant a specific tool
76
- agentController.session.grantTool('mastra_workspace_execute_command')
77
-
78
- // Check current grants
79
- const grants = agentController.session.getGrants()
80
- // { categories: ['edit'], tools: ['mastra_workspace_execute_command'] }
81
- ```
82
-
83
- ## Tool suspensions
84
-
85
- Interactive built-in tools (`ask_user`, `submit_plan`) use the native tool-suspension primitive instead of the approval flow. They emit a `tool_suspended` event with `toolCallId`, `toolName`, and `suspendPayload`. Resume with `respondToToolSuspension()`:
86
-
87
- ```typescript
88
- agentController.subscribe(event => {
89
- if (event.type === 'tool_suspended' && event.toolName === 'ask_user') {
90
- const { question } = event.suspendPayload as { question: string }
91
- // Show question to user, then resume:
92
- agentController.respondToToolSuspension({
93
- toolCallId: event.toolCallId,
94
- resumeData: 'User response here',
95
- })
96
- }
97
- })
98
- ```
99
-
100
- ### Plan approval
101
-
102
- The `submit_plan` tool suspends via the same mechanism. Resume with an `action` field:
103
-
104
- ```typescript
105
- // Approve the plan
106
- agentController.respondToToolSuspension({
107
- toolCallId: event.toolCallId,
108
- resumeData: { action: 'approved' },
109
- })
110
-
111
- // Reject with feedback
112
- agentController.respondToToolSuspension({
113
- toolCallId: event.toolCallId,
114
- resumeData: { action: 'rejected', feedback: 'Needs more detail' },
115
- })
116
- ```
117
-
118
- ## Built-in tools
119
-
120
- The AgentController provides these built-in tools to agents in every mode:
121
-
122
- | Tool | Description |
123
- | --------------- | ------------------------------------------------------------------- |
124
- | `ask_user` | Ask the user a question (free text, single-select, or multi-select) |
125
- | `submit_plan` | Submit a plan for user review and approval |
126
- | `task_write` | Create or replace a structured task list |
127
- | `task_update` | Update one tracked task by ID |
128
- | `task_complete` | Mark one tracked task completed |
129
- | `task_check` | Check task list completion status |
130
- | `subagent` | Spawn a focused subagent (requires `subagents` config) |
131
-
132
- Disable specific built-in tools with `disableBuiltinTools`:
133
-
134
- ```typescript
135
- const agentController = new AgentController({
136
- id: 'no-plans',
137
- disableBuiltinTools: ['submit_plan'],
138
- })
139
- ```
140
-
141
- ## Related
142
-
143
- - [AgentController overview](https://mastra.ai/docs/agent-controller/overview)
144
- - [Session](https://mastra.ai/docs/agent-controller/session)
145
- - [Subagents](https://mastra.ai/docs/agent-controller/subagents)
146
- - [Agent approval](https://mastra.ai/docs/agents/agent-approval)
147
- - [API reference](https://mastra.ai/reference/agent-controller/agent-controller-class)