@mastra/mcp-docs-server 1.2.15 → 1.2.16-alpha.3

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 (141) hide show
  1. package/.docs/docs/agents/agent-approval.md +5 -5
  2. package/.docs/docs/agents/overview.md +4 -4
  3. package/.docs/docs/browser/overview.md +1 -1
  4. package/.docs/docs/capabilities/channels.md +5 -5
  5. package/.docs/docs/capabilities/subagents.md +1 -1
  6. package/.docs/docs/connections/overview.md +1 -1
  7. package/.docs/docs/datasets/overview.md +1 -1
  8. package/.docs/docs/deployment/cloud-providers.md +4 -2
  9. package/.docs/docs/deployment/mastra-server.md +1 -1
  10. package/.docs/docs/deployment/monorepo.md +1 -1
  11. package/.docs/docs/deployment/overview.md +4 -1
  12. package/.docs/docs/deployment/sandbox.md +1 -1
  13. package/.docs/docs/deployment/web-framework.md +1 -1
  14. package/.docs/docs/deployment/workers.md +248 -2
  15. package/.docs/docs/evals/overview.md +1 -1
  16. package/.docs/docs/evals/quick-checks.md +1 -1
  17. package/.docs/docs/guides/multi-agent-systems.md +1 -1
  18. package/.docs/docs/harness/agent-controller.md +5 -5
  19. package/.docs/docs/harness/overview.md +1 -1
  20. package/.docs/docs/index.md +3 -3
  21. package/.docs/docs/long-running-agents/signal-providers.md +2 -2
  22. package/.docs/docs/mastra-platform/deploy.md +1 -1
  23. package/.docs/docs/mastra-platform/observability.md +63 -18
  24. package/.docs/docs/mastra-platform/overview.md +1 -1
  25. package/.docs/docs/mcp/overview.md +1 -1
  26. package/.docs/docs/memory/working-memory.md +1 -1
  27. package/.docs/docs/observability/integrations/exporters/mastra-storage.md +2 -2
  28. package/.docs/docs/observability/logging.md +1 -1
  29. package/.docs/docs/observability/metrics/overview.md +1 -1
  30. package/.docs/docs/observability/overview.md +1 -5
  31. package/.docs/docs/observability/tracing/overview.md +3 -6
  32. package/.docs/docs/server/auth/workers.md +1 -1
  33. package/.docs/docs/server/auth.md +5 -5
  34. package/.docs/docs/server/mastra-client.md +1 -1
  35. package/.docs/docs/server/mastra-server.md +1 -1
  36. package/.docs/docs/storage/overview.md +7 -6
  37. package/.docs/docs/workflows/human-in-the-loop.md +2 -2
  38. package/.docs/docs/workflows/overview.md +2 -2
  39. package/.docs/docs/workspace/lsp.md +27 -0
  40. package/.docs/docs/workspace/sandbox.md +11 -12
  41. package/.docs/integrations/agentic-ui/ai-sdk-ui.md +1 -1
  42. package/.docs/integrations/agentic-ui/assistant-ui.md +1 -1
  43. package/.docs/integrations/agentic-ui/copilotkit.md +1 -1
  44. package/.docs/integrations/agentic-ui/openui.md +1 -1
  45. package/.docs/integrations/databases/postgresql.md +8 -8
  46. package/.docs/integrations/deploy/amazon-ec2.md +2 -2
  47. package/.docs/integrations/deploy/aws-bedrock-agentcore.md +1 -1
  48. package/.docs/integrations/deploy/aws-lambda.md +2 -2
  49. package/.docs/integrations/deploy/azure-app-services.md +2 -2
  50. package/.docs/integrations/deploy/cloudflare.md +2 -2
  51. package/.docs/integrations/deploy/digital-ocean.md +2 -2
  52. package/.docs/integrations/deploy/inngest.md +1 -1
  53. package/.docs/integrations/deploy/kubernetes.md +2 -3
  54. package/.docs/integrations/deploy/netlify.md +2 -2
  55. package/.docs/integrations/deploy/temporal.md +1 -1
  56. package/.docs/integrations/deploy/vercel.md +2 -2
  57. package/.docs/integrations/file-storage/agentfs.md +1 -1
  58. package/.docs/integrations/file-storage/amazon-s3.md +1 -1
  59. package/.docs/integrations/file-storage/archil.md +1 -1
  60. package/.docs/integrations/file-storage/azure-blob.md +1 -1
  61. package/.docs/integrations/file-storage/google-cloud-storage.md +1 -1
  62. package/.docs/integrations/file-storage/google-drive.md +1 -1
  63. package/.docs/integrations/file-storage/mesa.md +1 -1
  64. package/.docs/integrations/file-storage/vercel-files.md +1 -1
  65. package/.docs/integrations/frameworks/astro.md +1 -1
  66. package/.docs/integrations/frameworks/electron.md +1 -1
  67. package/.docs/integrations/frameworks/express.md +1 -1
  68. package/.docs/integrations/frameworks/hono.md +1 -1
  69. package/.docs/integrations/frameworks/nestjs.md +1 -1
  70. package/.docs/integrations/frameworks/next-js.md +1 -1
  71. package/.docs/integrations/frameworks/nuxt.md +1 -1
  72. package/.docs/integrations/frameworks/sveltekit.md +1 -1
  73. package/.docs/integrations/frameworks/vite-react.md +1 -1
  74. package/.docs/integrations/sandboxes/agentcore.md +1 -1
  75. package/.docs/integrations/sandboxes/apple-container.md +1 -1
  76. package/.docs/integrations/sandboxes/blaxel.md +1 -1
  77. package/.docs/integrations/sandboxes/daytona.md +1 -1
  78. package/.docs/integrations/sandboxes/docker.md +1 -1
  79. package/.docs/integrations/sandboxes/e2b.md +1 -1
  80. package/.docs/integrations/sandboxes/modal.md +1 -1
  81. package/.docs/integrations/sandboxes/railway.md +1 -1
  82. package/.docs/integrations/sandboxes/vercel.md +3 -1
  83. package/.docs/integrations/tools/firecrawl.md +2 -2
  84. package/.docs/integrations/voice/livekit.md +3 -3
  85. package/.docs/integrations.md +108 -108
  86. package/.docs/models/environment-variables.md +2 -0
  87. package/.docs/models/gateways/openrouter.md +5 -1
  88. package/.docs/models/gateways/vercel.md +3 -2
  89. package/.docs/models/index.md +1 -1
  90. package/.docs/models/providers/aiand.md +3 -2
  91. package/.docs/models/providers/digitalocean.md +3 -2
  92. package/.docs/models/providers/edenai.md +88 -0
  93. package/.docs/models/providers/hyper.md +3 -3
  94. package/.docs/models/providers/inceptron.md +8 -9
  95. package/.docs/models/providers/kilo.md +11 -6
  96. package/.docs/models/providers/llmgateway.md +3 -1
  97. package/.docs/models/providers/merge-gateway.md +262 -0
  98. package/.docs/models/providers/nano-gpt.md +13 -37
  99. package/.docs/models/providers/opencode.md +2 -2
  100. package/.docs/models/providers/tinfoil.md +9 -8
  101. package/.docs/models/providers/xai.md +2 -1
  102. package/.docs/models/providers.md +2 -0
  103. package/.docs/reference/agents/getVoice.md +1 -1
  104. package/.docs/reference/configuration.md +1 -1
  105. package/.docs/reference/index.md +5 -1
  106. package/.docs/reference/manual-install.md +1 -1
  107. package/.docs/reference/migrations/network-to-supervisor.md +1 -1
  108. package/.docs/reference/migrations/upgrade-to-v1/tracing.md +1 -3
  109. package/.docs/reference/observability/tracing/exporters/cloud-exporter.md +0 -1
  110. package/.docs/reference/observability/tracing/exporters/console-exporter.md +0 -1
  111. package/.docs/reference/observability/tracing/exporters/default-exporter.md +0 -1
  112. package/.docs/reference/observability/tracing/exporters/mastra-platform-exporter.md +0 -1
  113. package/.docs/reference/observability/tracing/exporters/mastra-storage-exporter.md +0 -1
  114. package/.docs/reference/observability/tracing/processors/sensitive-data-filter.md +111 -99
  115. package/.docs/reference/observability/tracing/span-filtering.md +1 -1
  116. package/.docs/reference/storage/overview.md +1 -1
  117. package/.docs/reference/templates/overview.md +1 -1
  118. package/.docs/{guides → reference}/voice/overview.md +3 -3
  119. package/.docs/{guides → reference}/voice/speech-to-speech.md +1 -1
  120. package/.docs/{guides → reference}/voice/speech-to-text.md +1 -1
  121. package/.docs/{guides → reference}/voice/text-to-speech.md +2 -2
  122. package/CHANGELOG.md +14 -0
  123. package/package.json +4 -4
  124. package/.docs/docs/observability/integrations/exporters/mastra-platform.md +0 -201
  125. package/.docs/docs/observability/integrations/overview.md +0 -47
  126. package/.docs/docs/observability/integrations/processors/sensitive-data-filter.md +0 -302
  127. package/.docs/guides/deployment/mastra-workers.md +0 -578
  128. package/.docs/guides/getting-started/quickstart.md +0 -88
  129. package/.docs/guides/guide/ai-recruiter.md +0 -228
  130. package/.docs/guides/guide/code-review-bot.md +0 -228
  131. package/.docs/guides/guide/coding-agent.md +0 -392
  132. package/.docs/guides/guide/dev-assistant.md +0 -309
  133. package/.docs/guides/guide/docs-manager.md +0 -240
  134. package/.docs/guides/guide/github-actions-pr-description.md +0 -238
  135. package/.docs/guides/guide/notes-mcp-server.md +0 -418
  136. package/.docs/guides/guide/research-assistant.md +0 -350
  137. package/.docs/guides/guide/research-coordinator.md +0 -418
  138. package/.docs/guides/guide/signal-provider.md +0 -221
  139. package/.docs/guides/index.md +0 -24
  140. /package/.docs/{reference → docs}/mastra-platform/api.md +0 -0
  141. /package/.docs/{guides/agent-frameworks/ai-sdk.md → reference/ai-sdk/overview.md} +0 -0
@@ -1,418 +0,0 @@
1
- > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
-
3
- # Build a research coordinator with supervisor agents
4
-
5
- In this guide, you'll build a research coordinator that orchestrates multiple specialized agents using supervisor agents. The coordinator will delegate research tasks to a research agent and writing tasks to a writing agent, then synthesize the results into a detailed report.
6
-
7
- You'll set up subagents with clear roles and configure a supervisor agent to coordinate them. You'll also use delegation hooks to control execution and scorers to validate task completion.
8
-
9
- ## Prerequisites
10
-
11
- - Node.js `v22.13.0` or later installed
12
- - An API key from a supported [Model Provider](https://mastra.ai/models)
13
- - An existing Mastra project (Follow the [installation guide](https://mastra.ai/guides/getting-started/quickstart) to set up a new project)
14
-
15
- ## Create the research agent
16
-
17
- The research agent specializes in gathering factual information on any topic. It returns concise bullet-point summaries with key facts and sources.
18
-
19
- Create a new file `src/mastra/agents/research-agent.ts`:
20
-
21
- ```typescript
22
- import { Agent } from '@mastra/core/agent'
23
-
24
- export const researchAgent = new Agent({
25
- id: 'research-agent',
26
- name: 'Research Specialist',
27
- description:
28
- 'Specializes in gathering factual information and data on any topic. ' +
29
- 'Returns concise bullet-point summaries with key facts and sources. ' +
30
- 'Does not write full articles or narrative content.',
31
- instructions:
32
- 'You are a research specialist. When given a topic, gather key facts, ' +
33
- 'statistics, and information. Present findings as clear bullet points. ' +
34
- 'Include sources when possible. Focus on accuracy and completeness.',
35
- model: 'openai/gpt-5-mini',
36
- })
37
- ```
38
-
39
- The `description` field is critical - it helps the supervisor understand when to delegate to this agent. Clear descriptions improve delegation accuracy.
40
-
41
- ## Create the writing agent
42
-
43
- The writing agent transforms research into well-structured articles with complete paragraphs and proper flow.
44
-
45
- Create a new file `src/mastra/agents/writing-agent.ts`:
46
-
47
- ```typescript
48
- import { Agent } from '@mastra/core/agent'
49
-
50
- export const writingAgent = new Agent({
51
- id: 'writing-agent',
52
- name: 'Writing Specialist',
53
- description:
54
- 'Transforms research material into well-structured written content. ' +
55
- 'Produces full paragraphs and complete articles with proper flow. ' +
56
- 'Best used after research has been gathered.',
57
- instructions:
58
- 'You are a writing specialist. Transform research and information into ' +
59
- 'well-written articles. Use complete paragraphs, clear structure, and ' +
60
- 'engaging language. Maintain a professional yet accessible tone. ' +
61
- 'Ensure the content flows naturally from introduction to conclusion.',
62
- model: 'openai/gpt-5-mini',
63
- })
64
- ```
65
-
66
- ## Create the supervisor agent
67
-
68
- The supervisor coordinates research and writing tasks. Its instructions define the delegation strategy - when to use each subagent and how to synthesize results. Memory is configured directly on the agent.
69
-
70
- Create a new file `src/mastra/agents/supervisor-agent.ts`:
71
-
72
- ```typescript
73
- import { Agent } from '@mastra/core/agent'
74
- import { Memory } from '@mastra/memory'
75
- import { LibSQLStore } from '@mastra/libsql'
76
- import { researchAgent } from './research-agent'
77
- import { writingAgent } from './writing-agent'
78
-
79
- export const supervisorAgent = new Agent({
80
- id: 'supervisor-agent',
81
- name: 'Research Coordinator',
82
- instructions: `You coordinate research and writing tasks using specialized agents.
83
-
84
- Available resources:
85
- - research-agent: Gathers factual data and sources (returns bullet points)
86
- - writing-agent: Transforms research into well-structured articles (returns full paragraphs)
87
-
88
- Delegation strategy:
89
- 1. For research requests: Delegate to research-agent first to gather facts
90
- 2. For writing requests: Delegate to writing-agent with any available research context
91
- 3. For comprehensive reports: Delegate to research-agent first, then writing-agent
92
- 4. Always ensure you have gathered sufficient information before producing final output
93
-
94
- Success criteria:
95
- - All aspects of the user's request are addressed
96
- - Information is accurate and well-sourced
97
- - Final output is well-formatted and complete
98
- - If anything is missing or uncertain, continue gathering information`,
99
- model: 'openai/gpt-5.6-sol',
100
- agents: {
101
- researchAgent,
102
- writingAgent,
103
- },
104
- memory: new Memory({
105
- storage: new LibSQLStore({
106
- id: 'mastra-storage',
107
- url: 'file:mastra.db',
108
- }),
109
- }),
110
- defaultOptions: {
111
- maxSteps: 10,
112
-
113
- // Monitor progress after each iteration
114
- onIterationComplete: async context => {
115
- console.log(`\n✓ Iteration ${context.iteration} complete`)
116
- console.log(` Finish reason: ${context.finishReason}`)
117
- console.log(` Response length: ${context.text.length} chars\n`)
118
-
119
- // Continue until task is complete
120
- return { continue: true }
121
- },
122
-
123
- // Control delegations
124
- delegation: {
125
- onDelegationStart: async context => {
126
- console.log(`→ Delegating to: ${context.primitiveId}`)
127
-
128
- // Add context for specific agents
129
- if (context.primitiveId === 'research-agent') {
130
- return {
131
- proceed: true,
132
- modifiedPrompt: `${context.prompt}\n\nFocus on recent developments (2024-2025) and include statistics.`,
133
- }
134
- }
135
-
136
- return { proceed: true }
137
- },
138
-
139
- onDelegationComplete: async context => {
140
- console.log(`✓ Completed: ${context.primitiveId}\n`)
141
-
142
- // Handle errors: bail to stop execution and provide feedback
143
- if (context.error) {
144
- console.error('Delegation failed:', context.error)
145
- context.bail() // Stop further delegations
146
- return {
147
- feedback: `Delegation to ${context.primitiveId} failed: ${context.error}. Try a different approach.`,
148
- }
149
- }
150
- },
151
-
152
- // Only pass last 10 messages to subagents
153
- messageFilter: ({ messages }) => {
154
- return messages.slice(-10)
155
- },
156
- },
157
- },
158
- })
159
- ```
160
-
161
- Register the supervisor with Mastra in `src/mastra/index.ts`:
162
-
163
- ```typescript
164
- import { Mastra } from '@mastra/core'
165
- import { supervisorAgent } from './agents/supervisor-agent'
166
-
167
- export const mastra = new Mastra({
168
- agents: { supervisorAgent },
169
- })
170
- ```
171
-
172
- The `defaultOptions` on the supervisor agent configure delegation hooks and iteration monitoring:
173
-
174
- - `onDelegationStart` modifies the research agent's prompt to request recent data
175
- - `onDelegationComplete` logs completion and stops on errors, then provides feedback
176
- - `messageFilter` limits context to the last 10 messages for efficiency
177
- - `onIterationComplete` monitors progress after each iteration
178
-
179
- ## Test the basic supervisor
180
-
181
- Create a file to interact with the supervisor in `src/index.ts`:
182
-
183
- ```typescript
184
- import { supervisorAgent } from './mastra/agents/supervisor-agent'
185
-
186
- async function main() {
187
- const topic = 'artificial intelligence in education'
188
- console.log(`\nTopic: ${topic}\n`)
189
-
190
- const stream = await supervisorAgent.stream(
191
- `Research ${topic} and write a comprehensive article about it`,
192
- )
193
-
194
- // Stream the response
195
- console.log('📝 Final Report:\n')
196
- for await (const chunk of stream.textStream) {
197
- process.stdout.write(chunk)
198
- }
199
- console.log('\n')
200
- }
201
-
202
- main()
203
- ```
204
-
205
- The supervisor uses the delegation hooks and iteration monitoring configured in `defaultOptions`.
206
-
207
- ## Add task completion scoring
208
-
209
- Task completion scorers automatically validate whether the task is complete. They prevent the supervisor from finishing prematurely.
210
-
211
- Create a scorer in `src/mastra/scorers/task-complete-scorer.ts`:
212
-
213
- ```typescript
214
- import { createScorer } from '@mastra/core/evals'
215
-
216
- export const taskCompleteScorer = createScorer({
217
- id: 'task-complete',
218
- name: 'Task Completeness',
219
- description: 'Checks if the research and writing task has been fully completed',
220
- }).generateScore(async context => {
221
- const text = (context.run.output || '').toString()
222
-
223
- // Check if response contains required elements
224
- const hasSubstantialContent = text.length > 500
225
- const hasStructure = text.includes('\n\n') // Multiple paragraphs
226
- const hasContext = /\d{4}/.test(text) // Contains years/dates
227
-
228
- // Return 1 if complete, 0 if not
229
- if (hasSubstantialContent && hasStructure && hasContext) {
230
- return 1
231
- }
232
-
233
- return 0
234
- })
235
- ```
236
-
237
- Install the evals package:
238
-
239
- **npm**:
240
-
241
- ```bash
242
- npm install @mastra/evals
243
- ```
244
-
245
- **pnpm**:
246
-
247
- ```bash
248
- pnpm add @mastra/evals
249
- ```
250
-
251
- **Yarn**:
252
-
253
- ```bash
254
- yarn add @mastra/evals
255
- ```
256
-
257
- **Bun**:
258
-
259
- ```bash
260
- bun add @mastra/evals
261
- ```
262
-
263
- Update the supervisor agent to include task completion scoring in `defaultOptions` in `src/mastra/agents/supervisor-agent.ts`:
264
-
265
- ```typescript
266
- import { Agent } from '@mastra/core/agent'
267
- import { Memory } from '@mastra/memory'
268
- import { LibSQLStore } from '@mastra/libsql'
269
- import { researchAgent } from './research-agent'
270
- import { writingAgent } from './writing-agent'
271
- import { taskCompleteScorer } from '../scorers/task-complete-scorer'
272
-
273
- export const supervisorAgent = new Agent({
274
- id: 'supervisor-agent',
275
- name: 'Research Coordinator',
276
- instructions: `You coordinate research and writing tasks using specialized agents.
277
-
278
- Available resources:
279
- - research-agent: Gathers factual data and sources (returns bullet points)
280
- - writing-agent: Transforms research into well-structured articles (returns full paragraphs)
281
-
282
- Delegation strategy:
283
- 1. For research requests: Delegate to research-agent first to gather facts
284
- 2. For writing requests: Delegate to writing-agent with any available research context
285
- 3. For comprehensive reports: Delegate to research-agent first, then writing-agent
286
- 4. Always ensure you have gathered sufficient information before producing final output
287
-
288
- Success criteria:
289
- - All aspects of the user's request are addressed
290
- - Information is accurate and well-sourced
291
- - Final output is well-formatted and complete
292
- - If anything is missing or uncertain, continue gathering information`,
293
- model: 'openai/gpt-5.6-sol',
294
- agents: {
295
- researchAgent,
296
- writingAgent,
297
- },
298
- memory: new Memory({
299
- storage: new LibSQLStore({
300
- id: 'mastra-storage',
301
- url: 'file:mastra.db',
302
- }),
303
- }),
304
- defaultOptions: {
305
- maxSteps: 10,
306
-
307
- onIterationComplete: async context => {
308
- console.log(`\n✓ Iteration ${context.iteration} complete`)
309
- console.log(` Finish reason: ${context.finishReason}`)
310
- console.log(` Response length: ${context.text.length} chars\n`)
311
- return { continue: true }
312
- },
313
-
314
- delegation: {
315
- onDelegationStart: async context => {
316
- console.log(`→ Delegating to: ${context.primitiveId}`)
317
-
318
- if (context.primitiveId === 'research-agent') {
319
- return {
320
- proceed: true,
321
- modifiedPrompt: `${context.prompt}\n\nFocus on recent developments (2024-2025) and include statistics.`,
322
- }
323
- }
324
-
325
- return { proceed: true }
326
- },
327
-
328
- onDelegationComplete: async context => {
329
- console.log(`✓ Completed: ${context.primitiveId}\n`)
330
-
331
- if (context.error) {
332
- console.error('Delegation failed:', context.error)
333
- context.bail() // Stop further delegations
334
- return {
335
- feedback: `Delegation to ${context.primitiveId} failed: ${context.error}. Try a different approach.`,
336
- }
337
- }
338
- },
339
-
340
- messageFilter: ({ messages }) => {
341
- return messages.slice(-10)
342
- },
343
- },
344
-
345
- // Validate task completion
346
- isTaskComplete: {
347
- scorers: [taskCompleteScorer],
348
- strategy: 'all',
349
- onComplete: async result => {
350
- console.log('\n🎯 Completion Check:')
351
- console.log(` Complete: ${result.complete}`)
352
- console.log(` Score: ${result.scorers[0]?.score}\n`)
353
- },
354
- },
355
- },
356
- })
357
- ```
358
-
359
- The scorer checks for substantial content, proper structure, and contextual information. If the task isn't complete, the supervisor will continue iterating. Now all hooks and task completion scoring are configured in the agent's `defaultOptions`, making them apply to every call automatically.
360
-
361
- ## Test the research coordinator
362
-
363
- Run the coordinator to see it in action:
364
-
365
- ```bash
366
- npx tsx src/index.ts
367
- ```
368
-
369
- You'll see the supervisor delegate to the research agent first, then to the writing agent, with logs showing the delegation flow:
370
-
371
- ```text
372
- Topic: artificial intelligence in education
373
-
374
- → Delegating to: research-agent
375
- ✓ Iteration 1 complete
376
- Finish reason: tool-calls
377
- Response length: 0 chars
378
-
379
- ✓ Completed: research-agent
380
-
381
- → Delegating to: writing-agent
382
- ✓ Iteration 2 complete
383
- Finish reason: tool-calls
384
- Response length: 0 chars
385
-
386
- ✓ Completed: writing-agent
387
-
388
- 🎯 Completion Check:
389
- Complete: true
390
- Score: 1
391
-
392
- ✓ Iteration 3 complete
393
- Finish reason: stop
394
- Response length: 1247 chars
395
-
396
- 📝 Final Report:
397
-
398
- Artificial Intelligence in Education: Transforming Learning in 2024-2025
399
-
400
- [The coordinator will produce a comprehensive article combining research findings with well-structured writing...]
401
- ```
402
-
403
- Since agent responses are non-deterministic, your output may vary, but the delegation pattern will be the same.
404
-
405
- ## Next steps
406
-
407
- You can extend this research coordinator to:
408
-
409
- - Add more specialized agents (fact-checker, editor, citation-formatter)
410
- - Implement custom scorers for quality metrics (readability, source quality)
411
- - Add tools for web search or database access
412
- - Create workflows for complex multi-step research processes
413
- - Use structured output to generate reports in specific formats
414
-
415
- Learn more:
416
-
417
- - [Supervisor Agents](https://mastra.ai/docs/capabilities/subagents)
418
- - [Agent.stream() Reference](https://mastra.ai/reference/streaming/agents/stream)
@@ -1,221 +0,0 @@
1
- > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
-
3
- # Building a signal provider
4
-
5
- In this guide, you'll build a signal provider that polls an external service on an interval and pushes a notification into an agent thread whenever a watched resource changes. You'll learn how to extend the `SignalProvider` base class, track subscriptions, emit notifications from a poll loop, and register the provider on an agent.
6
-
7
- The example watches build pipelines in a fake CI service, but the pattern applies to any pull-based source: an issue tracker, a status API, a queue, or your own backend.
8
-
9
- > **Beta:** Breaking changes may occur without a major version bump until the API is stable.
10
-
11
- ## Prerequisites
12
-
13
- - Node.js `v22.13.0` or later installed
14
- - An API key from a supported [Model Provider](https://mastra.ai/models)
15
- - An existing Mastra project. Follow the [installation guide](https://mastra.ai/guides/getting-started/quickstart) if needed.
16
-
17
- This guide also assumes you understand [signals](https://mastra.ai/docs/long-running-agents/signals) at a high level. For the full API surface, see the [`SignalProvider` reference](https://mastra.ai/reference/signals/signal-provider).
18
-
19
- ## Add notification storage
20
-
21
- A signal provider pushes [notification signals](https://mastra.ai/docs/long-running-agents/signals) into threads, and notifications require a storage adapter that supports the notifications domain. Configure storage on your Mastra instance.
22
-
23
- ```typescript
24
- import { Mastra } from '@mastra/core'
25
- import { LibSQLStore } from '@mastra/libsql'
26
-
27
- export const mastra = new Mastra({
28
- storage: new LibSQLStore({
29
- id: 'mastra-storage',
30
- url: 'file:./mastra.db',
31
- }),
32
- })
33
- ```
34
-
35
- LibSQL, PostgreSQL, and MongoDB all support notification records. Without notification storage, the provider's `notify()` calls throw at runtime.
36
-
37
- ## Create the external service client
38
-
39
- Real providers call an external API. To keep this guide self-contained, create a small fake CI client that returns a build status for a pipeline. Swap this for your real API client later.
40
-
41
- ```typescript
42
- export type BuildStatus = {
43
- id: string
44
- pipeline: string
45
- status: 'passed' | 'failed' | 'running'
46
- }
47
-
48
- // Returns a random status so you can see notifications fire while testing.
49
- export async function fetchBuildStatus(pipeline: string): Promise<BuildStatus> {
50
- const states: BuildStatus['status'][] = ['passed', 'failed', 'running']
51
- const status = states[Math.floor(Math.random() * states.length)]!
52
- return { id: `build_${Date.now()}`, pipeline, status }
53
- }
54
- ```
55
-
56
- This client returns a random status each call. When you wire in a real API, only this file changes.
57
-
58
- ## Build the signal provider
59
-
60
- Extend `SignalProvider`, implement the abstract `id` field, set a `pollInterval`, and override `poll()`. The base class calls `poll()` on the interval with every active subscription. Emit a notification only for the builds you care about.
61
-
62
- ```typescript
63
- import { SignalProvider } from '@mastra/core/signals'
64
- import type { SignalProviderTarget, SignalSubscription } from '@mastra/core/signals'
65
- import { fetchBuildStatus } from './ci-client'
66
-
67
- export class CiSignals extends SignalProvider<'ci-signals'> {
68
- readonly id = 'ci-signals' as const
69
- readonly pollInterval = 10_000 // poll every 10 seconds
70
-
71
- // Public API so callers can subscribe a thread to a pipeline.
72
- watch(target: SignalProviderTarget, pipeline: string): SignalSubscription {
73
- return this.subscribe(target, pipeline)
74
- }
75
-
76
- unwatch(target: SignalProviderTarget, pipeline: string): boolean {
77
- return this.unsubscribe(target, pipeline)
78
- }
79
-
80
- async poll(subscriptions: SignalSubscription[]): Promise<void> {
81
- for (const sub of subscriptions) {
82
- const build = await fetchBuildStatus(sub.externalResourceId)
83
- if (build.status !== 'failed') continue
84
-
85
- await this.notify(
86
- {
87
- source: this.id,
88
- kind: 'ci-status',
89
- priority: 'high',
90
- summary: `Build failed for ${sub.externalResourceId}`,
91
- payload: build,
92
- dedupeKey: `${this.id}:${sub.externalResourceId}:${build.id}`,
93
- },
94
- { resourceId: sub.resourceId, threadId: sub.threadId },
95
- )
96
- }
97
- }
98
- }
99
- ```
100
-
101
- A few things to note:
102
-
103
- - `subscribe()` and `unsubscribe()` are protected on the base class. Wrap them in your own public methods (`watch` / `unwatch`) so callers can manage subscriptions.
104
- - `externalResourceId` is any provider-specific string. Here it's the pipeline name; a GitHub provider might use `"github:owner/repo#123"`.
105
- - `notify()` forwards a notification signal to the connected agent's thread. It throws if the provider was never registered on an agent.
106
- - `dedupeKey` prevents storing the same failure twice.
107
-
108
- ## Register the provider on an agent
109
-
110
- Pass the provider to the agent through `signals`. The agent connects it and starts the poll loop automatically.
111
-
112
- ```typescript
113
- import { Agent } from '@mastra/core/agent'
114
- import { CiSignals } from '../signals/ci-signals'
115
-
116
- export const ciSignals = new CiSignals()
117
-
118
- export const devAgent = new Agent({
119
- id: 'dev-agent',
120
- name: 'Dev Agent',
121
- instructions: 'Help the user triage CI build failures.',
122
- model: 'openai/gpt-5.6-sol',
123
- signals: [ciSignals],
124
- })
125
- ```
126
-
127
- Register the agent with Mastra and add the storage from the first step.
128
-
129
- ```typescript
130
- import { Mastra } from '@mastra/core'
131
- import { LibSQLStore } from '@mastra/libsql'
132
- import { devAgent } from './agents/dev-agent'
133
-
134
- export const mastra = new Mastra({
135
- agents: { devAgent },
136
- storage: new LibSQLStore({
137
- id: 'mastra-storage',
138
- url: 'file:./mastra.db',
139
- }),
140
- })
141
- ```
142
-
143
- ## Subscribe a thread
144
-
145
- A provider only polls resources that a thread is watching. Subscribe a thread to a pipeline so `poll()` has something to check.
146
-
147
- ```typescript
148
- import { ciSignals } from './agents/dev-agent'
149
-
150
- ciSignals.watch({ resourceId: 'user_123', threadId: 'thread_456' }, 'acme/app:main')
151
- ```
152
-
153
- Run this once after the agent is registered, for example from a setup script or an API route. The subscription lives in the provider's in-memory registry, so re-subscribe after a restart.
154
-
155
- ## Test the signal provider
156
-
157
- Start the dev server:
158
-
159
- **npm**:
160
-
161
- ```bash
162
- npm run dev
163
- ```
164
-
165
- **pnpm**:
166
-
167
- ```bash
168
- pnpm run dev
169
- ```
170
-
171
- **Yarn**:
172
-
173
- ```bash
174
- yarn dev
175
- ```
176
-
177
- **Bun**:
178
-
179
- ```bash
180
- bun run dev
181
- ```
182
-
183
- Make sure a thread is subscribed, then watch the logs. The fake client returns a random status each poll, so within a few cycles you'll see a failed build trigger a notification for the subscribed thread.
184
-
185
- To see the agent react to the notification, subscribe to the thread and stream it:
186
-
187
- ```typescript
188
- const subscription = await devAgent.subscribeToThread({
189
- resourceId: 'user_123',
190
- threadId: 'thread_456',
191
- })
192
-
193
- for await (const chunk of subscription.stream) {
194
- console.log(chunk)
195
- }
196
- ```
197
-
198
- When a build fails, the model receives the notification as context:
199
-
200
- ```xml
201
- <notification source="ci-signals" type="ci-status" priority="high" status="delivered">Build failed for acme/app:main</notification>
202
- ```
203
-
204
- Output is non-deterministic because the fake client randomizes status and the model phrases its reply freely, so the exact wording will vary.
205
-
206
- ## Next steps
207
-
208
- You can extend this signal provider to:
209
-
210
- - Replace `fetchBuildStatus()` with a real API client.
211
- - Persist subscriptions so they survive a restart, then rehydrate them in [`start()`](https://mastra.ai/reference/signals/signal-provider).
212
- - Add a [webhook](https://mastra.ai/docs/long-running-agents/signal-providers) entry point with [`handleWebhook()`](https://mastra.ai/reference/signals/signal-provider) for push-based sources.
213
- - Expose `subscribe` and `unsubscribe` tools with [`getTools()`](https://mastra.ai/reference/signals/signal-provider) so the agent can manage its own subscriptions.
214
- - Use [`dedupeKey` and `coalesceKey`](https://mastra.ai/reference/agents/agent) when notifications need deduplication or batching.
215
-
216
- Learn more:
217
-
218
- - [Building signal providers](https://mastra.ai/docs/long-running-agents/signal-providers)
219
- - [Signals](https://mastra.ai/docs/long-running-agents/signals)
220
- - [`SignalProvider` reference](https://mastra.ai/reference/signals/signal-provider)
221
- - [`WebhookSignalProvider` reference](https://mastra.ai/reference/signals/webhook-signal-provider)
@@ -1,24 +0,0 @@
1
- > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
-
3
- # Mastra Guides
4
-
5
- Mastra offers guides for building agents and workflows, using the Mastra SDK and API, and implementing different UI frameworks. Explore these guides to find the resources you need to get started and build with Mastra.
6
-
7
- ## New project
8
-
9
- The `npm create mastra@latest` command is the fastest way to build your first agent. It creates a ready-to-run agent harness that you can explore and adapt in [Studio](https://mastra.ai/docs/studio/overview) right away. You can always integrate Mastra with your framework or UI when you’re ready.
10
-
11
- - [Quickstart](https://mastra.ai/guides/getting-started/quickstart)
12
-
13
- ## Integrate with your framework
14
-
15
- Add Mastra to an existing project, or scaffold a new Mastra-powered app if you’re starting from scratch.
16
-
17
- - [Next.js](https://mastra.ai/integrations/frameworks/next-js)
18
- - [React](https://mastra.ai/integrations/frameworks/vite-react)
19
- - [SvelteKit](https://mastra.ai/integrations/frameworks/sveltekit)
20
- - [Astro](https://mastra.ai/integrations/frameworks/astro)
21
- - [Nuxt](https://mastra.ai/integrations/frameworks/nuxt)
22
- - [Express](https://mastra.ai/integrations/frameworks/express)
23
- - [Hono](https://mastra.ai/integrations/frameworks/hono)
24
- - [Electron](https://mastra.ai/integrations/frameworks/electron)