@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,579 @@
1
+ ### package.json
2
+ ```json
3
+ {
4
+ "name": "examples-mcp-configuration",
5
+ "type": "module",
6
+ "private": true,
7
+ "main": "index.js",
8
+ "scripts": {
9
+ "start": "npx bun src/index.ts",
10
+ "dev": "mastra dev",
11
+ "test": "cross-env NODE_OPTIONS='--experimental-vm-modules --max-old-space-size=8192' jest"
12
+ },
13
+ "keywords": [],
14
+ "author": "",
15
+ "license": "MIT",
16
+ "description": "",
17
+ "dependencies": {
18
+ "@ai-sdk/openai": "latest",
19
+ "@mastra/core": "latest",
20
+ "@mastra/mcp": "latest",
21
+ "@mastra/memory": "latest",
22
+ "@modelcontextprotocol/sdk": "^1.9.0",
23
+ "chalk": "^5.4.1",
24
+ "zod": "^3.24.3",
25
+ "zod-to-json-schema": "^3.24.5"
26
+ },
27
+ "devDependencies": {
28
+ "@jest/globals": "^29.7.0",
29
+ "jest": "^29.7.0",
30
+ "mastra": "latest",
31
+ "ts-jest": "^29.2.6",
32
+ "tsx": "^4.19.3"
33
+ },
34
+ "pnpm": {
35
+ "overrides": {
36
+ "@mastra/core": "link:../../packages/core",
37
+ "@mastra/mcp": "link:../../packages/mcp",
38
+ "@mastra/memory": "link:../../packages/memory",
39
+ "mastra": "link:../../packages/cli"
40
+ }
41
+ },
42
+ "version": "0.0.1",
43
+ "packageManager": "pnpm@10.10.0+sha512.d615db246fe70f25dcfea6d8d73dee782ce23e2245e3c4f6f888249fb568149318637dca73c2c5c8ef2a4ca0d5657fb9567188bfab47f566d1ee6ce987815c39"
44
+ }
45
+
46
+ ```
47
+
48
+ ### index.ts
49
+ ```typescript
50
+ import { openai } from '@ai-sdk/openai';
51
+ import { Agent } from '@mastra/core/agent';
52
+ import { MCPClient } from '@mastra/mcp';
53
+ import chalk from 'chalk';
54
+
55
+ // start sse server - in real life this would already be running but want to show using sse and stdio in this example
56
+ import './mastra/tools/sse';
57
+
58
+ console.log(chalk.blue(`Creating agent`));
59
+ export const stockWeatherAgent = new Agent({
60
+ name: 'Stock + Weather Agent',
61
+ instructions:
62
+ 'You are a helpful assistant that provides current stock prices. When asked about a stock, use the stock price tool to fetch the stock price. You also love to check the weather when your stock market buddies ask you what the weather is.',
63
+ model: openai('gpt-4o'),
64
+ });
65
+
66
+ console.log(chalk.blue(`Creating MCPClient`));
67
+ const mcp = new MCPClient({
68
+ servers: {
69
+ stockPrice: {
70
+ command: 'npx',
71
+ args: ['-y', 'tsx', './src/mastra/tools/stock-price.ts'],
72
+ env: {
73
+ FAKE_CREDS: 'let me in!',
74
+ },
75
+ },
76
+ weather: {
77
+ url: new URL('http://localhost:8080/sse'),
78
+ },
79
+ },
80
+ });
81
+
82
+ const toolsets = await mcp.getToolsets();
83
+
84
+ console.log({ toolsets });
85
+
86
+ const prompt = `Whats the weather in Seattle and what is the current stock price of Apple (AAPL)?`;
87
+ console.log(chalk.yellow(`Sending prompt:\n"${prompt}"\n\n`));
88
+ const response = await stockWeatherAgent.stream(prompt, {
89
+ toolsets,
90
+ });
91
+
92
+ for await (const part of response.fullStream) {
93
+ switch (part.type) {
94
+ case 'error':
95
+ console.error(part.error);
96
+ break;
97
+ case 'text-delta':
98
+ process.stdout.write(chalk.green(part.textDelta));
99
+ break;
100
+ case 'tool-call':
101
+ console.log(`calling tool ${part.toolName} with args ${chalk.red(JSON.stringify(part.args, null, 2))}`);
102
+ break;
103
+ case 'tool-result':
104
+ console.log(`tool result ${chalk.cyan(JSON.stringify(part.result, null, 2))}`);
105
+ break;
106
+ }
107
+ }
108
+
109
+ ```
110
+
111
+ ### mastra/agents/index.ts
112
+ ```typescript
113
+ import { openai } from '@ai-sdk/openai';
114
+ import { Agent } from '@mastra/core/agent';
115
+ import { MCPClient } from '@mastra/mcp';
116
+
117
+ // start sse server - in real life this would already be running but want to show using sse and stdio in this example
118
+ import '../tools/sse';
119
+
120
+ const mcp = new MCPClient({
121
+ servers: {
122
+ stockPrice: {
123
+ command: 'npx',
124
+ args: ['-y', 'tsx', '../../src/mastra/tools/stock-price.ts'],
125
+ env: {
126
+ FAKE_CREDS: 'let me in!',
127
+ },
128
+ },
129
+ weather: {
130
+ url: new URL('http://localhost:8080/sse'),
131
+ },
132
+ },
133
+ });
134
+
135
+ export const stockWeatherAgent = new Agent({
136
+ name: 'Stock + Weather Agent',
137
+ instructions:
138
+ 'You are a helpful assistant that provides current stock prices. When asked about a stock, use the stock price tool to fetch the stock price. You also love to check the weather when your stock market buddies ask you what the weather is.',
139
+ model: openai('gpt-4o'),
140
+ tools: await mcp.getTools(),
141
+ });
142
+
143
+ ```
144
+
145
+ ### mastra/index.ts
146
+ ```typescript
147
+ import { Mastra } from '@mastra/core';
148
+
149
+ import { stockWeatherAgent } from './agents';
150
+
151
+ export const mastra = new Mastra({
152
+ agents: { stockWeatherAgent },
153
+ });
154
+
155
+ ```
156
+
157
+ ### mastra/tools/sse.ts
158
+ ```typescript
159
+ import chalk from 'chalk';
160
+ import { spawn } from 'child_process';
161
+ import path from 'path';
162
+
163
+ function relativeFromRoot(pathString: string) {
164
+ if (import.meta.url.includes(`.mastra`)) {
165
+ return path.join(`../../`, pathString);
166
+ }
167
+
168
+ return path.join(`./`, pathString);
169
+ }
170
+
171
+ const sseFile = relativeFromRoot(`./src/mastra/tools/weather.ts`);
172
+
173
+ console.log(chalk.blue(`Starting mock sse server`));
174
+ // simulating an sse server that's already running
175
+ const sseProcess = spawn(`npx`, [`-y`, `tsx`, sseFile]);
176
+
177
+ sseProcess.stderr.on(`data`, chunk => {
178
+ const message = chunk.toString();
179
+ console.error(message);
180
+ });
181
+ await new Promise(res => {
182
+ sseProcess.stdout.on(`data`, chunk => {
183
+ const message = chunk.toString();
184
+ if (message.includes('server is running on SSE')) {
185
+ res(null);
186
+ } else {
187
+ console.log(message);
188
+ }
189
+ });
190
+ });
191
+
192
+ process.on(`exit`, () => {
193
+ sseProcess.kill(`SIGINT`);
194
+ });
195
+
196
+ ```
197
+
198
+ ### mastra/tools/stock-price.ts
199
+ ```typescript
200
+ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
201
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
202
+ import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js';
203
+ import { z } from 'zod';
204
+ import { zodToJsonSchema } from 'zod-to-json-schema';
205
+
206
+ const getStockPrice = async (symbol: string) => {
207
+ const data = await fetch(`https://mastra-stock-data.vercel.app/api/stock-data?symbol=${symbol}`).then(r => r.json());
208
+ return data.prices['4. close'];
209
+ };
210
+
211
+ const server = new Server(
212
+ {
213
+ name: 'Stock Price Server',
214
+ version: '1.0.0',
215
+ },
216
+ {
217
+ capabilities: {
218
+ tools: {},
219
+ },
220
+ },
221
+ );
222
+
223
+ const stockInputSchema = z.object({
224
+ symbol: z.string().describe('Stock symbol'),
225
+ });
226
+
227
+ const stockTool = {
228
+ name: 'getStockPrice',
229
+ description: "Fetches the last day's closing stock price for a given symbol",
230
+ execute: async (args: z.infer<typeof stockInputSchema>) => {
231
+ try {
232
+ console.log('Using tool to fetch stock price for', args.symbol);
233
+ const price = await getStockPrice(args.symbol);
234
+ return {
235
+ content: [
236
+ {
237
+ type: 'text',
238
+ text: JSON.stringify({
239
+ symbol: args.symbol,
240
+ currentPrice: price,
241
+ }),
242
+ },
243
+ ],
244
+ isError: false,
245
+ };
246
+ } catch (error) {
247
+ if (error instanceof Error) {
248
+ return {
249
+ content: [
250
+ {
251
+ type: 'text',
252
+ text: `Stock price fetch failed: ${error.message}`,
253
+ },
254
+ ],
255
+ isError: true,
256
+ };
257
+ }
258
+ return {
259
+ content: [
260
+ {
261
+ type: 'text',
262
+ text: 'An unknown error occurred.',
263
+ },
264
+ ],
265
+ isError: true,
266
+ };
267
+ }
268
+ },
269
+ };
270
+
271
+ // Set up request handlers
272
+ server.setRequestHandler(ListToolsRequestSchema, async () => ({
273
+ tools: [
274
+ {
275
+ name: stockTool.name,
276
+ description: stockTool.description,
277
+ inputSchema: zodToJsonSchema(stockInputSchema),
278
+ },
279
+ ],
280
+ }));
281
+
282
+ server.setRequestHandler(CallToolRequestSchema, async request => {
283
+ try {
284
+ switch (request.params.name) {
285
+ case 'getStockPrice': {
286
+ const args = stockInputSchema.parse(request.params.arguments);
287
+ return await stockTool.execute(args);
288
+ }
289
+ default:
290
+ return {
291
+ content: [
292
+ {
293
+ type: 'text',
294
+ text: `Unknown tool: ${request.params.name}`,
295
+ },
296
+ ],
297
+ isError: true,
298
+ };
299
+ }
300
+ } catch (error) {
301
+ if (error instanceof z.ZodError) {
302
+ return {
303
+ content: [
304
+ {
305
+ type: 'text',
306
+ text: `Invalid arguments: ${error.errors.map(e => `${e.path.join('.')}: ${e.message}`).join(', ')}`,
307
+ },
308
+ ],
309
+ isError: true,
310
+ };
311
+ }
312
+ return {
313
+ content: [
314
+ {
315
+ type: 'text',
316
+ text: `Error: ${error instanceof Error ? error.message : String(error)}`,
317
+ },
318
+ ],
319
+ isError: true,
320
+ };
321
+ }
322
+ });
323
+
324
+ // Start the server
325
+ const transport = new StdioServerTransport();
326
+ await server.connect(transport);
327
+
328
+ export { server };
329
+
330
+ ```
331
+
332
+ ### mastra/tools/weather.ts
333
+ ```typescript
334
+ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
335
+ import { SSEServerTransport } from '@modelcontextprotocol/sdk/server/sse.js';
336
+ import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js';
337
+ import { z } from 'zod';
338
+ import { zodToJsonSchema } from 'zod-to-json-schema';
339
+ import { createServer, IncomingMessage, ServerResponse } from 'http';
340
+
341
+ interface WeatherResponse {
342
+ current: {
343
+ time: string;
344
+ temperature_2m: number;
345
+ apparent_temperature: number;
346
+ relative_humidity_2m: number;
347
+ wind_speed_10m: number;
348
+ wind_gusts_10m: number;
349
+ weather_code: number;
350
+ };
351
+ }
352
+
353
+ const getWeather = async (location: string) => {
354
+ const geocodingUrl = `https://geocoding-api.open-meteo.com/v1/search?name=${encodeURIComponent(location)}&count=1`;
355
+ const geocodingResponse = await fetch(geocodingUrl);
356
+ const geocodingData = await geocodingResponse.json();
357
+
358
+ if (!geocodingData.results?.[0]) {
359
+ throw new Error(`Location '${location}' not found`);
360
+ }
361
+
362
+ const { latitude, longitude, name } = geocodingData.results[0];
363
+
364
+ 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`;
365
+
366
+ const response = await fetch(weatherUrl);
367
+ const data: WeatherResponse = await response.json();
368
+
369
+ return {
370
+ temperature: data.current.temperature_2m,
371
+ feelsLike: data.current.apparent_temperature,
372
+ humidity: data.current.relative_humidity_2m,
373
+ windSpeed: data.current.wind_speed_10m,
374
+ windGust: data.current.wind_gusts_10m,
375
+ conditions: getWeatherCondition(data.current.weather_code),
376
+ location: name,
377
+ };
378
+ };
379
+
380
+ function getWeatherCondition(code: number): string {
381
+ const conditions: Record<number, string> = {
382
+ 0: 'Clear sky',
383
+ 1: 'Mainly clear',
384
+ 2: 'Partly cloudy',
385
+ 3: 'Overcast',
386
+ 45: 'Foggy',
387
+ 48: 'Depositing rime fog',
388
+ 51: 'Light drizzle',
389
+ 53: 'Moderate drizzle',
390
+ 55: 'Dense drizzle',
391
+ 56: 'Light freezing drizzle',
392
+ 57: 'Dense freezing drizzle',
393
+ 61: 'Slight rain',
394
+ 63: 'Moderate rain',
395
+ 65: 'Heavy rain',
396
+ 66: 'Light freezing rain',
397
+ 67: 'Heavy freezing rain',
398
+ 71: 'Slight snow fall',
399
+ 73: 'Moderate snow fall',
400
+ 75: 'Heavy snow fall',
401
+ 77: 'Snow grains',
402
+ 80: 'Slight rain showers',
403
+ 81: 'Moderate rain showers',
404
+ 82: 'Violent rain showers',
405
+ 85: 'Slight snow showers',
406
+ 86: 'Heavy snow showers',
407
+ 95: 'Thunderstorm',
408
+ 96: 'Thunderstorm with slight hail',
409
+ 99: 'Thunderstorm with heavy hail',
410
+ };
411
+ return conditions[code] || 'Unknown';
412
+ }
413
+
414
+ const server = new Server(
415
+ {
416
+ name: 'Weather Server',
417
+ version: '1.0.0',
418
+ },
419
+ {
420
+ capabilities: {
421
+ tools: {},
422
+ },
423
+ },
424
+ );
425
+
426
+ const weatherInputSchema = z.object({
427
+ location: z.string().describe('City name'),
428
+ });
429
+
430
+ const weatherTool = {
431
+ name: 'getWeather',
432
+ description: 'Get current weather for a location',
433
+ execute: async (args: z.infer<typeof weatherInputSchema>) => {
434
+ try {
435
+ const weatherData = await getWeather(args.location);
436
+ return {
437
+ content: [
438
+ {
439
+ type: 'text',
440
+ text: JSON.stringify(weatherData),
441
+ },
442
+ ],
443
+ isError: false,
444
+ };
445
+ } catch (error) {
446
+ if (error instanceof Error) {
447
+ return {
448
+ content: [
449
+ {
450
+ type: 'text',
451
+ text: `Weather fetch failed: ${error.message}`,
452
+ },
453
+ ],
454
+ isError: true,
455
+ };
456
+ }
457
+ return {
458
+ content: [
459
+ {
460
+ type: 'text',
461
+ text: 'An unknown error occurred.',
462
+ },
463
+ ],
464
+ isError: true,
465
+ };
466
+ }
467
+ },
468
+ };
469
+
470
+ // Set up request handlers
471
+ server.setRequestHandler(ListToolsRequestSchema, async () => ({
472
+ tools: [
473
+ {
474
+ name: weatherTool.name,
475
+ description: weatherTool.description,
476
+ inputSchema: zodToJsonSchema(weatherInputSchema),
477
+ },
478
+ ],
479
+ }));
480
+
481
+ server.setRequestHandler(CallToolRequestSchema, async request => {
482
+ try {
483
+ switch (request.params.name) {
484
+ case 'getWeather': {
485
+ const args = weatherInputSchema.parse(request.params.arguments);
486
+ return await weatherTool.execute(args);
487
+ }
488
+ default:
489
+ return {
490
+ content: [
491
+ {
492
+ type: 'text',
493
+ text: `Unknown tool: ${request.params.name}`,
494
+ },
495
+ ],
496
+ isError: true,
497
+ };
498
+ }
499
+ } catch (error) {
500
+ if (error instanceof z.ZodError) {
501
+ return {
502
+ content: [
503
+ {
504
+ type: 'text',
505
+ text: `Invalid arguments: ${error.errors.map(e => `${e.path.join('.')}: ${e.message}`).join(', ')}`,
506
+ },
507
+ ],
508
+ isError: true,
509
+ };
510
+ }
511
+ return {
512
+ content: [
513
+ {
514
+ type: 'text',
515
+ text: `Error: ${error instanceof Error ? error.message : String(error)}`,
516
+ },
517
+ ],
518
+ isError: true,
519
+ };
520
+ }
521
+ });
522
+
523
+ // Start the server with SSE support
524
+ let transport: SSEServerTransport | undefined;
525
+
526
+ const httpServer = createServer(async (req: IncomingMessage, res: ServerResponse) => {
527
+ const url = new URL(req.url || '', `http://${req.headers.host}`);
528
+
529
+ if (url.pathname === '/sse') {
530
+ console.log('Received SSE connection');
531
+ transport = new SSEServerTransport('/message', res);
532
+ await server.connect(transport);
533
+
534
+ server.onclose = async () => {
535
+ await server.close();
536
+ transport = undefined;
537
+ };
538
+
539
+ // Handle client disconnection
540
+ res.on('close', () => {
541
+ transport = undefined;
542
+ });
543
+ } else if (url.pathname === '/message') {
544
+ console.log('Received message');
545
+ if (!transport) {
546
+ res.writeHead(503);
547
+ res.end('SSE connection not established');
548
+ return;
549
+ }
550
+ await transport.handlePostMessage(req, res);
551
+ } else {
552
+ console.log('Unknown path:', url.pathname);
553
+ res.writeHead(404);
554
+ res.end();
555
+ }
556
+ });
557
+
558
+ const PORT = process.env.PORT || 8080;
559
+ httpServer.listen(PORT, () => {
560
+ console.log(`Weather server is running on SSE at http://localhost:${PORT}`);
561
+ });
562
+
563
+ // Handle graceful shutdown
564
+ process.on('SIGINT', async () => {
565
+ console.log('Shutting down weather server...');
566
+ if (transport) {
567
+ await server.close();
568
+ transport = undefined;
569
+ }
570
+ // Close the HTTP server
571
+ httpServer.close(() => {
572
+ console.log('Weather server shut down complete');
573
+ process.exit(0);
574
+ });
575
+ });
576
+
577
+ export { server };
578
+
579
+ ```
@@ -15,7 +15,7 @@
15
15
  "author": "",
16
16
  "license": "MIT",
17
17
  "dependencies": {
18
- "@ai-sdk/openai": "^1.3.20",
18
+ "@ai-sdk/openai": "^1.3.22",
19
19
  "@mastra/core": "latest",
20
20
  "@mastra/mcp": "latest",
21
21
  "@mastra/mcp-registry-registry": "latest",
@@ -13,7 +13,7 @@
13
13
  "author": "",
14
14
  "license": "MIT",
15
15
  "dependencies": {
16
- "@ai-sdk/openai": "^1.2.1",
16
+ "@ai-sdk/openai": "^1.3.22",
17
17
  "@mastra/core": "latest",
18
18
  "@mastra/memory": "latest",
19
19
  "chalk": "^5.4.1",