@mastra/mcp-docs-server 1.2.3-alpha.12 → 1.2.3-alpha.13
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.
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
# File-based agents
|
|
2
|
+
|
|
3
|
+
**Added in:** `@mastra/core@1.48.0`
|
|
4
|
+
|
|
5
|
+
> **Beta:** This feature is in beta. Breaking changes may occur without a major version bump until the API is stable.
|
|
6
|
+
|
|
7
|
+
You can define an agent by file convention instead of constructing it in code. Mastra discovers a directory under `src/mastra/agents/<name>/`, assembles an [`Agent`](https://mastra.ai/reference/agents/agent), and registers it on your [`Mastra`](https://mastra.ai/reference/core/mastra-class) instance.
|
|
8
|
+
|
|
9
|
+
## When to use file-based agents
|
|
10
|
+
|
|
11
|
+
Use file-based agents when you want one directory per agent, with configuration, instructions, tools, skills, workspace files, and subagents grouped together.
|
|
12
|
+
|
|
13
|
+
Keep using [`new Agent()`](https://mastra.ai/reference/agents/agent) in code when you need dynamic configuration, programmatic registration, or a shared agent instance across modules. Both approaches can coexist: code-registered agents are always present, and the bundler adds file-based agents when you run through the Mastra CLI.
|
|
14
|
+
|
|
15
|
+
## Quickstart
|
|
16
|
+
|
|
17
|
+
Create a directory for the agent and add a `config.ts`. Use `agentConfig` so the partial config is typed while sibling files supply the rest.
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { agentConfig } from '@mastra/core/agent'
|
|
21
|
+
|
|
22
|
+
export default agentConfig({
|
|
23
|
+
model: 'openai/gpt-5.5',
|
|
24
|
+
// instructions omitted -> taken from instructions.md
|
|
25
|
+
// tools omitted -> taken from tools/*.ts
|
|
26
|
+
})
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Add the agent instructions:
|
|
30
|
+
|
|
31
|
+
```markdown
|
|
32
|
+
You are a helpful weather assistant. Answer questions about current conditions and forecasts.
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Add a tool. The filename becomes the tool key, so this file is exposed as `get_weather`.
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
import { createTool } from '@mastra/core/tools'
|
|
39
|
+
import { z } from 'zod'
|
|
40
|
+
|
|
41
|
+
export default createTool({
|
|
42
|
+
id: 'get_weather',
|
|
43
|
+
description: 'Get the current weather for a city',
|
|
44
|
+
inputSchema: z.object({ city: z.string() }),
|
|
45
|
+
execute: async ({ context }) => ({ city: context.city, tempC: 21 }),
|
|
46
|
+
})
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Your `src/mastra/index.ts` stays the same. The discovered agent is registered automatically when you run the app through `mastra dev` or `mastra build`.
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
import { Mastra } from '@mastra/core'
|
|
53
|
+
import { Agent } from '@mastra/core/agent'
|
|
54
|
+
|
|
55
|
+
const supportAgent = new Agent({
|
|
56
|
+
id: 'support',
|
|
57
|
+
name: 'support',
|
|
58
|
+
instructions: 'You are a support agent.',
|
|
59
|
+
model: 'openai/gpt-5.5',
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
// `support` is registered in code; `weather` is discovered from the filesystem.
|
|
63
|
+
export const mastra = new Mastra({
|
|
64
|
+
agents: { support: supportAgent },
|
|
65
|
+
})
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Start the app through the Mastra CLI:
|
|
69
|
+
|
|
70
|
+
**npm**:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
npx mastra dev
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
**pnpm**:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
pnpm dlx mastra dev
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
**Yarn**:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
yarn dlx mastra dev
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
**Bun**:
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
bun x mastra dev
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Folder structure
|
|
95
|
+
|
|
96
|
+
The following table shows the supported file-based agent surface:
|
|
97
|
+
|
|
98
|
+
| File / directory | Maps to |
|
|
99
|
+
| --------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
|
|
100
|
+
| `agents/<name>/config.ts` | Default export merged into the agent config. `id` and `name` default to `<name>`. |
|
|
101
|
+
| `agents/<name>/instructions.md` | The agent `instructions`. The file contents are inlined into generated code. |
|
|
102
|
+
| `agents/<name>/tools/*.ts` | Each default-exported [`createTool()`](https://mastra.ai/reference/tools/create-tool). The tool key defaults to the filename. |
|
|
103
|
+
| `agents/<name>/skills/*.ts` | Each default-exported [`createSkill()`](https://mastra.ai/reference/agents/createSkill), added to the agent `skills`. |
|
|
104
|
+
| `agents/<name>/skills/<skill>/SKILL.md` | A packaged skill. Frontmatter supplies `name` and `description`, the body is the instructions, and files under `references/` are inlined. |
|
|
105
|
+
| `agents/<name>/skills/<skill>.md` | A flat skill. The filename is the skill name and the body is the instructions. |
|
|
106
|
+
| `agents/<name>/workspace.ts` | Default export: a [`Workspace`](https://mastra.ai/reference/workspace/workspace-class) for the agent. |
|
|
107
|
+
| `agents/<name>/workspace/` | Seed files mirrored into the agent's default workspace at build time. |
|
|
108
|
+
| `agents/<name>/subagents/<childId>/` | A declared subagent with the same layout as an agent directory. Wired into the parent as a delegation tool named `<childId>`. |
|
|
109
|
+
|
|
110
|
+
Test files named `*.test.ts`, `*.spec.ts`, `*.test.js`, and `*.spec.js` are ignored during tool and skill discovery.
|
|
111
|
+
|
|
112
|
+
## Add skills
|
|
113
|
+
|
|
114
|
+
Add skills to a file-based agent by placing them under `agents/<name>/skills/`. Three layouts are supported, and they're inlined into the bundle at build time so the deployed agent doesn't read them from disk at runtime.
|
|
115
|
+
|
|
116
|
+
- A `.ts` file can default-export `createSkill()`:
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
import { createSkill } from '@mastra/core/skills'
|
|
120
|
+
|
|
121
|
+
export default createSkill({
|
|
122
|
+
name: 'forecasting',
|
|
123
|
+
description: 'Use when the user asks about multi-day forecasts.',
|
|
124
|
+
instructions: 'Summarize the forecast day by day and call out precipitation.',
|
|
125
|
+
})
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
> **Note:** Visit [`createSkill()` reference](https://mastra.ai/reference/agents/createSkill) for the full API.
|
|
129
|
+
|
|
130
|
+
- A packaged `SKILL.md` directory uses frontmatter for the name and description. Files under `references/` are inlined with the skill.
|
|
131
|
+
|
|
132
|
+
```markdown
|
|
133
|
+
---
|
|
134
|
+
name: severe-weather
|
|
135
|
+
description: Use when conditions include storms, flooding, or other hazards.
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
Lead with the active alert, then give safety guidance.
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
- A flat `<skill>.md` file uses the filename as the skill name:
|
|
142
|
+
|
|
143
|
+
```markdown
|
|
144
|
+
Always report temperatures in both Celsius and Fahrenheit.
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Discovered skills merge with any `skills` in `config.ts`. On a name collision, `config.skills` wins and a warning is logged. If `config.skills` is a function, discovered skills are ignored with a warning because they can't be statically merged.
|
|
148
|
+
|
|
149
|
+
## Add a workspace
|
|
150
|
+
|
|
151
|
+
When a file-based agent is discovered through `mastra dev` or `mastra build`, it gets a default workspace unless `config.workspace` or `workspace.ts` supplies one. The default workspace uses a contained filesystem and shell sandbox rooted at a per-agent `workspace/` directory in the bundle.
|
|
152
|
+
|
|
153
|
+
To customize it, add a `workspace.ts` that default-exports a [`Workspace`](https://mastra.ai/reference/workspace/workspace-class):
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
import { Workspace, LocalFilesystem, LocalSandbox } from '@mastra/core/workspace'
|
|
157
|
+
|
|
158
|
+
export default new Workspace({
|
|
159
|
+
name: 'weather-workspace',
|
|
160
|
+
filesystem: new LocalFilesystem({ basePath: './data/weather' }),
|
|
161
|
+
sandbox: new LocalSandbox({ workingDirectory: './data/weather' }),
|
|
162
|
+
})
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
You can also set `workspace` directly in `config.ts`. `config.workspace` wins over `workspace.ts`, and `workspace.ts` wins over the default workspace.
|
|
166
|
+
|
|
167
|
+
### Seed files
|
|
168
|
+
|
|
169
|
+
Add a `workspace/` directory to ship files with the agent. Mastra mirrors every file under it into the agent's default workspace at build time, so the agent starts with those files on disk:
|
|
170
|
+
|
|
171
|
+
```text
|
|
172
|
+
src/mastra/agents/weather/
|
|
173
|
+
config.ts
|
|
174
|
+
workspace/
|
|
175
|
+
README.md
|
|
176
|
+
data/cities.json
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Seed files are copied into the bundle next to the running server. Commit the starting files alongside the agent that uses them.
|
|
180
|
+
|
|
181
|
+
## Add subagents
|
|
182
|
+
|
|
183
|
+
A file-based agent can declare **subagents**, specialist child agents it can delegate to. Add a `subagents/` directory under the agent, with one directory per subagent. Each subagent directory has the same layout as a top-level agent: `config.ts`, `instructions.md`, `tools/`, `skills/`, `workspace.ts`, and `workspace/`.
|
|
184
|
+
|
|
185
|
+
```text
|
|
186
|
+
src/mastra/agents/
|
|
187
|
+
supervisor/
|
|
188
|
+
config.ts
|
|
189
|
+
instructions.md
|
|
190
|
+
subagents/
|
|
191
|
+
researcher/
|
|
192
|
+
config.ts
|
|
193
|
+
instructions.md
|
|
194
|
+
tools/
|
|
195
|
+
search.ts
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
Each subagent is assembled as its own agent and wired into the parent's `agents` map. The agent loop lowers it into a model-visible delegation tool. The tool name is the bare directory name, so the example above exposes `researcher` to the supervisor.
|
|
199
|
+
|
|
200
|
+
A subagent's `config.ts` must set a non-empty `description`. The description is what the model sees when deciding whether to delegate, so the build fails if it's missing.
|
|
201
|
+
|
|
202
|
+
```typescript
|
|
203
|
+
import { agentConfig } from '@mastra/core/agent'
|
|
204
|
+
|
|
205
|
+
export default agentConfig({
|
|
206
|
+
model: 'openai/gpt-5.5',
|
|
207
|
+
description: 'Researches a topic and returns cited findings.',
|
|
208
|
+
})
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
Subagents are isolated. A subagent inherits nothing from its parent. Its tools, skills, and workspace come only from its own directory, and any absent slot falls back to the same framework defaults as a top-level agent.
|
|
212
|
+
|
|
213
|
+
Subagents are one level deep. A `subagents/` directory nested inside a subagent is ignored with a warning.
|
|
214
|
+
|
|
215
|
+
Naming rules:
|
|
216
|
+
|
|
217
|
+
- A subagent id that collides with one of the parent's tool keys is a build error.
|
|
218
|
+
- A duplicate subagent id under the same parent is a build error.
|
|
219
|
+
- If a subagent id also exists in the parent's `config.agents`, the `config.agents` entry wins and logs a warning.
|
|
220
|
+
- If `config.agents` is a function, discovered subagents are ignored with a warning because they can't be statically merged.
|
|
221
|
+
|
|
222
|
+
## Precedence rules
|
|
223
|
+
|
|
224
|
+
File-based and code-based agents coexist with deterministic rules:
|
|
225
|
+
|
|
226
|
+
- **Code wins on name collisions:** If an agent name exists in both code and the filesystem, the code-registered agent is kept and a warning is logged.
|
|
227
|
+
- **A folder can hold a code agent:** If `config.ts` exports `new Agent({...})`, that instance is used as-is. Sibling `instructions.md`, `tools/`, `skills/`, `workspace.ts`, and `subagents/` entries are ignored with warnings.
|
|
228
|
+
- **Instructions:** Dynamic function instructions in `config.ts` win over `instructions.md`. Otherwise, `instructions.md` wins over a static `instructions` string. If neither is present, the build fails for that agent.
|
|
229
|
+
- **Model:** A missing `model` fails the build and names the agent directory.
|
|
230
|
+
- **Tools:** Tools from `tools/*.ts` merge with `config.tools`. On a key collision, `config.tools` wins and a warning is logged. If `config.tools` is a function, discovered tools are ignored with a warning.
|
|
231
|
+
- **Skills:** Skills from `skills/` merge with `config.skills`. On a name collision, `config.skills` wins and a warning is logged. If `config.skills` is a function, discovered skills are ignored with a warning.
|
|
232
|
+
- **Workspace:** `config.workspace` wins over `workspace.ts`, which wins over the default workspace.
|
|
233
|
+
- **Subagents:** Subagents from `subagents/` merge with `config.agents`. On an id collision, `config.agents` wins and a warning is logged. A subagent id that collides with a tool key, or a duplicate subagent id, is a build error.
|
|
234
|
+
|
|
235
|
+
## What happens at build time
|
|
236
|
+
|
|
237
|
+
File-based agents are discovered by the Mastra **bundler**, the step that runs under `mastra dev` and `mastra build`.
|
|
238
|
+
|
|
239
|
+
File-based agents are registered only when your app runs through the Mastra CLI. If you import your `mastra` instance directly, `agents/<name>/` directories aren't discovered.
|
|
240
|
+
|
|
241
|
+
When you consume Mastra as a library, register those agents in code instead of relying on file discovery:
|
|
242
|
+
|
|
243
|
+
```typescript
|
|
244
|
+
import { Mastra } from '@mastra/core'
|
|
245
|
+
import { Agent } from '@mastra/core/agent'
|
|
246
|
+
|
|
247
|
+
const weather = new Agent({
|
|
248
|
+
id: 'weather',
|
|
249
|
+
name: 'weather',
|
|
250
|
+
instructions: 'You are a helpful weather assistant.',
|
|
251
|
+
model: 'openai/gpt-5.5',
|
|
252
|
+
})
|
|
253
|
+
|
|
254
|
+
export const mastra = new Mastra({
|
|
255
|
+
agents: { weather },
|
|
256
|
+
})
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
## Related
|
|
260
|
+
|
|
261
|
+
- [Agents overview](https://mastra.ai/docs/agents/overview)
|
|
262
|
+
- [Tools](https://mastra.ai/docs/agents/using-tools)
|
|
263
|
+
- [Skills](https://mastra.ai/docs/agents/skills)
|
|
264
|
+
- [Supervisor agents](https://mastra.ai/docs/agents/supervisor-agents)
|
|
265
|
+
- [Workspace](https://mastra.ai/docs/workspace/overview)
|
|
266
|
+
- [Studio overview](https://mastra.ai/docs/studio/overview)
|
|
267
|
+
- [`Agent` reference](https://mastra.ai/reference/agents/agent)
|
|
268
|
+
- [`createTool()` reference](https://mastra.ai/reference/tools/create-tool)
|
|
269
|
+
- [`createSkill()` reference](https://mastra.ai/reference/agents/createSkill)
|
|
270
|
+
- [`Workspace` reference](https://mastra.ai/reference/workspace/workspace-class)
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
Your new Mastra project, created with the `create mastra` command, comes with a predefined set of files and folders to help you get started.
|
|
4
4
|
|
|
5
|
-
Mastra is a framework, but it's **unopinionated** about how you organize or colocate your files. The CLI provides a sensible default structure that works well for most projects, but you're free to adapt it to your workflow or team conventions. You could even build your entire project in a single file if you wanted! Whatever structure you choose, keep it consistent to ensure your code stays maintainable and straightforward to navigate.
|
|
5
|
+
Mastra is a framework, but it's mostly **unopinionated** about how you organize or colocate your files. The CLI provides a sensible default structure that works well for most projects, but you're free to adapt it to your workflow or team conventions. You could even build your entire project in a single file if you wanted! Whatever structure you choose, keep it consistent to ensure your code stays maintainable and straightforward to navigate.
|
|
6
6
|
|
|
7
7
|
## Default project structure
|
|
8
8
|
|
|
9
9
|
A project created with the `create mastra` command looks like this:
|
|
10
10
|
|
|
11
|
-
```
|
|
11
|
+
```bash
|
|
12
12
|
src/
|
|
13
13
|
├── mastra/
|
|
14
14
|
│ ├── agents/
|
|
@@ -25,21 +25,25 @@ src/
|
|
|
25
25
|
└── tsconfig.json
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
Use the predefined files as templates. Duplicate and adapt them to quickly create your own agents, tools, workflows, etc.
|
|
29
29
|
|
|
30
30
|
### Folders
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
| Folder | Description
|
|
35
|
-
| ---------------------- |
|
|
36
|
-
| `src/mastra` | Entry point for all Mastra-related code and configuration.
|
|
37
|
-
| `src/mastra/agents` | Define and configure your agents - their behavior, goals, and tools.
|
|
38
|
-
| `src/mastra/workflows` | Define multi-step workflows that orchestrate agents and tools together.
|
|
39
|
-
| `src/mastra/tools` | Create reusable tools that your agents can call
|
|
40
|
-
| `src/mastra/mcp` |
|
|
41
|
-
| `src/mastra/scorers` |
|
|
42
|
-
|
|
32
|
+
Mastra recommends organizing your code into the following folders:
|
|
33
|
+
|
|
34
|
+
| Folder | Description |
|
|
35
|
+
| ---------------------- | ----------------------------------------------------------------------- |
|
|
36
|
+
| `src/mastra` | Entry point for all Mastra-related code and configuration. |
|
|
37
|
+
| `src/mastra/agents` | Define and configure your agents - their behavior, goals, and tools. |
|
|
38
|
+
| `src/mastra/workflows` | Define multi-step workflows that orchestrate agents and tools together. |
|
|
39
|
+
| `src/mastra/tools` | Create reusable tools that your agents can call |
|
|
40
|
+
| `src/mastra/mcp` | Implement custom MCP servers to share your tools with external agents |
|
|
41
|
+
| `src/mastra/scorers` | Define scorers for evaluating agent performance over time |
|
|
42
|
+
|
|
43
|
+
There are two special folder conventions in Mastra:
|
|
44
|
+
|
|
45
|
+
- `src/mastra/agents/<name>`: You can define an agent by file convention instead of constructing it in code. Learn more in the [file-based agents](https://mastra.ai/docs/agents/file-based-agents) guide.
|
|
46
|
+
- `src/mastra/public`: Contents are copied into the `.build/output` directory during the build process, making them available for serving at runtime.
|
|
43
47
|
|
|
44
48
|
### Top-level files
|
|
45
49
|
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @mastra/mcp-docs-server
|
|
2
2
|
|
|
3
|
+
## 1.2.3-alpha.13
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`8be63b0`](https://github.com/mastra-ai/mastra/commit/8be63b015fb8d72cea1220f05e7dc3bb997cc249), [`345eecc`](https://github.com/mastra-ai/mastra/commit/345eecce6ba519b5d987f0e10b5de4c8e5734580), [`ee14cae`](https://github.com/mastra-ai/mastra/commit/ee14cae244805783bde518a6142de28b744b169c)]:
|
|
8
|
+
- @mastra/core@1.48.0-alpha.7
|
|
9
|
+
|
|
3
10
|
## 1.2.3-alpha.12
|
|
4
11
|
|
|
5
12
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/mcp-docs-server",
|
|
3
|
-
"version": "1.2.3-alpha.
|
|
3
|
+
"version": "1.2.3-alpha.13",
|
|
4
4
|
"description": "MCP server for accessing Mastra.ai documentation, changelogs, and news.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"jsdom": "^26.1.0",
|
|
29
29
|
"local-pkg": "^1.1.2",
|
|
30
30
|
"zod": "^4.4.3",
|
|
31
|
-
"@mastra/
|
|
32
|
-
"@mastra/
|
|
31
|
+
"@mastra/core": "1.48.0-alpha.7",
|
|
32
|
+
"@mastra/mcp": "^1.12.1-alpha.0"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@hono/node-server": "^1.19.11",
|
|
@@ -45,9 +45,9 @@
|
|
|
45
45
|
"tsx": "^4.22.4",
|
|
46
46
|
"typescript": "^6.0.3",
|
|
47
47
|
"vitest": "4.1.8",
|
|
48
|
-
"@internal/lint": "0.0.109",
|
|
49
48
|
"@internal/types-builder": "0.0.84",
|
|
50
|
-
"@
|
|
49
|
+
"@internal/lint": "0.0.109",
|
|
50
|
+
"@mastra/core": "1.48.0-alpha.7"
|
|
51
51
|
},
|
|
52
52
|
"homepage": "https://mastra.ai",
|
|
53
53
|
"repository": {
|