@mastra/mcp-docs-server 0.13.1-alpha.0 → 0.13.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 (77) hide show
  1. package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +15 -15
  2. package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +44 -44
  3. package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +15 -15
  4. package/.docs/organized/changelogs/%40mastra%2Fcore.md +37 -37
  5. package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +53 -53
  6. package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +53 -53
  7. package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +54 -54
  8. package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +63 -63
  9. package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +40 -0
  10. package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +19 -19
  11. package/.docs/organized/changelogs/%40mastra%2Fmcp-registry-registry.md +24 -24
  12. package/.docs/organized/changelogs/%40mastra%2Fmcp.md +8 -8
  13. package/.docs/organized/changelogs/%40mastra%2Fmemory.md +13 -13
  14. package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +14 -14
  15. package/.docs/organized/changelogs/%40mastra%2Fpg.md +31 -31
  16. package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +50 -50
  17. package/.docs/organized/changelogs/%40mastra%2Fserver.md +47 -47
  18. package/.docs/organized/changelogs/%40mastra%2Fupstash.md +37 -37
  19. package/.docs/organized/changelogs/%40mastra%2Fvoice-gladia.md +9 -0
  20. package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +12 -12
  21. package/.docs/organized/changelogs/create-mastra.md +15 -15
  22. package/.docs/organized/changelogs/mastra.md +86 -86
  23. package/.docs/organized/code-examples/agent.md +1 -1
  24. package/.docs/organized/code-examples/agui.md +4 -1
  25. package/.docs/organized/code-examples/ai-sdk-useChat.md +1 -1
  26. package/.docs/organized/code-examples/fireworks-r1.md +1 -1
  27. package/.docs/organized/code-examples/memory-with-processors.md +2 -2
  28. package/.docs/organized/code-examples/openapi-spec-writer.md +1 -1
  29. package/.docs/organized/code-examples/quick-start.md +1 -1
  30. package/.docs/organized/code-examples/weather-agent.md +7 -1
  31. package/.docs/raw/course/01-first-agent/03-verifying-installation.md +4 -2
  32. package/.docs/raw/course/01-first-agent/16-adding-memory-to-agent.md +1 -1
  33. package/.docs/raw/course/02-agent-tools-mcp/15-updating-mcp-config-github.md +1 -1
  34. package/.docs/raw/course/02-agent-tools-mcp/20-updating-mcp-config-hackernews.md +1 -1
  35. package/.docs/raw/course/02-agent-tools-mcp/26-updating-mcp-config-filesystem.md +1 -1
  36. package/.docs/raw/course/03-agent-memory/03-installing-memory.md +4 -2
  37. package/.docs/raw/course/03-agent-memory/04-creating-basic-memory-agent.md +1 -1
  38. package/.docs/raw/course/03-agent-memory/08-configuring-conversation-history.md +3 -3
  39. package/.docs/raw/course/03-agent-memory/13-vector-store-configuration.md +27 -0
  40. package/.docs/raw/course/03-agent-memory/{13-what-is-semantic-recall.md → 14-what-is-semantic-recall.md} +1 -1
  41. package/.docs/raw/course/03-agent-memory/16-configuring-semantic-recall.md +41 -0
  42. package/.docs/raw/course/03-agent-memory/18-advanced-configuration-semantic-recall.md +28 -0
  43. package/.docs/raw/course/03-agent-memory/21-configuring-working-memory.md +9 -9
  44. package/.docs/raw/course/03-agent-memory/22-custom-working-memory-templates.md +10 -2
  45. package/.docs/raw/course/03-agent-memory/25-combining-memory-features.md +8 -1
  46. package/.docs/raw/course/03-agent-memory/27-creating-learning-assistant.md +8 -1
  47. package/.docs/raw/deployment/deployment.mdx +26 -97
  48. package/.docs/raw/deployment/overview.mdx +18 -3
  49. package/.docs/raw/deployment/web-framework.mdx +63 -0
  50. package/.docs/raw/frameworks/web-frameworks/astro.mdx +7 -1
  51. package/.docs/raw/frameworks/web-frameworks/next-js.mdx +1 -1
  52. package/.docs/raw/getting-started/installation.mdx +98 -558
  53. package/.docs/raw/getting-started/project-structure.mdx +3 -16
  54. package/.docs/raw/rag/vector-databases.mdx +4 -7
  55. package/.docs/raw/reference/agents/generate.mdx +35 -3
  56. package/.docs/raw/reference/agents/stream.mdx +35 -3
  57. package/.docs/raw/reference/client-js/memory.mdx +14 -0
  58. package/.docs/raw/reference/client-js/workflows.mdx +28 -0
  59. package/.docs/raw/reference/deployer/cloudflare.mdx +9 -3
  60. package/.docs/raw/reference/deployer/deployer.mdx +1 -1
  61. package/.docs/raw/reference/deployer/netlify.mdx +25 -4
  62. package/.docs/raw/reference/deployer/vercel.mdx +10 -4
  63. package/.docs/raw/workflows/control-flow.mdx +45 -171
  64. package/.docs/raw/workflows/input-data-mapping.mdx +21 -88
  65. package/.docs/raw/workflows/overview.mdx +23 -46
  66. package/.docs/raw/workflows/suspend-and-resume.mdx +46 -34
  67. package/.docs/raw/workflows/using-with-agents-and-tools.mdx +55 -191
  68. package/dist/_tsup-dts-rollup.d.ts +14 -0
  69. package/dist/{chunk-QWIXFGFR.js → chunk-P5AHYMUI.js} +126 -20
  70. package/dist/prepare-docs/prepare.js +1 -1
  71. package/dist/stdio.js +42 -12
  72. package/package.json +4 -4
  73. package/.docs/raw/course/03-agent-memory/15-configuring-semantic-recall.md +0 -46
  74. package/.docs/raw/course/03-agent-memory/16-vector-store-configuration.md +0 -37
  75. package/.docs/raw/course/03-agent-memory/18-disabling-semantic-recall.md +0 -24
  76. /package/.docs/raw/{deployment/client.mdx → client-js/overview.mdx} +0 -0
  77. /package/.docs/raw/course/03-agent-memory/{14-how-semantic-recall-works.md → 15-how-semantic-recall-works.md} +0 -0
@@ -1,55 +1,28 @@
1
1
  ---
2
- title: "Installing Mastra Locally | Getting Started | Mastra Docs"
2
+ title: "Installing Mastra | Getting Started | Mastra Docs"
3
3
  description: Guide on installing Mastra and setting up the necessary prerequisites for running it with various LLM providers.
4
4
  ---
5
5
 
6
6
  import { Callout, Steps } from "nextra/components";
7
- import YouTube from "@/components/youtube";
8
7
  import { Tabs, Tab } from "@/components/tabs";
9
8
 
10
- # Installing Mastra Locally
9
+ # Install Mastra
11
10
 
12
- To run Mastra, you need access to an LLM. Typically, you'll want to get an API key from an LLM provider such as:
11
+ To get started with Mastra, you’ll need access to a large language model (LLM). By default, Mastra is set up to work with [OpenAI](https://platform.openai.com/), so you’ll need an API key to begin.
13
12
 
14
- - [OpenAI](https://platform.openai.com/)
15
- - [Anthropic](https://console.anthropic.com/settings/keys)
16
- - [Google Gemini](https://ai.google.dev/gemini-api/docs)
13
+ Mastra also supports other LLM providers. For a full list of supported models and setup instructions, see [Model Providers](/docs/getting-started/model-providers).
17
14
 
18
- You can also run Mastra with a local LLM using:
19
-
20
- - [Ollama](https://ollama.ai/).
21
-
22
- ## What You'll Build
23
-
24
- By the end of this guide, you'll have built a Weather Agent that generates weather reports using OpenAI's [gpt-4o-mini](https://platform.openai.com/docs/models/gpt-4o-mini) and the Open-Meteo [forecast](https://open-meteo.com/en/docs#api_documentation) endpoint. You can run it directly from the command line or test it in the Mastra Playground. With the Weather agent running you can ask questions like:
25
-
26
- > What is the weather in London? <br/>
27
- > Suggest indoor alternatives in Berlin if it rains tomorrow. <br />
28
- > Is it windy in San Francisco today?
29
15
 
30
16
  ## Prerequisites
31
17
 
32
18
  - Node.js `v20.0` or higher
33
- - Access to a [supported large language model (LLM)](/docs/frameworks/ai-sdk)
34
-
35
- ## Automatic Installation
36
-
37
- <YouTube id="spGlcTEjuXY" />
19
+ - An API key from a supported [Model Provider](/docs/getting-started/model-providers)
38
20
 
39
21
  <Steps>
40
22
 
41
- ### Create a New Project
23
+ ## Install using the `create-mastra` CLI
42
24
 
43
- There are two options when creating a new project with our CLI:
44
-
45
- - [Interactive](#interactive)
46
- - [Non-Interactive](#non-interactive)
47
-
48
- > We recommend starting a new Mastra project using the interactive setup, which guides you through scaffolding your project step by step.
49
-
50
- #### Interactive
51
-
52
- To create a project, run:
25
+ Our CLI is the fastest way to get started with Mastra. Run the following command to start the interactive setup:
53
26
 
54
27
  {/*
55
28
  LLM CONTEXT: This Tabs component shows different package manager commands for creating a new Mastra project.
@@ -60,77 +33,68 @@ All commands achieve the same result - creating a new Mastra project with the in
60
33
 
61
34
  <Tabs items={["npx", "npm", "yarn", "pnpm", "bun"]}>
62
35
  <Tab>
63
- ```bash copy
64
- npx create-mastra@latest
65
- ```
36
+ ```bash copy
37
+ npx create-mastra@latest
38
+ ```
66
39
  </Tab>
67
40
  <Tab>
68
- ```bash copy
69
- npm create mastra@latest
70
- ```
71
- </Tab>
41
+ ```bash copy
42
+ npm create mastra@latest
43
+ ```
44
+ </Tab>
72
45
  <Tab>
73
- ```bash copy
74
- yarn create mastra@latest
75
- ```
76
- </Tab>
46
+ ```bash copy
47
+ yarn create mastra@latest
48
+ ```
49
+ </Tab>
77
50
  <Tab>
78
- ```bash copy
79
- pnpm create mastra@latest
80
- ```
51
+ ```bash copy
52
+ pnpm create mastra@latest
53
+ ```
81
54
  </Tab>
82
- <Tab>
83
- ```bash copy
84
- bun create mastra@latest
85
- ```
55
+ <Tab>
56
+ ```bash copy
57
+ bun create mastra@latest
58
+ ```
86
59
  </Tab>
87
60
  </Tabs>
88
61
 
89
- After the prompts, `create-mastra` will:
90
-
91
- 1. Set up your project directory with TypeScript
92
- 2. Install dependencies
93
- 3. Configure your selected components and LLM provider
94
- 4. Configure the MCP server in your IDE (if selected) for instant access to docs, examples, and help while you code
95
-
96
- > If you're using a different IDE, you can install the MCP server manually by following the instructions in the [MCP server docs](/docs/getting-started/mcp-docs-server). **Also** note that there are additional steps for [Cursor and Windsurf](/docs/getting-started/mcp-docs-server#after-configuration) to activate the MCP server.
97
62
 
98
- #### Non-Interactive
63
+ **Install using CLI flags**
99
64
 
100
- You can run the Mastra CLI in fully non-interactive mode by passing all required flags, for example:
65
+ You can also run the Mastra CLI in non-interactive mode by passing all required flags, for example:
101
66
 
102
67
  ```bash copy
103
68
  npx create-mastra@latest --project-name hello-mastra --example --components tools,agents,workflows --llm openai
104
69
  ```
105
70
 
106
- > See the [mastra init](/reference/cli/init) documentation for a full list of available CLI options.
71
+ > See the [create-mastra](/reference/cli/create-mastra) documentation for a full list of available CLI options.
107
72
 
108
- ### Set Up your API Key
73
+ ### Add your API key
109
74
 
110
- Create a `.env` file in your project root directory and add your API key:
75
+ Add your API key to the `.env` file:
111
76
 
112
77
  ```bash filename=".env" copy
113
78
  OPENAI_API_KEY=<your-api-key>
114
79
  ```
80
+ > This example uses OpenAI. Each LLM provider uses a unique name. See [Model Capabilities](/docs/getting-started/model-capability) for more information.
115
81
 
116
- > Replace `your-api-key` with your API key.
82
+ You can now launch the [Mastra Development Server](/docs/local-dev/mastra-dev) and test your agent using the Mastra Playground.
117
83
 
118
84
  </Steps>
119
85
 
120
- ## Manual Installation
86
+ ## Install manually
121
87
 
122
- If you prefer to set up your Mastra project manually, follow these steps:
88
+ The following steps will walk you through installing Mastra manually.
123
89
 
124
90
  <Steps>
125
91
 
126
- ### Create a New Project
92
+ ### Create a new project
127
93
 
128
94
  Create a new project and change directory:
129
95
 
130
96
  ```bash copy
131
- mkdir hello-mastra
132
-
133
- cd hello-mastra
97
+ mkdir hello-mastra && cd hello-mastra
134
98
  ```
135
99
 
136
100
  Initialize a TypeScript project including the `@mastra/core` package:
@@ -188,10 +152,10 @@ This helps users manually set up a Mastra project with their preferred package m
188
152
 
189
153
  Add the `dev` and `build` scripts to `package.json`:
190
154
 
191
- ```json copy
155
+ ```json filename="package.json" copy
192
156
  {
193
157
  "scripts": {
194
- "test": "echo \"Error: no test specified\" && exit 1",
158
+ // ...
195
159
  "dev": "mastra dev",
196
160
  "build": "mastra build"
197
161
  }
@@ -200,9 +164,15 @@ Add the `dev` and `build` scripts to `package.json`:
200
164
 
201
165
  ### Initialize TypeScript
202
166
 
203
- Create a `tsconfig.json` file in your project root with the following configuration:
167
+ Create a `tsconfig.json` file:
204
168
 
205
- ```json copy
169
+ ```bash copy
170
+ touch tsconfig.json
171
+ ```
172
+
173
+ Add the following configuration:
174
+
175
+ ```json filename="tsconfig.json" copy
206
176
  {
207
177
  "compilerOptions": {
208
178
  "target": "ES2022",
@@ -212,24 +182,32 @@ Create a `tsconfig.json` file in your project root with the following configurat
212
182
  "forceConsistentCasingInFileNames": true,
213
183
  "strict": true,
214
184
  "skipLibCheck": true,
185
+ "noEmit": true,
215
186
  "outDir": "dist"
216
187
  },
217
- "include": ["src/**/*"],
218
- "exclude": ["node_modules", "dist", ".mastra"]
188
+ "include": [
189
+ "src/**/*"
190
+ ]
219
191
  }
220
192
  ```
221
193
 
222
194
  > This TypeScript configuration is optimized for Mastra projects, using modern module resolution and strict type checking.
223
195
 
224
- ### Set Up your API Key
196
+ ### Set up your API key
197
+
198
+ Create `.env` file:
225
199
 
226
- Create a `.env` file in your project root directory and add your API key:
200
+ ```bash copy
201
+ touch .env
202
+ ```
203
+
204
+ Add your API key:
227
205
 
228
206
  ```bash filename=".env" copy
229
207
  OPENAI_API_KEY=<your-api-key>
230
208
  ```
231
209
 
232
- > Replace `your-api-key` with your API key.
210
+ > This example uses OpenAI. Each LLM provider uses a unique name. See [Model Capabilities](/docs/getting-started/model-capability) for more information.
233
211
 
234
212
  ### Create a Tool
235
213
 
@@ -245,100 +223,25 @@ Add the following code:
245
223
  import { createTool } from "@mastra/core/tools";
246
224
  import { z } from "zod";
247
225
 
248
- interface WeatherResponse {
249
- current: {
250
- time: string;
251
- temperature_2m: number;
252
- apparent_temperature: number;
253
- relative_humidity_2m: number;
254
- wind_speed_10m: number;
255
- wind_gusts_10m: number;
256
- weather_code: number;
257
- };
258
- }
259
-
260
226
  export const weatherTool = createTool({
261
227
  id: "get-weather",
262
228
  description: "Get current weather for a location",
263
229
  inputSchema: z.object({
264
- location: z.string().describe("City name"),
230
+ location: z.string().describe("City name")
265
231
  }),
266
232
  outputSchema: z.object({
267
- temperature: z.number(),
268
- feelsLike: z.number(),
269
- humidity: z.number(),
270
- windSpeed: z.number(),
271
- windGust: z.number(),
272
- conditions: z.string(),
273
- location: z.string(),
233
+ output: z.string()
274
234
  }),
275
- execute: async ({ context }) => {
276
- return await getWeather(context.location);
277
- },
278
- });
279
-
280
- const getWeather = async (location: string) => {
281
- const geocodingUrl = `https://geocoding-api.open-meteo.com/v1/search?name=${encodeURIComponent(location)}&count=1`;
282
- const geocodingResponse = await fetch(geocodingUrl);
283
- const geocodingData = await geocodingResponse.json();
284
-
285
- if (!geocodingData.results?.[0]) {
286
- throw new Error(`Location '${location}' not found`);
235
+ execute: async () => {
236
+ return {
237
+ output: "The weather is sunny"
238
+ };
287
239
  }
288
-
289
- const { latitude, longitude, name } = geocodingData.results[0];
290
-
291
- 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`;
292
-
293
- const response = await fetch(weatherUrl);
294
- const data: WeatherResponse = await response.json();
295
-
296
- return {
297
- temperature: data.current.temperature_2m,
298
- feelsLike: data.current.apparent_temperature,
299
- humidity: data.current.relative_humidity_2m,
300
- windSpeed: data.current.wind_speed_10m,
301
- windGust: data.current.wind_gusts_10m,
302
- conditions: getWeatherCondition(data.current.weather_code),
303
- location: name,
304
- };
305
- };
306
-
307
- function getWeatherCondition(code: number): string {
308
- const conditions: Record<number, string> = {
309
- 0: "Clear sky",
310
- 1: "Mainly clear",
311
- 2: "Partly cloudy",
312
- 3: "Overcast",
313
- 45: "Foggy",
314
- 48: "Depositing rime fog",
315
- 51: "Light drizzle",
316
- 53: "Moderate drizzle",
317
- 55: "Dense drizzle",
318
- 56: "Light freezing drizzle",
319
- 57: "Dense freezing drizzle",
320
- 61: "Slight rain",
321
- 63: "Moderate rain",
322
- 65: "Heavy rain",
323
- 66: "Light freezing rain",
324
- 67: "Heavy freezing rain",
325
- 71: "Slight snow fall",
326
- 73: "Moderate snow fall",
327
- 75: "Heavy snow fall",
328
- 77: "Snow grains",
329
- 80: "Slight rain showers",
330
- 81: "Moderate rain showers",
331
- 82: "Violent rain showers",
332
- 85: "Slight snow showers",
333
- 86: "Heavy snow showers",
334
- 95: "Thunderstorm",
335
- 96: "Thunderstorm with slight hail",
336
- 99: "Thunderstorm with heavy hail",
337
- };
338
- return conditions[code] || "Unknown";
339
- }
240
+ });
340
241
  ```
341
242
 
243
+ > See the full weatherTool example in [Giving an Agent a Tool](/examples/agents/using-a-tool).
244
+
342
245
  ### Create an Agent
343
246
 
344
247
  Create a `weather-agent.ts` file:
@@ -355,226 +258,25 @@ import { Agent } from "@mastra/core/agent";
355
258
  import { weatherTool } from "../tools/weather-tool";
356
259
 
357
260
  export const weatherAgent = new Agent({
358
- name: "Weather Agent",
359
- instructions: `You are a helpful weather assistant that provides accurate weather information.
360
-
361
- Your primary function is to help users get weather details for specific locations. When responding:
362
- - Always ask for a location if none is provided
363
- - If the location name isn't in English, please translate it
364
- - Include relevant details like humidity, wind conditions, and precipitation
365
- - Keep responses concise but informative
366
-
367
- Use the weatherTool to fetch current weather data.`,
368
- model: openai("gpt-4o-mini"),
369
- tools: { weatherTool },
370
- });
371
- ```
372
-
373
- ### Create a Workflow
374
-
375
- Create a `weather-workflow.ts` file:
376
-
377
- ```bash copy
378
- mkdir -p src/mastra/workflows && touch src/mastra/workflows/weather-workflow.ts
379
- ```
380
-
381
- Add the following code:
382
-
383
- ```ts filename="src/mastra/workflows/weather-workflow.ts" showLineNumbers copy
384
- import { openai } from "@ai-sdk/openai";
385
- import { Agent } from "@mastra/core/agent";
386
- import { createStep, createWorkflow } from "@mastra/core/workflows";
387
- import { z } from "zod";
388
-
389
- const llm = openai("gpt-4o-mini");
390
-
391
- const agent = new Agent({
392
- name: "Weather Agent",
393
- model: llm,
261
+ name: 'Weather Agent',
394
262
  instructions: `
395
- You are a local activities and travel expert who excels at weather-based planning. Analyze the weather data and provide practical activity recommendations.
396
-
397
- For each day in the forecast, structure your response exactly as follows:
398
-
399
- 📅 [Day, Month Date, Year]
400
- ═══════════════════════════
401
-
402
- 🌡️ WEATHER SUMMARY
403
- • Conditions: [brief description]
404
- Temperature: [X°C/Y°F to A°C/B°F]
405
- • Precipitation: [X% chance]
406
-
407
- 🌅 MORNING ACTIVITIES
408
- Outdoor:
409
- • [Activity Name] - [Brief description including specific location/route]
410
- Best timing: [specific time range]
411
- Note: [relevant weather consideration]
412
-
413
- 🌞 AFTERNOON ACTIVITIES
414
- Outdoor:
415
- • [Activity Name] - [Brief description including specific location/route]
416
- Best timing: [specific time range]
417
- Note: [relevant weather consideration]
418
-
419
- 🏠 INDOOR ALTERNATIVES
420
- • [Activity Name] - [Brief description including specific venue]
421
- Ideal for: [weather condition that would trigger this alternative]
422
-
423
- ⚠️ SPECIAL CONSIDERATIONS
424
- • [Any relevant weather warnings, UV index, wind conditions, etc.]
425
-
426
- Guidelines:
427
- - Suggest 2-3 time-specific outdoor activities per day
428
- - Include 1-2 indoor backup options
429
- - For precipitation >50%, lead with indoor activities
430
- - All activities must be specific to the location
431
- - Include specific venues, trails, or locations
432
- - Consider activity intensity based on temperature
433
- - Keep descriptions concise but informative
434
-
435
- Maintain this exact formatting for consistency, using the emoji and section headers as shown.
436
- `,
437
- });
438
-
439
- const forecastSchema = z.object({
440
- date: z.string(),
441
- maxTemp: z.number(),
442
- minTemp: z.number(),
443
- precipitationChance: z.number(),
444
- condition: z.string(),
445
- location: z.string(),
446
- });
447
-
448
- function getWeatherCondition(code: number): string {
449
- const conditions: Record<number, string> = {
450
- 0: "Clear sky",
451
- 1: "Mainly clear",
452
- 2: "Partly cloudy",
453
- 3: "Overcast",
454
- 45: "Foggy",
455
- 48: "Depositing rime fog",
456
- 51: "Light drizzle",
457
- 53: "Moderate drizzle",
458
- 55: "Dense drizzle",
459
- 61: "Slight rain",
460
- 63: "Moderate rain",
461
- 65: "Heavy rain",
462
- 71: "Slight snow fall",
463
- 73: "Moderate snow fall",
464
- 75: "Heavy snow fall",
465
- 95: "Thunderstorm",
466
- };
467
- return conditions[code] || "Unknown";
468
- }
469
-
470
- const fetchWeather = createStep({
471
- id: "fetch-weather",
472
- description: "Fetches weather forecast for a given city",
473
- inputSchema: z.object({
474
- city: z.string().describe("The city to get the weather for"),
475
- }),
476
- outputSchema: forecastSchema,
477
- execute: async ({ inputData }) => {
478
- if (!inputData) {
479
- throw new Error("Input data not found");
480
- }
481
-
482
- const geocodingUrl = `https://geocoding-api.open-meteo.com/v1/search?name=${encodeURIComponent(inputData.city)}&count=1`;
483
- const geocodingResponse = await fetch(geocodingUrl);
484
- const geocodingData = (await geocodingResponse.json()) as {
485
- results: { latitude: number; longitude: number; name: string }[];
486
- };
487
-
488
- if (!geocodingData.results?.[0]) {
489
- throw new Error(`Location '${inputData.city}' not found`);
490
- }
491
-
492
- const { latitude, longitude, name } = geocodingData.results[0];
493
-
494
- const weatherUrl = `https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}&current=precipitation,weathercode&timezone=auto,&hourly=precipitation_probability,temperature_2m`;
495
- const response = await fetch(weatherUrl);
496
- const data = (await response.json()) as {
497
- current: {
498
- time: string;
499
- precipitation: number;
500
- weathercode: number;
501
- };
502
- hourly: {
503
- precipitation_probability: number[];
504
- temperature_2m: number[];
505
- };
506
- };
507
-
508
- const forecast = {
509
- date: new Date().toISOString(),
510
- maxTemp: Math.max(...data.hourly.temperature_2m),
511
- minTemp: Math.min(...data.hourly.temperature_2m),
512
- condition: getWeatherCondition(data.current.weathercode),
513
- precipitationChance: data.hourly.precipitation_probability.reduce(
514
- (acc, curr) => Math.max(acc, curr),
515
- 0,
516
- ),
517
- location: inputData.city,
518
- };
519
-
520
- return forecast;
521
- },
263
+ You are a helpful weather assistant that provides accurate weather information.
264
+
265
+ Your primary function is to help users get weather details for specific locations. When responding:
266
+ - Always ask for a location if none is provided
267
+ - If the location name isn’t in English, please translate it
268
+ - If giving a location with multiple parts (e.g. "New York, NY"), use the most relevant part (e.g. "New York")
269
+ - Include relevant details like humidity, wind conditions, and precipitation
270
+ - Keep responses concise but informative
271
+
272
+ Use the weatherTool to fetch current weather data.
273
+ `,
274
+ model: openai('gpt-4o-mini'),
275
+ tools: { weatherTool }
522
276
  });
523
-
524
- const planActivities = createStep({
525
- id: "plan-activities",
526
- description: "Suggests activities based on weather conditions",
527
- inputSchema: forecastSchema,
528
- outputSchema: z.object({
529
- activities: z.string(),
530
- }),
531
- execute: async ({ inputData }) => {
532
- const forecast = inputData;
533
-
534
- if (!forecast) {
535
- throw new Error("Forecast data not found");
536
- }
537
-
538
- const prompt = `Based on the following weather forecast for ${forecast.location}, suggest appropriate activities:
539
- ${JSON.stringify(forecast, null, 2)}
540
- `;
541
-
542
- const response = await agent.stream([
543
- {
544
- role: "user",
545
- content: prompt,
546
- },
547
- ]);
548
-
549
- let activitiesText = "";
550
-
551
- for await (const chunk of response.textStream) {
552
- process.stdout.write(chunk);
553
- activitiesText += chunk;
554
- }
555
-
556
- return {
557
- activities: activitiesText,
558
- };
559
- },
560
- });const weatherWorkflow = createWorkflow({
561
- id: "weather-workflow",
562
- inputSchema: z.object({
563
- city: z.string().describe("The city to get the weather for"),
564
- }),
565
- outputSchema: z.object({
566
- activities: z.string(),
567
- }),
568
- })
569
- .then(fetchWeather)
570
- .then(planActivities);
571
-
572
- weatherWorkflow.commit();
573
-
574
- export { weatherWorkflow };
575
277
  ```
576
278
 
577
- ### Register Agent
279
+ ### Register the Agent
578
280
 
579
281
  Create the Mastra entry point and register agent:
580
282
 
@@ -585,197 +287,35 @@ touch src/mastra/index.ts
585
287
  Add the following code:
586
288
 
587
289
  ```ts filename="src/mastra/index.ts" showLineNumbers copy
588
- import { Mastra } from "@mastra/core";
589
- import { PinoLogger } from "@mastra/loggers";
590
- import { LibSQLStore } from "@mastra/libsql";
591
- import { weatherWorkflow } from "./workflows/weather-workflow";
290
+ import { Mastra } from "@mastra/core/mastra";
592
291
  import { weatherAgent } from "./agents/weather-agent";
593
292
 
594
293
  export const mastra = new Mastra({
595
- workflows: { weatherWorkflow },
596
- agents: { weatherAgent },
597
- storage: new LibSQLStore({
598
- // stores telemetry, evals, ... into memory storage, if it needs to persist, change to file:../mastra.db
599
- url: ":memory:",
600
- }),
601
- logger: new PinoLogger({
602
- name: "Mastra",
603
- level: "info",
604
- }),
294
+ agents: { weatherAgent }
605
295
  });
606
296
  ```
607
297
 
608
- > This registers your agent with Mastra so that `mastra dev` can discover and serve it.
298
+ You can now launch the [Mastra Development Server](/docs/local-dev/mastra-dev) and test your agent using the Mastra Playground.
609
299
 
610
300
  </Steps>
611
301
 
612
- ## Start the Mastra Server
613
-
614
- Mastra provides commands to serve your agents via REST endpoints
615
-
616
- ### Development Server
617
-
618
- Run the following command to start the Mastra server:
619
-
620
- ```bash copy
621
- npm run dev
622
- ```
623
-
624
- If you have the mastra CLI installed, run:
625
-
626
- ```bash copy
627
- mastra dev
628
- ```
629
-
630
- This command creates REST API endpoints for your agents which are available on the following links:
631
-
632
- - Playground: [http://localhost:4111/](http://localhost:4111/)
633
- - Mastra API: [http://localhost:4111/api](http://localhost:4111/api)
634
- - OpenAPI Spec: [http://localhost:4111/openapi.json](http://localhost:4111/openapi.json)
635
- - Swagger UI – API explorer: [http://localhost:4111/swagger-ui](http://localhost:4111/swagger-ui)
636
-
637
- ### Test the Endpoint
638
-
639
- You can also test the agent's endpoint using `curl` or `fetch`:
640
-
641
- <Tabs items={['curl', 'fetch']}>
642
- <Tab>
643
- ```bash copy
644
- curl -X POST http://localhost:4111/api/agents/weatherAgent/generate \
645
- -H "Content-Type: application/json" \
646
- -d '{"messages": ["What is the weather in London?"]}'
647
- ```
648
- </Tab>
649
- <Tab>
650
- ```js copy showLineNumbers
651
- fetch('http://localhost:4111/api/agents/weatherAgent/generate', {
652
- method: 'POST',
653
- headers: {
654
- 'Content-Type': 'application/json',
655
- },
656
- body: JSON.stringify({
657
- messages: ['What is the weather in London?'],
658
- }),
659
- })
660
- .then(response => response.json())
661
- .then(data => {
662
- console.log('Agent response:', data.text);
663
- })
664
- .catch(error => {
665
- console.error('Error:', error);
666
- });
667
- ```
668
- </Tab>
669
- </Tabs>
670
-
671
- ### Run from the command line
672
-
673
- If you'd like to call agents directly from the command line, create a simple script to get and invoke an agent.
674
-
675
- Create a test file:
676
-
677
- ```bash copy
678
- touch src/test-agent.ts
679
- ```
680
-
681
- Install `dotenv` to load environment variables (e.g. your API keys):
682
-
683
- <Tabs items={["npm", "pnpm", "yarn", "bun"]}>
684
- <Tab>
685
- ```bash copy
686
- npm install dotenv --save-dev
687
- ```
688
- </Tab>
689
- <Tab>
690
- ```bash copy
691
- pnpm add dotenv --save-dev
692
- ```
693
- </Tab>
694
- <Tab>
695
- ```bash copy
696
- yarn add dotenv --dev
697
- ```
698
- </Tab>
699
- <Tab>
700
- ```bash copy
701
- bun add dotenv --dev
702
- ```
703
- </Tab>
704
- </Tabs>
705
-
706
- If you're using a `.env` file, add the following code:
707
-
708
- ```ts filename="src/test-agent.ts" showLineNumbers copy
709
- import "dotenv/config";
710
-
711
- import { mastra } from "./mastra";
712
-
713
- async function main() {
714
- const agent = await mastra.getAgent("weatherAgent");
715
-
716
- const result = await agent.generate("What is the weather in London?");
717
-
718
- console.log("Agent response:", result.text);
719
- }
720
-
721
- main();
722
- ```
723
-
724
- Or, if you're using a `.env.development` file, add the following code:
725
-
726
- ```ts filename="src/test-agent.ts" showLineNumbers copy
727
- import { config } from "dotenv";
728
- config({ path: ".env.development" });
729
-
730
- import { mastra } from "./mastra";
731
-
732
- async function main() {
733
- const agent = await mastra.getAgent("weatherAgent");
734
-
735
- const result = await agent.generate("What is the weather in London?");
736
-
737
- console.log("Agent response:", result.text);
738
- }
739
-
740
- main();
741
- ```
742
-
743
- Run the script to test the agent:
744
-
745
- ```bash copy
746
- npx tsx src/test-agent.ts
747
- ```
748
-
749
- You should see output similar to the following:
750
-
751
- ```plaintext
752
- Agent response: The current weather in London is as follows:
753
-
754
- - **Temperature:** 12.9°C (Feels like 9.7°C)
755
- - **Humidity:** 63%
756
- - **Wind Speed:** 14.7 km/h
757
- - **Wind Gusts:** 32.4 km/h
758
- - **Conditions:** Overcast
759
-
760
- Let me know if you need more information!
761
- ```
762
-
763
- ## Use Mastra on the Client
764
-
765
- To use Mastra in your frontend applications, use our type-safe client SDK to call your agents via the Mastra REST API.
766
-
767
- - [Mastra Client SDK](/docs/deployment/client)
302
+ ## Add to an existing project
768
303
 
769
- ## Existing Project Installation
304
+ Mastra can be installed and integrated into a wide range of projects. Below are links to integration guides to help you get started:
770
305
 
771
- To add Mastra to an existing project, see our Local development docs:
306
+ - [Next.js](/docs/frameworks/web-frameworks/next-js)
307
+ - [Vite + React](/docs/frameworks/web-frameworks/vite-react)
308
+ - [Astro](/docs/frameworks/web-frameworks/astro)
309
+ - [Express](/docs/frameworks/servers/express)
772
310
 
773
- - [Adding to an Existing Project](/docs/local-dev/add-to-existing-project)
774
311
 
775
- ## Next Steps
312
+ ### `mastra init`
776
313
 
777
- - [Deploy your Agent to Mastra Cloud](/docs/deployment/overview)
778
- - [Integrate Mastra in your Next.js project](/docs/frameworks/next-js)
314
+ To install Mastra in an existing project, use the `mastra init` command.
779
315
 
316
+ > See [mastra init](/reference/cli/init) for more information.
780
317
 
318
+ ## Next steps
781
319
 
320
+ - [Local Development](/docs/local-dev/mastra-dev)
321
+ - [Deploy to Mastra Cloud](/docs/deployment/overview)