@mastra/mcp-docs-server 1.1.3 → 1.1.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.
- package/.docs/docs/memory/observational-memory.md +2 -0
- package/.docs/docs/streaming/tool-streaming.md +6 -0
- package/.docs/docs/workspace/filesystem.md +21 -1
- package/.docs/guides/deployment/digital-ocean.md +65 -97
- package/.docs/reference/harness/harness-class.md +645 -0
- package/.docs/reference/index.md +1 -0
- package/.docs/reference/memory/memory-class.md +1 -1
- package/.docs/reference/memory/observational-memory.md +1 -0
- package/.docs/reference/workspace/local-filesystem.md +25 -0
- package/.docs/reference/workspace/workspace-class.md +1 -24
- package/CHANGELOG.md +14 -0
- package/package.json +8 -8
|
@@ -180,6 +180,8 @@ As the agent converses, message tokens accumulate. At regular intervals (`buffer
|
|
|
180
180
|
|
|
181
181
|
When message tokens reach the `messageTokens` threshold, buffered chunks activate: their observations move into the active observation log, and the corresponding raw messages are removed from the context window. The agent never pauses.
|
|
182
182
|
|
|
183
|
+
Buffered observations also include continuation hints — a suggested next response and the current task — so the main agent maintains conversational continuity after activation shrinks the context window.
|
|
184
|
+
|
|
183
185
|
If the agent produces messages faster than the Observer can process them, a `blockAfter` safety threshold forces a synchronous observation as a last resort.
|
|
184
186
|
|
|
185
187
|
Reflection works similarly — the Reflector runs in the background when observations reach a fraction of the reflection threshold.
|
|
@@ -147,6 +147,12 @@ export const weatherTool = createTool({
|
|
|
147
147
|
|
|
148
148
|
For detailed documentation on all lifecycle hooks, see the [createTool() reference](https://mastra.ai/reference/tools/create-tool).
|
|
149
149
|
|
|
150
|
+
### Streaming tool input in UIs
|
|
151
|
+
|
|
152
|
+
When a model generates a tool call, the arguments arrive incrementally as `tool-call-delta` stream chunks before the final `tool-call` chunk. UIs can listen for the corresponding `tool_input_start`, `tool_input_delta`, and `tool_input_end` events to render tool arguments as they stream in — for example, showing a file path or command immediately rather than waiting for the complete tool call.
|
|
153
|
+
|
|
154
|
+
Using a partial JSON parser on the accumulated `argsTextDelta` fragments lets you extract usable argument values before the JSON is complete. This enables features like live diff previews for edit tools, streaming file content for write tools, and instant display of search patterns or file paths.
|
|
155
|
+
|
|
150
156
|
## Tool using an agent
|
|
151
157
|
|
|
152
158
|
Pipe an agent's `fullStream` to the tool's `writer`. This streams partial output, and Mastra automatically aggregates the agent's usage into the tool run.
|
|
@@ -53,7 +53,27 @@ By default, `LocalFilesystem` runs in **contained mode** — all file operations
|
|
|
53
53
|
|
|
54
54
|
In contained mode, absolute paths that fall within `basePath` are used as-is, while other absolute paths are treated as virtual paths relative to `basePath` (e.g. `/file.txt` resolves to `basePath/file.txt`). Any resolved path that escapes `basePath` throws a `PermissionError`.
|
|
55
55
|
|
|
56
|
-
If your agent needs to access paths outside `basePath
|
|
56
|
+
If your agent needs to access specific paths outside `basePath`, use `allowedPaths` to grant access without disabling containment entirely:
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
const workspace = new Workspace({
|
|
60
|
+
filesystem: new LocalFilesystem({
|
|
61
|
+
basePath: './workspace',
|
|
62
|
+
allowedPaths: ['/home/user/.config', '/home/user/documents'],
|
|
63
|
+
}),
|
|
64
|
+
});
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Allowed paths can be updated at runtime using the `setAllowedPaths()` method:
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
// Add a path dynamically
|
|
71
|
+
workspace.filesystem.setAllowedPaths(prev => [...prev, '/home/user/documents']);
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
This is the recommended approach for least-privilege access — the agent can only reach the specific directories you allow.
|
|
75
|
+
|
|
76
|
+
If your agent needs unrestricted access to the entire filesystem, disable containment:
|
|
57
77
|
|
|
58
78
|
```typescript
|
|
59
79
|
const workspace = new Workspace({
|
|
@@ -1,37 +1,22 @@
|
|
|
1
|
-
# Digital Ocean
|
|
1
|
+
# Deploy Mastra to Digital Ocean
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This guide covers Digital Ocean's App Platform and Droplets. Each of these offerings has its own set of strengths and is suited for different types of projects and developer expertise. Read [Digital Ocean's comparison](https://www.digitalocean.com/community/conceptual-articles/digitalocean-app-platform-vs-doks-vs-droplets) to understand the differences and choose the best option for your project.
|
|
4
4
|
|
|
5
|
-
> **
|
|
5
|
+
> **Info:** This guide covers deploying the [Mastra server](https://mastra.ai/docs/server/mastra-server). If you're using a [server adapter](https://mastra.ai/docs/server/server-adapters) or [web framework](https://mastra.ai/docs/deployment/web-framework), deploy the way you normally would for that framework.
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## Before you begin
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
You'll need a [Mastra application](https://mastra.ai/guides/getting-started/quickstart) and a [Digital Ocean](https://www.digitalocean.com/) account.
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
- A Git repository containing your Mastra application. This can be a [GitHub](https://github.com/) repository, [GitLab](https://gitlab.com/) repository, or any other compatible source provider.
|
|
14
|
-
- A [Digital Ocean account](https://www.digitalocean.com/)
|
|
15
|
-
|
|
16
|
-
### Deployment Steps
|
|
11
|
+
The **App Platform** uses an ephemeral filesystem, so any storage you configure (including observability storage) must be hosted externally. If you're using [LibSQLStore](https://mastra.ai/reference/storage/libsql) with a file URL, switch to a remotely hosted database.
|
|
17
12
|
|
|
18
|
-
|
|
13
|
+
## App Platform
|
|
19
14
|
|
|
20
|
-
|
|
21
|
-
- Navigate to the [App Platform](https://docs.digitalocean.com/products/app-platform/) service.
|
|
22
|
-
- Select your source provider and create a new app.
|
|
15
|
+
After setting up your project, push it to your remote Git provider of choice (e.g. GitHub).
|
|
23
16
|
|
|
24
|
-
|
|
17
|
+
1. Follow the official [App Platform quickstart](https://docs.digitalocean.com/products/app-platform/getting-started/quickstart/#create-an-app). It'll guide you through connecting your repository, selecting the branch to deploy from, and configuring the source directory if necessary.
|
|
25
18
|
|
|
26
|
-
|
|
27
|
-
- Select the branch you want to deploy from.
|
|
28
|
-
- Configure the source directory if necessary. If your Mastra application uses the default directory structure, no action is required here.
|
|
29
|
-
- Head to the next step.
|
|
30
|
-
|
|
31
|
-
3. Configure Resource Settings and Environment Variables
|
|
32
|
-
|
|
33
|
-
- A Node.js build should be detected automatically.
|
|
34
|
-
- **Configure Build Command**: You need to add a custom build command for the app platform to build your Mastra project successfully. Set the build command based on your package manager:
|
|
19
|
+
2. Make sure that a "Node.js" build is detected. You'll need to configure a build command. Set it based on your package manager:
|
|
35
20
|
|
|
36
21
|
**npm**:
|
|
37
22
|
|
|
@@ -57,62 +42,29 @@ Deploy your Mastra applications to Digital Ocean's App Platform and Droplets.
|
|
|
57
42
|
bun run build
|
|
58
43
|
```
|
|
59
44
|
|
|
60
|
-
|
|
61
|
-
- You may choose to configure the size of your resource here.
|
|
62
|
-
- Other things you may optionally configure include, the region of your resource, the unique app name, and what project the resource belongs to.
|
|
63
|
-
- Once you're done, you may create the app after reviewing your configuration and pricing estimates.
|
|
64
|
-
|
|
65
|
-
4. Deployment
|
|
66
|
-
|
|
67
|
-
- Your app will be built and deployed automatically.
|
|
68
|
-
- Digital Ocean will provide you with a URL to access your deployed application.
|
|
69
|
-
|
|
70
|
-
You can now access your deployed application at the URL provided by Digital Ocean.
|
|
71
|
-
|
|
72
|
-
> **Warning:** The Digital Ocean App Platform uses an ephemeral file system, meaning that any files written to the file system are short-lived and may be lost. Remove any usage of [LibSQLStore](https://mastra.ai/reference/storage/libsql) with file URLs from your Mastra configuration. Use in-memory storage (`:memory:`) or external storage providers like Turso, PostgreSQL, or Upstash.
|
|
73
|
-
|
|
74
|
-
**Droplets**:
|
|
75
|
-
|
|
76
|
-
```bash
|
|
77
|
-
npm run build
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
**Tab 3**:
|
|
45
|
+
3. Add any required environment variables for your Mastra application. This includes API keys, database URLs, and other configuration values.
|
|
81
46
|
|
|
82
|
-
|
|
83
|
-
pnpm run build
|
|
84
|
-
```
|
|
47
|
+
4. Your app will be built and deployed automatically. Digital Ocean will provide you with a URL to access your deployed application.
|
|
85
48
|
|
|
86
|
-
|
|
49
|
+
5. You can now call your Mastra endpoints over HTTP.
|
|
87
50
|
|
|
88
|
-
|
|
89
|
-
yarn build
|
|
90
|
-
```
|
|
51
|
+
> **Warning:** Set up [authentication](https://mastra.ai/docs/server/auth) before exposing your endpoints publicly.
|
|
91
52
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
```bash
|
|
95
|
-
bun run build
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
**Tab 6**:
|
|
99
|
-
|
|
100
|
-
Deploy your Mastra application to Digital Ocean's Droplets.
|
|
53
|
+
## Droplets
|
|
101
54
|
|
|
102
55
|
### Prerequisites
|
|
103
56
|
|
|
104
|
-
- A
|
|
105
|
-
- A [Droplet](https://docs.digitalocean.com/products/droplets/) running Ubuntu 24+
|
|
57
|
+
- A Droplet running Ubuntu 24.04 LTS or later
|
|
106
58
|
- A domain name with an A record pointing to your droplet
|
|
107
59
|
- A reverse proxy configured (e.g., using [nginx](https://nginx.org/))
|
|
108
60
|
- SSL certificate configured (e.g., using [Let's Encrypt](https://letsencrypt.org/))
|
|
109
61
|
- Node.js 22.13.0 or later installed on your droplet
|
|
110
62
|
|
|
111
|
-
###
|
|
63
|
+
### Deploy
|
|
112
64
|
|
|
113
|
-
|
|
65
|
+
After setting up your project, push it to your remote Git provider of choice (e.g. GitHub). Connect to your Droplet and make sure `git` is installed.
|
|
114
66
|
|
|
115
|
-
|
|
67
|
+
1. Clone your repository:
|
|
116
68
|
|
|
117
69
|
**Public Repository**:
|
|
118
70
|
|
|
@@ -132,15 +84,33 @@ Deploy your Mastra application to Digital Ocean's Droplets.
|
|
|
132
84
|
cd "<your-repository>"
|
|
133
85
|
```
|
|
134
86
|
|
|
135
|
-
2. Install dependencies
|
|
87
|
+
2. Install the project dependencies:
|
|
88
|
+
|
|
89
|
+
**npm**:
|
|
136
90
|
|
|
137
91
|
```bash
|
|
138
92
|
npm install
|
|
139
93
|
```
|
|
140
94
|
|
|
141
|
-
|
|
95
|
+
**pnpm**:
|
|
142
96
|
|
|
143
|
-
|
|
97
|
+
```bash
|
|
98
|
+
pnpm install
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
**Yarn**:
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
yarn install
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
**Bun**:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
bun install
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
3. Set the required environment variables for your Mastra application. Create a `.env` file in the root of your project:
|
|
144
114
|
|
|
145
115
|
```bash
|
|
146
116
|
touch .env
|
|
@@ -149,52 +119,50 @@ Deploy your Mastra application to Digital Ocean's Droplets.
|
|
|
149
119
|
Edit the `.env` file and add your environment variables:
|
|
150
120
|
|
|
151
121
|
```bash
|
|
152
|
-
OPENAI_API_KEY
|
|
153
|
-
# Add other required environment variables
|
|
122
|
+
OPENAI_API_KEY=your-api-key
|
|
154
123
|
```
|
|
155
124
|
|
|
156
|
-
4. Build the
|
|
125
|
+
4. Build the project:
|
|
126
|
+
|
|
127
|
+
**npm**:
|
|
157
128
|
|
|
158
129
|
```bash
|
|
159
130
|
npm run build
|
|
160
131
|
```
|
|
161
132
|
|
|
162
|
-
|
|
133
|
+
**pnpm**:
|
|
163
134
|
|
|
164
135
|
```bash
|
|
165
|
-
|
|
136
|
+
pnpm run build
|
|
166
137
|
```
|
|
167
138
|
|
|
168
|
-
|
|
139
|
+
**Yarn**:
|
|
169
140
|
|
|
170
|
-
|
|
141
|
+
```bash
|
|
142
|
+
yarn build
|
|
143
|
+
```
|
|
171
144
|
|
|
172
|
-
|
|
173
|
-
git clone https://github.com/<your-username>/<your-repository>.git
|
|
174
|
-
```
|
|
145
|
+
**Bun**:
|
|
175
146
|
|
|
176
|
-
|
|
147
|
+
```bash
|
|
148
|
+
bun run build
|
|
149
|
+
```
|
|
177
150
|
|
|
178
|
-
|
|
179
|
-
git clone https://<your-username>:<your-personal-access-token>@github.com/<your-username>/<your-repository>.git
|
|
180
|
-
```
|
|
151
|
+
This will create a production build of Mastra's server in the `.mastra/output` directory.
|
|
181
152
|
|
|
182
|
-
|
|
153
|
+
5. You can run the [Mastra Server](https://mastra.ai/docs/deployment/mastra-server) by running the `mastra start` command:
|
|
183
154
|
|
|
184
|
-
|
|
155
|
+
```bash
|
|
156
|
+
mastra start
|
|
157
|
+
```
|
|
185
158
|
|
|
186
|
-
|
|
159
|
+
> **Info:** Your Mastra application will run on port 4111 by default. Ensure your reverse proxy is configured to forward requests to this port.
|
|
187
160
|
|
|
188
|
-
|
|
189
|
-
import { MastraClient } from "@mastra/client-js";
|
|
161
|
+
6. You can now call your Mastra endpoints over HTTP.
|
|
190
162
|
|
|
191
|
-
|
|
192
|
-
baseUrl: "https://<your-domain-name>",
|
|
193
|
-
});
|
|
194
|
-
```
|
|
163
|
+
> **Warning:** Set up [authentication](https://mastra.ai/docs/server/auth) before exposing your endpoints publicly.
|
|
195
164
|
|
|
196
|
-
##
|
|
165
|
+
## Related
|
|
197
166
|
|
|
198
|
-
- [
|
|
199
|
-
- [Digital Ocean
|
|
200
|
-
- [Digital Ocean Droplets documentation](https://docs.digitalocean.com/products/droplets/)
|
|
167
|
+
- [Digital Ocean App Platform](https://docs.digitalocean.com/products/app-platform/)
|
|
168
|
+
- [Digital Ocean Droplets](https://docs.digitalocean.com/products/droplets/)
|
|
@@ -0,0 +1,645 @@
|
|
|
1
|
+
# Harness Class
|
|
2
|
+
|
|
3
|
+
**Added in:** `@mastra/core@1.1.0`
|
|
4
|
+
|
|
5
|
+
The `Harness` class orchestrates multiple agent modes, shared state, memory, and storage. It provides a control layer that a TUI or other UI can drive to manage threads, switch models and modes, send messages, handle tool approvals, and track events.
|
|
6
|
+
|
|
7
|
+
## Usage example
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
import { Harness } from '@mastra/core/harness';
|
|
11
|
+
import { LibSQLStore } from '@mastra/libsql';
|
|
12
|
+
import { z } from 'zod';
|
|
13
|
+
|
|
14
|
+
const harness = new Harness({
|
|
15
|
+
id: 'my-coding-agent',
|
|
16
|
+
storage: new LibSQLStore({ url: 'file:./data.db' }),
|
|
17
|
+
stateSchema: z.object({
|
|
18
|
+
currentModelId: z.string().optional(),
|
|
19
|
+
}),
|
|
20
|
+
modes: [
|
|
21
|
+
{ id: 'plan', name: 'Plan', default: true, agent: planAgent },
|
|
22
|
+
{ id: 'build', name: 'Build', agent: buildAgent },
|
|
23
|
+
],
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
harness.subscribe((event) => {
|
|
27
|
+
if (event.type === 'message_update') {
|
|
28
|
+
renderMessage(event.message);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
await harness.init();
|
|
33
|
+
await harness.selectOrCreateThread();
|
|
34
|
+
await harness.sendMessage({ content: 'Hello!' });
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Constructor parameters
|
|
38
|
+
|
|
39
|
+
**id:** (`string`): Unique identifier for this harness instance.
|
|
40
|
+
|
|
41
|
+
**resourceId?:** (`string`): Resource ID for grouping threads (e.g., project identifier). Threads are scoped to this resource ID. Defaults to \`id\`.
|
|
42
|
+
|
|
43
|
+
**storage?:** (`MastraCompositeStore`): Storage backend for persistence (threads, messages, state).
|
|
44
|
+
|
|
45
|
+
**stateSchema?:** (`z.ZodObject`): Zod schema defining the shape of harness state. Used for validation and extracting defaults.
|
|
46
|
+
|
|
47
|
+
**initialState?:** (`Partial<z.infer<TState>>`): Initial state values. Must conform to the schema if provided.
|
|
48
|
+
|
|
49
|
+
**memory?:** (`MastraMemory`): Memory configuration shared across all modes. Propagated to mode agents that don't have their own memory.
|
|
50
|
+
|
|
51
|
+
**modes:** (`HarnessMode[]`): Available agent modes. At least one mode is required. Each mode defines an agent and optional defaults.
|
|
52
|
+
|
|
53
|
+
**tools?:** (`ToolsInput | ((ctx) => ToolsInput)`): Tools available to all agents across all modes. It can be a static tools object or a dynamic function that receives the request context.
|
|
54
|
+
|
|
55
|
+
**workspace?:** (`Workspace | WorkspaceConfig | ((ctx) => Workspace)`): Workspace configuration. Accepts a pre-constructed Workspace, a WorkspaceConfig for the harness to construct internally, or a dynamic factory function.
|
|
56
|
+
|
|
57
|
+
**subagents?:** (`HarnessSubagent[]`): Subagent definitions. When provided, the harness creates a built-in \`subagent\` tool that parent agents can call to spawn focused subagents.
|
|
58
|
+
|
|
59
|
+
**resolveModel?:** (`(modelId: string) => MastraLanguageModel`): Converts a model ID string (e.g., \`"anthropic/claude-sonnet-4"\`) to a language model instance. Used by subagents and observational memory model resolution.
|
|
60
|
+
|
|
61
|
+
**omConfig?:** (`HarnessOMConfig`): Default configuration for observational memory (observer/reflector model IDs and thresholds).
|
|
62
|
+
|
|
63
|
+
**heartbeatHandlers?:** (`HeartbeatHandler[]`): Periodic background tasks started during \`init()\`. Use for gateway sync, cache refresh, and similar tasks.
|
|
64
|
+
|
|
65
|
+
**idGenerator?:** (`() => string`): Custom ID generator for threads, messages, and other entities. (Default: `timestamp + random string`)
|
|
66
|
+
|
|
67
|
+
**modelAuthChecker?:** (`ModelAuthChecker`): Custom auth checker for model providers. Return \`true\`/\`false\` to override the default environment variable check, or \`undefined\` to fall back to defaults.
|
|
68
|
+
|
|
69
|
+
**modelUseCountProvider?:** (`ModelUseCountProvider`): Provides per-model use counts for sorting and display in \`listAvailableModels()\`.
|
|
70
|
+
|
|
71
|
+
**toolCategoryResolver?:** (`(toolName: string) => ToolCategory | null`): Maps tool names to permission categories (\`'read'\`, \`'edit'\`, \`'execute'\`, \`'mcp'\`, \`'other'\`). Used by the permission system to resolve category-level policies.
|
|
72
|
+
|
|
73
|
+
**threadLock?:** (`{ acquire, release }`): Thread locking callbacks to prevent concurrent access from multiple processes. \`acquire\` should throw if the lock is held.
|
|
74
|
+
|
|
75
|
+
### HarnessMode
|
|
76
|
+
|
|
77
|
+
Each entry in the `modes` array configures a single agent mode.
|
|
78
|
+
|
|
79
|
+
**id:** (`string`): Unique identifier for this mode (e.g., \`"plan"\`, \`"build"\`).
|
|
80
|
+
|
|
81
|
+
**name?:** (`string`): Human-readable name for display.
|
|
82
|
+
|
|
83
|
+
**default?:** (`boolean`): Whether this is the default mode when the harness starts. (Default: `false`)
|
|
84
|
+
|
|
85
|
+
**defaultModelId?:** (`string`): Default model ID for this mode (e.g., \`"anthropic/claude-sonnet-4-20250514"\`). Used when no per-mode model has been explicitly selected.
|
|
86
|
+
|
|
87
|
+
**color?:** (`string`): Hex color for the mode indicator (e.g., \`"#7c3aed"\`).
|
|
88
|
+
|
|
89
|
+
**agent:** (`Agent | ((state) => Agent)`): The agent for this mode. It can be a static Agent instance or a function that receives harness state and returns an Agent.
|
|
90
|
+
|
|
91
|
+
### HarnessSubagent
|
|
92
|
+
|
|
93
|
+
Each entry in the `subagents` array defines a subagent the harness can spawn.
|
|
94
|
+
|
|
95
|
+
**id:** (`string`): Unique identifier for this subagent type (e.g., \`"explore"\`, \`"execute"\`).
|
|
96
|
+
|
|
97
|
+
**name:** (`string`): Human-readable name shown in tool output.
|
|
98
|
+
|
|
99
|
+
**description:** (`string`): Description of what this subagent does. Used in the auto-generated tool description.
|
|
100
|
+
|
|
101
|
+
**instructions:** (`string`): System prompt for this subagent.
|
|
102
|
+
|
|
103
|
+
**tools?:** (`ToolsInput`): Tools this subagent has direct access to.
|
|
104
|
+
|
|
105
|
+
**allowedHarnessTools?:** (`string[]`): Tool IDs from the harness's shared \`tools\` config. Merged with \`tools\` above to let subagents use a subset of harness tools.
|
|
106
|
+
|
|
107
|
+
**defaultModelId?:** (`string`): Default model ID for this subagent type.
|
|
108
|
+
|
|
109
|
+
## Properties
|
|
110
|
+
|
|
111
|
+
**id:** (`string`): Harness identifier, set at construction.
|
|
112
|
+
|
|
113
|
+
## Methods
|
|
114
|
+
|
|
115
|
+
### Lifecycle
|
|
116
|
+
|
|
117
|
+
#### `init()`
|
|
118
|
+
|
|
119
|
+
Initialize the harness. Loads storage, initializes the workspace, propagates memory and workspace to mode agents, and starts heartbeat handlers. Call this before using the harness.
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
await harness.init();
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
#### `selectOrCreateThread()`
|
|
126
|
+
|
|
127
|
+
Select the most recent thread for the current resource, or create one if none exist. Loads thread metadata and acquires a thread lock.
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
const thread = await harness.selectOrCreateThread();
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
#### `destroy()`
|
|
134
|
+
|
|
135
|
+
Stop all heartbeat handlers and clean up resources.
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
await harness.destroy();
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### State
|
|
142
|
+
|
|
143
|
+
#### `getState()`
|
|
144
|
+
|
|
145
|
+
Return a read-only snapshot of the current harness state.
|
|
146
|
+
|
|
147
|
+
```typescript
|
|
148
|
+
const state = harness.getState();
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
#### `setState(updates)`
|
|
152
|
+
|
|
153
|
+
Update the harness state. Validates against `stateSchema` if provided, and emits a `state_changed` event with the new state and changed keys.
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
await harness.setState({ currentModelId: 'anthropic/claude-sonnet-4-20250514' });
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Modes
|
|
160
|
+
|
|
161
|
+
#### `listModes()`
|
|
162
|
+
|
|
163
|
+
Return all configured `HarnessMode` instances.
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
const modes = harness.listModes();
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
#### `getCurrentModeId()`
|
|
170
|
+
|
|
171
|
+
Return the ID of the currently active mode.
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
const modeId = harness.getCurrentModeId();
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
#### `getCurrentMode()`
|
|
178
|
+
|
|
179
|
+
Return the `HarnessMode` object for the current mode.
|
|
180
|
+
|
|
181
|
+
```typescript
|
|
182
|
+
const mode = harness.getCurrentMode();
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
#### `switchMode({ modeId })`
|
|
186
|
+
|
|
187
|
+
Switch to a different mode. Aborts any in-progress generation, saves the current model to the outgoing mode, loads the incoming mode's model, and emits `mode_changed` and `model_changed` events.
|
|
188
|
+
|
|
189
|
+
```typescript
|
|
190
|
+
await harness.switchMode({ modeId: 'build' });
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### Models
|
|
194
|
+
|
|
195
|
+
#### `getCurrentModelId()`
|
|
196
|
+
|
|
197
|
+
Return the ID of the currently selected model from state.
|
|
198
|
+
|
|
199
|
+
```typescript
|
|
200
|
+
const modelId = harness.getCurrentModelId();
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
#### `getModelName()`
|
|
204
|
+
|
|
205
|
+
Return a short display name from the current model ID. For example, `"claude-sonnet-4"` from `"anthropic/claude-sonnet-4"`.
|
|
206
|
+
|
|
207
|
+
```typescript
|
|
208
|
+
const name = harness.getModelName();
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
#### `getFullModelId()`
|
|
212
|
+
|
|
213
|
+
Return the complete model ID string.
|
|
214
|
+
|
|
215
|
+
```typescript
|
|
216
|
+
const fullId = harness.getFullModelId();
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
#### `hasModelSelected()`
|
|
220
|
+
|
|
221
|
+
Check if a model ID is currently selected.
|
|
222
|
+
|
|
223
|
+
```typescript
|
|
224
|
+
if (harness.hasModelSelected()) {
|
|
225
|
+
// Ready to send messages
|
|
226
|
+
}
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
#### `switchModel({ modelId, scope?, modeId? })`
|
|
230
|
+
|
|
231
|
+
Switch the active model. When `scope` is `'thread'`, the model ID is persisted to thread metadata so it's restored when switching back. Emits a `model_changed` event.
|
|
232
|
+
|
|
233
|
+
```typescript
|
|
234
|
+
// Set for current session only
|
|
235
|
+
await harness.switchModel({ modelId: 'anthropic/claude-sonnet-4-20250514' });
|
|
236
|
+
|
|
237
|
+
// Persist to the current thread
|
|
238
|
+
await harness.switchModel({ modelId: 'anthropic/claude-sonnet-4-20250514', scope: 'thread' });
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
#### `getCurrentModelAuthStatus()`
|
|
242
|
+
|
|
243
|
+
Check if the current model's provider has authentication configured. Uses `modelAuthChecker` if provided, falling back to environment variable checks from the provider registry.
|
|
244
|
+
|
|
245
|
+
```typescript
|
|
246
|
+
const status = await harness.getCurrentModelAuthStatus();
|
|
247
|
+
// { hasAuth: true, apiKeyEnvVar: 'ANTHROPIC_API_KEY' }
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
#### `listAvailableModels()`
|
|
251
|
+
|
|
252
|
+
Retrieve all available models from the provider registry, including their authentication status and use counts.
|
|
253
|
+
|
|
254
|
+
```typescript
|
|
255
|
+
const models = await harness.listAvailableModels();
|
|
256
|
+
// [{ id, provider, modelName, hasApiKey, apiKeyEnvVar, useCount }]
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
### Threads
|
|
260
|
+
|
|
261
|
+
#### `getCurrentThreadId()`
|
|
262
|
+
|
|
263
|
+
Return the ID of the currently active thread.
|
|
264
|
+
|
|
265
|
+
```typescript
|
|
266
|
+
const threadId = harness.getCurrentThreadId();
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
#### `createThread({ title? })`
|
|
270
|
+
|
|
271
|
+
Create a new thread. Initializes thread metadata, saves it to storage, acquires a thread lock, and emits a `thread_created` event.
|
|
272
|
+
|
|
273
|
+
```typescript
|
|
274
|
+
const thread = await harness.createThread({ title: 'New conversation' });
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
#### `switchThread({ threadId })`
|
|
278
|
+
|
|
279
|
+
Switch to a different thread. Aborts any in-progress operations, acquires a lock on the new thread, releases the lock on the previous thread, loads the thread's metadata, and emits a `thread_changed` event.
|
|
280
|
+
|
|
281
|
+
```typescript
|
|
282
|
+
await harness.switchThread({ threadId: 'thread-abc123' });
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
#### `listThreads(options?)`
|
|
286
|
+
|
|
287
|
+
List threads from storage. By default, only threads for the current resource are returned.
|
|
288
|
+
|
|
289
|
+
```typescript
|
|
290
|
+
// List threads for current resource
|
|
291
|
+
const threads = await harness.listThreads();
|
|
292
|
+
|
|
293
|
+
// List all threads across resources
|
|
294
|
+
const allThreads = await harness.listThreads({ allResources: true });
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
#### `renameThread({ title })`
|
|
298
|
+
|
|
299
|
+
Update the title of the current thread.
|
|
300
|
+
|
|
301
|
+
```typescript
|
|
302
|
+
await harness.renameThread({ title: 'Updated title' });
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
#### `getResourceId()`
|
|
306
|
+
|
|
307
|
+
Return the current resource ID.
|
|
308
|
+
|
|
309
|
+
```typescript
|
|
310
|
+
const resourceId = harness.getResourceId();
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
#### `setResourceId({ resourceId })`
|
|
314
|
+
|
|
315
|
+
Set the resource ID and clear the current thread.
|
|
316
|
+
|
|
317
|
+
```typescript
|
|
318
|
+
harness.setResourceId({ resourceId: 'project-xyz' });
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
#### `getSession()`
|
|
322
|
+
|
|
323
|
+
Return current session information including thread ID, mode ID, and the list of threads.
|
|
324
|
+
|
|
325
|
+
```typescript
|
|
326
|
+
const session = await harness.getSession();
|
|
327
|
+
// { currentThreadId, currentModeId, threads }
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
### Messages
|
|
331
|
+
|
|
332
|
+
#### `sendMessage({ content, images? })`
|
|
333
|
+
|
|
334
|
+
Send a message to the current agent. Creates a thread if none exists, builds a `RequestContext` and toolsets, and streams the agent's response. Handles tool calls, approvals, and errors automatically.
|
|
335
|
+
|
|
336
|
+
```typescript
|
|
337
|
+
await harness.sendMessage({ content: 'Explain the authentication flow' });
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
#### `listMessages(options?)`
|
|
341
|
+
|
|
342
|
+
Retrieve messages for the current thread.
|
|
343
|
+
|
|
344
|
+
```typescript
|
|
345
|
+
const messages = await harness.listMessages();
|
|
346
|
+
|
|
347
|
+
// Limit to the last 50 messages
|
|
348
|
+
const recent = await harness.listMessages({ limit: 50 });
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
#### `listMessagesForThread({ threadId, limit? })`
|
|
352
|
+
|
|
353
|
+
Retrieve messages for a specific thread.
|
|
354
|
+
|
|
355
|
+
```typescript
|
|
356
|
+
const messages = await harness.listMessagesForThread({ threadId: 'thread-abc123' });
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
#### `getFirstUserMessageForThread({ threadId })`
|
|
360
|
+
|
|
361
|
+
Retrieve the first user message for a given thread.
|
|
362
|
+
|
|
363
|
+
```typescript
|
|
364
|
+
const firstMsg = await harness.getFirstUserMessageForThread({ threadId: 'thread-abc123' });
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
### Flow control
|
|
368
|
+
|
|
369
|
+
#### `abort()`
|
|
370
|
+
|
|
371
|
+
Abort any in-progress generation.
|
|
372
|
+
|
|
373
|
+
```typescript
|
|
374
|
+
harness.abort();
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
#### `steer({ content })`
|
|
378
|
+
|
|
379
|
+
Steer the agent mid-stream by injecting an instruction into the current generation.
|
|
380
|
+
|
|
381
|
+
```typescript
|
|
382
|
+
harness.steer({ content: 'Focus on security implications' });
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
#### `followUp({ content })`
|
|
386
|
+
|
|
387
|
+
Queue a follow-up message to be sent after the current generation completes. If no operation is running, sends the message immediately.
|
|
388
|
+
|
|
389
|
+
```typescript
|
|
390
|
+
harness.followUp({ content: 'Now apply those changes' });
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
### Tool approvals
|
|
394
|
+
|
|
395
|
+
#### `respondToToolApproval({ decision })`
|
|
396
|
+
|
|
397
|
+
Respond to a pending tool approval request. Called when a `tool_approval_required` event is received.
|
|
398
|
+
|
|
399
|
+
```typescript
|
|
400
|
+
harness.respondToToolApproval({ decision: 'approve' });
|
|
401
|
+
harness.respondToToolApproval({ decision: 'decline' });
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
### Questions and plans
|
|
405
|
+
|
|
406
|
+
#### `respondToQuestion({ questionId, answer })`
|
|
407
|
+
|
|
408
|
+
Respond to a pending question from the `ask_user` built-in tool.
|
|
409
|
+
|
|
410
|
+
```typescript
|
|
411
|
+
harness.respondToQuestion({ questionId: 'q-123', answer: 'Yes, proceed with the refactor' });
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
#### `respondToPlanApproval({ planId, response })`
|
|
415
|
+
|
|
416
|
+
Respond to a pending plan approval from the `submit_plan` built-in tool. The `response` object contains `action` (`'approved'` or `'rejected'`) and an optional `feedback` string.
|
|
417
|
+
|
|
418
|
+
```typescript
|
|
419
|
+
harness.respondToPlanApproval({ planId: 'plan-123', response: { action: 'approved' } });
|
|
420
|
+
harness.respondToPlanApproval({ planId: 'plan-123', response: { action: 'rejected', feedback: 'Needs more detail' } });
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
### Permissions
|
|
424
|
+
|
|
425
|
+
#### `grantSessionCategory({ category })`
|
|
426
|
+
|
|
427
|
+
Grant a tool category for the current session. Tools in this category are auto-approved without prompting.
|
|
428
|
+
|
|
429
|
+
```typescript
|
|
430
|
+
harness.grantSessionCategory({ category: 'edit' });
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
#### `grantSessionTool({ toolName })`
|
|
434
|
+
|
|
435
|
+
Grant a specific tool for the current session.
|
|
436
|
+
|
|
437
|
+
```typescript
|
|
438
|
+
harness.grantSessionTool({ toolName: 'mastra_workspace_execute_command' });
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
#### `getSessionGrants()`
|
|
442
|
+
|
|
443
|
+
Return currently granted session categories and tools.
|
|
444
|
+
|
|
445
|
+
```typescript
|
|
446
|
+
const grants = harness.getSessionGrants();
|
|
447
|
+
// { categories: Set<string>, tools: Set<string> }
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
#### `setPermissionForCategory({ category, policy })`
|
|
451
|
+
|
|
452
|
+
Set the permission policy for a tool category.
|
|
453
|
+
|
|
454
|
+
```typescript
|
|
455
|
+
harness.setPermissionForCategory({ category: 'execute', policy: 'ask' });
|
|
456
|
+
```
|
|
457
|
+
|
|
458
|
+
#### `setPermissionForTool({ toolName, policy })`
|
|
459
|
+
|
|
460
|
+
Set the permission policy for a specific tool. Per-tool policies take precedence over category policies.
|
|
461
|
+
|
|
462
|
+
```typescript
|
|
463
|
+
harness.setPermissionForTool({ toolName: 'dangerous_tool', policy: 'deny' });
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
#### `getPermissionRules()`
|
|
467
|
+
|
|
468
|
+
Return the current permission rules.
|
|
469
|
+
|
|
470
|
+
```typescript
|
|
471
|
+
const rules = harness.getPermissionRules();
|
|
472
|
+
// { categories: { execute: 'ask' }, tools: { dangerous_tool: 'deny' } }
|
|
473
|
+
```
|
|
474
|
+
|
|
475
|
+
#### `getToolCategory({ toolName })`
|
|
476
|
+
|
|
477
|
+
Resolve a tool's category using the configured `toolCategoryResolver`.
|
|
478
|
+
|
|
479
|
+
```typescript
|
|
480
|
+
const category = harness.getToolCategory({ toolName: 'mastra_workspace_write_file' });
|
|
481
|
+
// 'edit'
|
|
482
|
+
```
|
|
483
|
+
|
|
484
|
+
### Observational memory
|
|
485
|
+
|
|
486
|
+
#### `loadOMProgress()`
|
|
487
|
+
|
|
488
|
+
Load observational memory records for the current thread and emit an `om_status` event with reconstructed progress.
|
|
489
|
+
|
|
490
|
+
```typescript
|
|
491
|
+
await harness.loadOMProgress();
|
|
492
|
+
```
|
|
493
|
+
|
|
494
|
+
#### `getObserverModelId()`
|
|
495
|
+
|
|
496
|
+
Return the observer model ID from state or the default from `omConfig`.
|
|
497
|
+
|
|
498
|
+
```typescript
|
|
499
|
+
const modelId = harness.getObserverModelId();
|
|
500
|
+
```
|
|
501
|
+
|
|
502
|
+
#### `getReflectorModelId()`
|
|
503
|
+
|
|
504
|
+
Return the reflector model ID from state or the default from `omConfig`.
|
|
505
|
+
|
|
506
|
+
```typescript
|
|
507
|
+
const modelId = harness.getReflectorModelId();
|
|
508
|
+
```
|
|
509
|
+
|
|
510
|
+
#### `switchObserverModel({ modelId })`
|
|
511
|
+
|
|
512
|
+
Switch the observer model. Persists the setting to thread metadata and emits an `om_model_changed` event.
|
|
513
|
+
|
|
514
|
+
```typescript
|
|
515
|
+
await harness.switchObserverModel({ modelId: 'anthropic/claude-haiku-3.5' });
|
|
516
|
+
```
|
|
517
|
+
|
|
518
|
+
#### `switchReflectorModel({ modelId })`
|
|
519
|
+
|
|
520
|
+
Switch the reflector model. Persists the setting to thread metadata and emits an `om_model_changed` event.
|
|
521
|
+
|
|
522
|
+
```typescript
|
|
523
|
+
await harness.switchReflectorModel({ modelId: 'anthropic/claude-haiku-3.5' });
|
|
524
|
+
```
|
|
525
|
+
|
|
526
|
+
#### `getObservationThreshold()`
|
|
527
|
+
|
|
528
|
+
Return the observation threshold in tokens from state or the default from `omConfig`.
|
|
529
|
+
|
|
530
|
+
```typescript
|
|
531
|
+
const threshold = harness.getObservationThreshold();
|
|
532
|
+
```
|
|
533
|
+
|
|
534
|
+
#### `getReflectionThreshold()`
|
|
535
|
+
|
|
536
|
+
Return the reflection threshold in tokens from state or the default from `omConfig`.
|
|
537
|
+
|
|
538
|
+
```typescript
|
|
539
|
+
const threshold = harness.getReflectionThreshold();
|
|
540
|
+
```
|
|
541
|
+
|
|
542
|
+
### Subagents
|
|
543
|
+
|
|
544
|
+
#### `getSubagentModelId({ agentType? })`
|
|
545
|
+
|
|
546
|
+
Retrieve the subagent model ID. Prioritizes per-type settings over the global setting.
|
|
547
|
+
|
|
548
|
+
```typescript
|
|
549
|
+
const modelId = harness.getSubagentModelId({ agentType: 'explore' });
|
|
550
|
+
```
|
|
551
|
+
|
|
552
|
+
#### `setSubagentModelId({ modelId, agentType? })`
|
|
553
|
+
|
|
554
|
+
Set the subagent model ID. Pass an `agentType` to set a per-type override, or omit it to set the global default. Persists to thread settings and emits a `subagent_model_changed` event.
|
|
555
|
+
|
|
556
|
+
```typescript
|
|
557
|
+
// Set global subagent model
|
|
558
|
+
await harness.setSubagentModelId({ modelId: 'anthropic/claude-sonnet-4-20250514' });
|
|
559
|
+
|
|
560
|
+
// Set per-type model
|
|
561
|
+
await harness.setSubagentModelId({ modelId: 'anthropic/claude-haiku-3.5', agentType: 'explore' });
|
|
562
|
+
```
|
|
563
|
+
|
|
564
|
+
### Events
|
|
565
|
+
|
|
566
|
+
#### `subscribe(listener)`
|
|
567
|
+
|
|
568
|
+
Register an event listener. Returns an unsubscribe function.
|
|
569
|
+
|
|
570
|
+
```typescript
|
|
571
|
+
const unsubscribe = harness.subscribe((event) => {
|
|
572
|
+
switch (event.type) {
|
|
573
|
+
case 'message_update':
|
|
574
|
+
renderMessage(event.message);
|
|
575
|
+
break;
|
|
576
|
+
case 'tool_approval_required':
|
|
577
|
+
showApprovalPrompt(event.toolName);
|
|
578
|
+
break;
|
|
579
|
+
case 'error':
|
|
580
|
+
console.error(event.error);
|
|
581
|
+
break;
|
|
582
|
+
}
|
|
583
|
+
});
|
|
584
|
+
|
|
585
|
+
// Later:
|
|
586
|
+
unsubscribe();
|
|
587
|
+
```
|
|
588
|
+
|
|
589
|
+
## Events
|
|
590
|
+
|
|
591
|
+
The harness emits events through registered listeners. The following table lists the available event types:
|
|
592
|
+
|
|
593
|
+
| Event type | Description |
|
|
594
|
+
| -------------------------- | ------------------------------------------------------------------- |
|
|
595
|
+
| `mode_changed` | The active mode changed. |
|
|
596
|
+
| `model_changed` | The active model changed. |
|
|
597
|
+
| `thread_changed` | The active thread changed. |
|
|
598
|
+
| `thread_created` | A new thread was created. |
|
|
599
|
+
| `state_changed` | Harness state was updated. |
|
|
600
|
+
| `agent_start` | The agent started processing. |
|
|
601
|
+
| `agent_end` | The agent finished processing. |
|
|
602
|
+
| `message_start` | A new message started streaming. |
|
|
603
|
+
| `message_update` | A message was updated with new content. |
|
|
604
|
+
| `message_end` | A message finished streaming. |
|
|
605
|
+
| `tool_start` | A tool call started. |
|
|
606
|
+
| `tool_approval_required` | A tool call requires user approval. |
|
|
607
|
+
| `tool_update` | A tool call was updated with progress. |
|
|
608
|
+
| `tool_end` | A tool call finished. |
|
|
609
|
+
| `tool_input_start` | Tool input started streaming. |
|
|
610
|
+
| `tool_input_delta` | Tool input received a streaming delta. |
|
|
611
|
+
| `tool_input_end` | Tool input finished streaming. |
|
|
612
|
+
| `usage_update` | Token usage was updated. |
|
|
613
|
+
| `error` | An error occurred. |
|
|
614
|
+
| `info` | An informational message was emitted. |
|
|
615
|
+
| `follow_up_queued` | A follow-up message was queued. |
|
|
616
|
+
| `workspace_status_changed` | The workspace status changed. |
|
|
617
|
+
| `workspace_ready` | The workspace finished initializing. |
|
|
618
|
+
| `workspace_error` | The workspace encountered an error. |
|
|
619
|
+
| `om_status` | Observational memory status update. |
|
|
620
|
+
| `om_observation_start` | An observation started. |
|
|
621
|
+
| `om_observation_end` | An observation completed. |
|
|
622
|
+
| `om_reflection_start` | A reflection started. |
|
|
623
|
+
| `om_reflection_end` | A reflection completed. |
|
|
624
|
+
| `ask_question` | The agent asked a question via the `ask_user` tool. |
|
|
625
|
+
| `plan_approval_required` | The agent submitted a plan for approval via the `submit_plan` tool. |
|
|
626
|
+
| `plan_approved` | A plan was approved. |
|
|
627
|
+
| `subagent_start` | A subagent started processing. |
|
|
628
|
+
| `subagent_text_delta` | A subagent emitted a text delta. |
|
|
629
|
+
| `subagent_tool_start` | A subagent started a tool call. |
|
|
630
|
+
| `subagent_tool_end` | A subagent finished a tool call. |
|
|
631
|
+
| `subagent_end` | A subagent finished processing. |
|
|
632
|
+
| `subagent_model_changed` | A subagent's model changed. |
|
|
633
|
+
| `task_updated` | A task list was updated. |
|
|
634
|
+
|
|
635
|
+
## Built-in tools
|
|
636
|
+
|
|
637
|
+
The harness provides built-in tools to agents in every mode:
|
|
638
|
+
|
|
639
|
+
| Tool | Description |
|
|
640
|
+
| ------------- | ------------------------------------------------------------------------------------------------ |
|
|
641
|
+
| `ask_user` | Ask the user a question and wait for their response. |
|
|
642
|
+
| `submit_plan` | Submit a plan for user review and approval. |
|
|
643
|
+
| `task_write` | Create or update a structured task list for tracking progress. |
|
|
644
|
+
| `task_check` | Check the completion status of the current task list. |
|
|
645
|
+
| `subagent` | Spawn a focused subagent with constrained tools (only available when `subagents` is configured). |
|
package/.docs/reference/index.md
CHANGED
|
@@ -194,6 +194,7 @@ The Reference section provides documentation of Mastra's API, including paramete
|
|
|
194
194
|
- [E2BSandbox](https://mastra.ai/reference/workspace/e2b-sandbox)
|
|
195
195
|
- [WorkspaceFilesystem](https://mastra.ai/reference/workspace/filesystem)
|
|
196
196
|
- [WorkspaceSandbox](https://mastra.ai/reference/workspace/sandbox)
|
|
197
|
+
- [Harness Class](https://mastra.ai/reference/harness/harness-class)
|
|
197
198
|
- [.stream()](https://mastra.ai/reference/streaming/agents/stream)
|
|
198
199
|
- [.streamLegacy()](https://mastra.ai/reference/streaming/agents/streamLegacy)
|
|
199
200
|
- [MastraModelOutput](https://mastra.ai/reference/streaming/agents/MastraModelOutput)
|
|
@@ -36,7 +36,7 @@ export const agent = new Agent({
|
|
|
36
36
|
|
|
37
37
|
### Options parameters
|
|
38
38
|
|
|
39
|
-
**lastMessages?:** (`number | false`): Number of most recent messages to
|
|
39
|
+
**lastMessages?:** (`number | false`): Number of most recent messages to include in context. Set to \`false\` to disable loading conversation history into context. Use \`Number.MAX\_SAFE\_INTEGER\` to retrieve all messages with no limit. To prevent saving new messages, use the \`readOnly\` option instead. (Default: `10`)
|
|
40
40
|
|
|
41
41
|
**readOnly?:** (`boolean`): When true, prevents memory from saving new messages and provides working memory as read-only context (without the updateWorkingMemory tool). Useful for read-only operations like previews, internal routing agents, or sub agents that should reference but not modify memory. (Default: `false`)
|
|
42
42
|
|
|
@@ -221,6 +221,7 @@ Default settings:
|
|
|
221
221
|
|
|
222
222
|
- `observation.bufferTokens: 0.2` — buffer every 20% of `messageTokens` (e.g. every \~6k tokens with a 30k threshold)
|
|
223
223
|
- `observation.bufferActivation: 0.8` — on activation, remove enough messages to keep only 20% of the threshold remaining
|
|
224
|
+
- Buffered observations include continuation hints (`suggestedResponse`, `currentTask`) that survive activation to maintain conversational continuity
|
|
224
225
|
- `reflection.bufferActivation: 0.5` — start background reflection at 50% of observation threshold
|
|
225
226
|
|
|
226
227
|
To customize:
|
|
@@ -36,6 +36,10 @@ const response = await agent.generate('List all files in the workspace');
|
|
|
36
36
|
|
|
37
37
|
**id?:** (`string`): Unique identifier for this filesystem instance (Default: `Auto-generated`)
|
|
38
38
|
|
|
39
|
+
**contained?:** (`boolean`): When true, all file operations are restricted to stay within basePath. Prevents path traversal attacks and symlink escapes. See \[containment]\(/docs/workspace/filesystem#containment). (Default: `true`)
|
|
40
|
+
|
|
41
|
+
**allowedPaths?:** (`string[]`): Additional absolute paths that are allowed beyond basePath. Useful with \`contained: true\` to grant access to specific directories without disabling containment entirely. Paths are resolved to absolute paths. (Default: `[]`)
|
|
42
|
+
|
|
39
43
|
**readOnly?:** (`boolean`): When true, all write operations are blocked. Read operations are still allowed. (Default: `false`)
|
|
40
44
|
|
|
41
45
|
## Properties
|
|
@@ -50,6 +54,8 @@ const response = await agent.generate('List all files in the workspace');
|
|
|
50
54
|
|
|
51
55
|
**readOnly:** (`boolean | undefined`): Whether the filesystem is in read-only mode
|
|
52
56
|
|
|
57
|
+
**allowedPaths:** (`readonly string[]`): Current set of additional allowed paths (absolute, resolved). These paths are permitted beyond basePath when containment is enabled.
|
|
58
|
+
|
|
53
59
|
## Methods
|
|
54
60
|
|
|
55
61
|
### `init()`
|
|
@@ -76,6 +82,25 @@ await filesystem.destroy();
|
|
|
76
82
|
|
|
77
83
|
Called by `workspace.destroy()`.
|
|
78
84
|
|
|
85
|
+
### `setAllowedPaths(pathsOrUpdater)`
|
|
86
|
+
|
|
87
|
+
Update the allowed paths at runtime. Accepts a new paths array (replaces current) or an updater callback that receives the current paths and returns the new set.
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
// Set directly
|
|
91
|
+
filesystem.setAllowedPaths(['/home/user/.config']);
|
|
92
|
+
|
|
93
|
+
// Update with callback
|
|
94
|
+
filesystem.setAllowedPaths(prev => [...prev, '/home/user/documents']);
|
|
95
|
+
|
|
96
|
+
// Clear all allowed paths
|
|
97
|
+
filesystem.setAllowedPaths([]);
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
**Parameters:**
|
|
101
|
+
|
|
102
|
+
**pathsOrUpdater:** (`string[] | ((current: readonly string[]) => string[])`): New allowed paths array or updater function receiving current paths
|
|
103
|
+
|
|
79
104
|
### `readFile(path, options?)`
|
|
80
105
|
|
|
81
106
|
Read file contents.
|
|
@@ -176,22 +176,6 @@ const context = workspace.getPathContext();
|
|
|
176
176
|
// { filesystem?, sandbox?, instructions }
|
|
177
177
|
```
|
|
178
178
|
|
|
179
|
-
**Returns:** `PathContext`
|
|
180
|
-
|
|
181
|
-
```typescript
|
|
182
|
-
interface PathContext {
|
|
183
|
-
filesystem?: {
|
|
184
|
-
provider: string;
|
|
185
|
-
basePath?: string;
|
|
186
|
-
};
|
|
187
|
-
sandbox?: {
|
|
188
|
-
provider: string;
|
|
189
|
-
workingDirectory?: string;
|
|
190
|
-
};
|
|
191
|
-
instructions: string;
|
|
192
|
-
}
|
|
193
|
-
```
|
|
194
|
-
|
|
195
179
|
The `instructions` field contains provider-generated descriptions combined from the filesystem and sandbox. These instructions are included in tool descriptions to help agents understand the execution context.
|
|
196
180
|
|
|
197
181
|
#### `getToolsConfig()`
|
|
@@ -239,11 +223,4 @@ Added when BM25 or vector search is configured:
|
|
|
239
223
|
| `mastra_workspace_search` | Search indexed content using keyword (BM25), semantic (vector), or hybrid search. Returns ranked results with scores. |
|
|
240
224
|
| `mastra_workspace_index` | Index content for search. Associates content with a path for later retrieval. |
|
|
241
225
|
|
|
242
|
-
The `index` tool is excluded when the filesystem is in read-only mode.
|
|
243
|
-
|
|
244
|
-
## Related
|
|
245
|
-
|
|
246
|
-
- [Workspace overview](https://mastra.ai/docs/workspace/overview)
|
|
247
|
-
- [Search and indexing](https://mastra.ai/docs/workspace/search)
|
|
248
|
-
- [Filesystem reference](https://mastra.ai/reference/workspace/filesystem)
|
|
249
|
-
- [Sandbox reference](https://mastra.ai/reference/workspace/sandbox)
|
|
226
|
+
The `index` tool is excluded when the filesystem is in read-only mode.
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @mastra/mcp-docs-server
|
|
2
2
|
|
|
3
|
+
## 1.1.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`0d9efb4`](https://github.com/mastra-ai/mastra/commit/0d9efb47992c34aa90581c18b9f51f774f6252a5), [`5caa13d`](https://github.com/mastra-ai/mastra/commit/5caa13d1b2a496e2565ab124a11de9a51ad3e3b9), [`940163f`](https://github.com/mastra-ai/mastra/commit/940163fc492401d7562301e6f106ccef4fefe06f), [`47892c8`](https://github.com/mastra-ai/mastra/commit/47892c85708eac348209f99f10f9a5f5267e11c0), [`45bb78b`](https://github.com/mastra-ai/mastra/commit/45bb78b70bd9db29678fe49476cd9f4ed01bfd0b), [`70eef84`](https://github.com/mastra-ai/mastra/commit/70eef84b8f44493598fdafa2980a0e7283415eda), [`d84e52d`](https://github.com/mastra-ai/mastra/commit/d84e52d0f6511283ddd21ed5fe7f945449d0f799), [`24b80af`](https://github.com/mastra-ai/mastra/commit/24b80af87da93bb84d389340181e17b7477fa9ca), [`608e156`](https://github.com/mastra-ai/mastra/commit/608e156def954c9604c5e3f6d9dfce3bcc7aeab0), [`2b2e157`](https://github.com/mastra-ai/mastra/commit/2b2e157a092cd597d9d3f0000d62b8bb4a7348ed), [`59d30b5`](https://github.com/mastra-ai/mastra/commit/59d30b5d0cb44ea7a1c440e7460dfb57eac9a9b5), [`453693b`](https://github.com/mastra-ai/mastra/commit/453693bf9e265ddccecef901d50da6caaea0fbc6), [`78d1c80`](https://github.com/mastra-ai/mastra/commit/78d1c808ad90201897a300af551bcc1d34458a20), [`c204b63`](https://github.com/mastra-ai/mastra/commit/c204b632d19e66acb6d6e19b11c4540dd6ad5380), [`742a417`](https://github.com/mastra-ai/mastra/commit/742a417896088220a3b5560c354c45c5ca6d88b9)]:
|
|
8
|
+
- @mastra/core@1.6.0
|
|
9
|
+
|
|
10
|
+
## 1.1.4-alpha.0
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Updated dependencies [[`0d9efb4`](https://github.com/mastra-ai/mastra/commit/0d9efb47992c34aa90581c18b9f51f774f6252a5), [`5caa13d`](https://github.com/mastra-ai/mastra/commit/5caa13d1b2a496e2565ab124a11de9a51ad3e3b9), [`940163f`](https://github.com/mastra-ai/mastra/commit/940163fc492401d7562301e6f106ccef4fefe06f), [`b260123`](https://github.com/mastra-ai/mastra/commit/b2601234bd093d358c92081a58f9b0befdae52b3), [`47892c8`](https://github.com/mastra-ai/mastra/commit/47892c85708eac348209f99f10f9a5f5267e11c0), [`45bb78b`](https://github.com/mastra-ai/mastra/commit/45bb78b70bd9db29678fe49476cd9f4ed01bfd0b), [`70eef84`](https://github.com/mastra-ai/mastra/commit/70eef84b8f44493598fdafa2980a0e7283415eda), [`d84e52d`](https://github.com/mastra-ai/mastra/commit/d84e52d0f6511283ddd21ed5fe7f945449d0f799), [`24b80af`](https://github.com/mastra-ai/mastra/commit/24b80af87da93bb84d389340181e17b7477fa9ca), [`608e156`](https://github.com/mastra-ai/mastra/commit/608e156def954c9604c5e3f6d9dfce3bcc7aeab0), [`2b2e157`](https://github.com/mastra-ai/mastra/commit/2b2e157a092cd597d9d3f0000d62b8bb4a7348ed), [`59d30b5`](https://github.com/mastra-ai/mastra/commit/59d30b5d0cb44ea7a1c440e7460dfb57eac9a9b5), [`453693b`](https://github.com/mastra-ai/mastra/commit/453693bf9e265ddccecef901d50da6caaea0fbc6), [`78d1c80`](https://github.com/mastra-ai/mastra/commit/78d1c808ad90201897a300af551bcc1d34458a20), [`c204b63`](https://github.com/mastra-ai/mastra/commit/c204b632d19e66acb6d6e19b11c4540dd6ad5380), [`742a417`](https://github.com/mastra-ai/mastra/commit/742a417896088220a3b5560c354c45c5ca6d88b9)]:
|
|
15
|
+
- @mastra/core@1.6.0-alpha.0
|
|
16
|
+
|
|
3
17
|
## 1.1.3
|
|
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.1.
|
|
3
|
+
"version": "1.1.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,15 +29,15 @@
|
|
|
29
29
|
"jsdom": "^26.1.0",
|
|
30
30
|
"local-pkg": "^1.1.2",
|
|
31
31
|
"zod": "^3.25.76",
|
|
32
|
-
"@mastra/core": "1.
|
|
32
|
+
"@mastra/core": "1.6.0",
|
|
33
33
|
"@mastra/mcp": "^1.0.1"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@hono/node-server": "^1.19.9",
|
|
37
37
|
"@types/jsdom": "^21.1.7",
|
|
38
38
|
"@types/node": "22.19.7",
|
|
39
|
-
"@vitest/coverage-v8": "4.0.
|
|
40
|
-
"@vitest/ui": "4.0.
|
|
39
|
+
"@vitest/coverage-v8": "4.0.18",
|
|
40
|
+
"@vitest/ui": "4.0.18",
|
|
41
41
|
"@wong2/mcp-cli": "^1.13.0",
|
|
42
42
|
"cross-env": "^10.1.0",
|
|
43
43
|
"eslint": "^9.37.0",
|
|
@@ -45,10 +45,10 @@
|
|
|
45
45
|
"tsup": "^8.5.1",
|
|
46
46
|
"tsx": "^4.21.0",
|
|
47
47
|
"typescript": "^5.9.3",
|
|
48
|
-
"vitest": "4.0.
|
|
49
|
-
"@internal/lint": "0.0.
|
|
50
|
-
"@internal/types-builder": "0.0.
|
|
51
|
-
"@mastra/core": "1.
|
|
48
|
+
"vitest": "4.0.18",
|
|
49
|
+
"@internal/lint": "0.0.61",
|
|
50
|
+
"@internal/types-builder": "0.0.36",
|
|
51
|
+
"@mastra/core": "1.6.0"
|
|
52
52
|
},
|
|
53
53
|
"homepage": "https://mastra.ai",
|
|
54
54
|
"repository": {
|