@mastra/mcp-docs-server 0.0.0-commonjs-20250414101718

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 (254) hide show
  1. package/.docs/organized/changelogs/%40mastra%2Fastra.md +302 -0
  2. package/.docs/organized/changelogs/%40mastra%2Fchroma.md +302 -0
  3. package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +161 -0
  4. package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +302 -0
  5. package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +110 -0
  6. package/.docs/organized/changelogs/%40mastra%2Fcore.md +302 -0
  7. package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +302 -0
  8. package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +302 -0
  9. package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +302 -0
  10. package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +302 -0
  11. package/.docs/organized/changelogs/%40mastra%2Fevals.md +302 -0
  12. package/.docs/organized/changelogs/%40mastra%2Ffirecrawl.md +302 -0
  13. package/.docs/organized/changelogs/%40mastra%2Fgithub.md +302 -0
  14. package/.docs/organized/changelogs/%40mastra%2Floggers.md +302 -0
  15. package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +302 -0
  16. package/.docs/organized/changelogs/%40mastra%2Fmcp-registry-registry.md +26 -0
  17. package/.docs/organized/changelogs/%40mastra%2Fmcp.md +302 -0
  18. package/.docs/organized/changelogs/%40mastra%2Fmem0.md +196 -0
  19. package/.docs/organized/changelogs/%40mastra%2Fmemory.md +302 -0
  20. package/.docs/organized/changelogs/%40mastra%2Fpg.md +302 -0
  21. package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +302 -0
  22. package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +302 -0
  23. package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +302 -0
  24. package/.docs/organized/changelogs/%40mastra%2Frag.md +302 -0
  25. package/.docs/organized/changelogs/%40mastra%2Fragie.md +302 -0
  26. package/.docs/organized/changelogs/%40mastra%2Fserver.md +302 -0
  27. package/.docs/organized/changelogs/%40mastra%2Fspeech-azure.md +302 -0
  28. package/.docs/organized/changelogs/%40mastra%2Fspeech-deepgram.md +302 -0
  29. package/.docs/organized/changelogs/%40mastra%2Fspeech-elevenlabs.md +302 -0
  30. package/.docs/organized/changelogs/%40mastra%2Fspeech-google.md +302 -0
  31. package/.docs/organized/changelogs/%40mastra%2Fspeech-ibm.md +302 -0
  32. package/.docs/organized/changelogs/%40mastra%2Fspeech-murf.md +302 -0
  33. package/.docs/organized/changelogs/%40mastra%2Fspeech-openai.md +302 -0
  34. package/.docs/organized/changelogs/%40mastra%2Fspeech-playai.md +302 -0
  35. package/.docs/organized/changelogs/%40mastra%2Fspeech-replicate.md +302 -0
  36. package/.docs/organized/changelogs/%40mastra%2Fspeech-speechify.md +302 -0
  37. package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +302 -0
  38. package/.docs/organized/changelogs/%40mastra%2Fupstash.md +302 -0
  39. package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +302 -0
  40. package/.docs/organized/changelogs/%40mastra%2Fvoice-azure.md +250 -0
  41. package/.docs/organized/changelogs/%40mastra%2Fvoice-cloudflare.md +250 -0
  42. package/.docs/organized/changelogs/%40mastra%2Fvoice-deepgram.md +302 -0
  43. package/.docs/organized/changelogs/%40mastra%2Fvoice-elevenlabs.md +302 -0
  44. package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +302 -0
  45. package/.docs/organized/changelogs/%40mastra%2Fvoice-murf.md +302 -0
  46. package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +302 -0
  47. package/.docs/organized/changelogs/%40mastra%2Fvoice-openai.md +302 -0
  48. package/.docs/organized/changelogs/%40mastra%2Fvoice-playai.md +302 -0
  49. package/.docs/organized/changelogs/%40mastra%2Fvoice-sarvam.md +302 -0
  50. package/.docs/organized/changelogs/%40mastra%2Fvoice-speechify.md +302 -0
  51. package/.docs/organized/changelogs/create-mastra.md +302 -0
  52. package/.docs/organized/changelogs/mastra.md +302 -0
  53. package/.docs/organized/code-examples/agent-network.md +282 -0
  54. package/.docs/organized/code-examples/agent.md +388 -0
  55. package/.docs/organized/code-examples/ai-sdk-useChat.md +378 -0
  56. package/.docs/organized/code-examples/assistant-ui.md +37 -0
  57. package/.docs/organized/code-examples/bird-checker-with-express.md +235 -0
  58. package/.docs/organized/code-examples/bird-checker-with-nextjs-and-eval.md +360 -0
  59. package/.docs/organized/code-examples/bird-checker-with-nextjs.md +250 -0
  60. package/.docs/organized/code-examples/client-side-tools.md +69 -0
  61. package/.docs/organized/code-examples/crypto-chatbot.md +96 -0
  62. package/.docs/organized/code-examples/fireworks-r1.md +159 -0
  63. package/.docs/organized/code-examples/mcp-registry-registry.md +63 -0
  64. package/.docs/organized/code-examples/memory-todo-agent.md +164 -0
  65. package/.docs/organized/code-examples/memory-with-context.md +167 -0
  66. package/.docs/organized/code-examples/memory-with-libsql.md +204 -0
  67. package/.docs/organized/code-examples/memory-with-mem0.md +121 -0
  68. package/.docs/organized/code-examples/memory-with-pg.md +224 -0
  69. package/.docs/organized/code-examples/memory-with-upstash.md +268 -0
  70. package/.docs/organized/code-examples/quick-start.md +129 -0
  71. package/.docs/organized/code-examples/stock-price-tool.md +124 -0
  72. package/.docs/organized/code-examples/weather-agent.md +353 -0
  73. package/.docs/organized/code-examples/workflow-ai-recruiter.md +159 -0
  74. package/.docs/organized/code-examples/workflow-with-inline-steps.md +111 -0
  75. package/.docs/organized/code-examples/workflow-with-memory.md +393 -0
  76. package/.docs/organized/code-examples/workflow-with-separate-steps.md +131 -0
  77. package/.docs/raw/agents/adding-tools.mdx +317 -0
  78. package/.docs/raw/agents/adding-voice.mdx +175 -0
  79. package/.docs/raw/agents/agent-memory.mdx +62 -0
  80. package/.docs/raw/agents/mcp-guide.mdx +215 -0
  81. package/.docs/raw/agents/overview.mdx +303 -0
  82. package/.docs/raw/community/discord.mdx +12 -0
  83. package/.docs/raw/community/licensing.mdx +63 -0
  84. package/.docs/raw/deployment/client.mdx +120 -0
  85. package/.docs/raw/deployment/deployment.mdx +127 -0
  86. package/.docs/raw/deployment/server.mdx +282 -0
  87. package/.docs/raw/evals/custom-eval.mdx +22 -0
  88. package/.docs/raw/evals/overview.mdx +95 -0
  89. package/.docs/raw/evals/running-in-ci.mdx +81 -0
  90. package/.docs/raw/evals/textual-evals.mdx +54 -0
  91. package/.docs/raw/faq/index.mdx +63 -0
  92. package/.docs/raw/frameworks/ai-sdk.mdx +296 -0
  93. package/.docs/raw/frameworks/next-js.mdx +238 -0
  94. package/.docs/raw/getting-started/installation.mdx +442 -0
  95. package/.docs/raw/getting-started/mcp-docs-server.mdx +141 -0
  96. package/.docs/raw/getting-started/project-structure.mdx +80 -0
  97. package/.docs/raw/index.mdx +22 -0
  98. package/.docs/raw/integrations/index.mdx +213 -0
  99. package/.docs/raw/local-dev/add-to-existing-project.mdx +48 -0
  100. package/.docs/raw/local-dev/creating-a-new-project.mdx +54 -0
  101. package/.docs/raw/local-dev/mastra-dev.mdx +108 -0
  102. package/.docs/raw/memory/memory-processors.mdx +131 -0
  103. package/.docs/raw/memory/overview.mdx +119 -0
  104. package/.docs/raw/memory/semantic-recall.mdx +122 -0
  105. package/.docs/raw/memory/working-memory.mdx +87 -0
  106. package/.docs/raw/observability/logging.mdx +38 -0
  107. package/.docs/raw/observability/nextjs-tracing.mdx +108 -0
  108. package/.docs/raw/observability/tracing.mdx +115 -0
  109. package/.docs/raw/rag/chunking-and-embedding.mdx +156 -0
  110. package/.docs/raw/rag/overview.mdx +85 -0
  111. package/.docs/raw/rag/retrieval.mdx +365 -0
  112. package/.docs/raw/rag/vector-databases.mdx +340 -0
  113. package/.docs/raw/reference/agents/createTool.mdx +229 -0
  114. package/.docs/raw/reference/agents/generate.mdx +334 -0
  115. package/.docs/raw/reference/agents/getAgent.mdx +54 -0
  116. package/.docs/raw/reference/agents/stream.mdx +369 -0
  117. package/.docs/raw/reference/cli/build.mdx +55 -0
  118. package/.docs/raw/reference/cli/dev.mdx +134 -0
  119. package/.docs/raw/reference/cli/init.mdx +43 -0
  120. package/.docs/raw/reference/client-js/agents.mdx +107 -0
  121. package/.docs/raw/reference/client-js/error-handling.mdx +38 -0
  122. package/.docs/raw/reference/client-js/logs.mdx +24 -0
  123. package/.docs/raw/reference/client-js/memory.mdx +97 -0
  124. package/.docs/raw/reference/client-js/telemetry.mdx +20 -0
  125. package/.docs/raw/reference/client-js/tools.mdx +44 -0
  126. package/.docs/raw/reference/client-js/vectors.mdx +79 -0
  127. package/.docs/raw/reference/client-js/workflows.mdx +136 -0
  128. package/.docs/raw/reference/core/mastra-class.mdx +232 -0
  129. package/.docs/raw/reference/deployer/cloudflare.mdx +207 -0
  130. package/.docs/raw/reference/deployer/deployer.mdx +159 -0
  131. package/.docs/raw/reference/deployer/netlify.mdx +109 -0
  132. package/.docs/raw/reference/deployer/vercel.mdx +117 -0
  133. package/.docs/raw/reference/evals/answer-relevancy.mdx +186 -0
  134. package/.docs/raw/reference/evals/bias.mdx +186 -0
  135. package/.docs/raw/reference/evals/completeness.mdx +174 -0
  136. package/.docs/raw/reference/evals/content-similarity.mdx +183 -0
  137. package/.docs/raw/reference/evals/context-position.mdx +190 -0
  138. package/.docs/raw/reference/evals/context-precision.mdx +189 -0
  139. package/.docs/raw/reference/evals/context-relevancy.mdx +188 -0
  140. package/.docs/raw/reference/evals/contextual-recall.mdx +191 -0
  141. package/.docs/raw/reference/evals/faithfulness.mdx +193 -0
  142. package/.docs/raw/reference/evals/hallucination.mdx +219 -0
  143. package/.docs/raw/reference/evals/keyword-coverage.mdx +176 -0
  144. package/.docs/raw/reference/evals/prompt-alignment.mdx +238 -0
  145. package/.docs/raw/reference/evals/summarization.mdx +205 -0
  146. package/.docs/raw/reference/evals/textual-difference.mdx +161 -0
  147. package/.docs/raw/reference/evals/tone-consistency.mdx +181 -0
  148. package/.docs/raw/reference/evals/toxicity.mdx +165 -0
  149. package/.docs/raw/reference/index.mdx +12 -0
  150. package/.docs/raw/reference/memory/Memory.mdx +212 -0
  151. package/.docs/raw/reference/memory/createThread.mdx +95 -0
  152. package/.docs/raw/reference/memory/getThreadById.mdx +46 -0
  153. package/.docs/raw/reference/memory/getThreadsByResourceId.mdx +48 -0
  154. package/.docs/raw/reference/memory/query.mdx +167 -0
  155. package/.docs/raw/reference/networks/agent-network.mdx +159 -0
  156. package/.docs/raw/reference/observability/create-logger.mdx +106 -0
  157. package/.docs/raw/reference/observability/logger.mdx +55 -0
  158. package/.docs/raw/reference/observability/otel-config.mdx +120 -0
  159. package/.docs/raw/reference/observability/providers/braintrust.mdx +40 -0
  160. package/.docs/raw/reference/observability/providers/dash0.mdx +40 -0
  161. package/.docs/raw/reference/observability/providers/index.mdx +16 -0
  162. package/.docs/raw/reference/observability/providers/laminar.mdx +41 -0
  163. package/.docs/raw/reference/observability/providers/langfuse.mdx +51 -0
  164. package/.docs/raw/reference/observability/providers/langsmith.mdx +48 -0
  165. package/.docs/raw/reference/observability/providers/langwatch.mdx +45 -0
  166. package/.docs/raw/reference/observability/providers/new-relic.mdx +40 -0
  167. package/.docs/raw/reference/observability/providers/signoz.mdx +40 -0
  168. package/.docs/raw/reference/observability/providers/traceloop.mdx +40 -0
  169. package/.docs/raw/reference/rag/astra.mdx +258 -0
  170. package/.docs/raw/reference/rag/chroma.mdx +281 -0
  171. package/.docs/raw/reference/rag/chunk.mdx +235 -0
  172. package/.docs/raw/reference/rag/document.mdx +127 -0
  173. package/.docs/raw/reference/rag/embeddings.mdx +160 -0
  174. package/.docs/raw/reference/rag/extract-params.mdx +226 -0
  175. package/.docs/raw/reference/rag/graph-rag.mdx +182 -0
  176. package/.docs/raw/reference/rag/libsql.mdx +357 -0
  177. package/.docs/raw/reference/rag/metadata-filters.mdx +298 -0
  178. package/.docs/raw/reference/rag/pg.mdx +477 -0
  179. package/.docs/raw/reference/rag/pinecone.mdx +281 -0
  180. package/.docs/raw/reference/rag/qdrant.mdx +236 -0
  181. package/.docs/raw/reference/rag/rerank.mdx +212 -0
  182. package/.docs/raw/reference/rag/turbopuffer.mdx +249 -0
  183. package/.docs/raw/reference/rag/upstash.mdx +247 -0
  184. package/.docs/raw/reference/rag/vectorize.mdx +298 -0
  185. package/.docs/raw/reference/storage/libsql.mdx +74 -0
  186. package/.docs/raw/reference/storage/postgresql.mdx +48 -0
  187. package/.docs/raw/reference/storage/upstash.mdx +86 -0
  188. package/.docs/raw/reference/tools/client.mdx +207 -0
  189. package/.docs/raw/reference/tools/document-chunker-tool.mdx +141 -0
  190. package/.docs/raw/reference/tools/graph-rag-tool.mdx +154 -0
  191. package/.docs/raw/reference/tools/mcp-configuration.mdx +206 -0
  192. package/.docs/raw/reference/tools/vector-query-tool.mdx +212 -0
  193. package/.docs/raw/reference/voice/composite-voice.mdx +140 -0
  194. package/.docs/raw/reference/voice/deepgram.mdx +164 -0
  195. package/.docs/raw/reference/voice/elevenlabs.mdx +216 -0
  196. package/.docs/raw/reference/voice/google.mdx +198 -0
  197. package/.docs/raw/reference/voice/mastra-voice.mdx +394 -0
  198. package/.docs/raw/reference/voice/murf.mdx +251 -0
  199. package/.docs/raw/reference/voice/openai-realtime.mdx +431 -0
  200. package/.docs/raw/reference/voice/openai.mdx +168 -0
  201. package/.docs/raw/reference/voice/playai.mdx +159 -0
  202. package/.docs/raw/reference/voice/sarvam.mdx +260 -0
  203. package/.docs/raw/reference/voice/speechify.mdx +145 -0
  204. package/.docs/raw/reference/voice/voice.answer.mdx +122 -0
  205. package/.docs/raw/reference/voice/voice.connect.mdx +124 -0
  206. package/.docs/raw/reference/voice/voice.listen.mdx +195 -0
  207. package/.docs/raw/reference/voice/voice.on.mdx +189 -0
  208. package/.docs/raw/reference/voice/voice.send.mdx +118 -0
  209. package/.docs/raw/reference/voice/voice.speak.mdx +203 -0
  210. package/.docs/raw/reference/workflows/after.mdx +88 -0
  211. package/.docs/raw/reference/workflows/afterEvent.mdx +76 -0
  212. package/.docs/raw/reference/workflows/commit.mdx +37 -0
  213. package/.docs/raw/reference/workflows/createRun.mdx +77 -0
  214. package/.docs/raw/reference/workflows/else.mdx +72 -0
  215. package/.docs/raw/reference/workflows/events.mdx +305 -0
  216. package/.docs/raw/reference/workflows/execute.mdx +110 -0
  217. package/.docs/raw/reference/workflows/if.mdx +107 -0
  218. package/.docs/raw/reference/workflows/resume.mdx +155 -0
  219. package/.docs/raw/reference/workflows/resumeWithEvent.mdx +133 -0
  220. package/.docs/raw/reference/workflows/snapshots.mdx +207 -0
  221. package/.docs/raw/reference/workflows/start.mdx +84 -0
  222. package/.docs/raw/reference/workflows/step-class.mdx +100 -0
  223. package/.docs/raw/reference/workflows/step-condition.mdx +134 -0
  224. package/.docs/raw/reference/workflows/step-function.mdx +92 -0
  225. package/.docs/raw/reference/workflows/step-options.mdx +69 -0
  226. package/.docs/raw/reference/workflows/step-retries.mdx +203 -0
  227. package/.docs/raw/reference/workflows/suspend.mdx +70 -0
  228. package/.docs/raw/reference/workflows/then.mdx +74 -0
  229. package/.docs/raw/reference/workflows/until.mdx +165 -0
  230. package/.docs/raw/reference/workflows/watch.mdx +118 -0
  231. package/.docs/raw/reference/workflows/while.mdx +168 -0
  232. package/.docs/raw/reference/workflows/workflow.mdx +233 -0
  233. package/.docs/raw/storage/overview.mdx +378 -0
  234. package/.docs/raw/voice/overview.mdx +135 -0
  235. package/.docs/raw/voice/speech-to-text.mdx +45 -0
  236. package/.docs/raw/voice/text-to-speech.mdx +52 -0
  237. package/.docs/raw/voice/voice-to-voice.mdx +310 -0
  238. package/.docs/raw/workflows/control-flow.mdx +778 -0
  239. package/.docs/raw/workflows/dynamic-workflows.mdx +236 -0
  240. package/.docs/raw/workflows/error-handling.mdx +183 -0
  241. package/.docs/raw/workflows/nested-workflows.mdx +352 -0
  242. package/.docs/raw/workflows/overview.mdx +203 -0
  243. package/.docs/raw/workflows/steps.mdx +108 -0
  244. package/.docs/raw/workflows/suspend-and-resume.mdx +404 -0
  245. package/.docs/raw/workflows/variables.mdx +313 -0
  246. package/LICENSE.md +46 -0
  247. package/README.md +129 -0
  248. package/dist/_tsup-dts-rollup.d.ts +149 -0
  249. package/dist/chunk-QWYMT5LP.js +194 -0
  250. package/dist/prepare-docs/prepare.d.ts +1 -0
  251. package/dist/prepare-docs/prepare.js +1 -0
  252. package/dist/stdio.d.ts +1 -0
  253. package/dist/stdio.js +518 -0
  254. package/package.json +60 -0
@@ -0,0 +1,353 @@
1
+ ### package.json
2
+ ```json
3
+ {
4
+ "name": "examples-weather-agent",
5
+ "type": "module",
6
+ "private": true,
7
+ "description": "",
8
+ "main": "index.js",
9
+ "scripts": {
10
+ "dev": "npx tsx src/mastra/index.ts"
11
+ },
12
+ "keywords": [],
13
+ "author": "",
14
+ "license": "MIT",
15
+ "dependencies": {
16
+ "@ai-sdk/openai": "latest",
17
+ "@mastra/core": "workspace:*",
18
+ "zod": "^3.24.2"
19
+ },
20
+ "version": "0.0.1"
21
+ }
22
+
23
+ ```
24
+
25
+ ### mastra/agents/index.ts
26
+ ```typescript
27
+ import { openai } from '@ai-sdk/openai';
28
+ import { Agent } from '@mastra/core/agent';
29
+
30
+ import { weatherTool } from '../tools';
31
+
32
+ export const weatherAgent = new Agent({
33
+ name: 'Weather Agent',
34
+ instructions: `You are a helpful weather assistant that provides accurate weather information.
35
+
36
+ Your primary function is to help users get weather details for specific locations. When responding:
37
+ - Always ask for a location if none is provided
38
+ - If the location name isn’t in English, please translate it
39
+ - If giving a location with multiple parts (e.g. "New York, NY"), use the most relevant part (e.g. "New York")
40
+ - Include relevant details like humidity, wind conditions, and precipitation
41
+ - Keep responses concise but informative
42
+
43
+ Use the weatherTool to fetch current weather data.`,
44
+ model: openai('gpt-4o'),
45
+ tools: { weatherTool },
46
+ });
47
+
48
+ ```
49
+
50
+ ### mastra/index.ts
51
+ ```typescript
52
+ import { Mastra } from '@mastra/core';
53
+
54
+ import { weatherAgent } from './agents';
55
+ import { weatherWorkflow } from './workflows';
56
+
57
+ const mastra = new Mastra({
58
+ agents: { weatherAgent },
59
+ workflows: { weatherWorkflow },
60
+ });
61
+
62
+ async function agentExample() {
63
+ const agent = await mastra.getAgent('weatherAgent');
64
+ const result = await agent.generate('What is the weather in London?');
65
+ console.log(result.text);
66
+ }
67
+
68
+ async function workflowExample() {
69
+ const { start } = mastra.getWorkflow('weatherWorkflow').createRun();
70
+
71
+ const result = await start({
72
+ triggerData: {
73
+ city: 'London',
74
+ },
75
+ });
76
+
77
+ console.log('\n \n');
78
+ console.log(result);
79
+ }
80
+
81
+ // agentExample();
82
+ workflowExample();
83
+
84
+ ```
85
+
86
+ ### mastra/tools/index.ts
87
+ ```typescript
88
+ import { createTool } from '@mastra/core/tools';
89
+ import { z } from 'zod';
90
+
91
+ interface WeatherResponse {
92
+ current: {
93
+ time: string;
94
+ temperature_2m: number;
95
+ apparent_temperature: number;
96
+ relative_humidity_2m: number;
97
+ wind_speed_10m: number;
98
+ wind_gusts_10m: number;
99
+ weather_code: number;
100
+ };
101
+ }
102
+
103
+ export const weatherTool = createTool({
104
+ id: 'get-weather',
105
+ description: 'Get current weather for a location',
106
+ inputSchema: z.object({
107
+ location: z.string().describe('City name'),
108
+ }),
109
+ outputSchema: z.object({
110
+ temperature: z.number(),
111
+ feelsLike: z.number(),
112
+ humidity: z.number(),
113
+ windSpeed: z.number(),
114
+ windGust: z.number(),
115
+ conditions: z.string(),
116
+ location: z.string(),
117
+ }),
118
+ execute: async ({ context }) => {
119
+ return await getWeather(context.location);
120
+ },
121
+ });
122
+
123
+ const getWeather = async (location: string) => {
124
+ const geocodingUrl = `https://geocoding-api.open-meteo.com/v1/search?name=${encodeURIComponent(location)}&count=1`;
125
+ const geocodingResponse = await fetch(geocodingUrl);
126
+ const geocodingData = await geocodingResponse.json();
127
+
128
+ if (!geocodingData.results?.[0]) {
129
+ throw new Error(`Location '${location}' not found`);
130
+ }
131
+
132
+ const { latitude, longitude, name } = geocodingData.results[0];
133
+
134
+ const weatherUrl = `https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}&current=temperature_2m,apparent_temperature,relative_humidity_2m,wind_speed_10m,wind_gusts_10m,weather_code`;
135
+
136
+ const response = await fetch(weatherUrl);
137
+ const data: WeatherResponse = await response.json();
138
+
139
+ return {
140
+ temperature: data.current.temperature_2m,
141
+ feelsLike: data.current.apparent_temperature,
142
+ humidity: data.current.relative_humidity_2m,
143
+ windSpeed: data.current.wind_speed_10m,
144
+ windGust: data.current.wind_gusts_10m,
145
+ conditions: getWeatherCondition(data.current.weather_code),
146
+ location: name,
147
+ };
148
+ };
149
+
150
+ function getWeatherCondition(code: number): string {
151
+ const conditions: Record<number, string> = {
152
+ 0: 'Clear sky',
153
+ 1: 'Mainly clear',
154
+ 2: 'Partly cloudy',
155
+ 3: 'Overcast',
156
+ 45: 'Foggy',
157
+ 48: 'Depositing rime fog',
158
+ 51: 'Light drizzle',
159
+ 53: 'Moderate drizzle',
160
+ 55: 'Dense drizzle',
161
+ 56: 'Light freezing drizzle',
162
+ 57: 'Dense freezing drizzle',
163
+ 61: 'Slight rain',
164
+ 63: 'Moderate rain',
165
+ 65: 'Heavy rain',
166
+ 66: 'Light freezing rain',
167
+ 67: 'Heavy freezing rain',
168
+ 71: 'Slight snow fall',
169
+ 73: 'Moderate snow fall',
170
+ 75: 'Heavy snow fall',
171
+ 77: 'Snow grains',
172
+ 80: 'Slight rain showers',
173
+ 81: 'Moderate rain showers',
174
+ 82: 'Violent rain showers',
175
+ 85: 'Slight snow showers',
176
+ 86: 'Heavy snow showers',
177
+ 95: 'Thunderstorm',
178
+ 96: 'Thunderstorm with slight hail',
179
+ 99: 'Thunderstorm with heavy hail',
180
+ };
181
+ return conditions[code] || 'Unknown';
182
+ }
183
+
184
+ ```
185
+
186
+ ### mastra/workflows/index.ts
187
+ ```typescript
188
+ import { openai } from '@ai-sdk/openai';
189
+ import { Agent } from '@mastra/core/agent';
190
+ import { Step, Workflow } from '@mastra/core/workflows';
191
+ import { z } from 'zod';
192
+
193
+ const agent = new Agent({
194
+ name: 'Weather Agent',
195
+ instructions: `
196
+ You are a local activities and travel expert who excels at weather-based planning. Analyze the weather data and provide practical activity recommendations.
197
+ For each day in the forecast, structure your response exactly as follows:
198
+ 📅 [Day, Month Date, Year]
199
+ ═══════════════════════════
200
+ 🌡️ WEATHER SUMMARY
201
+ • Conditions: [brief description]
202
+ • Temperature: [X°C/Y°F to A°C/B°F]
203
+ • Precipitation: [X% chance]
204
+ 🌅 MORNING ACTIVITIES
205
+ Outdoor:
206
+ • [Activity Name] - [Brief description including specific location/route]
207
+ Best timing: [specific time range]
208
+ Note: [relevant weather consideration]
209
+ 🌞 AFTERNOON ACTIVITIES
210
+ Outdoor:
211
+ • [Activity Name] - [Brief description including specific location/route]
212
+ Best timing: [specific time range]
213
+ Note: [relevant weather consideration]
214
+ 🏠 INDOOR ALTERNATIVES
215
+ • [Activity Name] - [Brief description including specific venue]
216
+ Ideal for: [weather condition that would trigger this alternative]
217
+ ⚠️ SPECIAL CONSIDERATIONS
218
+ • [Any relevant weather warnings, UV index, wind conditions, etc.]
219
+ Guidelines:
220
+ - Suggest 2-3 time-specific outdoor activities per day
221
+ - Include 1-2 indoor backup options
222
+ - For precipitation >50%, lead with indoor activities
223
+ - All activities must be specific to the location
224
+ - Include specific venues, trails, or locations
225
+ - Consider activity intensity based on temperature
226
+ - Keep descriptions concise but informative
227
+ Maintain this exact formatting for consistency, using the emoji and section headers as shown.
228
+ `,
229
+ model: openai('gpt-4o'),
230
+ });
231
+
232
+ const fetchWeather = new Step({
233
+ id: 'fetch-weather',
234
+ description: 'Fetches weather forecast for a given city',
235
+ inputSchema: z.object({
236
+ city: z.string().describe('The city to get the weather for'),
237
+ }),
238
+ execute: async ({ context }) => {
239
+ const triggerData = context?.getStepResult<{ city: string }>('trigger');
240
+
241
+ if (!triggerData) {
242
+ throw new Error('Trigger data not found');
243
+ }
244
+
245
+ const geocodingUrl = `https://geocoding-api.open-meteo.com/v1/search?name=${encodeURIComponent(triggerData.city)}&count=1`;
246
+ const geocodingResponse = await fetch(geocodingUrl);
247
+ const geocodingData = await geocodingResponse.json();
248
+
249
+ if (!geocodingData.results?.[0]) {
250
+ throw new Error(`Location '${triggerData.city}' not found`);
251
+ }
252
+
253
+ const { latitude, longitude, name } = geocodingData.results[0];
254
+
255
+ const weatherUrl = `https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}&daily=temperature_2m_max,temperature_2m_min,precipitation_probability_mean,weathercode&timezone=auto`;
256
+ const response = await fetch(weatherUrl);
257
+ const data = await response.json();
258
+
259
+ const forecast = data.daily.time.map((date: string, index: number) => ({
260
+ date,
261
+ maxTemp: data.daily.temperature_2m_max[index],
262
+ minTemp: data.daily.temperature_2m_min[index],
263
+ precipitationChance: data.daily.precipitation_probability_mean[index],
264
+ condition: getWeatherCondition(data.daily.weathercode[index]),
265
+ location: name,
266
+ }));
267
+
268
+ return forecast;
269
+ },
270
+ });
271
+
272
+ const forecastSchema = z.array(
273
+ z.object({
274
+ date: z.string(),
275
+ maxTemp: z.number(),
276
+ minTemp: z.number(),
277
+ precipitationChance: z.number(),
278
+ condition: z.string(),
279
+ location: z.string(),
280
+ }),
281
+ );
282
+
283
+ const planActivities = new Step({
284
+ id: 'plan-activities',
285
+ description: 'Suggests activities based on weather conditions',
286
+ inputSchema: forecastSchema,
287
+ execute: async ({ context, mastra }) => {
288
+ const forecast = context?.getStepResult<z.infer<typeof forecastSchema>>('fetch-weather');
289
+
290
+ if (!forecast) {
291
+ throw new Error('Forecast data not found');
292
+ }
293
+
294
+ const prompt = `Based on the following weather forecast for ${forecast[0].location}, suggest appropriate activities:
295
+ ${JSON.stringify(forecast, null, 2)}
296
+ `;
297
+
298
+ const response = await agent.stream([
299
+ {
300
+ role: 'user',
301
+ content: prompt,
302
+ },
303
+ ]);
304
+
305
+ let activitiesText = '';
306
+
307
+ for await (const chunk of response.textStream) {
308
+ process.stdout.write(chunk);
309
+ activitiesText += chunk;
310
+ }
311
+
312
+ return {
313
+ activities: activitiesText,
314
+ };
315
+ },
316
+ });
317
+
318
+ function getWeatherCondition(code: number): string {
319
+ const conditions: Record<number, string> = {
320
+ 0: 'Clear sky',
321
+ 1: 'Mainly clear',
322
+ 2: 'Partly cloudy',
323
+ 3: 'Overcast',
324
+ 45: 'Foggy',
325
+ 48: 'Depositing rime fog',
326
+ 51: 'Light drizzle',
327
+ 53: 'Moderate drizzle',
328
+ 55: 'Dense drizzle',
329
+ 61: 'Slight rain',
330
+ 63: 'Moderate rain',
331
+ 65: 'Heavy rain',
332
+ 71: 'Slight snow fall',
333
+ 73: 'Moderate snow fall',
334
+ 75: 'Heavy snow fall',
335
+ 95: 'Thunderstorm',
336
+ };
337
+ return conditions[code] || 'Unknown';
338
+ }
339
+
340
+ const weatherWorkflow = new Workflow({
341
+ name: 'weather-workflow',
342
+ triggerSchema: z.object({
343
+ city: z.string().describe('The city to get the weather for'),
344
+ }),
345
+ })
346
+ .step(fetchWeather)
347
+ .then(planActivities);
348
+
349
+ weatherWorkflow.commit();
350
+
351
+ export { weatherWorkflow };
352
+
353
+ ```
@@ -0,0 +1,159 @@
1
+ ### package.json
2
+ ```json
3
+ {
4
+ "name": "examples-workflow-ai-recruiter",
5
+ "type": "module",
6
+ "private": true,
7
+ "main": "index.js",
8
+ "scripts": {
9
+ "test": "echo \"Error: no test specified\" && exit 1",
10
+ "dev": "mastra dev",
11
+ "start:dev": "npx bun src/mastra/index.ts"
12
+ },
13
+ "keywords": [],
14
+ "author": "",
15
+ "license": "MIT",
16
+ "description": "",
17
+ "devDependencies": {
18
+ "@types/node": "^20.17.27",
19
+ "mastra": "workspace:*",
20
+ "tsx": "^4.19.3",
21
+ "typescript": "^5.8.2",
22
+ "zod": "^3.24.2"
23
+ },
24
+ "dependencies": {
25
+ "@ai-sdk/openai": "latest",
26
+ "@mastra/core": "workspace:*",
27
+ "ai": "latest"
28
+ },
29
+ "version": "0.0.1-alpha.2"
30
+ }
31
+
32
+ ```
33
+
34
+ ### mastra/index.ts
35
+ ```typescript
36
+ import { openai } from '@ai-sdk/openai';
37
+ import { Mastra } from '@mastra/core';
38
+ import { Agent } from '@mastra/core/agent';
39
+ import { Step, Workflow } from '@mastra/core/workflows';
40
+ import { z } from 'zod';
41
+
42
+ const recruiter = new Agent({
43
+ name: 'Recruiter Agent',
44
+ instructions: `You are a recruiter.`,
45
+ model: openai('gpt-4o-mini'),
46
+ });
47
+
48
+ const gatherCandidateInfo = new Step({
49
+ id: 'gatherCandidateInfo',
50
+ inputSchema: z.object({
51
+ resumeText: z.string(),
52
+ }),
53
+ outputSchema: z.object({
54
+ candidateName: z.string(),
55
+ isTechnical: z.boolean(),
56
+ specialty: z.string(),
57
+ resumeText: z.string(),
58
+ }),
59
+ execute: async ({ context, mastra }) => {
60
+ const resumeText = context?.getStepResult<{ resumeText: string }>('trigger')?.resumeText;
61
+
62
+ const prompt = `
63
+ You are given this resume text:
64
+ "${resumeText}"
65
+ `;
66
+ const res = await recruiter.generate(prompt, {
67
+ output: z.object({
68
+ candidateName: z.string(),
69
+ isTechnical: z.boolean(),
70
+ specialty: z.string(),
71
+ resumeText: z.string(),
72
+ }),
73
+ });
74
+
75
+ return res.object;
76
+ },
77
+ });
78
+
79
+ interface CandidateInfo {
80
+ candidateName: string;
81
+ isTechnical: boolean;
82
+ specialty: string;
83
+ resumeText: string;
84
+ }
85
+
86
+ const askAboutSpecialty = new Step({
87
+ id: 'askAboutSpecialty',
88
+ outputSchema: z.object({
89
+ question: z.string(),
90
+ }),
91
+ execute: async ({ context, mastra }) => {
92
+ const candidateInfo = context?.getStepResult<CandidateInfo>('gatherCandidateInfo');
93
+
94
+ const prompt = `
95
+ You are a recruiter. Given the resume below, craft a short question
96
+ for ${candidateInfo?.candidateName} about how they got into "${candidateInfo?.specialty}".
97
+ Resume: ${candidateInfo?.resumeText}
98
+ `;
99
+ const res = await recruiter.generate(prompt);
100
+ return { question: res?.text?.trim() || '' };
101
+ },
102
+ });
103
+
104
+ const askAboutRole = new Step({
105
+ id: 'askAboutRole',
106
+ outputSchema: z.object({
107
+ question: z.string(),
108
+ }),
109
+ execute: async ({ context, mastra }) => {
110
+ const candidateInfo = context?.getStepResult<CandidateInfo>('gatherCandidateInfo');
111
+
112
+ const prompt = `
113
+ You are a recruiter. Given the resume below, craft a short question
114
+ for ${candidateInfo?.candidateName} asking what interests them most about this role.
115
+ Resume: ${candidateInfo?.resumeText}
116
+ `;
117
+ const res = await recruiter.generate(prompt);
118
+ return { question: res?.text?.trim() || '' };
119
+ },
120
+ });
121
+
122
+ const candidateWorkflow = new Workflow({
123
+ name: 'candidate-workflow',
124
+ triggerSchema: z.object({
125
+ resumeText: z.string(),
126
+ }),
127
+ });
128
+
129
+ candidateWorkflow
130
+ .step(gatherCandidateInfo)
131
+ .then(askAboutSpecialty, {
132
+ when: { 'gatherCandidateInfo.isTechnical': true },
133
+ })
134
+ .after(gatherCandidateInfo)
135
+ .step(askAboutRole, {
136
+ when: { 'gatherCandidateInfo.isTechnical': false },
137
+ });
138
+
139
+ candidateWorkflow.commit();
140
+
141
+ const mastra = new Mastra({
142
+ workflows: {
143
+ candidateWorkflow,
144
+ },
145
+ });
146
+
147
+ (async () => {
148
+ const { runId, start } = mastra.getWorkflow('candidateWorkflow').createRun();
149
+
150
+ console.log('Run', runId);
151
+
152
+ const runResult = await start({
153
+ triggerData: { resumeText: 'Simulated resume content...' },
154
+ });
155
+
156
+ console.log('Final output:', runResult.results);
157
+ })();
158
+
159
+ ```
@@ -0,0 +1,111 @@
1
+ ### package.json
2
+ ```json
3
+ {
4
+ "name": "workflow-with-inline-steps",
5
+ "main": "index.js",
6
+ "private": true,
7
+ "scripts": {
8
+ "test": "echo \"Error: no test specified\" && exit 1",
9
+ "dev": "mastra dev"
10
+ },
11
+ "keywords": [],
12
+ "author": "",
13
+ "license": "MIT",
14
+ "description": "",
15
+ "devDependencies": {
16
+ "@types/node": "^20.17.27",
17
+ "mastra": "workspace:*",
18
+ "tsx": "^4.19.3",
19
+ "typescript": "^5.8.2",
20
+ "zod": "^3.24.2"
21
+ },
22
+ "dependencies": {
23
+ "@mastra/core": "workspace:*"
24
+ },
25
+ "version": "0.0.1-alpha.2"
26
+ }
27
+
28
+ ```
29
+
30
+ ### mastra/index.ts
31
+ ```typescript
32
+ import { Mastra } from '@mastra/core';
33
+
34
+ import { myWorkflow } from './workflows';
35
+
36
+ export const mastra = new Mastra({
37
+ workflows: {
38
+ myWorkflow,
39
+ },
40
+ });
41
+
42
+ ```
43
+
44
+ ### mastra/workflows/index.ts
45
+ ```typescript
46
+ import { Step, Workflow } from '@mastra/core/workflows';
47
+ import { z } from 'zod';
48
+
49
+ const myWorkflow = new Workflow({
50
+ name: 'my-workflow',
51
+ triggerSchema: z.object({
52
+ inputValue: z.number(),
53
+ }),
54
+ });
55
+
56
+ myWorkflow
57
+ .step(
58
+ new Step({
59
+ id: 'stepOne',
60
+ inputSchema: z.object({
61
+ value: z.number(),
62
+ }),
63
+ outputSchema: z.object({
64
+ doubledValue: z.number(),
65
+ }),
66
+ execute: async ({ context }) => {
67
+ const doubledValue = context?.triggerData.inputValue * 2;
68
+ return { doubledValue };
69
+ },
70
+ }),
71
+ )
72
+ .then(
73
+ new Step({
74
+ id: 'stepTwo',
75
+ inputSchema: z.object({
76
+ valueToIncrement: z.number(),
77
+ }),
78
+ outputSchema: z.object({
79
+ incrementedValue: z.number(),
80
+ }),
81
+ execute: async ({ context }) => {
82
+ if (context?.steps.stepOne.status === 'success') {
83
+ const incrementedValue = context?.steps.stepOne.output.doubledValue + 1;
84
+ return { incrementedValue };
85
+ }
86
+ return { incrementedValue: 0 };
87
+ },
88
+ }),
89
+ )
90
+ .then(
91
+ new Step({
92
+ id: 'stepThree',
93
+ execute: async ({ context, suspend }) => {
94
+ if (context?.resumeData?.confirm !== 'true') {
95
+ return suspend({
96
+ message: 'Do you accept?',
97
+ });
98
+ }
99
+
100
+ return {
101
+ message: 'Thank you for accepting',
102
+ };
103
+ },
104
+ }),
105
+ );
106
+
107
+ myWorkflow.commit();
108
+
109
+ export { myWorkflow };
110
+
111
+ ```