@mastra/mcp-docs-server 1.2.7-alpha.4 → 1.2.7-alpha.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/.docs/docs/agent-builder/overview.md +4 -3
  2. package/.docs/docs/agent-controller/overview.md +2 -1
  3. package/.docs/docs/agents/a2a.md +2 -1
  4. package/.docs/docs/agents/guardrails.md +2 -1
  5. package/.docs/docs/agents/overview.md +2 -2
  6. package/.docs/docs/agents/skills.md +1 -1
  7. package/.docs/docs/agents/supervisor-agents.md +2 -1
  8. package/.docs/docs/browser/overview.md +2 -1
  9. package/.docs/docs/capabilities/channels/discord.md +98 -0
  10. package/.docs/docs/capabilities/channels/other-adapters.md +68 -0
  11. package/.docs/docs/capabilities/channels/overview.md +257 -0
  12. package/.docs/docs/capabilities/channels/slack.md +225 -0
  13. package/.docs/docs/capabilities/channels/teams.md +100 -0
  14. package/.docs/docs/capabilities/channels/telegram.md +98 -0
  15. package/.docs/docs/capabilities/channels/whatsapp.md +99 -0
  16. package/.docs/docs/evals/datasets/overview.md +2 -1
  17. package/.docs/docs/evals/datasets/running-experiments.md +2 -0
  18. package/.docs/docs/evals/overview.md +4 -1
  19. package/.docs/docs/getting-started/file-based-agents.md +114 -0
  20. package/.docs/docs/long-running-agents/signals.md +4 -1
  21. package/.docs/docs/mastra-platform/observability.md +5 -1
  22. package/.docs/docs/memory/observational-memory.md +2 -1
  23. package/.docs/docs/memory/overview.md +2 -0
  24. package/.docs/docs/memory/semantic-recall.md +1 -1
  25. package/.docs/docs/memory/working-memory.md +3 -3
  26. package/.docs/docs/studio/overview.md +1 -1
  27. package/.docs/docs/workflows/control-flow.md +0 -2
  28. package/.docs/docs/workflows/overview.md +2 -3
  29. package/.docs/docs/workspace/overview.md +2 -1
  30. package/.docs/docs/workspace/sandbox.md +2 -0
  31. package/.docs/guides/getting-started/quickstart.md +3 -1
  32. package/.docs/guides/guide/chef-michel.md +0 -2
  33. package/.docs/guides/guide/slack-assistant.md +2 -2
  34. package/.docs/guides/guide/stock-agent.md +0 -2
  35. package/.docs/models/environment-variables.md +2 -0
  36. package/.docs/models/gateways/netlify.md +4 -1
  37. package/.docs/models/gateways/openrouter.md +7 -6
  38. package/.docs/models/gateways/vercel.md +5 -1
  39. package/.docs/models/index.md +1 -1
  40. package/.docs/models/providers/crossmodel.md +109 -0
  41. package/.docs/models/providers/llmgateway.md +185 -181
  42. package/.docs/models/providers/meta.md +101 -0
  43. package/.docs/models/providers/nano-gpt.md +2 -2
  44. package/.docs/models/providers/neon.md +40 -29
  45. package/.docs/models/providers/openai.md +5 -1
  46. package/.docs/models/providers/poolside.md +6 -5
  47. package/.docs/models/providers/routing-run.md +20 -34
  48. package/.docs/models/providers/the-grid-ai.md +3 -3
  49. package/.docs/models/providers.md +2 -0
  50. package/.docs/reference/agents/channels.md +2 -2
  51. package/.docs/reference/channels/channel-provider.md +1 -1
  52. package/.docs/reference/channels/slack-provider.md +2 -2
  53. package/.docs/reference/cli/mastra.md +1 -0
  54. package/.docs/reference/file-based-agents/config.md +97 -0
  55. package/.docs/reference/file-based-agents/instructions.md +54 -0
  56. package/.docs/reference/file-based-agents/memory.md +58 -0
  57. package/.docs/reference/file-based-agents/observability.md +32 -0
  58. package/.docs/reference/file-based-agents/processors.md +56 -0
  59. package/.docs/reference/file-based-agents/server.md +37 -0
  60. package/.docs/reference/file-based-agents/skills.md +56 -0
  61. package/.docs/reference/file-based-agents/storage.md +30 -0
  62. package/.docs/reference/file-based-agents/studio.md +56 -0
  63. package/.docs/reference/file-based-agents/subagents.md +123 -0
  64. package/.docs/reference/file-based-agents/tools.md +63 -0
  65. package/.docs/reference/file-based-agents/workflows.md +52 -0
  66. package/.docs/reference/file-based-agents/workspace.md +74 -0
  67. package/.docs/reference/index.md +13 -0
  68. package/.docs/reference/memory/memory-class.md +1 -1
  69. package/.docs/reference/memory/serialized-memory-config.md +1 -1
  70. package/.docs/reference/project-structure.md +1 -1
  71. package/.docs/reference/pubsub/lease-provider.md +1 -1
  72. package/.docs/reference/storage/clickhouse.md +32 -0
  73. package/.docs/reference/storage/composite.md +27 -1
  74. package/.docs/reference/storage/retention.md +11 -0
  75. package/CHANGELOG.md +14 -0
  76. package/package.json +4 -4
  77. package/.docs/docs/agents/channels.md +0 -225
  78. package/.docs/docs/agents/file-based-agents.md +0 -297
@@ -105,6 +105,8 @@ Deletes rows older than their configured `maxAge` across every domain that has a
105
105
 
106
106
  `prune()` is designed to be safe on tables with millions of rows. It deletes in bounded, batched chunks — each batch is its own transaction — so it never takes a long lock or bloats the transaction log. It never runs a `VACUUM`.
107
107
 
108
+ Pass `options.retention` to replace the configured policies for that call only — for example to skip a domain (keep chat history) or prune more aggressively than the standing config. The store's configured `retention` is unchanged.
109
+
108
110
  Anchor-column indexes are created lazily on the first `prune()` call for each table with a policy — never at `init()` — so deployments that don't configure retention pay no extra index write or disk overhead. The first prune of an existing large table pays a one-time index build; subsequent prunes reuse the index.
109
111
 
110
112
  ```typescript
@@ -116,6 +118,13 @@ const results = await storage.prune({
116
118
  for (const r of results) {
117
119
  console.log(`${r.domain}.${r.table}: deleted ${r.deleted}, done=${r.done}`)
118
120
  }
121
+
122
+ // One-off pass with different policies (configured retention untouched):
123
+ await storage.prune({
124
+ retention: {
125
+ observability: { spans: { maxAge: '1d' } },
126
+ },
127
+ })
119
128
  ```
120
129
 
121
130
  Returns: `Promise<PruneResult[]>`
@@ -130,6 +139,8 @@ Returns: `Promise<PruneResult[]>`
130
139
 
131
140
  **signal** (`AbortSignal`): Cooperative cancellation. The batch loop checks it between batches and stops cleanly, returning partial results with done: false.
132
141
 
142
+ **retention** (`RetentionConfig`): Replaces the store's configured retention policies for this call only — e.g. to skip a domain or prune more aggressively. The configured retention is unchanged.
143
+
133
144
  ##### PruneResult
134
145
 
135
146
  Each result describes one table's progress:
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @mastra/mcp-docs-server
2
2
 
3
+ ## 1.2.7-alpha.7
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`177010f`](https://github.com/mastra-ai/mastra/commit/177010ff096d2e4b28d89803be5b1a4cad2a0d6b), [`54a51e0`](https://github.com/mastra-ai/mastra/commit/54a51e0a484fe1ebad3fb1f7ef5282a075709eb7)]:
8
+ - @mastra/core@1.51.0-alpha.3
9
+
10
+ ## 1.2.7-alpha.5
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies [[`e955965`](https://github.com/mastra-ai/mastra/commit/e955965dce575a903e37cf054d28ea99aa48785e), [`860ef7e`](https://github.com/mastra-ai/mastra/commit/860ef7e77d92b63469cbe5857aa1e626197e43e9), [`17e818c`](https://github.com/mastra-ai/mastra/commit/17e818c51a958ba90641b1a959dc38faf8c034e9), [`4451dfe`](https://github.com/mastra-ai/mastra/commit/4451dfe857428e7abcc0261a507a2e186dae6d47), [`1d39058`](https://github.com/mastra-ai/mastra/commit/1d39058e548efd691799985d5c8af2737f1c3bd2)]:
15
+ - @mastra/core@1.51.0-alpha.2
16
+
3
17
  ## 1.2.7-alpha.2
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.2.7-alpha.4",
3
+ "version": "1.2.7-alpha.8",
4
4
  "description": "MCP server for accessing Mastra.ai documentation, changelogs, and news.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -28,7 +28,7 @@
28
28
  "jsdom": "^26.1.0",
29
29
  "local-pkg": "^1.1.2",
30
30
  "zod": "^4.4.3",
31
- "@mastra/core": "1.50.2-alpha.1",
31
+ "@mastra/core": "1.51.0-alpha.3",
32
32
  "@mastra/mcp": "^1.13.1"
33
33
  },
34
34
  "devDependencies": {
@@ -45,9 +45,9 @@
45
45
  "tsx": "^4.22.4",
46
46
  "typescript": "^6.0.3",
47
47
  "vitest": "4.1.9",
48
- "@internal/lint": "0.0.113",
49
48
  "@internal/types-builder": "0.0.88",
50
- "@mastra/core": "1.50.2-alpha.1"
49
+ "@internal/lint": "0.0.113",
50
+ "@mastra/core": "1.51.0-alpha.3"
51
51
  },
52
52
  "homepage": "https://mastra.ai",
53
53
  "repository": {
@@ -1,225 +0,0 @@
1
- > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
-
3
- # Channels
4
-
5
- **Added in:** `@mastra/core@1.22.0`
6
-
7
- Channels connect your agents to messaging platforms like Slack, Discord, and Telegram. When a user sends a message on a platform, the agent receives it, processes it through the normal agent pipeline, and streams the response back to the conversation.
8
-
9
- ## When to use channels
10
-
11
- Use channels when you want your agent to:
12
-
13
- - Respond to messages in Slack workspaces, Discord servers, or Telegram chats
14
- - Handle both direct messages and mentions in group conversations
15
-
16
- ## Quickstart
17
-
18
- Configure channels directly on your agent using adapters from the [Chat SDK](https://chat-sdk.dev/adapters):
19
-
20
- ```typescript
21
- import { Agent } from '@mastra/core/agent'
22
- import { createSlackAdapter } from '@chat-adapter/slack'
23
-
24
- export const supportAgent = new Agent({
25
- id: 'support-agent',
26
- name: 'Support Agent',
27
- instructions: 'You are a helpful support assistant.',
28
- model: 'openai/gpt-5.5',
29
- channels: {
30
- adapters: {
31
- slack: createSlackAdapter(),
32
- },
33
- },
34
- })
35
- ```
36
-
37
- Register the agent in your Mastra instance with storage so channel state persists across restarts:
38
-
39
- ```typescript
40
- import { Mastra } from '@mastra/core'
41
- import { LibSQLStore } from '@mastra/libsql'
42
- import { supportAgent } from './agents/support-agent'
43
-
44
- export const mastra = new Mastra({
45
- agents: { supportAgent },
46
- storage: new LibSQLStore({
47
- url: process.env.DATABASE_URL,
48
- }),
49
- })
50
- ```
51
-
52
- Each adapter reads credentials from environment variables by default.
53
-
54
- ## Platform setup
55
-
56
- Each platform requires credentials and event configuration. See the Chat SDK adapter docs for full setup: [Slack](https://chat-sdk.dev/adapters/slack), [Discord](https://chat-sdk.dev/adapters/discord), [Telegram](https://chat-sdk.dev/adapters/telegram).
57
-
58
- Mastra generates a webhook route for each platform at:
59
-
60
- ```text
61
- /api/agents/{agentId}/channels/{platform}/webhook
62
- ```
63
-
64
- For example: `/api/agents/support-agent/channels/slack/webhook`
65
-
66
- Point your platform's webhook or interactions URL to this path.
67
-
68
- ### Local development
69
-
70
- Platform webhooks need a public URL to reach your local server. Use a tunnel to expose `localhost:4111`:
71
-
72
- ```bash
73
- # ngrok
74
- ngrok http 4111
75
-
76
- # cloudflared
77
- npx cloudflared tunnel --url http://localhost:4111
78
- ```
79
-
80
- Copy the generated URL and use it as the base for your webhook paths (e.g. `https://abc123.ngrok.io/api/agents/support-agent/channels/slack/webhook`).
81
-
82
- ## Thread context
83
-
84
- When a user mentions the agent mid-conversation in a channel thread, the agent may not have prior context. By default, Mastra fetches the last 10 messages from the platform on the first mention.
85
-
86
- 1. On the **first mention** in a thread, the agent fetches recent messages from the platform.
87
- 2. These messages are prepended to the user's message as conversation context.
88
- 3. After responding, the agent subscribes to the thread and has full history via Mastra's memory.
89
- 4. Subsequent messages in that thread **don't** re-fetch from the platform.
90
-
91
- Set `threadContext: { maxMessages: 0 }` to disable this behavior. This only applies to non-DM threads.
92
-
93
- Mastra also adds a short system message telling the agent which channel and platform the request came from (DM vs public channel, platform name, bot display name). Set `threadContext: { addSystemMessage: false }` to skip it.
94
-
95
- ## Tool approval
96
-
97
- Tools with `requireApproval: true` render as interactive cards with Approve and Deny buttons:
98
-
99
- ```typescript
100
- import { createTool } from '@mastra/core/tools'
101
- import { z } from 'zod'
102
-
103
- const deleteFile = createTool({
104
- id: 'delete-file',
105
- description: 'Delete a file from the system',
106
- inputSchema: z.object({
107
- path: z.string().describe('Path to the file to delete'),
108
- }),
109
- requireApproval: true,
110
- execute: async ({ path }) => {
111
- await fs.unlink(path)
112
- return { deleted: path }
113
- },
114
- })
115
- ```
116
-
117
- When the agent calls this tool, users see a card with the tool name, arguments, and Approve/Deny buttons. The tool only executes after approval.
118
-
119
- Set `toolDisplay: 'text'` on an adapter to render tool calls as plain text instead of interactive cards. In `'hidden'` mode the agent uses `autoResumeSuspendedTools` to let the LLM decide based on the conversation context, since hidden mode doesn't post approval buttons.
120
-
121
- ## Multi-user awareness
122
-
123
- In group conversations, Mastra automatically prefixes each message with the sender's name and platform ID so the agent can distinguish between speakers:
124
-
125
- ```text
126
- [Alice (@U123ABC)]: Can you help me with this?
127
- [Bob (@U456DEF)]: I have a question too.
128
- ```
129
-
130
- ## Multimodal content
131
-
132
- Models like Gemini can natively process images, video, and audio. Combine `inlineMedia` and `inlineLinks` to let users share rich content with your agent across platforms:
133
-
134
- ```typescript
135
- import { Agent } from '@mastra/core/agent'
136
- import { createDiscordAdapter } from '@chat-adapter/discord'
137
- import { google } from '@ai-sdk/google'
138
-
139
- export const visionAgent = new Agent({
140
- id: 'vision-agent',
141
- name: 'Vision Agent',
142
- instructions: 'You can see images, watch videos, and listen to audio.',
143
- model: google('gemini-3.1-flash-image-preview'),
144
- channels: {
145
- adapters: {
146
- discord: createDiscordAdapter(),
147
- },
148
- inlineMedia: ['image/*', 'video/*', 'audio/*'],
149
- inlineLinks: [
150
- // Gemini treats YouTube URLs as native video file parts
151
- { match: 'youtube.com', mimeType: 'video/*' },
152
- { match: 'youtu.be', mimeType: 'video/*' },
153
- 'imgur.com', // HEAD-check imgur links; inline as file part if mimeType matches inlineMedia
154
- ],
155
- },
156
- })
157
- ```
158
-
159
- With this configuration:
160
-
161
- - A user uploads a screenshot and the agent describes what it sees
162
- - A user uploads an `.mp4` clip and the agent summarizes the video
163
- - A user pastes a YouTube link and the agent watches and discusses the video
164
- - A user pastes an imgur link and the agent sees the image directly
165
-
166
- By default, only images are sent inline (`inlineMedia: ['image/*']`). Unsupported types are described as text summaries so the agent knows about the file without crashing models that reject them.
167
-
168
- > **Note:** See [Channels reference](https://mastra.ai/reference/agents/channels) for all `inlineMedia` patterns and [inlineLinks reference](https://mastra.ai/reference/agents/channels) for domain matching, HEAD detection, and forced mime types.
169
-
170
- ## Serverless deployment
171
-
172
- On serverless platforms like Vercel, each request runs in a separate, short-lived instance. Channels need two things to work reliably in that environment: a way to keep the function alive while the agent responds, and a shared pub/sub so instances can coordinate.
173
-
174
- ### Keep the function alive with `waitUntil`
175
-
176
- A channel webhook returns a `200` response right away, then the agent runs in the background to post its reply. On most serverless platforms the function is frozen as soon as it responds, which kills the run before the agent answers. Pass a `waitUntil` function so the platform keeps the instance alive until the run finishes.
177
-
178
- On Vercel, pass `waitUntil` from `@vercel/functions`:
179
-
180
- ```typescript
181
- import { Agent } from '@mastra/core/agent'
182
- import { createSlackAdapter } from '@chat-adapter/slack'
183
- import { waitUntil } from '@vercel/functions'
184
-
185
- export const agent = new Agent({
186
- id: 'agent',
187
- channels: {
188
- adapters: {
189
- slack: createSlackAdapter(),
190
- },
191
- waitUntil,
192
- },
193
- })
194
- ```
195
-
196
- Vercel and AWS Lambda require `waitUntil`, since they freeze the function as soon as the response is sent. Cloudflare Workers and Netlify Functions are detected automatically from the request context, so they don't need it. For runtimes where `waitUntil` lives on the request context but isn't detected automatically, use `resolveWaitUntil`. See the [Channels reference](https://mastra.ai/reference/agents/channels) for details.
197
-
198
- ### Coordinate instances with a shared pub/sub
199
-
200
- Channels route messages through the agent's signal pipeline, and each run acquires a lease on its thread so a single run owns the conversation at a time. The default in-memory pub/sub can't cross instance boundaries, so on serverless a follow-up message can land on a different instance than the one running the agent. Without a shared pub/sub, that instance can't reach the active run and starts its own, leaving the original run untouched and the thread processed twice.
201
-
202
- Configure a shared pub/sub backed by Redis Streams on the `Mastra` instance so leases and signals coordinate across instances:
203
-
204
- ```typescript
205
- import { Mastra } from '@mastra/core'
206
- import { RedisStreamsPubSub } from '@mastra/redis-streams'
207
-
208
- export const mastra = new Mastra({
209
- agents: { agent },
210
- pubsub: new RedisStreamsPubSub({
211
- url: process.env.REDIS_URL,
212
- keyPrefix: 'mastra:my-app',
213
- }),
214
- })
215
- ```
216
-
217
- Vercel's managed Redis integration and Upstash Redis both work well. For more on when a distributed pub/sub is needed, see the [PubSub guide](https://mastra.ai/docs/server/pubsub) and the [`RedisStreamsPubSub` reference](https://mastra.ai/reference/pubsub/redis-streams).
218
-
219
- ## Related
220
-
221
- - [Guide: Building a Slack assistant](https://mastra.ai/guides/guide/slack-assistant)
222
- - [Agent overview](https://mastra.ai/docs/agents/overview)
223
- - [Tool approval](https://mastra.ai/docs/agents/agent-approval)
224
- - [Channels reference](https://mastra.ai/reference/agents/channels)
225
- - [Chat SDK adapters](https://chat-sdk.dev/adapters)
@@ -1,297 +0,0 @@
1
- > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
-
3
- # File-based agents
4
-
5
- **Added in:** `@mastra/core@1.48.0`
6
-
7
- > **Beta:** This feature is in beta. Breaking changes may occur without a major version bump until the API is stable.
8
-
9
- 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.
10
-
11
- ## When to use file-based agents
12
-
13
- Use file-based agents when you want one directory per agent, with configuration, instructions, tools, skills, workspace files, and subagents grouped together.
14
-
15
- 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.
16
-
17
- ## Quickstart
18
-
19
- 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.
20
-
21
- ```typescript
22
- import { agentConfig } from '@mastra/core/agent'
23
-
24
- export default agentConfig({
25
- model: 'openai/gpt-5.5',
26
- // instructions omitted -> taken from instructions.md
27
- // tools omitted -> taken from tools/*.ts
28
- })
29
- ```
30
-
31
- Add the agent instructions:
32
-
33
- ```markdown
34
- You are a helpful weather assistant. Answer questions about current conditions and forecasts.
35
- ```
36
-
37
- Add a tool. The filename becomes the tool key, so this file is exposed as `get_weather`.
38
-
39
- ```typescript
40
- import { createTool } from '@mastra/core/tools'
41
- import { z } from 'zod'
42
-
43
- export default createTool({
44
- id: 'get_weather',
45
- description: 'Get the current weather for a city',
46
- inputSchema: z.object({ city: z.string() }),
47
- execute: async ({ context }) => ({ city: context.city, tempC: 21 }),
48
- })
49
- ```
50
-
51
- 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`.
52
-
53
- ```typescript
54
- import { Mastra } from '@mastra/core'
55
- import { Agent } from '@mastra/core/agent'
56
-
57
- const supportAgent = new Agent({
58
- id: 'support',
59
- name: 'support',
60
- instructions: 'You are a support agent.',
61
- model: 'openai/gpt-5.5',
62
- })
63
-
64
- // `support` is registered in code; `weather` is discovered from the filesystem.
65
- export const mastra = new Mastra({
66
- agents: { support: supportAgent },
67
- })
68
- ```
69
-
70
- Start the app through the Mastra CLI:
71
-
72
- **npm**:
73
-
74
- ```bash
75
- npx mastra dev
76
- ```
77
-
78
- **pnpm**:
79
-
80
- ```bash
81
- pnpm dlx mastra dev
82
- ```
83
-
84
- **Yarn**:
85
-
86
- ```bash
87
- yarn dlx mastra dev
88
- ```
89
-
90
- **Bun**:
91
-
92
- ```bash
93
- bun x mastra dev
94
- ```
95
-
96
- ## Folder structure
97
-
98
- The following table shows the supported file-based agent surface:
99
-
100
- | File / directory | Maps to |
101
- | --------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
102
- | `agents/<name>/config.ts` | Default export merged into the agent config. `id` and `name` default to `<name>`. |
103
- | `agents/<name>/instructions.md` | The agent `instructions`. The file contents are inlined into generated code. |
104
- | `agents/<name>/tools/*.ts` | Each default-exported [`createTool()`](https://mastra.ai/reference/tools/create-tool). The tool key defaults to the filename. |
105
- | `agents/<name>/skills/*.ts` | Each default-exported [`createSkill()`](https://mastra.ai/reference/agents/createSkill), added to the agent `skills`. |
106
- | `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. |
107
- | `agents/<name>/skills/<skill>.md` | A flat skill. The filename is the skill name and the body is the instructions. |
108
- | `agents/<name>/memory.ts` | Default export: a [`Memory`](https://mastra.ai/reference/memory/memory-class) instance used as the agent `memory`. |
109
- | `agents/<name>/workspace.ts` | Default export: a [`Workspace`](https://mastra.ai/reference/workspace/workspace-class) for the agent. |
110
- | `agents/<name>/workspace/` | Seed files mirrored into the agent's default workspace at build time. |
111
- | `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>`. |
112
-
113
- Test files named `*.test.ts`, `*.spec.ts`, `*.test.js`, and `*.spec.js` are ignored during tool and skill discovery.
114
-
115
- ## Add skills
116
-
117
- 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.
118
-
119
- - A `.ts` file can default-export `createSkill()`:
120
-
121
- ```typescript
122
- import { createSkill } from '@mastra/core/skills'
123
-
124
- export default createSkill({
125
- name: 'forecasting',
126
- description: 'Use when the user asks about multi-day forecasts.',
127
- instructions: 'Summarize the forecast day by day and call out precipitation.',
128
- })
129
- ```
130
-
131
- > **Note:** Visit [`createSkill()` reference](https://mastra.ai/reference/agents/createSkill) for the full API.
132
-
133
- - A packaged `SKILL.md` directory uses frontmatter for the name and description. Files under `references/` are inlined with the skill.
134
-
135
- ```markdown
136
- ---
137
- name: severe-weather
138
- description: Use when conditions include storms, flooding, or other hazards.
139
- ---
140
-
141
- Lead with the active alert, then give safety guidance.
142
- ```
143
-
144
- - A flat `<skill>.md` file uses the filename as the skill name:
145
-
146
- ```markdown
147
- Always report temperatures in both Celsius and Fahrenheit.
148
- ```
149
-
150
- 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.
151
-
152
- ## Add memory
153
-
154
- Give a file-based agent [memory](https://mastra.ai/docs/memory/overview) by adding a `memory.ts` that default-exports a [`Memory`](https://mastra.ai/reference/memory/memory-class) instance:
155
-
156
- ```typescript
157
- import { Memory } from '@mastra/memory'
158
-
159
- export default new Memory()
160
- ```
161
-
162
- The exported instance becomes the agent's `memory`. You can also set `memory` directly in `config.ts`. `config.memory` wins over `memory.ts`, and a warning is logged when both are present. If neither is present, the agent has no memory, which is the default.
163
-
164
- ## Add a workspace
165
-
166
- 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.
167
-
168
- To customize it, add a `workspace.ts` that default-exports a [`Workspace`](https://mastra.ai/reference/workspace/workspace-class):
169
-
170
- ```typescript
171
- import { Workspace, LocalFilesystem, LocalSandbox } from '@mastra/core/workspace'
172
-
173
- export default new Workspace({
174
- name: 'weather-workspace',
175
- filesystem: new LocalFilesystem({ basePath: './data/weather' }),
176
- sandbox: new LocalSandbox({ workingDirectory: './data/weather' }),
177
- })
178
- ```
179
-
180
- You can also set `workspace` directly in `config.ts`. `config.workspace` wins over `workspace.ts`, and `workspace.ts` wins over the default workspace.
181
-
182
- ### Seed files
183
-
184
- 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:
185
-
186
- ```text
187
- src/mastra/agents/weather/
188
- config.ts
189
- workspace/
190
- README.md
191
- data/cities.json
192
- ```
193
-
194
- Seed files are copied into the bundle next to the running server. Commit the starting files alongside the agent that uses them.
195
-
196
- ## Add subagents
197
-
198
- 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/`, `memory.ts`, `workspace.ts`, and `workspace/`.
199
-
200
- ```text
201
- src/mastra/agents/
202
- supervisor/
203
- config.ts
204
- instructions.md
205
- subagents/
206
- researcher/
207
- config.ts
208
- instructions.md
209
- tools/
210
- search.ts
211
- ```
212
-
213
- 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.
214
-
215
- 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.
216
-
217
- ```typescript
218
- import { agentConfig } from '@mastra/core/agent'
219
-
220
- export default agentConfig({
221
- model: 'openai/gpt-5.5',
222
- description: 'Researches a topic and returns cited findings.',
223
- })
224
- ```
225
-
226
- 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.
227
-
228
- Subagents can declare their own `subagents/` directories, nesting up to three levels below the top-level agent. A `subagents/` directory deeper than that's ignored with a warning.
229
-
230
- ```text
231
- src/mastra/agents/
232
- supervisor/ # depth 0
233
- subagents/
234
- researcher/ # depth 1
235
- subagents/
236
- summarizer/ # depth 2
237
- ```
238
-
239
- Naming rules:
240
-
241
- - A subagent id that collides with one of the parent's tool keys is a build error.
242
- - A duplicate subagent id under the same parent is a build error.
243
- - If a subagent id also exists in the parent's `config.agents`, the `config.agents` entry wins and logs a warning.
244
- - If `config.agents` is a function, discovered subagents are ignored with a warning because they can't be statically merged.
245
-
246
- ## Precedence rules
247
-
248
- File-based and code-based agents coexist with deterministic rules:
249
-
250
- - **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.
251
- - **A folder can hold a code agent:** If `config.ts` exports a configured `new Agent({ id: 'file-based-agent', ... })`, that instance is used as-is. Sibling `instructions.md`, `tools/`, `skills/`, `memory.ts`, `workspace.ts`, and `subagents/` entries are ignored with warnings.
252
- - **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.
253
- - **Model:** A missing `model` fails the build and names the agent directory.
254
- - **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.
255
- - **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.
256
- - **Memory:** `config.memory` wins over `memory.ts`, and a warning is logged when both are present. If neither is set, the agent has no memory.
257
- - **Workspace:** `config.workspace` wins over `workspace.ts`, which wins over the default workspace.
258
- - **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.
259
-
260
- ## What happens at build time
261
-
262
- File-based agents are discovered by the Mastra **bundler**, the step that runs under `mastra dev` and `mastra build`.
263
-
264
- 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.
265
-
266
- When you consume Mastra as a library, register those agents in code instead of relying on file discovery:
267
-
268
- ```typescript
269
- import { Mastra } from '@mastra/core'
270
- import { Agent } from '@mastra/core/agent'
271
-
272
- const weather = new Agent({
273
- id: 'weather',
274
- name: 'weather',
275
- instructions: 'You are a helpful weather assistant.',
276
- model: 'openai/gpt-5.5',
277
- })
278
-
279
- export const mastra = new Mastra({
280
- agents: { weather },
281
- })
282
- ```
283
-
284
- ## Related
285
-
286
- - [Agents overview](https://mastra.ai/docs/agents/overview)
287
- - [Tools](https://mastra.ai/docs/agents/using-tools)
288
- - [Skills](https://mastra.ai/docs/agents/skills)
289
- - [Memory](https://mastra.ai/docs/memory/overview)
290
- - [Supervisor agents](https://mastra.ai/docs/agents/supervisor-agents)
291
- - [Workspace](https://mastra.ai/docs/workspace/overview)
292
- - [Studio overview](https://mastra.ai/docs/studio/overview)
293
- - [`Agent` reference](https://mastra.ai/reference/agents/agent)
294
- - [`createTool()` reference](https://mastra.ai/reference/tools/create-tool)
295
- - [`createSkill()` reference](https://mastra.ai/reference/agents/createSkill)
296
- - [`Memory` reference](https://mastra.ai/reference/memory/memory-class)
297
- - [`Workspace` reference](https://mastra.ai/reference/workspace/workspace-class)