@mastra/mcp-docs-server 0.0.13 → 0.0.14-alpha.1

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 (83) hide show
  1. package/.docs/organized/changelogs/%40mastra%2Fastra.md +34 -34
  2. package/.docs/organized/changelogs/%40mastra%2Fchroma.md +35 -35
  3. package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +34 -34
  4. package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +39 -39
  5. package/.docs/organized/changelogs/%40mastra%2Fcloud.md +33 -0
  6. package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +33 -0
  7. package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +34 -34
  8. package/.docs/organized/changelogs/%40mastra%2Fcore.md +32 -32
  9. package/.docs/organized/changelogs/%40mastra%2Fcouchbase.md +34 -0
  10. package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +38 -38
  11. package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +38 -38
  12. package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +39 -39
  13. package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +43 -43
  14. package/.docs/organized/changelogs/%40mastra%2Fevals.md +34 -34
  15. package/.docs/organized/changelogs/%40mastra%2Ffastembed.md +7 -0
  16. package/.docs/organized/changelogs/%40mastra%2Ffirecrawl.md +37 -37
  17. package/.docs/organized/changelogs/%40mastra%2Fgithub.md +34 -34
  18. package/.docs/organized/changelogs/%40mastra%2Flibsql.md +33 -0
  19. package/.docs/organized/changelogs/%40mastra%2Floggers.md +34 -34
  20. package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +39 -39
  21. package/.docs/organized/changelogs/%40mastra%2Fmcp-registry-registry.md +34 -34
  22. package/.docs/organized/changelogs/%40mastra%2Fmcp.md +49 -49
  23. package/.docs/organized/changelogs/%40mastra%2Fmem0.md +34 -34
  24. package/.docs/organized/changelogs/%40mastra%2Fmemory.md +34 -34
  25. package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +33 -0
  26. package/.docs/organized/changelogs/%40mastra%2Fopensearch.md +35 -1
  27. package/.docs/organized/changelogs/%40mastra%2Fpg.md +34 -34
  28. package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +35 -35
  29. package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +45 -45
  30. package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +35 -35
  31. package/.docs/organized/changelogs/%40mastra%2Frag.md +34 -34
  32. package/.docs/organized/changelogs/%40mastra%2Fragie.md +34 -34
  33. package/.docs/organized/changelogs/%40mastra%2Fserver.md +39 -39
  34. package/.docs/organized/changelogs/%40mastra%2Fspeech-azure.md +34 -34
  35. package/.docs/organized/changelogs/%40mastra%2Fspeech-deepgram.md +34 -34
  36. package/.docs/organized/changelogs/%40mastra%2Fspeech-elevenlabs.md +34 -34
  37. package/.docs/organized/changelogs/%40mastra%2Fspeech-google.md +34 -34
  38. package/.docs/organized/changelogs/%40mastra%2Fspeech-ibm.md +34 -34
  39. package/.docs/organized/changelogs/%40mastra%2Fspeech-murf.md +34 -34
  40. package/.docs/organized/changelogs/%40mastra%2Fspeech-openai.md +34 -34
  41. package/.docs/organized/changelogs/%40mastra%2Fspeech-playai.md +34 -34
  42. package/.docs/organized/changelogs/%40mastra%2Fspeech-replicate.md +34 -34
  43. package/.docs/organized/changelogs/%40mastra%2Fspeech-speechify.md +34 -34
  44. package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +34 -34
  45. package/.docs/organized/changelogs/%40mastra%2Fupstash.md +34 -34
  46. package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +35 -35
  47. package/.docs/organized/changelogs/%40mastra%2Fvoice-azure.md +34 -34
  48. package/.docs/organized/changelogs/%40mastra%2Fvoice-cloudflare.md +34 -34
  49. package/.docs/organized/changelogs/%40mastra%2Fvoice-deepgram.md +34 -34
  50. package/.docs/organized/changelogs/%40mastra%2Fvoice-elevenlabs.md +34 -34
  51. package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +34 -34
  52. package/.docs/organized/changelogs/%40mastra%2Fvoice-murf.md +34 -34
  53. package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +34 -34
  54. package/.docs/organized/changelogs/%40mastra%2Fvoice-openai.md +34 -34
  55. package/.docs/organized/changelogs/%40mastra%2Fvoice-playai.md +34 -34
  56. package/.docs/organized/changelogs/%40mastra%2Fvoice-sarvam.md +34 -34
  57. package/.docs/organized/changelogs/%40mastra%2Fvoice-speechify.md +34 -34
  58. package/.docs/organized/changelogs/create-mastra.md +12 -12
  59. package/.docs/organized/changelogs/mastra.md +46 -46
  60. package/.docs/organized/code-examples/a2a.md +202 -0
  61. package/.docs/organized/code-examples/agent-network.md +1 -1
  62. package/.docs/organized/code-examples/agent.md +113 -26
  63. package/.docs/organized/code-examples/ai-sdk-useChat.md +2 -2
  64. package/.docs/organized/code-examples/client-side-tools.md +1 -1
  65. package/.docs/organized/code-examples/crypto-chatbot.md +1 -1
  66. package/.docs/organized/code-examples/fireworks-r1.md +2 -2
  67. package/.docs/organized/code-examples/mcp-configuration.md +579 -0
  68. package/.docs/organized/code-examples/mcp-registry-registry.md +1 -1
  69. package/.docs/organized/code-examples/memory-with-context.md +1 -1
  70. package/.docs/organized/code-examples/memory-with-processors.md +609 -0
  71. package/.docs/organized/code-examples/openapi-spec-writer.md +588 -0
  72. package/.docs/organized/code-examples/quick-start.md +1 -1
  73. package/.docs/raw/agents/dynamic-agents.mdx +47 -0
  74. package/.docs/raw/agents/using-tools-and-mcp.mdx +19 -0
  75. package/.docs/raw/memory/working-memory.mdx +78 -1
  76. package/.docs/raw/reference/cli/mcp-docs-server.mdx +82 -0
  77. package/.docs/raw/reference/deployer/cloudflare.mdx +7 -0
  78. package/.docs/raw/reference/deployer/netlify.mdx +5 -0
  79. package/.docs/raw/reference/deployer/vercel.mdx +6 -0
  80. package/dist/{chunk-OKBMABZO.js → chunk-JWLYN5OI.js} +3 -2
  81. package/dist/prepare-docs/prepare.js +1 -1
  82. package/dist/stdio.js +1 -1
  83. package/package.json +3 -3
@@ -0,0 +1,588 @@
1
+ ### package.json
2
+ ```json
3
+ {
4
+ "name": "examples-openapi-spec-writer",
5
+ "type": "module",
6
+ "private": true,
7
+ "scripts": {
8
+ "dev": "next dev --turbopack",
9
+ "build": "next build",
10
+ "start": "next start",
11
+ "lint": "next lint"
12
+ },
13
+ "dependencies": {
14
+ "@ai-sdk/openai": "^1.3.22",
15
+ "@mastra/core": "latest",
16
+ "@mastra/firecrawl": "latest",
17
+ "@mastra/github": "latest",
18
+ "@mastra/loggers": "latest",
19
+ "@mastra/rag": "latest",
20
+ "@radix-ui/react-accordion": "^1.2.3",
21
+ "@radix-ui/react-dialog": "^1.1.6",
22
+ "@radix-ui/react-select": "^2.1.6",
23
+ "@radix-ui/react-slot": "^1.1.2",
24
+ "class-variance-authority": "^0.7.1",
25
+ "clsx": "^2.1.1",
26
+ "lucide-react": "^0.454.0",
27
+ "next": "15.2.3",
28
+ "react": "^19.0.0",
29
+ "react-dom": "^19.0.0",
30
+ "react-syntax-highlighter": "^15.6.1",
31
+ "sharp": "^0.33.5",
32
+ "tailwind-merge": "^2.6.0",
33
+ "tailwindcss-animate": "^1.0.7",
34
+ "vaul": "^1.1.2",
35
+ "zod": "^3.24.3"
36
+ },
37
+ "devDependencies": {
38
+ "@libsql/client": "^0.15.4",
39
+ "@types/js-yaml": "^4.0.9",
40
+ "@types/node": "^20.17.24",
41
+ "@types/react": "^19.0.10",
42
+ "@types/react-dom": "^19.0.4",
43
+ "@types/react-syntax-highlighter": "^15.5.13",
44
+ "eslint": "^8.57.1",
45
+ "eslint-config-next": "15.0.2",
46
+ "postcss": "^8.5.3",
47
+ "tailwindcss": "^3.4.17",
48
+ "typescript": "^5.8.2"
49
+ },
50
+ "peerDependencies": {
51
+ "react": ">= 0.14.0 || 19",
52
+ "react-dom": ">= 0.14.0 || 19"
53
+ },
54
+ "version": "0.0.1",
55
+ "pnpm": {
56
+ "overrides": {
57
+ "@mastra/core": "link:../../packages/core",
58
+ "@mastra/firecrawl": "link:../../integrations/firecrawl",
59
+ "@mastra/github": "link:../../integrations/github",
60
+ "@mastra/loggers": "link:../../packages/loggers",
61
+ "@mastra/rag": "link:../../packages/rag"
62
+ }
63
+ },
64
+ "packageManager": "pnpm@10.10.0+sha512.d615db246fe70f25dcfea6d8d73dee782ce23e2245e3c4f6f888249fb568149318637dca73c2c5c8ef2a4ca0d5657fb9567188bfab47f566d1ee6ce987815c39"
65
+ }
66
+
67
+ ```
68
+
69
+ ### lib/hooks/useCopyToClipboard.ts
70
+ ```typescript
71
+ "use client";
72
+
73
+ import * as React from "react";
74
+
75
+ export interface useCopyToClipboardProps {
76
+ timeout?: number;
77
+ }
78
+
79
+ export function useCopyToClipboard({
80
+ timeout = 2000,
81
+ }: useCopyToClipboardProps) {
82
+ const [isCopied, setIsCopied] = React.useState<Boolean>(false);
83
+
84
+ const copyToClipboard = (value: string) => {
85
+ if (typeof window === "undefined" || !navigator.clipboard?.writeText) {
86
+ return;
87
+ }
88
+
89
+ if (!value) {
90
+ return;
91
+ }
92
+
93
+ navigator.clipboard.writeText(value).then(() => {
94
+ setIsCopied(true);
95
+
96
+ setTimeout(() => {
97
+ setIsCopied(false);
98
+ }, timeout);
99
+ });
100
+ };
101
+
102
+ return { isCopied, copyToClipboard };
103
+ }
104
+
105
+ ```
106
+
107
+ ### lib/utils.ts
108
+ ```typescript
109
+ import { clsx, type ClassValue } from "clsx";
110
+ import { twMerge } from "tailwind-merge";
111
+
112
+ export function cn(...inputs: ClassValue[]) {
113
+ return twMerge(clsx(inputs));
114
+ }
115
+
116
+ ```
117
+
118
+ ### mastra/agents/index.ts
119
+ ```typescript
120
+ import { Agent } from "@mastra/core/agent";
121
+ import { openai } from "@ai-sdk/openai";
122
+
123
+ export const agentOne = new Agent({
124
+ name: "openapi-spec-gen-agent",
125
+ instructions:
126
+ "You are an expert Open API spec writer. You can take markdown documentation and extract all the information you can to generate an amazing Open API spec. You are also able to merge multiple fragmented Open API specs from the same source into a single compliant spec.",
127
+ model: openai("gpt-3.5-turbo"),
128
+ });
129
+
130
+ ```
131
+
132
+ ### mastra/index.ts
133
+ ```typescript
134
+ import { createLogger } from "@mastra/core/logger";
135
+ import { Mastra } from "@mastra/core/mastra";
136
+ import { UpstashTransport } from "@mastra/loggers/upstash";
137
+ import { agentOne } from "./agents";
138
+ import { makePRToMastraWorkflow, openApiSpecGenWorkflow } from "./workflows";
139
+
140
+ export const mastra = new Mastra({
141
+ logger: createLogger({
142
+ name: "OPENAPI_SPEC_WRITER",
143
+ level: "debug",
144
+ transports: {
145
+ upstash: new UpstashTransport({
146
+ upstashToken: process.env.UPSTASH_API_KEY!,
147
+ upstashUrl: process.env.UPSTASH_URL!,
148
+ }),
149
+ },
150
+ }),
151
+ agents: { "openapi-spec-gen-agent": agentOne },
152
+ telemetry: {
153
+ serviceName: "mastra-vnext",
154
+ sampling: {
155
+ type: "always_on",
156
+ },
157
+ enabled: true,
158
+ export: {
159
+ type: "otlp",
160
+ },
161
+ },
162
+ workflows: {
163
+ openApiSpecGenWorkflow,
164
+ makePRToMastraWorkflow,
165
+ },
166
+ });
167
+
168
+ ```
169
+
170
+ ### mastra/integrations/index.ts
171
+ ```typescript
172
+ import { GithubIntegration } from "@mastra/github";
173
+ import { FirecrawlIntegration } from "@mastra/firecrawl";
174
+
175
+ export const github = new GithubIntegration({
176
+ config: {
177
+ PERSONAL_ACCESS_TOKEN: process.env.GITHUB_API_KEY!,
178
+ },
179
+ })
180
+
181
+ export const firecrawl = new FirecrawlIntegration({
182
+ config: {
183
+ API_KEY: process.env.FIRECRAWL_API_KEY!,
184
+ },
185
+ })
186
+
187
+ ```
188
+
189
+ ### mastra/tools/index.ts
190
+ ```typescript
191
+ import { createTool } from "@mastra/core/tools";
192
+ import { z } from "zod";
193
+ import { firecrawl, github } from "../integrations";
194
+ import { randomUUID } from "crypto";
195
+
196
+ export const siteCrawlTool = createTool({
197
+ id: "site-crawl",
198
+ label: "Site Crawl",
199
+ inputSchema: z.object({
200
+ url: z.string(),
201
+ pathRegex: z.string(),
202
+ limit: z.number(),
203
+ }),
204
+ description: "Crawl a website and extract the markdown content",
205
+ outputSchema: z.object({
206
+ success: z.boolean(),
207
+ crawlData: z.array(
208
+ z.object({
209
+ markdown: z.string(),
210
+ metadata: z.object({
211
+ sourceURL: z.string(),
212
+ }),
213
+ })
214
+ ),
215
+ entityType: z.string(),
216
+ }),
217
+ execute: async ({ context }) => {
218
+ const client = await firecrawl.getApiClient();
219
+
220
+ console.log("Starting crawl", context.url);
221
+
222
+ const res = await client.crawlUrls({
223
+ body: {
224
+ url: context.url,
225
+ limit: context.limit || 3,
226
+ includePaths: [context.pathRegex],
227
+ scrapeOptions: {
228
+ formats: ["markdown"],
229
+ includeTags: ["main"],
230
+ excludeTags: [
231
+ "img",
232
+ "footer",
233
+ "nav",
234
+ "header",
235
+ "#navbar",
236
+ ".table-of-contents-content",
237
+ ],
238
+ onlyMainContent: true,
239
+ },
240
+ },
241
+ });
242
+
243
+ if (res.error) {
244
+ console.error({ error: JSON.stringify(res.error, null, 2) });
245
+ throw new Error(res.error.error);
246
+ }
247
+
248
+ const crawlId = res.data?.id;
249
+
250
+ let crawl = await client.getCrawlStatus({
251
+ path: {
252
+ id: crawlId!,
253
+ },
254
+ });
255
+
256
+ while (crawl.data?.status === "scraping") {
257
+ await new Promise((resolve) => setTimeout(resolve, 5000));
258
+
259
+ crawl = await client.getCrawlStatus({
260
+ path: {
261
+ id: crawlId!,
262
+ },
263
+ });
264
+ }
265
+
266
+ const entityType = `CRAWL_${context.url}`;
267
+
268
+ return {
269
+ success: true,
270
+ crawlData: (crawl?.data?.data || []).map((item) => ({
271
+ markdown: item.markdown || "",
272
+ metadata: {
273
+ sourceURL: item?.metadata?.sourceURL || "",
274
+ ...item.metadata,
275
+ },
276
+ })),
277
+ entityType: entityType,
278
+ };
279
+ },
280
+ });
281
+
282
+ export const generateSpecTool = createTool({
283
+ id: "generate-spec",
284
+ label: "Generate Spec",
285
+ inputSchema: z.object({
286
+ mastra_entity_type: z.string(),
287
+ }),
288
+ outputSchema: z.object({
289
+ success: z.boolean(),
290
+ mergedSpec: z.string(),
291
+ }),
292
+ description: "Generate a spec from a website",
293
+ execute: async ({ context, runId, mastra }) => {
294
+ const crawledData =
295
+ context?.steps?.["site-crawl"]?.status === "success"
296
+ ? context?.steps?.["site-crawl"]?.output
297
+ ?.crawlData
298
+ : [];
299
+
300
+ if (!crawledData) {
301
+ throw new Error("No crawled data found");
302
+ }
303
+
304
+ const agent = mastra?.agents?.["openapi-spec-gen-agent"];
305
+
306
+ if (!agent) {
307
+ throw new Error("Agent not found");
308
+ }
309
+
310
+ const openapiResponses = [];
311
+ let mergedSpecAnswer = "";
312
+
313
+ for (const d of crawledData) {
314
+ const data = await agent.generate(
315
+ `I wrote another page of docs, turn this into an Open API spec: ${d.data.markdown}`,
316
+ { runId }
317
+ );
318
+
319
+ openapiResponses.push(data.text);
320
+ }
321
+
322
+ console.log(
323
+ "inspect this, openapiResponses used to come back in structured output yaml"
324
+ );
325
+
326
+ const mergedSpec = await agent?.generate(
327
+ `I have generated the following Open API specs: ${openapiResponses
328
+ .map((r) => r)
329
+ .join("\n\n")} - merge them into a single spec,
330
+ `,
331
+ { runId }
332
+ );
333
+
334
+ mergedSpecAnswer = mergedSpec.text
335
+ .replace(/```yaml/g, "")
336
+ .replace(/```/g, "");
337
+
338
+ console.log(
339
+ "MERGED SPEC ==================",
340
+ JSON.stringify(mergedSpecAnswer, null, 2)
341
+ );
342
+
343
+ return { success: true, mergedSpec: mergedSpecAnswer };
344
+ },
345
+ });
346
+
347
+ export const addToGitHubTool = createTool({
348
+ id: "add-to-github",
349
+ label: "Add to Git",
350
+ inputSchema: z.object({
351
+ yaml: z.string(),
352
+ integration_name: z.string(),
353
+ owner: z.string(),
354
+ repo: z.string(),
355
+ site_url: z.string(),
356
+ }),
357
+ outputSchema: z.object({
358
+ success: z.boolean(),
359
+ pr_url: z.string().optional(),
360
+ }),
361
+ description: "Commit the spec to GitHub",
362
+ execute: async ({ context, runId, mastra }) => {
363
+ const client = await github.getApiClient();
364
+
365
+ const content = context.yaml;
366
+ const integrationName = context.integration_name.toLowerCase();
367
+
368
+ console.log("Writing to Github for", context.integration_name);
369
+ const agent = mastra?.agents?.["openapi-spec-gen-agent"];
370
+
371
+ const d = await agent?.generate(
372
+ `Can you take this text blob and format it into proper YAML? ${content}`,
373
+ { runId }
374
+ );
375
+
376
+ if (!d) {
377
+ console.error("Agent failed to process the text blob");
378
+ return { success: false };
379
+ }
380
+
381
+ if (Array.isArray(d.toolCalls)) {
382
+ const answer = d.text;
383
+ const strippedYaml = answer.replace(/```yaml/g, "").replace(/```/g, "");
384
+
385
+ const base64Content = Buffer.from(strippedYaml).toString("base64");
386
+
387
+ const reposPathMap = {
388
+ [`integrations-next/${integrationName}/openapi.yaml`]: base64Content,
389
+ [`integrations-next/${integrationName}/README.md`]: Buffer.from(
390
+ `# ${integrationName}\n\nThis repo contains the Open API spec for the ${integrationName} integration`
391
+ ).toString("base64"),
392
+ };
393
+
394
+ const mainRef = await client.gitGetRef({
395
+ path: {
396
+ ref: "heads/main",
397
+ owner: context.owner,
398
+ repo: context.repo,
399
+ },
400
+ });
401
+
402
+ console.log({ context, mainRef });
403
+
404
+ const mainSha = mainRef.data?.object?.sha;
405
+
406
+ console.log("Main SHA", mainSha);
407
+
408
+ const branchName = `open-api-spec-writer/${integrationName}-${randomUUID()}`;
409
+
410
+ console.log("Branch name", branchName);
411
+
412
+ if (mainSha) {
413
+ await client.gitCreateRef({
414
+ body: {
415
+ ref: `refs/heads/${branchName}`,
416
+ sha: mainSha,
417
+ },
418
+ path: {
419
+ owner: context.owner,
420
+ repo: context.repo,
421
+ },
422
+ });
423
+
424
+ for (const [path, content] of Object.entries(reposPathMap)) {
425
+ console.log({ path, content });
426
+ await client.reposCreateOrUpdateFileContents({
427
+ body: {
428
+ message: `Add open api spec from ${context.site_url}`,
429
+ content,
430
+ branch: branchName,
431
+ },
432
+ path: {
433
+ owner: context.owner,
434
+ repo: context.repo,
435
+ path,
436
+ },
437
+ });
438
+ }
439
+
440
+ const pullData = await client.pullsCreate({
441
+ body: {
442
+ title: `Add open api spec from ${context.site_url} for ${integrationName}`,
443
+ head: branchName,
444
+ base: "main",
445
+ },
446
+ path: {
447
+ owner: context.owner,
448
+ repo: context.repo,
449
+ },
450
+ });
451
+
452
+ return { success: true, pr_url: pullData.data?.html_url };
453
+ }
454
+ }
455
+
456
+ return { success: true };
457
+ },
458
+ });
459
+
460
+ ```
461
+
462
+ ### mastra/workflows/index.ts
463
+ ```typescript
464
+ import { Workflow, Step } from "@mastra/core/workflows";
465
+ import { z } from "zod";
466
+ import { addToGitHubTool, generateSpecTool, siteCrawlTool } from "../tools";
467
+ // import { MDocument } from "@mastra/rag";
468
+
469
+ const syncStep = new Step({
470
+ id: "site-crawl-sync-step",
471
+ outputSchema: z.object({
472
+ success: z.boolean(),
473
+ crawlData: z.array(
474
+ z.object({
475
+ markdown: z.string(),
476
+ metadata: z.object({
477
+ sourceURL: z.string(),
478
+ }),
479
+ })
480
+ ),
481
+ entityType: z.string(),
482
+ }),
483
+ description:
484
+ "Crawl a website and extract the markdown content and sync it to the database",
485
+ execute: async ({ context, runId, suspend }) => {
486
+ const toolResult = await siteCrawlTool.execute({
487
+ context: context?.triggerData,
488
+ runId,
489
+ suspend,
490
+ });
491
+
492
+ const { crawlData, entityType } = toolResult;
493
+
494
+ if (!crawlData) {
495
+ return {
496
+ success: false,
497
+ crawlData: [],
498
+ entityType: "",
499
+ };
500
+ }
501
+
502
+ // const recordsToPersist = await Promise.all(
503
+ // crawlData?.flatMap(async ({ markdown, metadata }) => {
504
+ // const doc = MDocument.fromMarkdown(markdown, metadata);
505
+
506
+ // await doc.chunk({
507
+ // strategy: "markdown",
508
+ // maxSize: 8190,
509
+ // });
510
+
511
+ // const chunks = doc.getDocs();
512
+
513
+ // return chunks.map((c, i) => {
514
+ // return {
515
+ // externalId: `${c.metadata?.sourceURL}_chunk_${i}`,
516
+ // data: { markdown: c.text },
517
+ // };
518
+ // });
519
+ // })
520
+ // );
521
+
522
+ return {
523
+ success: true,
524
+ crawlData,
525
+ entityType,
526
+ };
527
+ },
528
+ });
529
+
530
+ export const openApiSpecGenWorkflow = new Workflow({
531
+ name: "openApiSpecGenWorkflow",
532
+ triggerSchema: z.object({
533
+ url: z.string().describe("The URL of the website to crawl"),
534
+ pathRegex: z.string().optional().describe("The regex to match the paths"),
535
+ }),
536
+ })
537
+ .step(syncStep, {
538
+ variables: {
539
+ pathRegex: {
540
+ path: "pathRegex",
541
+ step: "trigger",
542
+ },
543
+ url: {
544
+ path: "url",
545
+ step: "trigger",
546
+ },
547
+ },
548
+ })
549
+ .then(generateSpecTool, {
550
+ variables: {
551
+ mastra_entity_type: {
552
+ step: syncStep,
553
+ path: "entityType",
554
+ },
555
+ },
556
+ });
557
+
558
+ openApiSpecGenWorkflow.commit();
559
+
560
+ export const makePRToMastraWorkflow = new Workflow({
561
+ name: "makePRToMastra",
562
+ triggerSchema: z.object({
563
+ integration_name: z.string(),
564
+ site_url: z.string().describe("The URL of the website to crawl"),
565
+ owner: z.string().describe("Owner of the repo"),
566
+ repo: z.string().describe("Name of the repo"),
567
+ yaml: z.string().describe("The Open API spec in YAML format"),
568
+ }),
569
+ }).step(addToGitHubTool, {
570
+ variables: {
571
+ yaml: {
572
+ path: "yaml",
573
+ step: "trigger",
574
+ },
575
+ integration_name: {
576
+ path: "integration_name",
577
+ step: "trigger",
578
+ },
579
+ site_url: {
580
+ path: "site_url",
581
+ step: "trigger",
582
+ },
583
+ },
584
+ });
585
+
586
+ makePRToMastraWorkflow.commit();
587
+
588
+ ```
@@ -19,7 +19,7 @@
19
19
  "zod": "^3.24.3"
20
20
  },
21
21
  "dependencies": {
22
- "@ai-sdk/anthropic": "^1.1.15",
22
+ "@ai-sdk/anthropic": "^1.2.11",
23
23
  "@ai-sdk/groq": "latest",
24
24
  "@ai-sdk/openai": "latest",
25
25
  "@mastra/core": "latest",
@@ -0,0 +1,47 @@
1
+ ---
2
+
3
+ title: Dynamic Agents | Agents | Mastra Docs
4
+ description: Dynamically configure your agent's instruction, model and tools using runtime context.
5
+
6
+ # Dynamic Agents
7
+
8
+ Dynamic agents use [runtime context](./runtime-variables), like user IDs and other important parameters, to adjust their settings in real-time. This means they can change the model they use, update their instructions, and select different tools as needed. By using this context, agents can better respond to each user's needs. They can also call any API to gather more information, which helps improve what the agents can do.
9
+
10
+ ## Key Benefits
11
+
12
+ - **Flexibility**: Adjust agent behavior dynamically without altering the core code.
13
+ - **Efficiency**: Consolidate multiple agents into a single dynamic agent.
14
+ - **Scalability**: Easily scale agent capabilities by modifying runtime context.
15
+
16
+ ### Example Configuration
17
+
18
+ Here's an example of how to configure a dynamic agent with model, instructions, and tools:
19
+
20
+ ```typescript
21
+ const dynamicAgent = new Agent({
22
+ name: "Master Chef Agent",
23
+ instructions: async ({ runtimeContext }) => {
24
+ // Fetch user preferences from API using user ID from runtime context
25
+ const userId = runtimeContext.get("userId");
26
+ const userPreferences = await fetchUserPreferences(userId);
27
+
28
+ return `You are a master chef specializing in personalized recipes.
29
+ The current user (${userId}) has the following dietary preferences:
30
+ - Allergies: ${userPreferences.allergies.join(", ") || "None"}
31
+ - Preferred cuisines: ${userPreferences.cuisines.join(", ")}
32
+ - Dietary restrictions: ${userPreferences.restrictions.join(", ") || "None"}
33
+
34
+ Tailor your cooking advice and recipes to match these preferences.`;
35
+ },
36
+ model: ({ runtimeContext }) => openai("gpt-4o-mini"),
37
+ tools: ({ runtimeContext }) => {
38
+ return {
39
+ recipeDatabase,
40
+ ingredientSubstitutions,
41
+ nutritionalCalculator,
42
+ };
43
+ },
44
+ });
45
+ ```
46
+
47
+ In this example, the agent's instructions, model, and tools are configured using the runtime context, allowing for a highly adaptable and responsive agent.
@@ -107,3 +107,22 @@ const agent = new Agent({
107
107
  ```
108
108
 
109
109
  For more details on configuring `MCPClient` and the difference between static and dynamic MCP server configurations, see the [MCP Overview](/docs/tools-mcp/mcp-overview).
110
+
111
+ ## Accessing MCP Resources
112
+
113
+ In addition to tools, MCP servers can also expose resources - data or content that can be retrieved and used in your application.
114
+
115
+ ```typescript filename="src/mastra/resources.ts" {3-8}
116
+ import { mcp } from "./mcp";
117
+
118
+ // Get resources from all connected MCP servers
119
+ const resources = await mcp.getResources();
120
+
121
+ // Access resources from a specific server
122
+ if (resources.filesystem) {
123
+ const resource = resources.filesystem.find(r => r.uri === 'filesystem://Downloads');
124
+ console.log(`Resource: ${resource?.name}`);
125
+ }
126
+ ```
127
+
128
+ Each resource has a URI, name, description, and MIME type. The `getResources()` method handles errors gracefully - if a server fails or doesn't support resources, it will be omitted from the results.