@mastra/mcp-docs-server 1.2.3 → 1.2.4-alpha.5

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 (91) hide show
  1. package/.docs/docs/agent-controller/overview.md +1 -0
  2. package/.docs/docs/agent-controller/subagents.md +1 -0
  3. package/.docs/docs/agent-controller/threads-and-state.md +1 -0
  4. package/.docs/docs/agents/background-tasks.md +3 -3
  5. package/.docs/docs/agents/channels.md +4 -1
  6. package/.docs/docs/agents/code-mode.md +2 -0
  7. package/.docs/docs/agents/durable-agents.md +1 -1
  8. package/.docs/docs/agents/file-based-agents.md +1 -1
  9. package/.docs/docs/agents/goals.md +2 -0
  10. package/.docs/docs/agents/heartbeats.md +1 -1
  11. package/.docs/docs/agents/overview.md +104 -0
  12. package/.docs/docs/agents/processors.md +8 -2
  13. package/.docs/docs/agents/supervisor-agents.md +1 -0
  14. package/.docs/docs/agents/using-tools.md +3 -0
  15. package/.docs/docs/editor/overview.md +1 -0
  16. package/.docs/docs/evals/overview.md +1 -0
  17. package/.docs/docs/evals/quick-checks.md +1 -0
  18. package/.docs/docs/getting-started/build-with-ai.md +3 -5
  19. package/.docs/docs/getting-started/manual-install.md +15 -5
  20. package/.docs/docs/index.md +104 -0
  21. package/.docs/docs/memory/memory-processors.md +2 -0
  22. package/.docs/docs/memory/observational-memory.md +4 -0
  23. package/.docs/docs/memory/overview.md +3 -1
  24. package/.docs/docs/memory/semantic-recall.md +6 -0
  25. package/.docs/docs/observability/integrations/exporters/langfuse.md +1 -0
  26. package/.docs/docs/workspace/filesystem.md +3 -1
  27. package/.docs/docs/workspace/sandbox.md +2 -0
  28. package/.docs/guides/getting-started/quickstart.md +2 -0
  29. package/.docs/guides/migrations/agentnetwork.md +1 -0
  30. package/.docs/guides/migrations/upgrade-to-v1/memory.md +1 -0
  31. package/.docs/guides/migrations/upgrade-to-v1/voice.md +1 -0
  32. package/.docs/models/environment-variables.md +142 -0
  33. package/.docs/models/gateways/netlify.md +3 -2
  34. package/.docs/models/gateways/openrouter.md +4 -2
  35. package/.docs/models/gateways/vercel.md +4 -1
  36. package/.docs/models/index.md +8 -8
  37. package/.docs/models/providers/cerebras.md +5 -4
  38. package/.docs/models/providers/google.md +3 -1
  39. package/.docs/models/providers/llmgateway.md +2 -1
  40. package/.docs/models/providers/opencode.md +5 -1
  41. package/.docs/models/providers/zhipuai.md +1 -1
  42. package/.docs/reference/agents/agent.md +3 -2
  43. package/.docs/reference/agents/channels.md +5 -0
  44. package/.docs/reference/evals/hallucination.md +1 -0
  45. package/.docs/reference/evals/prompt-alignment.md +1 -0
  46. package/.docs/reference/index.md +2 -0
  47. package/.docs/reference/memory/memory-class.md +1 -0
  48. package/.docs/reference/memory/observational-memory.md +8 -0
  49. package/.docs/reference/observability/tracing/exporters/langfuse.md +1 -0
  50. package/.docs/reference/processors/batch-parts-processor.md +1 -0
  51. package/.docs/reference/processors/cost-guard-processor.md +1 -0
  52. package/.docs/reference/processors/message-history-processor.md +1 -0
  53. package/.docs/reference/processors/moderation-processor.md +2 -0
  54. package/.docs/reference/processors/pii-detector.md +2 -0
  55. package/.docs/reference/processors/prefill-error-handler.md +2 -0
  56. package/.docs/reference/processors/processor-interface.md +3 -2
  57. package/.docs/reference/processors/prompt-injection-detector.md +1 -0
  58. package/.docs/reference/processors/provider-history-compat.md +2 -0
  59. package/.docs/reference/processors/regex-filter-processor.md +1 -0
  60. package/.docs/reference/processors/response-cache.md +1 -0
  61. package/.docs/reference/processors/semantic-recall-processor.md +1 -0
  62. package/.docs/reference/processors/skill-search-processor.md +1 -0
  63. package/.docs/reference/processors/stream-error-retry-processor.md +2 -0
  64. package/.docs/reference/processors/system-prompt-scrubber.md +1 -0
  65. package/.docs/reference/processors/token-limiter-processor.md +3 -0
  66. package/.docs/reference/processors/tool-call-filter.md +2 -0
  67. package/.docs/reference/processors/tool-search-processor.md +2 -0
  68. package/.docs/reference/processors/working-memory-processor.md +1 -0
  69. package/.docs/reference/signals/signal-provider.md +1 -0
  70. package/.docs/reference/signals/task-signal-provider.md +1 -0
  71. package/.docs/reference/signals/webhook-signal-provider.md +1 -0
  72. package/.docs/reference/templates/overview.md +1 -0
  73. package/.docs/reference/tools/create-code-mode.md +1 -0
  74. package/.docs/reference/tools/create-tool.md +2 -0
  75. package/.docs/reference/tools/mcp-client.md +1 -0
  76. package/.docs/reference/tools/mcp-server.md +1 -1
  77. package/.docs/reference/voice/voice.addInstructions.md +1 -0
  78. package/.docs/reference/workspace/agentcore-runtime-sandbox.md +1 -0
  79. package/.docs/reference/workspace/agentfs-filesystem.md +1 -0
  80. package/.docs/reference/workspace/apple-container-sandbox.md +257 -0
  81. package/.docs/reference/workspace/archil-filesystem.md +1 -0
  82. package/.docs/reference/workspace/azure-blob-filesystem.md +1 -0
  83. package/.docs/reference/workspace/docker-sandbox.md +1 -0
  84. package/.docs/reference/workspace/e2b-sandbox.md +1 -0
  85. package/.docs/reference/workspace/files-sdk-filesystem.md +1 -0
  86. package/.docs/reference/workspace/gcs-filesystem.md +1 -0
  87. package/.docs/reference/workspace/mesa-filesystem.md +319 -0
  88. package/.docs/reference/workspace/s3-filesystem.md +1 -0
  89. package/.docs/reference/workspace/vercel.md +1 -0
  90. package/CHANGELOG.md +22 -0
  91. package/package.json +5 -5
@@ -54,6 +54,7 @@ import { AgentController } from '@mastra/core/agent-controller'
54
54
  import { LibSQLStore } from '@mastra/libsql'
55
55
 
56
56
  const agent = new Agent({
57
+ id: 'assistant',
57
58
  name: 'assistant',
58
59
  instructions: 'Help the user plan and complete tasks.',
59
60
  model: 'openai/gpt-5.5',
@@ -11,6 +11,7 @@ import { Agent } from '@mastra/core/agent'
11
11
  import { AgentController } from '@mastra/core/agent-controller'
12
12
 
13
13
  const agent = new Agent({
14
+ id: 'assistant',
14
15
  name: 'assistant',
15
16
  instructions: 'Use subagents when a focused task needs a narrower toolset.',
16
17
  model: 'openai/gpt-5.5',
@@ -84,6 +84,7 @@ import { AgentController } from '@mastra/core/agent-controller'
84
84
  import { z } from 'zod'
85
85
 
86
86
  const agent = new Agent({
87
+ id: 'assistant',
87
88
  name: 'assistant',
88
89
  instructions: 'Help the user manage a stateful session.',
89
90
  model: 'openai/gpt-5.5',
@@ -2,7 +2,7 @@
2
2
 
3
3
  **Added in:** `@mastra/core@1.29.0`
4
4
 
5
- Background tasks let an agent dispatch a long-running tool call without blocking the agentic loop. The tool returns an immediate acknowledgement, the LLM continues responding, and the task runs to completion in the background. When it finishes, its result is written to memory and if you use `stream()` with the [`untilIdle`](https://mastra.ai/reference/agents/agent) option the agent is re-invoked automatically so the result is processed in the same call.
5
+ Background tasks let an agent dispatch a long-running tool call without blocking the agentic loop. The tool returns an immediate acknowledgement, the LLM continues responding, and the task runs to completion in the background. When it finishes, its result is written to memory and if you use `stream()` with the [`untilIdle`](https://mastra.ai/reference/streaming/agents/stream) option the agent is re-invoked automatically so the result is processed in the same call.
6
6
 
7
7
  ## When to use background tasks
8
8
 
@@ -166,7 +166,7 @@ const stream = await agent.stream('Research solana for me', {
166
166
  })
167
167
  ```
168
168
 
169
- > **Note:** Visit [`Agent.stream()`](https://mastra.ai/reference/agents/agent) for the full API.
169
+ > **Note:** Visit [`Agent.stream()`](https://mastra.ai/reference/streaming/agents/stream) for the full API.
170
170
 
171
171
  ### Aggregate properties
172
172
 
@@ -372,7 +372,7 @@ These read from storage rather than the pubsub stream, so they're suitable for p
372
372
 
373
373
  ## Related
374
374
 
375
- - [`Agent.stream()` reference](https://mastra.ai/reference/agents/agent)
375
+ - [`Agent.stream()` reference](https://mastra.ai/reference/streaming/agents/stream)
376
376
  - [backgroundTasks configuration reference](https://mastra.ai/reference/configuration)
377
377
  - [Durable agents](https://mastra.ai/docs/agents/durable-agents)
378
378
  - [Supervisor agents](https://mastra.ai/docs/agents/supervisor-agents)
@@ -135,6 +135,7 @@ import { createDiscordAdapter } from '@chat-adapter/discord'
135
135
  import { google } from '@ai-sdk/google'
136
136
 
137
137
  export const visionAgent = new Agent({
138
+ id: 'vision-agent',
138
139
  name: 'Vision Agent',
139
140
  instructions: 'You can see images, watch videos, and listen to audio.',
140
141
  model: google('gemini-3.1-flash-image-preview'),
@@ -175,10 +176,12 @@ A channel webhook returns a `200` response right away, then the agent runs in th
175
176
  On Vercel, pass `waitUntil` from `@vercel/functions`:
176
177
 
177
178
  ```typescript
179
+ import { Agent } from '@mastra/core/agent'
180
+ import { createSlackAdapter } from '@chat-adapter/slack'
178
181
  import { waitUntil } from '@vercel/functions'
179
182
 
180
183
  export const agent = new Agent({
181
- // ...
184
+ id: 'agent',
182
185
  channels: {
183
186
  adapters: {
184
187
  slack: createSlackAdapter(),
@@ -59,6 +59,7 @@ const { tool, instructions } = createCodeMode({
59
59
  })
60
60
 
61
61
  const agent = new Agent({
62
+ id: 'shop-assistant',
62
63
  name: 'shop-assistant',
63
64
  instructions: ['You are a helpful shopping assistant.', instructions],
64
65
  model: 'openai/gpt-5.5',
@@ -113,6 +114,7 @@ const inventory = createCodeMode({
113
114
  })
114
115
 
115
116
  const agent = new Agent({
117
+ id: 'ops-assistant',
116
118
  name: 'ops-assistant',
117
119
  instructions: ['You are an ops assistant.', sales.instructions, inventory.instructions],
118
120
  model: 'openai/gpt-5.5',
@@ -172,7 +172,7 @@ export const durableAgent = createDurableAgent({
172
172
 
173
173
  ## Streaming with background tasks
174
174
 
175
- Durable agents support the same [`untilIdle`](https://mastra.ai/reference/agents/durable-agent) option as regular agents. When `untilIdle` is set, `stream()` keeps the connection open across background-task continuations until the agent is idle:
175
+ Durable agents support the same [`untilIdle`](https://mastra.ai/reference/streaming/agents/stream) option as regular agents. When `untilIdle` is set, `stream()` keeps the connection open across background-task continuations until the agent is idle:
176
176
 
177
177
  ```typescript
178
178
  const { output, cleanup } = await durableAgent.stream('Research and summarize the topic', {
@@ -237,7 +237,7 @@ Naming rules:
237
237
  File-based and code-based agents coexist with deterministic rules:
238
238
 
239
239
  - **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.
240
- - **A folder can hold a code agent:** If `config.ts` exports `new Agent({...})`, that instance is used as-is. Sibling `instructions.md`, `tools/`, `skills/`, `memory.ts`, `workspace.ts`, and `subagents/` entries are ignored with warnings.
240
+ - **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.
241
241
  - **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.
242
242
  - **Model:** A missing `model` fails the build and names the agent directory.
243
243
  - **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.
@@ -26,6 +26,7 @@ Goals require a configured [storage](https://mastra.ai/docs/memory/storage) back
26
26
  import { Agent } from '@mastra/core/agent'
27
27
 
28
28
  const worker = new Agent({
29
+ id: 'worker',
29
30
  name: 'worker',
30
31
  instructions: 'You complete software tasks end to end.',
31
32
  model: 'openai/gpt-5.5',
@@ -66,6 +67,7 @@ By default the step uses a built-in LLM-as-judge scorer that returns `1` when th
66
67
 
67
68
  ```typescript
68
69
  const worker = new Agent({
70
+ id: 'worker',
69
71
  name: 'worker',
70
72
  instructions: 'You complete software tasks end to end.',
71
73
  model: 'openai/gpt-5.5',
@@ -2,7 +2,7 @@
2
2
 
3
3
  **Added in:** `@mastra/core@1.46.0`
4
4
 
5
- > **Beta:** This feature is in alpha. Breaking changes may occur without a major version bump until the API is stable.
5
+ > **Beta:** This feature is in beta. Breaking changes may occur without a major version bump until the API is stable.
6
6
 
7
7
  A heartbeat runs an agent on a cron schedule. On each fire, Mastra sends a prompt to the agent, either as a [signal](https://mastra.ai/docs/agents/signals) into a thread or as a threadless `agent.generate()` run. Use heartbeats for recurring agent work such as daily summaries, periodic checks, or scheduled nudges into a conversation.
8
8
 
@@ -2,6 +2,110 @@
2
2
 
3
3
  Agents use LLMs and tools to solve open-ended tasks. They reason about goals, decide which tools to use, retain conversation memory, and iterate internally until the model emits a final answer or an optional stop condition is met. Agents produce structured responses you can render in your UI or process programmatically. Use agents directly or compose them into workflows or multi-agent systems.
4
4
 
5
+ **For AI agents:** If you're tasked to build a Mastra project from scratch, follow the condensed instructions until the next heading. Adjust the example code for the agent & tool to your needs. A complete list of documentation is available at <https://mastra.ai/llms.txt>
6
+
7
+ Create a `package.json` file with `{ "type": "module" }`. Install the required dependencies: `npm install @mastra/core@latest zod@latest typescript@latest @types/node@latest mastra@latest`
8
+
9
+ Create a tsconfig.json file:
10
+
11
+ ```json
12
+ {
13
+ "compilerOptions": {
14
+ "target": "ES2022",
15
+ "module": "ES2022",
16
+ "moduleResolution": "bundler",
17
+ "esModuleInterop": true,
18
+ "forceConsistentCasingInFileNames": true,
19
+ "strict": true,
20
+ "skipLibCheck": true,
21
+ "noEmit": true,
22
+ "allowImportingTsExtensions": true,
23
+ "outDir": "dist"
24
+ },
25
+ "include": ["src/**/*"]
26
+ }
27
+ ```
28
+
29
+ If you need to add a tool to the agent, create a new file and use `import { createTool } from "@mastra/core/tools"`. Plain object tool definitions silently fail to execute; tools MUST be defined via createTool() with id, description, inputSchema (zod), execute.
30
+
31
+ Example:
32
+
33
+ ```ts
34
+ // src/mastra/tools/weather-tool.ts
35
+ import { createTool } from '@mastra/core/tools'
36
+ import { z } from 'zod'
37
+
38
+ export const weatherTool = createTool({
39
+ id: 'get-weather',
40
+ description: 'Get current weather for a location',
41
+ inputSchema: z.object({
42
+ location: z.string().describe('City name'),
43
+ }),
44
+ outputSchema: z.object({
45
+ output: z.string(),
46
+ }),
47
+ execute: async ({ location }) => {
48
+ return {
49
+ output: `The weather in ${location} is sunny`,
50
+ }
51
+ },
52
+ })
53
+ ```
54
+
55
+ If you need to create an agent, create a new file and use `import { Agent } from "@mastra/core/agent"`. Constructor takes `{ id, name, instructions, model: 'openai/gpt-5.5' }`. The model string is Mastra's model router format ('provider/model'; use / and not : to separate provider and model). Do not install any ai-sdk package unless Mastra's documentation says otherwise.
56
+
57
+ Add a tool an agent by importing the tool and passing it to the agent constructor as a tools object.
58
+
59
+ Example:
60
+
61
+ ```ts
62
+ // src/mastra/agents/weather-agent.ts
63
+ import { Agent } from '@mastra/core/agent'
64
+ import { weatherTool } from '../tools/weather-tool.ts'
65
+
66
+ export const weatherAgent = new Agent({
67
+ id: 'weather-agent',
68
+ name: 'Weather Agent',
69
+ instructions: `
70
+ You are a helpful weather assistant that provides accurate weather information.
71
+
72
+ Your primary function is to help users get weather details for specific locations. When responding:
73
+ - Include relevant details like humidity, wind conditions, and precipitation
74
+ - Keep responses concise but informative
75
+
76
+ Use the weatherTool to fetch current weather data.
77
+ `,
78
+ model: 'openai/gpt-5.5',
79
+ tools: { weatherTool },
80
+ })
81
+ ```
82
+
83
+ The defined model requires an environment variable to be set for the provider. OpenAI: `OPENAI_API_KEY`. Anthropic: `ANTHROPIC_API_KEY`. Google: `GOOGLE_API_KEY`. Go to <https://mastra.ai/models/environment-variables> for a full list of supported providers and their environment variable names.
84
+
85
+ Create a Mastra entry point at `src/mastra/index.ts` and register the agent:
86
+
87
+ ```ts
88
+ import { Mastra } from '@mastra/core'
89
+ import { weatherAgent } from './agents/weather-agent.ts'
90
+
91
+ export const mastra = new Mastra({
92
+ agents: { weatherAgent },
93
+ })
94
+ ```
95
+
96
+ You're now able to run the agent directly. For this, import the Mastra instance and call the agent.generate() after retrieving the agent by its id. Node.js 22.18.0 and later are able to run TypeScript files directly. Make sure to add file extensions when importing local files. Example:
97
+
98
+ ```ts
99
+ // run.mjs
100
+ import { mastra } from './src/mastra/index.ts'
101
+
102
+ const agent = mastra.getAgentById('weather-agent')
103
+ const response = await agent.generate('Weather in SF')
104
+ console.log(response.text)
105
+ ```
106
+
107
+ If your tasks requires to add other features, refer to the full list of docs at <https://mastra.ai/llms.txt>
108
+
5
109
  ## When to use agents
6
110
 
7
111
  Use agents when the task is open-ended and the steps aren't known in advance. An agent decides which tools to call, how many times to loop, and when to stop. You provide the goal and constraints instead of defining each step. For predetermined, multi-step processes with explicit control flow, use [workflows](https://mastra.ai/docs/workflows/overview) instead.
@@ -37,6 +37,7 @@ import { Agent } from '@mastra/core/agent'
37
37
  import { ModerationProcessor } from '@mastra/core/processors'
38
38
 
39
39
  export const moderatedAgent = new Agent({
40
+ id: 'moderated-agent',
40
41
  name: 'moderated-agent',
41
42
  instructions: 'You are a helpful assistant',
42
43
  model: 'openai/gpt-5-mini',
@@ -92,6 +93,7 @@ import { Agent } from '@mastra/core/agent'
92
93
  import { PrefillErrorHandler, TokenLimiter, ModerationProcessor } from '@mastra/core/processors'
93
94
 
94
95
  const agent = new Agent({
96
+ id: 'support-agent',
95
97
  name: 'support-agent',
96
98
  model: 'openai/gpt-5',
97
99
  instructions: '...',
@@ -112,7 +114,7 @@ Each array also accepts a function that returns an array, so processors can be b
112
114
 
113
115
  ```typescript
114
116
  new Agent({
115
- // ...
117
+ id: 'processors-agent',
116
118
  inputProcessors: ({ requestContext }) => {
117
119
  const limit = requestContext.get('tokenLimit') ?? 4000
118
120
  return [new TokenLimiter(limit)]
@@ -381,6 +383,7 @@ import { Agent } from '@mastra/core/agent'
381
383
  import { TokenLimiter } from '@mastra/core/processors'
382
384
 
383
385
  const agent = new Agent({
386
+ id: 'my-agent',
384
387
  name: 'my-agent',
385
388
  model: 'openai/gpt-5.5',
386
389
  inputProcessors: [new TokenLimiter(127000)],
@@ -449,6 +452,7 @@ import { ResponseCache } from '@mastra/core/processors'
449
452
  const cache = new InMemoryServerCache()
450
453
 
451
454
  export const searchAgent = new Agent({
455
+ id: 'search-agent',
452
456
  name: 'Search Agent',
453
457
  instructions: 'You answer questions concisely.',
454
458
  model: 'openai/gpt-5',
@@ -494,7 +498,7 @@ Override explicitly when you need a different scope:
494
498
 
495
499
  ```typescript
496
500
  new Agent({
497
- // ...
501
+ id: 'processors-agent',
498
502
  inputProcessors: [
499
503
  new ResponseCache({
500
504
  cache,
@@ -518,6 +522,7 @@ import { RedisCache } from '@mastra/redis'
518
522
  const cache = new RedisCache({ url: process.env.REDIS_URL })
519
523
 
520
524
  export const agent = new Agent({
525
+ id: 'cached-agent',
521
526
  name: 'Cached Agent',
522
527
  instructions: '...',
523
528
  model: 'openai/gpt-5',
@@ -617,6 +622,7 @@ import { EnsureFinalResponseProcessor } from '../processors/ensure-final-respons
617
622
  const MAX_STEPS = 5
618
623
 
619
624
  const agent = new Agent({
625
+ id: 'agent',
620
626
  instructions: `You are a helpful assistant.
621
627
 
622
628
  Some messages you receive may contain <system-reminder>...</system-reminder> tags.
@@ -351,6 +351,7 @@ Each subagent should have a clear `description` that explains what it does, what
351
351
 
352
352
  ```typescript
353
353
  const supervisor = new Agent({
354
+ id: 'supervisor',
354
355
  instructions: `You coordinate research and writing tasks.
355
356
 
356
357
  Available resources:
@@ -242,6 +242,7 @@ Use `hooks` to run custom logic before and after every tool call an agent makes.
242
242
  import { Agent } from '@mastra/core/agent'
243
243
 
244
244
  export const supportAgent = new Agent({
245
+ id: 'support-agent',
245
246
  name: 'support-agent',
246
247
  instructions: 'Help users with their questions.',
247
248
  model: 'openai/gpt-5.5',
@@ -260,6 +261,7 @@ export const supportAgent = new Agent({
260
261
 
261
262
  ```typescript
262
263
  const guardedAgent = new Agent({
264
+ id: 'guarded-agent',
263
265
  name: 'guarded-agent',
264
266
  instructions: 'Run shell commands for the user.',
265
267
  model: 'openai/gpt-5.5',
@@ -392,6 +394,7 @@ Subagents and workflows follow the same pattern. They're converted to tools with
392
394
 
393
395
  ```typescript
394
396
  const orchestrator = new Agent({
397
+ id: 'orchestrator',
395
398
  agents: {
396
399
  weather: weatherAgent, // toolName: "agent-weather"
397
400
  },
@@ -194,6 +194,7 @@ Use the `editor` field on a code-defined agent to control which fields the edito
194
194
  import { Agent } from '@mastra/core/agent'
195
195
 
196
196
  export const supportAgent = new Agent({
197
+ id: 'support-agent',
197
198
  name: 'support-agent',
198
199
  model: 'openai/gpt-5.5',
199
200
  editor: { instructions: true, tools: { description: true } },
@@ -55,6 +55,7 @@ import { Agent } from '@mastra/core/agent'
55
55
  import { createAnswerRelevancyScorer, createToxicityScorer } from '@mastra/evals/scorers/prebuilt'
56
56
 
57
57
  export const evaluatedAgent = new Agent({
58
+ id: 'evaluated-agent',
58
59
  scorers: {
59
60
  relevancy: {
60
61
  scorer: createAnswerRelevancyScorer({ model: 'openai/gpt-5-mini' }),
@@ -100,6 +100,7 @@ import { Agent } from '@mastra/core/agent'
100
100
  import { checks } from '@mastra/evals/checks'
101
101
 
102
102
  export const weatherAgent = new Agent({
103
+ id: 'weather-agent',
103
104
  name: 'Weather Agent',
104
105
  instructions: 'Answer weather questions using the get_weather tool.',
105
106
  model: 'openai/gpt-5.5',
@@ -132,13 +132,11 @@ In addition to the [context files](#context-files) each documentation page also
132
132
 
133
133
  ## MCP docs server
134
134
 
135
- The `@mastra/mcp-docs-server` package provides direct access to Mastra’s full documentation via the [Model Context Protocol (MCP)](https://modelcontextprotocol.io/docs/getting-started/intro). It works with Cursor, Windsurf, Cline, Claude Code, VS Code, Codex or any tool that supports MCP.
135
+ The `@mastra/mcp-docs-server` package provides direct local access to Mastra’s full documentation via the [Model Context Protocol (MCP)](https://modelcontextprotocol.io/docs/getting-started/intro). It works with Cursor, Windsurf, Cline, Claude Code, VS Code, Codex or any tool that supports MCP.
136
136
 
137
- These tools are designed to help agents retrieve precise, task-specific information whether you're adding a feature to an agent, scaffolding a new project, or exploring how something works.
137
+ These tools are designed to help agents retrieve precise, task-specific information, whether you're adding a feature to an agent, scaffolding a new project, or exploring how something works.
138
138
 
139
- In this guide you'll learn how to add Mastra's MCP server to your AI tooling.
140
-
141
- [YouTube video player](https://www.youtube-nocookie.com/embed/vciV57lF0og)
139
+ If you're unable to use a local MCP server and need to connect to a remote server, use this URL: `https://mastra.mcp.kapa.ai`. You need to authenticate with your Google Account (only an anonymous ID is transmitted) for rate-limiting purposes. If possible, Mastra recommends using a local MCP server for better performance and reliability.
142
140
 
143
141
  ### Installation
144
142
 
@@ -1,5 +1,7 @@
1
1
  # Manual install
2
2
 
3
+ **For AI agents:** Use this guide when tasked to create a runnable Mastra project from scratch without a CLI/boilerplate. It provides code examples for agents, tools, model configuration and how to install dependencies. Do not navigate to the quickstart guide, which is for humans.
4
+
3
5
  > **Info:** Use this guide to manually build a standalone Mastra server step by step. In most cases, it's quicker to follow the [quickstart guide](https://mastra.ai/guides/getting-started/quickstart), which achieves the same result using the [`mastra create`](https://mastra.ai/reference/cli/create-mastra) command. For existing projects, you can also use [`mastra init`](https://mastra.ai/reference/cli/mastra).
4
6
 
5
7
  If you prefer not to use our automatic CLI tool, you can set up your project yourself by following the guide below.
@@ -118,12 +120,16 @@ If you prefer not to use our automatic CLI tool, you can set up your project you
118
120
 
119
121
  > **Note:** This guide uses Google Gemini, but you can use any supported [model provider](https://mastra.ai/models), including OpenAI, Anthropic, and more.
120
122
 
123
+ You can also use OpenAI (`OPENAI_API_KEY`) or Anthropic (`ANTHROPIC_API_KEY`) instead of Google Gemini. Go to <https://mastra.ai/models/environment-variables> for a full list of supported providers and their environment variable names.
124
+
121
125
  4. Create a `weather-tool.ts` file:
122
126
 
123
127
  ```bash
124
128
  mkdir -p src/mastra/tools && touch src/mastra/tools/weather-tool.ts
125
129
  ```
126
130
 
131
+ Use `import { createTool } from "@mastra/core/tools"`. Plain object tool definitions silently fail to execute; tools MUST be defined via createTool() with id, description, inputSchema (zod), execute
132
+
127
133
  Add the following code:
128
134
 
129
135
  ```ts
@@ -139,9 +145,9 @@ If you prefer not to use our automatic CLI tool, you can set up your project you
139
145
  outputSchema: z.object({
140
146
  output: z.string(),
141
147
  }),
142
- execute: async () => {
148
+ execute: async ({ location }) => {
143
149
  return {
144
- output: 'The weather is sunny',
150
+ output: `The weather in ${location} is sunny`,
145
151
  }
146
152
  },
147
153
  })
@@ -155,11 +161,13 @@ If you prefer not to use our automatic CLI tool, you can set up your project you
155
161
  mkdir -p src/mastra/agents && touch src/mastra/agents/weather-agent.ts
156
162
  ```
157
163
 
164
+ Use `import { Agent } from "@mastra/core/agent"`. Constructor takes `{ id, name, instructions, model: 'openai/gpt-5.5' }`. The model string is Mastra's model router format ('provider/model'; use / and not : to separate provider and model). Do not install any ai-sdk package unless Mastra's documentation says otherwise.
165
+
158
166
  Add the following code:
159
167
 
160
168
  ```ts
161
169
  import { Agent } from '@mastra/core/agent'
162
- import { weatherTool } from '../tools/weather-tool'
170
+ import { weatherTool } from '../tools/weather-tool.ts'
163
171
 
164
172
  export const weatherAgent = new Agent({
165
173
  id: 'weather-agent',
@@ -191,14 +199,16 @@ If you prefer not to use our automatic CLI tool, you can set up your project you
191
199
 
192
200
  ```ts
193
201
  import { Mastra } from '@mastra/core'
194
- import { weatherAgent } from './agents/weather-agent'
202
+ import { weatherAgent } from './agents/weather-agent.ts'
195
203
 
196
204
  export const mastra = new Mastra({
197
205
  agents: { weatherAgent },
198
206
  })
199
207
  ```
200
208
 
201
- 7. You can now launch [Studio](https://mastra.ai/docs/studio/overview) and test your agent.
209
+ 7. **For AI agents:** Do not launch Studio when working on a script that e.g. should print to the console. Studio is a long-running web-based interfaced for humans. Instead, call the agent.generate() method directly. Example: `import { mastra } from './src/mastra/index.ts'; const agent = mastra.getAgentById('weather-agent'); const response = await agent.generate('Weather in SF'); console.log(response.text);`
210
+
211
+ You can now launch [Studio](https://mastra.ai/docs/studio/overview) and test your agent.
202
212
 
203
213
  **npm**:
204
214
 
@@ -2,6 +2,110 @@
2
2
 
3
3
  Build AI agents your users actually depend on. Mastra is a TypeScript framework that gives you everything you need to prototype fast and ship with confidence. Create your first agent with a single command and start building.
4
4
 
5
+ **For AI agents:** If you're tasked to build a Mastra project from scratch, follow the condensed instructions until the next heading. Adjust the example code for the agent & tool to your needs. A complete list of documentation is available at <https://mastra.ai/llms.txt>
6
+
7
+ Create a `package.json` file with `{ "type": "module" }`. Install the required dependencies: `npm install @mastra/core@latest zod@latest typescript@latest @types/node@latest mastra@latest`
8
+
9
+ Create a tsconfig.json file:
10
+
11
+ ```json
12
+ {
13
+ "compilerOptions": {
14
+ "target": "ES2022",
15
+ "module": "ES2022",
16
+ "moduleResolution": "bundler",
17
+ "esModuleInterop": true,
18
+ "forceConsistentCasingInFileNames": true,
19
+ "strict": true,
20
+ "skipLibCheck": true,
21
+ "noEmit": true,
22
+ "allowImportingTsExtensions": true,
23
+ "outDir": "dist"
24
+ },
25
+ "include": ["src/**/*"]
26
+ }
27
+ ```
28
+
29
+ If you need to add a tool to the agent, create a new file and use `import { createTool } from "@mastra/core/tools"`. Plain object tool definitions silently fail to execute; tools MUST be defined via createTool() with id, description, inputSchema (zod), execute.
30
+
31
+ Example:
32
+
33
+ ```ts
34
+ // src/mastra/tools/weather-tool.ts
35
+ import { createTool } from '@mastra/core/tools'
36
+ import { z } from 'zod'
37
+
38
+ export const weatherTool = createTool({
39
+ id: 'get-weather',
40
+ description: 'Get current weather for a location',
41
+ inputSchema: z.object({
42
+ location: z.string().describe('City name'),
43
+ }),
44
+ outputSchema: z.object({
45
+ output: z.string(),
46
+ }),
47
+ execute: async ({ location }) => {
48
+ return {
49
+ output: `The weather in ${location} is sunny`,
50
+ }
51
+ },
52
+ })
53
+ ```
54
+
55
+ If you need to create an agent, create a new file and use `import { Agent } from "@mastra/core/agent"`. Constructor takes `{ id, name, instructions, model: 'openai/gpt-5.5' }`. The model string is Mastra's model router format ('provider/model'; use / and not : to separate provider and model). Do not install any ai-sdk package unless Mastra's documentation says otherwise.
56
+
57
+ Add a tool an agent by importing the tool and passing it to the agent constructor as a tools object.
58
+
59
+ Example:
60
+
61
+ ```ts
62
+ // src/mastra/agents/weather-agent.ts
63
+ import { Agent } from '@mastra/core/agent'
64
+ import { weatherTool } from '../tools/weather-tool.ts'
65
+
66
+ export const weatherAgent = new Agent({
67
+ id: 'weather-agent',
68
+ name: 'Weather Agent',
69
+ instructions: `
70
+ You are a helpful weather assistant that provides accurate weather information.
71
+
72
+ Your primary function is to help users get weather details for specific locations. When responding:
73
+ - Include relevant details like humidity, wind conditions, and precipitation
74
+ - Keep responses concise but informative
75
+
76
+ Use the weatherTool to fetch current weather data.
77
+ `,
78
+ model: 'openai/gpt-5.5',
79
+ tools: { weatherTool },
80
+ })
81
+ ```
82
+
83
+ The defined model requires an environment variable to be set for the provider. OpenAI: `OPENAI_API_KEY`. Anthropic: `ANTHROPIC_API_KEY`. Google: `GOOGLE_API_KEY`. Go to <https://mastra.ai/models/environment-variables> for a full list of supported providers and their environment variable names.
84
+
85
+ Create a Mastra entry point at `src/mastra/index.ts` and register the agent:
86
+
87
+ ```ts
88
+ import { Mastra } from '@mastra/core'
89
+ import { weatherAgent } from './agents/weather-agent.ts'
90
+
91
+ export const mastra = new Mastra({
92
+ agents: { weatherAgent },
93
+ })
94
+ ```
95
+
96
+ You're now able to run the agent directly. For this, import the Mastra instance and call the agent.generate() after retrieving the agent by its id. Node.js 22.18.0 and later are able to run TypeScript files directly. Make sure to add file extensions when importing local files. Example:
97
+
98
+ ```ts
99
+ // run.mjs
100
+ import { mastra } from './src/mastra/index.ts'
101
+
102
+ const agent = mastra.getAgentById('weather-agent')
103
+ const response = await agent.generate('Weather in SF')
104
+ console.log(response.text)
105
+ ```
106
+
107
+ If your tasks requires to add other features, refer to the full list of docs at <https://mastra.ai/llms.txt>
108
+
5
109
  ## Quickstart
6
110
 
7
111
  Run this command to create a new project:
@@ -248,6 +248,7 @@ const contentBlocker = {
248
248
  }
249
249
 
250
250
  const agent = new Agent({
251
+ id: 'safe-agent',
251
252
  name: 'safe-agent',
252
253
  instructions: 'You are a helpful assistant',
253
254
  model: 'openai/gpt-5.5',
@@ -287,6 +288,7 @@ const inputValidator = {
287
288
  }
288
289
 
289
290
  const agent = new Agent({
291
+ id: 'validated-agent',
290
292
  name: 'validated-agent',
291
293
  instructions: 'You are a helpful assistant',
292
294
  model: 'openai/gpt-5.5',
@@ -13,6 +13,7 @@ import { Memory } from '@mastra/memory'
13
13
  import { Agent } from '@mastra/core/agent'
14
14
 
15
15
  export const agent = new Agent({
16
+ id: 'my-agent',
16
17
  name: 'my-agent',
17
18
  instructions: 'You are a helpful assistant.',
18
19
  model: 'openai/gpt-5-mini',
@@ -57,6 +58,7 @@ import { Memory } from '@mastra/memory'
57
58
  import { Agent } from '@mastra/core/agent'
58
59
 
59
60
  export const agent = new Agent({
61
+ id: 'my-agent',
60
62
  name: 'my-agent',
61
63
  instructions: 'You are a helpful assistant.',
62
64
  model: 'openai/gpt-5-mini',
@@ -196,6 +198,7 @@ const memory = new Memory({
196
198
  })
197
199
 
198
200
  export const agent = new Agent({
201
+ id: 'assistant',
199
202
  name: 'assistant',
200
203
  instructions: 'You are a helpful assistant.',
201
204
  model: 'openai/gpt-5-mini',
@@ -281,6 +284,7 @@ If your Observer model is text-only or its API rejects multimodal input, set `ob
281
284
 
282
285
  ```typescript
283
286
  new Agent({
287
+ id: 'assistant',
284
288
  name: 'assistant',
285
289
  instructions: 'You are a helpful assistant.',
286
290
  model: 'openai/gpt-5-mini',
@@ -174,7 +174,9 @@ Each delegation creates a fresh `threadId` and a deterministic `resourceId` for
174
174
 
175
175
  - **Thread ID**: Unique per delegation. The subagent starts with a clean message history every time it's called.
176
176
  - **Resource ID**: Derived as `{parentResourceId}-{agentName}`. Because the resource ID is stable across delegations, resource-scoped memory persists between calls. A subagent remembers facts from previous delegations by the same user.
177
- - **Memory instance**: If a subagent has no memory configured, it inherits the supervisor's `Memory` instance. If the subagent defines its own, that takes precedence.
177
+ - **Memory instance**: If a subagent has no memory configured, it inherits the supervisor's `Memory` instance, including all of its options. If the subagent defines its own, that takes precedence.
178
+
179
+ > **Note:** Title generation (`generateTitle`) is a top-level thread concern and is **not** applied to inherited subagent threads. Because each delegation creates an ephemeral thread that no one sees, running title generation for it would waste an LLM call per delegation. To generate titles for a subagent's own threads, give that subagent its own memory configuration.
178
180
 
179
181
  The supervisor forwards its conversation context to the subagent so it has enough background to complete the task. Only the delegation prompt and the subagent's response are saved — the full parent conversation isn't stored. You can control which messages reach the subagent with the [`messageFilter`](https://mastra.ai/docs/agents/supervisor-agents) callback.
180
182