@mastra/mcp-docs-server 1.1.6 → 1.1.7
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/course/02-agent-tools-mcp/07-what-is-zapier-mcp.md +10 -1
- package/.docs/course/02-agent-tools-mcp/08-getting-zapier-mcp-url.md +14 -9
- package/.docs/course/02-agent-tools-mcp/09-updating-mcp-config-zapier.md +13 -1
- package/.docs/course/02-agent-tools-mcp/12-troubleshooting-zapier.md +10 -8
- package/.docs/course/02-agent-tools-mcp/13-what-is-github-mcp.md +1 -1
- package/.docs/course/02-agent-tools-mcp/14-getting-github-mcp-url.md +28 -20
- package/.docs/course/02-agent-tools-mcp/15-updating-mcp-config-github.md +18 -2
- package/.docs/course/02-agent-tools-mcp/18-troubleshooting-github.md +5 -5
- package/.docs/course/02-agent-tools-mcp/20-updating-mcp-config-hackernews.md +11 -1
- package/.docs/course/02-agent-tools-mcp/26-updating-mcp-config-filesystem.md +11 -1
- package/.docs/course/02-agent-tools-mcp/32-conclusion.md +1 -1
- package/.docs/docs/agents/using-tools.md +34 -0
- package/.docs/docs/deployment/studio.md +8 -0
- package/.docs/docs/memory/observational-memory.md +3 -5
- package/.docs/docs/server/auth/better-auth.md +23 -6
- package/.docs/docs/workspace/sandbox.md +2 -0
- package/.docs/guides/deployment/vercel.md +19 -0
- package/.docs/guides/index.md +20 -1
- package/.docs/models/gateways/netlify.md +11 -6
- package/.docs/models/gateways/openrouter.md +4 -1
- package/.docs/models/gateways/vercel.md +13 -3
- package/.docs/models/index.md +1 -1
- package/.docs/models/providers/aihubmix.md +7 -1
- package/.docs/models/providers/anthropic.md +3 -2
- package/.docs/models/providers/baseten.md +7 -5
- package/.docs/models/providers/chutes.md +2 -1
- package/.docs/models/providers/cloudferro-sherlock.md +74 -0
- package/.docs/models/providers/evroc.md +83 -0
- package/.docs/models/providers/fireworks-ai.md +20 -26
- package/.docs/models/providers/firmware.md +2 -1
- package/.docs/models/providers/friendli.md +5 -6
- package/.docs/models/providers/google.md +3 -1
- package/.docs/models/providers/meganova.md +89 -0
- package/.docs/models/providers/opencode-go.md +73 -0
- package/.docs/models/providers/opencode.md +33 -33
- package/.docs/models/providers/perplexity-agent.md +113 -0
- package/.docs/models/providers/perplexity.md +2 -1
- package/.docs/models/providers/poe.md +2 -1
- package/.docs/models/providers/qihang-ai.md +79 -0
- package/.docs/models/providers/qiniu-ai.md +146 -0
- package/.docs/models/providers/siliconflow-cn.md +5 -1
- package/.docs/models/providers/togetherai.md +2 -1
- package/.docs/models/providers/zenmux.md +5 -1
- package/.docs/models/providers.md +7 -0
- package/.docs/reference/agents/network.md +38 -1
- package/.docs/reference/ai-sdk/with-mastra.md +5 -1
- package/.docs/reference/deployer/vercel.md +28 -3
- package/.docs/reference/harness/harness-class.md +58 -6
- package/.docs/reference/index.md +1 -1
- package/.docs/reference/memory/cloneThread.md +13 -1
- package/.docs/reference/memory/observational-memory.md +4 -2
- package/.docs/reference/streaming/agents/stream.md +34 -0
- package/.docs/reference/tools/create-tool.md +48 -0
- package/.docs/reference/workspace/daytona-sandbox.md +580 -0
- package/.docs/reference/workspace/s3-filesystem.md +2 -0
- package/CHANGELOG.md +16 -0
- package/LICENSE.md +15 -0
- package/package.json +6 -6
- package/.docs/docs/mastra-code/configuration.md +0 -299
- package/.docs/docs/mastra-code/customization.md +0 -228
- package/.docs/docs/mastra-code/modes.md +0 -104
- package/.docs/docs/mastra-code/overview.md +0 -135
- package/.docs/docs/mastra-code/tools.md +0 -229
- package/.docs/reference/mastra-code/createMastraCode.md +0 -108
|
@@ -1,299 +0,0 @@
|
|
|
1
|
-
# Configuration
|
|
2
|
-
|
|
3
|
-
Mastra Code is configured through project-level files, global settings, and environment variables. Configuration files live in `.mastracode/` directories at the project and user levels.
|
|
4
|
-
|
|
5
|
-
## Authentication
|
|
6
|
-
|
|
7
|
-
Mastra Code supports two authentication methods: **API keys** (environment variables) and **OAuth** (provider subscriptions). You can use either or both.
|
|
8
|
-
|
|
9
|
-
### API keys
|
|
10
|
-
|
|
11
|
-
The simplest way to get started is to set API key environment variables for the providers you want to use. Mastra Code auto-detects these on startup:
|
|
12
|
-
|
|
13
|
-
```sh
|
|
14
|
-
export ANTHROPIC_API_KEY=sk-ant-...
|
|
15
|
-
export OPENAI_API_KEY=sk-...
|
|
16
|
-
export GOOGLE_GENERATIVE_AI_API_KEY=...
|
|
17
|
-
export DEEPSEEK_API_KEY=...
|
|
18
|
-
export CEREBRAS_API_KEY=...
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
Mastra Code uses Mastra's [model router](https://mastra.ai/models), which routes requests to the correct provider based on the model ID and available API keys. No OAuth login is required when using API keys.
|
|
22
|
-
|
|
23
|
-
### OAuth login (optional)
|
|
24
|
-
|
|
25
|
-
If you have an Anthropic Claude Max or OpenAI ChatGPT Plus subscription, you can authenticate via OAuth to use your subscription instead of API keys. Run `/login` in the TUI to start the flow.
|
|
26
|
-
|
|
27
|
-
| Provider | OAuth flow | What you get |
|
|
28
|
-
| ------------- | ----------------------- | --------------------------------------------- |
|
|
29
|
-
| **Anthropic** | Claude Max subscription | Access to Claude models via your subscription |
|
|
30
|
-
| **OpenAI** | ChatGPT Plus / Codex | Access to OpenAI models via your subscription |
|
|
31
|
-
|
|
32
|
-
OAuth credentials are stored in `auth.json` alongside the database in the [app data directory](#database-location). During onboarding, you can skip the OAuth step if you already have API keys configured.
|
|
33
|
-
|
|
34
|
-
### Anthropic OAuth warning
|
|
35
|
-
|
|
36
|
-
Authenticating with a Claude Max subscription through OAuth is a grey area. Anthropic has reportedly banned users for using Claude max credentials outside of Claude Code, so it may violate Anthropic Terms of Service.
|
|
37
|
-
|
|
38
|
-
## MCP servers
|
|
39
|
-
|
|
40
|
-
Mastra Code can connect to external [MCP](https://mastra.ai/docs/mcp/overview) servers and make their tools available to the agent. Configure servers in JSON files:
|
|
41
|
-
|
|
42
|
-
| Priority | Path | Scope |
|
|
43
|
-
| -------- | ----------------------------- | -------------------------------- |
|
|
44
|
-
| Highest | `.mastracode/mcp.json` | Project |
|
|
45
|
-
| | `~/.mastracode/mcp.json` | Global |
|
|
46
|
-
| Lowest | `.claude/settings.local.json` | Project (Claude Code compatible) |
|
|
47
|
-
|
|
48
|
-
Project config overrides global config by server name. Claude Code settings are the lowest priority fallback.
|
|
49
|
-
|
|
50
|
-
### MCP config format
|
|
51
|
-
|
|
52
|
-
```json
|
|
53
|
-
{
|
|
54
|
-
"mcpServers": {
|
|
55
|
-
"my-server": {
|
|
56
|
-
"command": "npx",
|
|
57
|
-
"args": ["-y", "@my-org/mcp-server"],
|
|
58
|
-
"env": {
|
|
59
|
-
"API_KEY": "your-key"
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
Each server entry requires a `command` field. The `args` and `env` fields are optional.
|
|
67
|
-
|
|
68
|
-
On startup, Mastra Code connects to all configured servers and reports the status:
|
|
69
|
-
|
|
70
|
-
```text
|
|
71
|
-
MCP: 2 server(s) connected, 15 tool(s)
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
Tools from MCP servers are namespaced as `serverName_toolName` and appear in the agent's tool list alongside built-in tools.
|
|
75
|
-
|
|
76
|
-
## Hooks
|
|
77
|
-
|
|
78
|
-
Hooks are user-configured shell commands that run at specific lifecycle events. Use hooks for custom validation, logging, notifications, or integration with external systems.
|
|
79
|
-
|
|
80
|
-
### Hook config format
|
|
81
|
-
|
|
82
|
-
```json
|
|
83
|
-
{
|
|
84
|
-
"PreToolUse": [
|
|
85
|
-
{
|
|
86
|
-
"type": "command",
|
|
87
|
-
"command": "node scripts/validate-tool.js",
|
|
88
|
-
"matcher": {
|
|
89
|
-
"tool_name": "execute_command"
|
|
90
|
-
},
|
|
91
|
-
"timeout": 5000,
|
|
92
|
-
"description": "Validate shell commands before execution"
|
|
93
|
-
}
|
|
94
|
-
],
|
|
95
|
-
"PostToolUse": [
|
|
96
|
-
{
|
|
97
|
-
"type": "command",
|
|
98
|
-
"command": "node scripts/log-tool.js",
|
|
99
|
-
"description": "Log tool usage"
|
|
100
|
-
}
|
|
101
|
-
]
|
|
102
|
-
}
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
### Hook events
|
|
106
|
-
|
|
107
|
-
| Event | When it fires | Can block? |
|
|
108
|
-
| ------------------ | --------------------------------------------------------------- | ---------- |
|
|
109
|
-
| `PreToolUse` | Before a tool call executes | Yes |
|
|
110
|
-
| `PostToolUse` | After a tool call completes | No |
|
|
111
|
-
| `Stop` | When an agent response ends (`complete`, `aborted`, or `error`) | Yes |
|
|
112
|
-
| `UserPromptSubmit` | When the user sends a message | Yes |
|
|
113
|
-
| `SessionStart` | When a session begins | No |
|
|
114
|
-
| `SessionEnd` | When a session ends | No |
|
|
115
|
-
| `Notification` | When the TUI fires a notification | No |
|
|
116
|
-
|
|
117
|
-
`UserPromptSubmit` runs before a non-command prompt is sent to the agent. If a hook blocks, the prompt is not sent.
|
|
118
|
-
|
|
119
|
-
### Hook I/O protocol
|
|
120
|
-
|
|
121
|
-
Hook processes receive a JSON payload on stdin with context about the event:
|
|
122
|
-
|
|
123
|
-
```json
|
|
124
|
-
{
|
|
125
|
-
"session_id": "thread-abc123",
|
|
126
|
-
"cwd": "/path/to/project",
|
|
127
|
-
"hook_event_name": "PreToolUse",
|
|
128
|
-
"tool_name": "execute_command",
|
|
129
|
-
"tool_input": { "command": "npm test" }
|
|
130
|
-
}
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
For blocking events (`PreToolUse`, `Stop`, `UserPromptSubmit`), the hook can respond on stdout with a JSON object:
|
|
134
|
-
|
|
135
|
-
```json
|
|
136
|
-
{
|
|
137
|
-
"decision": "block",
|
|
138
|
-
"reason": "This command is not allowed"
|
|
139
|
-
}
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
### Hook config locations
|
|
143
|
-
|
|
144
|
-
| Priority | Path | Scope |
|
|
145
|
-
| -------- | -------------------------- | ------------------------------- |
|
|
146
|
-
| Higher | `.mastracode/hooks.json` | Project (appended after global) |
|
|
147
|
-
| Lower | `~/.mastracode/hooks.json` | Global (runs first) |
|
|
148
|
-
|
|
149
|
-
Global hooks run before project hooks. For the same event, all hooks execute in order.
|
|
150
|
-
|
|
151
|
-
## Custom slash commands
|
|
152
|
-
|
|
153
|
-
Define reusable prompt templates as markdown files. Mastra Code scans these directories for `.md` files:
|
|
154
|
-
|
|
155
|
-
| Priority | Path | Scope |
|
|
156
|
-
| -------- | ------------------------- | -------------------------------- |
|
|
157
|
-
| Highest | `.mastracode/commands/` | Project |
|
|
158
|
-
| | `.claude/commands/` | Project (Claude Code compatible) |
|
|
159
|
-
| | `~/.mastracode/commands/` | Global |
|
|
160
|
-
| Lowest | `~/.claude/commands/` | Global (Claude Code compatible) |
|
|
161
|
-
|
|
162
|
-
Each command file can include YAML frontmatter with `name` and `description` fields:
|
|
163
|
-
|
|
164
|
-
```yaml
|
|
165
|
-
---
|
|
166
|
-
name: review
|
|
167
|
-
description: Review the current diff for issues
|
|
168
|
-
---
|
|
169
|
-
Review my current git diff. Look for bugs, security issues,
|
|
170
|
-
and violations of the project's coding standards.
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
The filename (or directory structure) determines the command name. For example, `git/commit.md` becomes `/git:commit`.
|
|
174
|
-
|
|
175
|
-
Commands support variables like `$ARGUMENTS` for positional args, `@filename` for file content injection, and `!command` for shell command output.
|
|
176
|
-
|
|
177
|
-
## Skills
|
|
178
|
-
|
|
179
|
-
Skills are structured instruction files that the agent loads automatically based on trigger conditions. They provide domain-specific guidance without manually pasting instructions.
|
|
180
|
-
|
|
181
|
-
Mastra Code scans these directories for skills:
|
|
182
|
-
|
|
183
|
-
| Priority | Path | Scope |
|
|
184
|
-
| -------- | ----------------------- | -------------------------------- |
|
|
185
|
-
| Highest | `.mastracode/skills/` | Project |
|
|
186
|
-
| | `.claude/skills/` | Project (Claude Code compatible) |
|
|
187
|
-
| | `~/.mastracode/skills/` | Global |
|
|
188
|
-
| Lowest | `~/.claude/skills/` | Global (Claude Code compatible) |
|
|
189
|
-
|
|
190
|
-
Each skill is a directory containing a `SKILL.md` file with instructions and trigger descriptions. Skills installed via symlinks (e.g., from `npx skills add`) are automatically resolved.
|
|
191
|
-
|
|
192
|
-
## Agent instructions
|
|
193
|
-
|
|
194
|
-
Mastra Code loads project-specific instructions from `AGENTS.md` or `CLAUDE.md` files and injects them into the agent's system prompt. This is how you can customize the agent's behavior for your project.
|
|
195
|
-
|
|
196
|
-
### Lookup order
|
|
197
|
-
|
|
198
|
-
For project instructions (first match wins):
|
|
199
|
-
|
|
200
|
-
1. `AGENTS.md` or `CLAUDE.md` in the project root
|
|
201
|
-
2. `.claude/AGENTS.md` or `.claude/CLAUDE.md`
|
|
202
|
-
3. `.mastracode/AGENTS.md` or `.mastracode/CLAUDE.md`
|
|
203
|
-
|
|
204
|
-
For global instructions (first match wins):
|
|
205
|
-
|
|
206
|
-
1. `~/.claude/AGENTS.md` or `~/.claude/CLAUDE.md`
|
|
207
|
-
2. `~/.mastracode/AGENTS.md` or `~/.mastracode/CLAUDE.md`
|
|
208
|
-
3. `~/.config/claude/AGENTS.md` or `~/.config/claude/CLAUDE.md`
|
|
209
|
-
4. `~/.config/mastracode/AGENTS.md` or `~/.config/mastracode/CLAUDE.md`
|
|
210
|
-
|
|
211
|
-
`AGENTS.md` takes priority over `CLAUDE.md` when both exist at the same location.
|
|
212
|
-
|
|
213
|
-
## Storage
|
|
214
|
-
|
|
215
|
-
Mastra Code stores threads, messages, state, and observational memory in a database. It uses LibSQL by default with a local file — no setup needed.
|
|
216
|
-
|
|
217
|
-
To switch to a remote LibSQL (Turso) or PostgreSQL backend, run `/settings` and select a storage backend. You'll be prompted for a connection URL.
|
|
218
|
-
|
|
219
|
-
If a PostgreSQL connection fails on startup, Mastra Code falls back to LibSQL and shows a warning so you can fix the connection via `/settings`.
|
|
220
|
-
|
|
221
|
-
## Observational memory
|
|
222
|
-
|
|
223
|
-
[Observational memory](https://mastra.ai/docs/memory/observational-memory) (OM) uses background agents to maintain a dense log of observations and reflections about the conversation, providing long-term context that persists across sessions.
|
|
224
|
-
|
|
225
|
-
### OM scope
|
|
226
|
-
|
|
227
|
-
Control whether observations are scoped to individual threads or shared across all threads for a project:
|
|
228
|
-
|
|
229
|
-
| Scope | Behavior |
|
|
230
|
-
| ------------------ | --------------------------------------------------------------- |
|
|
231
|
-
| `thread` (default) | Observations are private to each conversation thread |
|
|
232
|
-
| `resource` | Observations are shared across all threads for the same project |
|
|
233
|
-
|
|
234
|
-
Configure the scope through:
|
|
235
|
-
|
|
236
|
-
1. `MASTRA_OM_SCOPE` environment variable (`"thread"` or `"resource"`)
|
|
237
|
-
2. `.mastracode/database.json` → `omScope` field
|
|
238
|
-
3. `~/.mastracode/database.json` → `omScope` field
|
|
239
|
-
|
|
240
|
-
### OM model settings
|
|
241
|
-
|
|
242
|
-
The observer and reflector models default to `google/gemini-2.5-flash`. Override them per-thread through the `/settings` panel or in the harness state.
|
|
243
|
-
|
|
244
|
-
### OM thresholds
|
|
245
|
-
|
|
246
|
-
| Threshold | Default | Description |
|
|
247
|
-
| --------------------- | ------------- | --------------------------------------------- |
|
|
248
|
-
| Observation threshold | 30,000 tokens | Token count that triggers an observation pass |
|
|
249
|
-
| Reflection threshold | 40,000 tokens | Token count that triggers a reflection pass |
|
|
250
|
-
|
|
251
|
-
## Color theme
|
|
252
|
-
|
|
253
|
-
Mastra Code detects your terminal's color scheme and applies a matching dark or light theme. You can override the detected theme with the `/theme` slash command or the `MASTRA_THEME` environment variable.
|
|
254
|
-
|
|
255
|
-
### Detection order
|
|
256
|
-
|
|
257
|
-
1. `MASTRA_THEME` environment variable — explicit `dark` or `light`
|
|
258
|
-
2. Persisted setting from `/theme` command (stored in `settings.json`)
|
|
259
|
-
3. OSC 11 query — asks your terminal for its actual background color
|
|
260
|
-
4. `COLORFGBG` environment variable (set by some terminals like iTerm2 and Konsole)
|
|
261
|
-
5. Falls back to dark theme
|
|
262
|
-
|
|
263
|
-
### Switching themes
|
|
264
|
-
|
|
265
|
-
Use the `/theme` command to change the theme at runtime:
|
|
266
|
-
|
|
267
|
-
```text
|
|
268
|
-
/theme light
|
|
269
|
-
/theme dark
|
|
270
|
-
/theme auto
|
|
271
|
-
```
|
|
272
|
-
|
|
273
|
-
Running `/theme` with no arguments shows the current theme. The choice is persisted across sessions.
|
|
274
|
-
|
|
275
|
-
## Environment variables
|
|
276
|
-
|
|
277
|
-
| Variable | Description |
|
|
278
|
-
| ---------------------- | -------------------------------------------------------------- |
|
|
279
|
-
| `MASTRA_DB_URL` | LibSQL database URL (e.g., `libsql://...` or `file:./data.db`) |
|
|
280
|
-
| `MASTRA_DB_AUTH_TOKEN` | Auth token for remote LibSQL database |
|
|
281
|
-
| `MASTRA_DB_PATH` | Override the local database file path |
|
|
282
|
-
| `MASTRA_USER_ID` | Override the auto-detected user identity |
|
|
283
|
-
| `MASTRA_RESOURCE_ID` | Override the auto-detected project resource ID |
|
|
284
|
-
| `MASTRA_OM_SCOPE` | Observational memory scope (`thread` or `resource`) |
|
|
285
|
-
| `DEFAULT_OM_MODEL_ID` | Default model for OM observer and reflector |
|
|
286
|
-
| `MASTRA_THEME` | Color theme override (`dark` or `light`) |
|
|
287
|
-
| `TAVILY_API_KEY` | Enable Tavily-powered web search and extract tools |
|
|
288
|
-
|
|
289
|
-
## Resource ID override
|
|
290
|
-
|
|
291
|
-
Resource IDs determine how threads are grouped. By default, Mastra Code generates one from the Git remote URL or filesystem path. Override it to share threads across repositories or isolate threads within a monorepo:
|
|
292
|
-
|
|
293
|
-
```json
|
|
294
|
-
{
|
|
295
|
-
"resourceId": "my-custom-project-id"
|
|
296
|
-
}
|
|
297
|
-
```
|
|
298
|
-
|
|
299
|
-
You can also set `MASTRA_RESOURCE_ID` as an environment variable. Two users who set the same resource ID share threads and observations for that resource.
|
|
@@ -1,228 +0,0 @@
|
|
|
1
|
-
# Customization
|
|
2
|
-
|
|
3
|
-
Mastra Code is designed as a composable library. The [`createMastraCode()`](https://mastra.ai/reference/mastra-code/createMastraCode) factory function accepts configuration overrides, and the returned [`Harness`](https://mastra.ai/reference/harness/harness-class) can drive any frontend, not just the built-in TUI.
|
|
4
|
-
|
|
5
|
-
## Programmatic usage
|
|
6
|
-
|
|
7
|
-
Import `createMastraCode` to bootstrap Mastra Code in your own application:
|
|
8
|
-
|
|
9
|
-
```typescript
|
|
10
|
-
import { createMastraCode } from 'mastracode'
|
|
11
|
-
|
|
12
|
-
const { harness, mcpManager, authStorage } = createMastraCode({
|
|
13
|
-
cwd: '/path/to/project',
|
|
14
|
-
initialState: {
|
|
15
|
-
yolo: false,
|
|
16
|
-
},
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
await harness.init()
|
|
20
|
-
await harness.selectOrCreateThread()
|
|
21
|
-
|
|
22
|
-
harness.subscribe(event => {
|
|
23
|
-
if (event.type === 'message_update') {
|
|
24
|
-
console.log(event.message.content)
|
|
25
|
-
}
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
await harness.sendMessage({ content: 'Explain the auth module' })
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
The `harness` object is a standard [Harness](https://mastra.ai/reference/harness/harness-class) instance. You can subscribe to events, switch modes, manage threads, and send messages through its API.
|
|
32
|
-
|
|
33
|
-
## Custom modes
|
|
34
|
-
|
|
35
|
-
Override the default Build/Plan/Fast modes by passing a `modes` array:
|
|
36
|
-
|
|
37
|
-
```typescript
|
|
38
|
-
import { createMastraCode } from 'mastracode'
|
|
39
|
-
import { Agent } from '@mastra/core/agent'
|
|
40
|
-
|
|
41
|
-
const reviewAgent = new Agent({
|
|
42
|
-
id: 'review-agent',
|
|
43
|
-
name: 'Review Agent',
|
|
44
|
-
instructions:
|
|
45
|
-
'You are a code review specialist. Analyze code for bugs, security issues, and best practices.',
|
|
46
|
-
model: 'anthropic/claude-sonnet-4',
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
const { harness } = createMastraCode({
|
|
50
|
-
modes: [
|
|
51
|
-
{
|
|
52
|
-
id: 'review',
|
|
53
|
-
name: 'Review',
|
|
54
|
-
default: true,
|
|
55
|
-
defaultModelId: 'anthropic/claude-sonnet-4',
|
|
56
|
-
color: '#f59e0b',
|
|
57
|
-
agent: reviewAgent,
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
id: 'build',
|
|
61
|
-
name: 'Build',
|
|
62
|
-
defaultModelId: 'anthropic/claude-opus-4-6',
|
|
63
|
-
color: '#7c3aed',
|
|
64
|
-
agent: reviewAgent,
|
|
65
|
-
},
|
|
66
|
-
],
|
|
67
|
-
})
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
Each mode requires an `id` and an `agent`. The `name`, `defaultModelId`, and `color` fields control how the mode appears in the TUI.
|
|
71
|
-
|
|
72
|
-
## Extra tools
|
|
73
|
-
|
|
74
|
-
Add custom tools to the agent's tool set without replacing the built-in tools:
|
|
75
|
-
|
|
76
|
-
```typescript
|
|
77
|
-
import { createMastraCode } from 'mastracode'
|
|
78
|
-
import { createTool } from '@mastra/core/tools'
|
|
79
|
-
import { z } from 'zod'
|
|
80
|
-
|
|
81
|
-
const deployTool = createTool({
|
|
82
|
-
id: 'deploy',
|
|
83
|
-
description: 'Deploy the current branch to staging',
|
|
84
|
-
inputSchema: z.object({
|
|
85
|
-
environment: z.enum(['staging', 'production']),
|
|
86
|
-
}),
|
|
87
|
-
execute: async ({ environment }) => {
|
|
88
|
-
return { content: `Deployed to ${environment}` }
|
|
89
|
-
},
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
const { harness } = createMastraCode({
|
|
93
|
-
extraTools: { deploy: deployTool },
|
|
94
|
-
})
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
Extra tools are merged with the dynamic tool set and are available to the agent in all modes.
|
|
98
|
-
|
|
99
|
-
## Custom subagents
|
|
100
|
-
|
|
101
|
-
Override the default Explore/Plan/Execute subagents. Each subagent receives its own set of tools, scoping what it can do:
|
|
102
|
-
|
|
103
|
-
```typescript
|
|
104
|
-
import { createMastraCode } from 'mastracode'
|
|
105
|
-
import { createTool } from '@mastra/core/tools'
|
|
106
|
-
|
|
107
|
-
const { harness } = createMastraCode({
|
|
108
|
-
subagents: [
|
|
109
|
-
{
|
|
110
|
-
id: 'explore',
|
|
111
|
-
name: 'Explore',
|
|
112
|
-
description: 'Read-only codebase exploration',
|
|
113
|
-
instructions:
|
|
114
|
-
'You are an expert code explorer. Use read-only tools to answer questions about the codebase.',
|
|
115
|
-
},
|
|
116
|
-
{
|
|
117
|
-
id: 'test-writer',
|
|
118
|
-
name: 'Test Writer',
|
|
119
|
-
description: 'Write tests for the specified module',
|
|
120
|
-
instructions:
|
|
121
|
-
'You are a test-writing specialist. Generate comprehensive tests for the given module.',
|
|
122
|
-
},
|
|
123
|
-
],
|
|
124
|
-
})
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
## Custom storage
|
|
128
|
-
|
|
129
|
-
Connect to a remote database instead of the default local SQLite:
|
|
130
|
-
|
|
131
|
-
```typescript
|
|
132
|
-
import { createMastraCode } from 'mastracode'
|
|
133
|
-
|
|
134
|
-
const { harness } = createMastraCode({
|
|
135
|
-
storage: {
|
|
136
|
-
url: 'libsql://my-db.turso.io',
|
|
137
|
-
authToken: 'my-auth-token',
|
|
138
|
-
},
|
|
139
|
-
})
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
This is equivalent to setting `.mastracode/database.json` but allows configuration at the code level.
|
|
143
|
-
|
|
144
|
-
## Custom heartbeat handlers
|
|
145
|
-
|
|
146
|
-
Replace or extend the default background tasks:
|
|
147
|
-
|
|
148
|
-
```typescript
|
|
149
|
-
import { createMastraCode } from 'mastracode'
|
|
150
|
-
|
|
151
|
-
const { harness } = createMastraCode({
|
|
152
|
-
heartbeatHandlers: [
|
|
153
|
-
{
|
|
154
|
-
id: 'sync-config',
|
|
155
|
-
intervalMs: 60_000,
|
|
156
|
-
handler: async () => {
|
|
157
|
-
await syncConfigFromRemote()
|
|
158
|
-
},
|
|
159
|
-
},
|
|
160
|
-
],
|
|
161
|
-
})
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
Heartbeat handlers run on a fixed interval. They start when `harness.init()` is called and stop when `harness.destroy()` is called.
|
|
165
|
-
|
|
166
|
-
## Building a custom TUI
|
|
167
|
-
|
|
168
|
-
Mastra Code exports the `MastraTUI` class from `mastracode/tui` for building custom terminal interfaces. The TUI is driven by the Harness event system:
|
|
169
|
-
|
|
170
|
-
```typescript
|
|
171
|
-
import { createMastraCode } from 'mastracode'
|
|
172
|
-
import { MastraTUI } from 'mastracode/tui'
|
|
173
|
-
|
|
174
|
-
const { harness, mcpManager, hookManager, authStorage } = createMastraCode()
|
|
175
|
-
|
|
176
|
-
const tui = new MastraTUI({
|
|
177
|
-
harness,
|
|
178
|
-
hookManager,
|
|
179
|
-
authStorage,
|
|
180
|
-
mcpManager,
|
|
181
|
-
appName: 'My Coding Agent',
|
|
182
|
-
version: '1.0.0',
|
|
183
|
-
})
|
|
184
|
-
|
|
185
|
-
tui.run()
|
|
186
|
-
```
|
|
187
|
-
|
|
188
|
-
The TUI subscribes to harness events and renders messages, tool calls, approvals, and status information in real time.
|
|
189
|
-
|
|
190
|
-
## Initial state overrides
|
|
191
|
-
|
|
192
|
-
Control default behavior through `initialState`:
|
|
193
|
-
|
|
194
|
-
```typescript
|
|
195
|
-
import { createMastraCode } from 'mastracode'
|
|
196
|
-
|
|
197
|
-
const { harness } = createMastraCode({
|
|
198
|
-
initialState: {
|
|
199
|
-
yolo: false,
|
|
200
|
-
thinkingLevel: 'high',
|
|
201
|
-
smartEditing: true,
|
|
202
|
-
notifications: 'system',
|
|
203
|
-
permissionRules: {
|
|
204
|
-
categories: {
|
|
205
|
-
read: 'allow',
|
|
206
|
-
edit: 'ask',
|
|
207
|
-
execute: 'ask',
|
|
208
|
-
mcp: 'deny',
|
|
209
|
-
},
|
|
210
|
-
tools: {},
|
|
211
|
-
},
|
|
212
|
-
},
|
|
213
|
-
})
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
### Available state fields
|
|
217
|
-
|
|
218
|
-
| Field | Type | Default | Description |
|
|
219
|
-
| ---------------------- | --------------------------------------- | --------------------------- | -------------------------------------------- |
|
|
220
|
-
| `yolo` | `boolean` | `true` | Auto-approve all tool calls |
|
|
221
|
-
| `thinkingLevel` | `string` | `"off"` | Extended thinking depth for Anthropic models |
|
|
222
|
-
| `smartEditing` | `boolean` | `true` | Use AST-based analysis for code edits |
|
|
223
|
-
| `notifications` | `"bell" \| "system" \| "both" \| "off"` | `"off"` | Alert when the TUI needs attention |
|
|
224
|
-
| `permissionRules` | `object` | Default policies | Per-category and per-tool approval policies |
|
|
225
|
-
| `observerModelId` | `string` | `"google/gemini-2.5-flash"` | Model for observational memory observer |
|
|
226
|
-
| `reflectorModelId` | `string` | `"google/gemini-2.5-flash"` | Model for observational memory reflector |
|
|
227
|
-
| `observationThreshold` | `number` | `30000` | Token count triggering observation pass |
|
|
228
|
-
| `reflectionThreshold` | `number` | `40000` | Token count triggering reflection pass |
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
# Modes
|
|
2
|
-
|
|
3
|
-
Mastra Code operates in one of three modes, each tailored to a different kind of task. Modes control which tools the agent has access to, how it approaches problems, and which default model it uses.
|
|
4
|
-
|
|
5
|
-
Switch modes with the `/mode` slash command.
|
|
6
|
-
|
|
7
|
-
## Build mode
|
|
8
|
-
|
|
9
|
-
Build mode is the default. The agent has full access to all tools — reading, writing, editing files, and running shell commands.
|
|
10
|
-
|
|
11
|
-
Use Build mode when you want the agent to make changes to your codebase: implementing features, fixing bugs, refactoring code, or running tests.
|
|
12
|
-
|
|
13
|
-
### Working style
|
|
14
|
-
|
|
15
|
-
- **Simple tasks** (typo fixes, single-file changes): The agent acts immediately without planning.
|
|
16
|
-
- **Non-trivial tasks** (3+ files, architectural decisions): The agent creates a task list, works through each step, and verifies changes before moving on.
|
|
17
|
-
|
|
18
|
-
### Implementation loop
|
|
19
|
-
|
|
20
|
-
For each change, the agent follows this cycle:
|
|
21
|
-
|
|
22
|
-
1. **Understand**: Read the relevant code and check existing conventions.
|
|
23
|
-
2. **Implement**: Make the change following existing patterns.
|
|
24
|
-
3. **Verify**: Run tests, type-check, or manually confirm the behavior.
|
|
25
|
-
4. **Clean up**: Remove debug statements and ensure no half-done work.
|
|
26
|
-
|
|
27
|
-
### Approved plans
|
|
28
|
-
|
|
29
|
-
When a plan is approved in Plan mode, Mastra Code automatically switches to Build mode and injects the plan into the agent's instructions. The agent then implements the plan step by step.
|
|
30
|
-
|
|
31
|
-
## Plan mode
|
|
32
|
-
|
|
33
|
-
Plan mode is read-only. The agent can explore the codebase but cannot modify files or run side-effect commands.
|
|
34
|
-
|
|
35
|
-
Use Plan mode when you want to analyze architecture, design an approach, or create a detailed implementation plan before writing code.
|
|
36
|
-
|
|
37
|
-
### Available tools
|
|
38
|
-
|
|
39
|
-
- `view`: Read files and list directories
|
|
40
|
-
- `search_content`: Search file contents
|
|
41
|
-
- `find_files`: Find files by pattern
|
|
42
|
-
- `execute_command`: Only for read-only commands (`git status`, `git log`, `git diff`)
|
|
43
|
-
|
|
44
|
-
### Plan submission
|
|
45
|
-
|
|
46
|
-
When the agent finishes analyzing the codebase, it submits a structured plan using the `submit_plan` tool. The plan includes:
|
|
47
|
-
|
|
48
|
-
- **Overview**: What the change does and why.
|
|
49
|
-
- **Complexity estimate**: Size, risk level, and dependencies.
|
|
50
|
-
- **Steps**: Specific files, changes, and rationale in dependency order.
|
|
51
|
-
- **Verification**: What tests to run and what to check.
|
|
52
|
-
|
|
53
|
-
After submission, you can:
|
|
54
|
-
|
|
55
|
-
- **Approve**: Mastra Code switches to Build mode and begins implementation.
|
|
56
|
-
- **Reject**: Stay in Plan mode.
|
|
57
|
-
- **Request changes**: Provide feedback for the agent to revise and resubmit.
|
|
58
|
-
|
|
59
|
-
## Fast mode
|
|
60
|
-
|
|
61
|
-
Fast mode prioritizes speed and brevity. The agent uses a faster model and keeps responses short.
|
|
62
|
-
|
|
63
|
-
Use Fast mode for quick lookups, simple questions, and small edits where latency matters more than depth.
|
|
64
|
-
|
|
65
|
-
### Rules
|
|
66
|
-
|
|
67
|
-
- Responses stay under 200 words unless the task requires more.
|
|
68
|
-
- No planning phase; the agent acts directly.
|
|
69
|
-
- For general programming questions, the agent answers from knowledge without searching the codebase.
|
|
70
|
-
- For project-specific questions, the agent reads the relevant code and answers concisely.
|
|
71
|
-
|
|
72
|
-
## Default models
|
|
73
|
-
|
|
74
|
-
Each mode has a default model that's selected when you switch to it:
|
|
75
|
-
|
|
76
|
-
| Mode | Default model |
|
|
77
|
-
| ----- | --------------------------- |
|
|
78
|
-
| Build | `anthropic/claude-opus-4-6` |
|
|
79
|
-
| Plan | `openai/gpt-5.2-codex` |
|
|
80
|
-
| Fast | `cerebras/zai-glm-4.7` |
|
|
81
|
-
|
|
82
|
-
Override the model for any mode using the `/models` command. Per-mode model selections persist to the thread, so switching back to a mode restores the last model you used in it.
|
|
83
|
-
|
|
84
|
-
> **Note:** Visit [`createMastraCode()` reference](https://mastra.ai/reference/mastra-code/createMastraCode) for details on configuring custom modes and default models.
|
|
85
|
-
|
|
86
|
-
## Subagents
|
|
87
|
-
|
|
88
|
-
In Build mode, the agent can spawn subagents to parallelize work. Subagents run as focused, independent tasks with their own tool access:
|
|
89
|
-
|
|
90
|
-
| Subagent | Access | Use case |
|
|
91
|
-
| ----------- | ------------ | ---------------------------------------------------------------------- |
|
|
92
|
-
| **Explore** | Read-only | "Find all usages of X", "How does module Y work" |
|
|
93
|
-
| **Plan** | Read-only | "Create an implementation plan for X", "Analyze the architecture of Y" |
|
|
94
|
-
| **Execute** | Read + write | "Implement feature X", "Fix bug Y", "Refactor module Z" |
|
|
95
|
-
|
|
96
|
-
The parent agent spawns subagents only when multiple tasks can run in parallel. For a single task, the agent handles it directly. Subagent outputs are treated as untrusted — the parent agent verifies results before moving on.
|
|
97
|
-
|
|
98
|
-
## Thinking level
|
|
99
|
-
|
|
100
|
-
You can control thinking depth through the `/settings` panel (or `/think`). Stored levels remain `off`, `low`, `medium`, `high`, and `xhigh` across providers. For OpenAI models, the UI shows provider-specific labels (for example, `Very High (xhigh)`), while non-OpenAI models keep generic labels.
|
|
101
|
-
|
|
102
|
-
## YOLO mode
|
|
103
|
-
|
|
104
|
-
YOLO mode auto-approves all tool calls without prompting. It's enabled by default and can be toggled through `/settings`. When disabled, Mastra Code prompts for approval before executing write operations or shell commands, based on the [permission system](https://mastra.ai/docs/mastra-code/tools).
|