@mastra/mcp-docs-server 1.1.6 → 1.1.7-alpha.0
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 +8 -0
- package/LICENSE.md +15 -0
- package/package.json +5 -5
- 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,135 +0,0 @@
|
|
|
1
|
-
# Mastra Code overview
|
|
2
|
-
|
|
3
|
-
Mastra Code is a terminal-based AI coding agent built on Mastra's [Harness](https://mastra.ai/reference/harness/harness-class), [Agent](https://mastra.ai/docs/agents/overview), and [Memory](https://mastra.ai/docs/memory/overview) primitives. It runs in your terminal, connects to 70+ AI models, and provides tools for reading, searching, editing, and executing code.
|
|
4
|
-
|
|
5
|
-
Mastra Code organizes its capabilities around these areas:
|
|
6
|
-
|
|
7
|
-
- [**Modes**](https://mastra.ai/docs/mastra-code/modes): Switch between Build, Plan, and Fast modes to match your workflow.
|
|
8
|
-
- [**Tools**](https://mastra.ai/docs/mastra-code/tools): Built-in tools for file viewing, editing, searching, shell commands, and web search.
|
|
9
|
-
- [**Configuration**](https://mastra.ai/docs/mastra-code/configuration): Project-scoped threads, MCP servers, hooks, custom commands, skills, and database settings.
|
|
10
|
-
- [**Customization**](https://mastra.ai/docs/mastra-code/customization): Extend Mastra Code programmatically with custom modes, tools, subagents, and storage.
|
|
11
|
-
|
|
12
|
-
## When to use Mastra Code
|
|
13
|
-
|
|
14
|
-
- **Day-to-day coding**: Ask questions about your codebase, make edits, run tests, and manage Git.
|
|
15
|
-
- **Code exploration**: Use Plan mode to analyze architecture and create implementation plans before writing code.
|
|
16
|
-
- **Quick lookups**: Switch to Fast mode for brief answers and small edits with minimal latency.
|
|
17
|
-
- **Multi-model workflows**: Compare responses across different AI providers by switching models mid-conversation.
|
|
18
|
-
|
|
19
|
-
## Prerequisites
|
|
20
|
-
|
|
21
|
-
Mastra Code requires Node.js 22.13.0 or later.
|
|
22
|
-
|
|
23
|
-
## Get started
|
|
24
|
-
|
|
25
|
-
1. Install Mastra Code globally:
|
|
26
|
-
|
|
27
|
-
**npm**:
|
|
28
|
-
|
|
29
|
-
```sh
|
|
30
|
-
npm install -g mastracode
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
**pnpm**:
|
|
34
|
-
|
|
35
|
-
```sh
|
|
36
|
-
pnpm add -g mastracode
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
**Yarn**:
|
|
40
|
-
|
|
41
|
-
```sh
|
|
42
|
-
yarn global add mastracode
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
**Bun**:
|
|
46
|
-
|
|
47
|
-
```sh
|
|
48
|
-
bun add --global mastracode
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
Or run it with `npx`:
|
|
52
|
-
|
|
53
|
-
**npm**:
|
|
54
|
-
|
|
55
|
-
```sh
|
|
56
|
-
npx mastracode
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
**pnpm**:
|
|
60
|
-
|
|
61
|
-
```sh
|
|
62
|
-
pnpm dlx mastracode
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
**Yarn**:
|
|
66
|
-
|
|
67
|
-
```sh
|
|
68
|
-
yarn dlx mastracode
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
**Bun**:
|
|
72
|
-
|
|
73
|
-
```sh
|
|
74
|
-
bun x mastracode
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
2. Navigate to your project directory and start Mastra Code:
|
|
78
|
-
|
|
79
|
-
```sh
|
|
80
|
-
cd your-project
|
|
81
|
-
mastracode
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
3. Set an API key for your preferred provider (e.g. `export ANTHROPIC_API_KEY=sk-ant-...`), or run `/login` to authenticate with an Anthropic or OpenAI subscription. See [Configuration](https://mastra.ai/docs/mastra-code/configuration) for all supported providers.
|
|
85
|
-
|
|
86
|
-
4. Type a message and press Enter. The agent responds with streaming text and can read, edit, and run code in your project.
|
|
87
|
-
|
|
88
|
-
## Slash commands
|
|
89
|
-
|
|
90
|
-
Mastra Code provides built-in slash commands for managing sessions and settings:
|
|
91
|
-
|
|
92
|
-
| Command | Description |
|
|
93
|
-
| ----------- | ------------------------------------------------- |
|
|
94
|
-
| `/new` | Start a new conversation thread |
|
|
95
|
-
| `/threads` | List all threads for this project |
|
|
96
|
-
| `/models` | Select a different AI model |
|
|
97
|
-
| `/mode` | Switch between Build, Plan, and Fast modes |
|
|
98
|
-
| `/cost` | Show token usage for the current conversation |
|
|
99
|
-
| `/login` | Authenticate with OAuth providers |
|
|
100
|
-
| `/logout` | Log out from a provider |
|
|
101
|
-
| `/settings` | Open the settings panel |
|
|
102
|
-
| `/theme` | Switch color theme (auto, dark, or light) |
|
|
103
|
-
| `/sandbox` | Add external directories to the allowed path list |
|
|
104
|
-
| `/diff` | Show files modified in the current session |
|
|
105
|
-
| `/help` | Show available commands |
|
|
106
|
-
| `/exit` | Exit the TUI |
|
|
107
|
-
|
|
108
|
-
You can also define custom slash commands as markdown files. See [Configuration](https://mastra.ai/docs/mastra-code/configuration) for details.
|
|
109
|
-
|
|
110
|
-
## Keyboard shortcuts
|
|
111
|
-
|
|
112
|
-
| Shortcut | Action |
|
|
113
|
-
| -------- | --------------------------------------------------- |
|
|
114
|
-
| `Ctrl+C` | Interrupt current operation |
|
|
115
|
-
| `Ctrl+D` | Exit (when editor is empty) |
|
|
116
|
-
| `Ctrl+T` | Toggle thinking blocks visibility |
|
|
117
|
-
| `Ctrl+E` | Expand/collapse all tool outputs |
|
|
118
|
-
| `Ctrl+F` | Send a follow-up message while the agent is running |
|
|
119
|
-
|
|
120
|
-
## Architecture
|
|
121
|
-
|
|
122
|
-
Mastra Code is built on four layers:
|
|
123
|
-
|
|
124
|
-
1. **TUI**: Terminal interface (`pi-tui` components)
|
|
125
|
-
2. **Harness**: Mode management, thread persistence, event system, state management
|
|
126
|
-
3. **Mastra Agent**: Dynamic model selection, tool execution, memory integration, subagents
|
|
127
|
-
4. **LibSQL Storage**: Thread persistence, message history, token usage tracking, observational memory
|
|
128
|
-
|
|
129
|
-
## Next steps
|
|
130
|
-
|
|
131
|
-
- [Modes](https://mastra.ai/docs/mastra-code/modes)
|
|
132
|
-
- [Tools](https://mastra.ai/docs/mastra-code/tools)
|
|
133
|
-
- [Configuration](https://mastra.ai/docs/mastra-code/configuration)
|
|
134
|
-
- [Customization](https://mastra.ai/docs/mastra-code/customization)
|
|
135
|
-
- [API reference](https://mastra.ai/reference/mastra-code/createMastraCode)
|
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
# Tools
|
|
2
|
-
|
|
3
|
-
Mastra Code provides built-in tools that the agent uses to interact with your codebase. Each tool is designed for a specific task, and the agent selects the right one based on what it needs to do.
|
|
4
|
-
|
|
5
|
-
## File tools
|
|
6
|
-
|
|
7
|
-
### `view`
|
|
8
|
-
|
|
9
|
-
Read file contents with line numbers or list directory contents. The agent uses this tool before editing a file.
|
|
10
|
-
|
|
11
|
-
- Displays line-numbered output (like `cat -n`) for easy reference.
|
|
12
|
-
- For directories, lists files up to 2 levels deep, excluding hidden items.
|
|
13
|
-
- Supports `view_range` to read specific line ranges in large files.
|
|
14
|
-
- Output is truncated if the file exceeds the token limit. Use `view_range` to read specific sections.
|
|
15
|
-
|
|
16
|
-
| Parameter | Type | Required | Description |
|
|
17
|
-
| ------------ | ------------------ | -------- | -------------------------------------------------------- |
|
|
18
|
-
| `path` | `string` | Yes | Path to the file or directory (relative to project root) |
|
|
19
|
-
| `view_range` | `[number, number]` | No | Line range `[start, end]` to view a section of the file |
|
|
20
|
-
|
|
21
|
-
### `string_replace_lsp`
|
|
22
|
-
|
|
23
|
-
Edit a file by replacing an exact text match with new content. Returns Language Server Protocol (LSP) diagnostics showing any errors or warnings introduced by the edit.
|
|
24
|
-
|
|
25
|
-
- The agent reads the file first with `view` before editing.
|
|
26
|
-
- `old_str` must be an exact substring of the current file content.
|
|
27
|
-
- Include enough surrounding context to uniquely identify the replacement location.
|
|
28
|
-
- When `new_str` is omitted or empty, the matched text is deleted.
|
|
29
|
-
- After editing, TypeScript errors, linting warnings, and other diagnostics are returned automatically.
|
|
30
|
-
|
|
31
|
-
| Parameter | Type | Required | Description |
|
|
32
|
-
| ------------ | -------- | -------- | -------------------------------------------------- |
|
|
33
|
-
| `path` | `string` | Yes | Path to the file |
|
|
34
|
-
| `old_str` | `string` | Yes | Exact text to find and replace |
|
|
35
|
-
| `new_str` | `string` | No | Replacement text (omit to delete the matched text) |
|
|
36
|
-
| `start_line` | `number` | No | Line number to narrow the search region |
|
|
37
|
-
|
|
38
|
-
### `ast_smart_edit`
|
|
39
|
-
|
|
40
|
-
Edit code using abstract syntax tree (AST) analysis for intelligent, structure-aware transformations. Powered by [ast-grep](https://ast-grep.github.io/), this tool understands code structure rather than treating files as raw text.
|
|
41
|
-
|
|
42
|
-
Supported transformations:
|
|
43
|
-
|
|
44
|
-
- **Pattern-based search and replace**: Find and replace code using AST patterns with `$VARIABLE` placeholders (e.g., replace `console.log($ARG)` with `logger.debug($ARG)`).
|
|
45
|
-
- **Add/remove imports**: Intelligently insert or remove import statements.
|
|
46
|
-
- **Rename functions**: Rename function declarations and all call sites with scope awareness.
|
|
47
|
-
- **Rename variables**: Rename variable declarations and all references.
|
|
48
|
-
- **Selector queries**: Find AST nodes matching a CSS-like selector (e.g., `"FunctionDeclaration"`).
|
|
49
|
-
|
|
50
|
-
| Parameter | Type | Required | Description |
|
|
51
|
-
| ------------- | -------- | -------- | ------------------------------------------------------------------------------------------------------------------------------- |
|
|
52
|
-
| `path` | `string` | Yes | File path relative to project root |
|
|
53
|
-
| `pattern` | `string` | No | AST pattern to search for (supports `$VARIABLE` placeholders) |
|
|
54
|
-
| `replacement` | `string` | No | Replacement pattern (can use captured `$VARIABLES`) |
|
|
55
|
-
| `selector` | `string` | No | CSS-like selector for AST nodes |
|
|
56
|
-
| `transform` | `string` | No | Transformation type: `add-import`, `remove-import`, `rename-function`, `rename-variable`, `extract-function`, `inline-variable` |
|
|
57
|
-
| `targetName` | `string` | No | Name of the target element (for rename/remove operations) |
|
|
58
|
-
| `newName` | `string` | No | New name (for rename operations) |
|
|
59
|
-
| `importSpec` | `object` | No | Import specification for `add-import`: `{ module, names, isDefault? }` |
|
|
60
|
-
|
|
61
|
-
### `write_file`
|
|
62
|
-
|
|
63
|
-
Create a new file or overwrite an existing file entirely.
|
|
64
|
-
|
|
65
|
-
- Use for creating new files. For editing existing files, prefer `string_replace_lsp`.
|
|
66
|
-
- Parent directories are created automatically if they don't exist.
|
|
67
|
-
- If overwriting an existing file, the agent reads it first with `view`.
|
|
68
|
-
|
|
69
|
-
| Parameter | Type | Required | Description |
|
|
70
|
-
| --------- | -------- | -------- | ------------------------------------------------ |
|
|
71
|
-
| `path` | `string` | Yes | File path to write to (relative to project root) |
|
|
72
|
-
| `content` | `string` | Yes | Full content to write to the file |
|
|
73
|
-
|
|
74
|
-
## Search tools
|
|
75
|
-
|
|
76
|
-
### `search_content`
|
|
77
|
-
|
|
78
|
-
Search file contents using regular expressions. Uses ripgrep when available, falling back to grep.
|
|
79
|
-
|
|
80
|
-
- Supports full regex syntax (e.g., `"function\\s+\\w+"`, `"import.*from"`).
|
|
81
|
-
- Respects `.gitignore` automatically in Git repositories.
|
|
82
|
-
- Always preferred over running `grep` or `rg` via `execute_command`.
|
|
83
|
-
|
|
84
|
-
| Parameter | Type | Required | Description |
|
|
85
|
-
| --------------- | --------- | -------- | ----------------------------------------------------------------------------------- |
|
|
86
|
-
| `pattern` | `string` | Yes | Regex pattern to search for in file contents |
|
|
87
|
-
| `path` | `string` | No | Directory or file to search in (relative to project root, defaults to project root) |
|
|
88
|
-
| `glob` | `string` | No | Glob pattern to filter files (e.g., `"*.ts"`, `"*.{js,jsx}"`, `"test/**"`) |
|
|
89
|
-
| `contextLines` | `number` | No | Number of lines to show before and after each match (default: 0) |
|
|
90
|
-
| `maxResults` | `number` | No | Maximum number of matching lines to return (default: 100) |
|
|
91
|
-
| `caseSensitive` | `boolean` | No | Whether the search is case-sensitive (default: true) |
|
|
92
|
-
|
|
93
|
-
### `find_files`
|
|
94
|
-
|
|
95
|
-
Find files by name pattern using glob matching. Results are sorted by modification time (most recent first).
|
|
96
|
-
|
|
97
|
-
- Supports standard glob syntax: `*` (any characters), `**` (any path segments), `?` (single character), `{a,b}` (alternatives).
|
|
98
|
-
- Respects `.gitignore` automatically in Git repositories.
|
|
99
|
-
- Always preferred over running `find` or `ls` via `execute_command`.
|
|
100
|
-
|
|
101
|
-
| Parameter | Type | Required | Description |
|
|
102
|
-
| --------- | -------- | -------- | --------------------------------------------------------------------------- |
|
|
103
|
-
| `pattern` | `string` | Yes | Glob pattern (e.g., `"**/*.ts"`, `"src/**/*.test.*"`, `"**/package.json"`) |
|
|
104
|
-
| `path` | `string` | No | Directory to search in (relative to project root, defaults to project root) |
|
|
105
|
-
|
|
106
|
-
## Shell execution
|
|
107
|
-
|
|
108
|
-
### `execute_command`
|
|
109
|
-
|
|
110
|
-
Execute a shell command in the project directory.
|
|
111
|
-
|
|
112
|
-
- Use for Git commands, package managers (`npm`, `pnpm`), build tools, test runners, Docker, and other terminal operations.
|
|
113
|
-
- Commands run with a 30-second default timeout. Use the `timeout` parameter for longer operations.
|
|
114
|
-
- Output is stripped of ANSI codes and streamed to the TUI in real time.
|
|
115
|
-
- Pipe to `| tail -N` for commands with long output — full output streams to the user, but only the last N lines are returned to the agent.
|
|
116
|
-
- The `CI=true` environment variable is set automatically to prevent interactive prompts.
|
|
117
|
-
|
|
118
|
-
| Parameter | Type | Required | Description |
|
|
119
|
-
| --------- | -------- | -------- | -------------------------------------------- |
|
|
120
|
-
| `command` | `string` | Yes | Shell command to execute |
|
|
121
|
-
| `cwd` | `string` | No | Working directory (defaults to project root) |
|
|
122
|
-
| `timeout` | `number` | No | Timeout in seconds (default: 30) |
|
|
123
|
-
|
|
124
|
-
### `request_sandbox_access`
|
|
125
|
-
|
|
126
|
-
Request access to directories outside the project root. The user is prompted to approve or deny the request.
|
|
127
|
-
|
|
128
|
-
| Parameter | Type | Required | Description |
|
|
129
|
-
| --------- | -------- | -------- | --------------------------------------------- |
|
|
130
|
-
| `path` | `string` | Yes | Absolute path to the directory needing access |
|
|
131
|
-
| `reason` | `string` | Yes | Explanation of why access is needed |
|
|
132
|
-
|
|
133
|
-
## Web tools
|
|
134
|
-
|
|
135
|
-
### `web_search`
|
|
136
|
-
|
|
137
|
-
Search the web for documentation, error messages, package APIs, and other information.
|
|
138
|
-
|
|
139
|
-
This tool is available through two providers:
|
|
140
|
-
|
|
141
|
-
- **Tavily**: When the `TAVILY_API_KEY` environment variable is set.
|
|
142
|
-
- **Anthropic web search**: Built into Anthropic models, used as a fallback when no Tavily key is configured.
|
|
143
|
-
|
|
144
|
-
| Parameter | Type | Required | Description |
|
|
145
|
-
| --------------- | ----------------------- | -------- | --------------------------------------- |
|
|
146
|
-
| `query` | `string` | Yes | The search query |
|
|
147
|
-
| `searchDepth` | `"basic" \| "advanced"` | No | Search depth (default: `"basic"`) |
|
|
148
|
-
| `maxResults` | `number` | No | Maximum number of results (default: 10) |
|
|
149
|
-
| `includeImages` | `boolean` | No | Include related images (default: false) |
|
|
150
|
-
|
|
151
|
-
### `web_extract`
|
|
152
|
-
|
|
153
|
-
Extract the full content of one or more web pages. Requires a Tavily API key (`TAVILY_API_KEY`).
|
|
154
|
-
|
|
155
|
-
| Parameter | Type | Required | Description |
|
|
156
|
-
| --------------- | ----------------------- | -------- | --------------------------------------------- |
|
|
157
|
-
| `urls` | `string[]` | Yes | URLs to extract content from (max 20) |
|
|
158
|
-
| `extractDepth` | `"basic" \| "advanced"` | No | Extraction depth (default: `"basic"`) |
|
|
159
|
-
| `includeImages` | `boolean` | No | Include extracted image URLs (default: false) |
|
|
160
|
-
|
|
161
|
-
## Task management
|
|
162
|
-
|
|
163
|
-
### `task_write`
|
|
164
|
-
|
|
165
|
-
Create or update a structured task list for tracking progress on complex, multi-step work.
|
|
166
|
-
|
|
167
|
-
- Each task has a `content` (imperative form), `status` (`pending`, `in_progress`, `completed`), and `activeForm` (present continuous form shown during execution).
|
|
168
|
-
- Pass the full task list each time — it replaces the previous list.
|
|
169
|
-
- Only one task should be `in_progress` at a time.
|
|
170
|
-
|
|
171
|
-
### `task_check`
|
|
172
|
-
|
|
173
|
-
Check the completion status of the current task list. The agent uses this before finishing to verify all tasks are complete.
|
|
174
|
-
|
|
175
|
-
## Interactive tools
|
|
176
|
-
|
|
177
|
-
### `ask_user`
|
|
178
|
-
|
|
179
|
-
Ask the user a structured question. The agent uses this when it needs clarification, wants to validate assumptions, or needs the user to make a decision. Questions render inline in the conversation flow and support optional multiple-choice options.
|
|
180
|
-
|
|
181
|
-
### `submit_plan`
|
|
182
|
-
|
|
183
|
-
Submit a structured implementation plan for user review and approval (Plan mode only). The plan renders inline, and the user can approve, reject, or request changes.
|
|
184
|
-
|
|
185
|
-
## MCP tools
|
|
186
|
-
|
|
187
|
-
When [MCP servers](https://mastra.ai/docs/mastra-code/configuration) are configured, their tools are automatically available to the agent. MCP tools are namespaced as `serverName_toolName` to avoid collisions with built-in tools.
|
|
188
|
-
|
|
189
|
-
MCP tools fall under the `mcp` permission category. When YOLO mode is disabled, they require approval before execution.
|
|
190
|
-
|
|
191
|
-
## Tool availability by mode
|
|
192
|
-
|
|
193
|
-
Not all tools are available in every mode:
|
|
194
|
-
|
|
195
|
-
| Tool | Build | Plan | Fast |
|
|
196
|
-
| ------------------------ | ----- | --------- | ---- |
|
|
197
|
-
| `view` | Yes | Yes | Yes |
|
|
198
|
-
| `search_content` | Yes | Yes | Yes |
|
|
199
|
-
| `find_files` | Yes | Yes | Yes |
|
|
200
|
-
| `execute_command` | Yes | Read-only | Yes |
|
|
201
|
-
| `string_replace_lsp` | Yes | No | Yes |
|
|
202
|
-
| `ast_smart_edit` | Yes | No | Yes |
|
|
203
|
-
| `write_file` | Yes | No | Yes |
|
|
204
|
-
| `web_search` | Yes | Yes | Yes |
|
|
205
|
-
| `web_extract` | Yes | Yes | Yes |
|
|
206
|
-
| `task_write` | Yes | Yes | Yes |
|
|
207
|
-
| `task_check` | Yes | Yes | Yes |
|
|
208
|
-
| `ask_user` | Yes | Yes | Yes |
|
|
209
|
-
| `submit_plan` | No | Yes | No |
|
|
210
|
-
| `request_sandbox_access` | Yes | Yes | Yes |
|
|
211
|
-
|
|
212
|
-
In Plan mode, `execute_command` is available but restricted to read-only commands (`git status`, `git log`, `git diff`, etc.).
|
|
213
|
-
|
|
214
|
-
## Permission system
|
|
215
|
-
|
|
216
|
-
Tools are grouped into four categories, each with a configurable approval policy:
|
|
217
|
-
|
|
218
|
-
| Category | Tools | Default policy |
|
|
219
|
-
| ----------- | ------------------------------------------------------------------- | -------------- |
|
|
220
|
-
| **Read** | `view`, `search_content`, `find_files`, `web_search`, `web_extract` | `allow` |
|
|
221
|
-
| **Edit** | `string_replace_lsp`, `ast_smart_edit`, `write_file`, `subagent` | `ask` |
|
|
222
|
-
| **Execute** | `execute_command` | `ask` |
|
|
223
|
-
| **MCP** | All MCP server tools | `ask` |
|
|
224
|
-
|
|
225
|
-
When YOLO mode is enabled (the default), all categories are set to `allow`. When disabled, the agent prompts for approval based on the category policy.
|
|
226
|
-
|
|
227
|
-
You can configure per-category or per-tool overrides through `/settings`, and session-level grants let you approve a category once for the rest of the session.
|
|
228
|
-
|
|
229
|
-
> **Note:** Visit [Modes](https://mastra.ai/docs/mastra-code/modes) for details on how modes affect tool access and approval behavior.
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
# createMastraCode()
|
|
2
|
-
|
|
3
|
-
`createMastraCode()` is the main factory function that bootstraps the Mastra Code coding agent. It wires together project detection, storage, authentication, MCP servers, hooks, modes, subagents, and the [Harness](https://mastra.ai/reference/harness/harness-class) that drives the TUI or any other frontend.
|
|
4
|
-
|
|
5
|
-
## Usage example
|
|
6
|
-
|
|
7
|
-
```typescript
|
|
8
|
-
import { createMastraCode } from 'mastracode'
|
|
9
|
-
|
|
10
|
-
const { harness, mcpManager, hookManager, authStorage } = createMastraCode()
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
Pass a config object to customize behavior:
|
|
14
|
-
|
|
15
|
-
```typescript
|
|
16
|
-
import { createMastraCode } from 'mastracode'
|
|
17
|
-
|
|
18
|
-
const { harness } = createMastraCode({
|
|
19
|
-
cwd: '/path/to/project',
|
|
20
|
-
disableMcp: true,
|
|
21
|
-
initialState: { yolo: false },
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
await harness.init()
|
|
25
|
-
await harness.selectOrCreateThread()
|
|
26
|
-
await harness.sendMessage({ content: 'Explain the auth flow' })
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
## Parameters
|
|
30
|
-
|
|
31
|
-
`createMastraCode()` accepts an optional `MastraCodeConfig` object:
|
|
32
|
-
|
|
33
|
-
**cwd?:** (`string`): Working directory for project detection. Mastra Code uses this path to find the Git root, determine the project name, and scope threads. (Default: `process.cwd()`)
|
|
34
|
-
|
|
35
|
-
**modes?:** (`HarnessMode[]`): Override the default agent modes. Each mode defines an agent, a default model, and a display color. When omitted, Mastra Code ships with Build, Plan, and Fast modes.
|
|
36
|
-
|
|
37
|
-
**subagents?:** (`HarnessSubagent[]`): Override the default subagent definitions. When omitted, Mastra Code includes Explore (read-only codebase exploration), Plan (read-only analysis and planning), and Execute (task execution with write access).
|
|
38
|
-
|
|
39
|
-
**extraTools?:** (`Record<string, any>`): Additional tools merged into the dynamic tool set available to the agent.
|
|
40
|
-
|
|
41
|
-
**storage?:** (`{ url: string; authToken?: string }`): Custom LibSQL storage configuration. When omitted, Mastra Code auto-detects storage from environment variables, project config, global config, or falls back to a local SQLite database.
|
|
42
|
-
|
|
43
|
-
**initialState?:** (`Record<string, unknown>`): Initial harness state overrides. Merged with defaults like \`yolo\`, \`thinkingLevel\`, and project info.
|
|
44
|
-
|
|
45
|
-
**heartbeatHandlers?:** (`HeartbeatHandler[]`): Override the default periodic background tasks. The default handler syncs model gateways every 5 minutes.
|
|
46
|
-
|
|
47
|
-
**disableMcp?:** (`boolean`): Disable MCP server discovery and connection. (Default: `false`)
|
|
48
|
-
|
|
49
|
-
**disableHooks?:** (`boolean`): Disable the hooks system (lifecycle shell commands). (Default: `false`)
|
|
50
|
-
|
|
51
|
-
## Return value
|
|
52
|
-
|
|
53
|
-
`createMastraCode()` returns an object with four properties:
|
|
54
|
-
|
|
55
|
-
**harness:** (`Harness`): The Harness instance that orchestrates modes, threads, state, memory, and agent interactions. This is the primary interface for sending messages, switching models, and managing conversations.
|
|
56
|
-
|
|
57
|
-
**mcpManager:** (`McpManager | undefined`): The MCP manager for connecting to external MCP servers. \`undefined\` when \`disableMcp\` is \`true\`.
|
|
58
|
-
|
|
59
|
-
**hookManager:** (`HookManager | undefined`): The hook manager for executing lifecycle shell commands. \`undefined\` when \`disableHooks\` is \`true\`.
|
|
60
|
-
|
|
61
|
-
**authStorage:** (`AuthStorage`): The authentication storage instance. Manages OAuth credentials for AI providers (Anthropic Claude Max, OpenAI Codex).
|
|
62
|
-
|
|
63
|
-
## Default modes
|
|
64
|
-
|
|
65
|
-
When no `modes` are specified, Mastra Code creates three modes:
|
|
66
|
-
|
|
67
|
-
| Mode | Default model | Description |
|
|
68
|
-
| ------------------- | --------------------------- | ---------------------------------------------------------------------- |
|
|
69
|
-
| **Build** (default) | `anthropic/claude-opus-4-6` | Full tool access. Read, write, edit files, and execute commands. |
|
|
70
|
-
| **Plan** | `openai/gpt-5.2-codex` | Read-only mode. Explore the codebase and produce implementation plans. |
|
|
71
|
-
| **Fast** | `cerebras/zai-glm-4.7` | Quick answers and small edits with minimal overhead. |
|
|
72
|
-
|
|
73
|
-
## Default subagents
|
|
74
|
-
|
|
75
|
-
When no `subagents` are specified, Mastra Code creates three subagent types:
|
|
76
|
-
|
|
77
|
-
| Subagent | Tools | Description |
|
|
78
|
-
| ----------- | -------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
|
|
79
|
-
| **Explore** | `view`, `search_content`, `find_files` | Read-only codebase exploration for answering questions about code structure. |
|
|
80
|
-
| **Plan** | `view`, `search_content`, `find_files` | Read-only analysis and planning with structured plan output. |
|
|
81
|
-
| **Execute** | All read tools + `string_replace_lsp`, `write_file`, `execute_command`, `task_write`, `task_check` | Focused task execution with full write capabilities. |
|
|
82
|
-
|
|
83
|
-
## Project detection
|
|
84
|
-
|
|
85
|
-
Mastra Code automatically detects project identity from the working directory:
|
|
86
|
-
|
|
87
|
-
1. **Git remote URL** — if available, normalizes SSH and HTTPS URLs to create a stable identifier shared across clones and worktrees.
|
|
88
|
-
2. **Absolute path** — falls back to the filesystem path when Git isn't available.
|
|
89
|
-
|
|
90
|
-
The resulting `resourceId` scopes threads to the project, so conversations are shared across clones, worktrees, and SSH/HTTPS URLs of the same repository.
|
|
91
|
-
|
|
92
|
-
## Storage resolution
|
|
93
|
-
|
|
94
|
-
Storage configuration is resolved in priority order:
|
|
95
|
-
|
|
96
|
-
1. `storage` parameter passed to `createMastraCode()`
|
|
97
|
-
2. `MASTRA_DB_URL` and `MASTRA_DB_AUTH_TOKEN` environment variables
|
|
98
|
-
3. Project config at `.mastracode/database.json`
|
|
99
|
-
4. Global config at `~/.mastracode/database.json`
|
|
100
|
-
5. Local SQLite database at the platform-specific app data directory
|
|
101
|
-
|
|
102
|
-
> **Note:** The returned `harness` object is a full [Harness](https://mastra.ai/reference/harness/harness-class) instance with methods for sending messages, switching modes and models, managing threads, and subscribing to events.
|
|
103
|
-
|
|
104
|
-
## Related
|
|
105
|
-
|
|
106
|
-
- [Mastra Code overview](https://mastra.ai/docs/mastra-code/overview)
|
|
107
|
-
- [Harness Class reference](https://mastra.ai/reference/harness/harness-class)
|
|
108
|
-
- [Mastra Code configuration](https://mastra.ai/docs/mastra-code/configuration)
|