@mastra/mcp-docs-server 1.2.8-alpha.9 → 1.2.8

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 (143) hide show
  1. package/.docs/docs/agent-builder/integrations.md +1 -3
  2. package/.docs/docs/agent-builder/overview.md +2 -0
  3. package/.docs/docs/agents/overview.md +17 -13
  4. package/.docs/docs/agents/skills.md +1 -3
  5. package/.docs/docs/agents/structured-output.md +2 -0
  6. package/.docs/docs/agents/using-tools.md +66 -49
  7. package/.docs/docs/browser/agent-browser.md +1 -0
  8. package/.docs/docs/browser/firecrawl.md +129 -0
  9. package/.docs/docs/browser/overview.md +16 -2
  10. package/.docs/docs/capabilities/channels/slack.md +111 -1
  11. package/.docs/docs/deployment/mastra-server.md +35 -0
  12. package/.docs/docs/deployment/monorepo.md +2 -0
  13. package/.docs/docs/deployment/overview.md +6 -0
  14. package/.docs/docs/deployment/sandbox.md +277 -0
  15. package/.docs/docs/editor/overview.md +2 -6
  16. package/.docs/docs/editor/tools.md +2 -6
  17. package/.docs/docs/evals/running-in-ci.md +3 -9
  18. package/.docs/docs/getting-started/build-with-ai.md +2 -6
  19. package/.docs/docs/getting-started/manual-install.md +1 -1
  20. package/.docs/docs/index.md +17 -13
  21. package/.docs/docs/long-running-agents/background-tasks.md +2 -2
  22. package/.docs/docs/long-running-agents/goals.md +3 -1
  23. package/.docs/docs/mastra-platform/database.md +12 -6
  24. package/.docs/docs/mastra-platform/deploy.md +14 -7
  25. package/.docs/docs/mastra-platform/environments.md +5 -4
  26. package/.docs/docs/mastra-platform/observability.md +4 -12
  27. package/.docs/docs/mastra-platform/overview.md +1 -1
  28. package/.docs/docs/mastra-platform/regions.md +73 -0
  29. package/.docs/docs/mastra-platform/workspace.md +111 -0
  30. package/.docs/docs/memory/observational-memory.md +77 -2
  31. package/.docs/docs/memory/overview.md +4 -0
  32. package/.docs/docs/observability/feedback.md +4 -0
  33. package/.docs/docs/observability/integrations/bridges/otel.md +1 -3
  34. package/.docs/docs/observability/integrations/exporters/otel.md +1 -3
  35. package/.docs/docs/server/auth/fga.md +40 -0
  36. package/.docs/docs/server/auth/simple-auth.md +1 -3
  37. package/.docs/docs/studio/overview.md +2 -0
  38. package/.docs/docs/workflows/control-flow.md +1 -3
  39. package/.docs/docs/workspace/filesystem.md +1 -0
  40. package/.docs/docs/workspace/sandbox.md +1 -0
  41. package/.docs/guides/getting-started/quickstart.md +40 -25
  42. package/.docs/guides/index.md +1 -1
  43. package/.docs/guides/migrations/vnext-to-standard-apis.md +1 -3
  44. package/.docs/models/environment-variables.md +2 -0
  45. package/.docs/models/gateways/netlify.md +3 -6
  46. package/.docs/models/gateways/openrouter.md +343 -346
  47. package/.docs/models/gateways/vercel.md +6 -5
  48. package/.docs/models/index.md +1 -1
  49. package/.docs/models/providers/aki-io.md +78 -0
  50. package/.docs/models/providers/alibaba-token-plan-cn.md +22 -21
  51. package/.docs/models/providers/alibaba-token-plan.md +22 -21
  52. package/.docs/models/providers/ambient.md +12 -10
  53. package/.docs/models/providers/baseten.md +2 -1
  54. package/.docs/models/providers/cline-pass.md +82 -0
  55. package/.docs/models/providers/cortecs.md +2 -1
  56. package/.docs/models/providers/crossmodel.md +2 -1
  57. package/.docs/models/providers/deepinfra.md +4 -7
  58. package/.docs/models/providers/deepseek.md +3 -1
  59. package/.docs/models/providers/empiriolabs.md +2 -1
  60. package/.docs/models/providers/google.md +4 -2
  61. package/.docs/models/providers/huggingface.md +2 -1
  62. package/.docs/models/providers/inferx.md +3 -3
  63. package/.docs/models/providers/kenari.md +44 -29
  64. package/.docs/models/providers/kimi-for-coding.md +6 -9
  65. package/.docs/models/providers/llmgateway.md +4 -1
  66. package/.docs/models/providers/moonshotai-cn.md +1 -1
  67. package/.docs/models/providers/moonshotai.md +1 -1
  68. package/.docs/models/providers/nebius.md +3 -1
  69. package/.docs/models/providers/novita-ai.md +3 -1
  70. package/.docs/models/providers/opencode-go.md +4 -3
  71. package/.docs/models/providers/opencode.md +4 -2
  72. package/.docs/models/providers/poolside.md +2 -2
  73. package/.docs/models/providers/togetherai.md +2 -6
  74. package/.docs/models/providers/wandb.md +2 -1
  75. package/.docs/models/providers/zenmux.md +3 -1
  76. package/.docs/models/providers.md +2 -0
  77. package/.docs/reference/agent-controller/session.md +13 -0
  78. package/.docs/reference/agents/agent.md +13 -1
  79. package/.docs/reference/agents/generate.md +18 -0
  80. package/.docs/reference/browser/firecrawl-browser.md +71 -0
  81. package/.docs/reference/cli/create-mastra.md +118 -43
  82. package/.docs/reference/cli/mastra.md +59 -5
  83. package/.docs/reference/code-sdk/mount-agent-controller.md +4 -4
  84. package/.docs/reference/core/getMCPServer.md +1 -3
  85. package/.docs/reference/core/getMCPServerById.md +1 -3
  86. package/.docs/reference/core/getWorkflow.md +1 -3
  87. package/.docs/reference/core/listMCPServers.md +2 -6
  88. package/.docs/reference/datasets/addItem.md +1 -3
  89. package/.docs/reference/datasets/addItems.md +1 -3
  90. package/.docs/reference/datasets/compareExperiments.md +1 -3
  91. package/.docs/reference/datasets/create.md +1 -3
  92. package/.docs/reference/datasets/dataset.md +2 -6
  93. package/.docs/reference/datasets/datasets-manager.md +5 -15
  94. package/.docs/reference/datasets/delete.md +1 -3
  95. package/.docs/reference/datasets/deleteExperiment.md +1 -3
  96. package/.docs/reference/datasets/deleteItem.md +1 -3
  97. package/.docs/reference/datasets/deleteItems.md +1 -3
  98. package/.docs/reference/datasets/get.md +1 -3
  99. package/.docs/reference/datasets/getDetails.md +1 -3
  100. package/.docs/reference/datasets/getExperiment.md +1 -3
  101. package/.docs/reference/datasets/getItem.md +1 -3
  102. package/.docs/reference/datasets/getItemHistory.md +1 -3
  103. package/.docs/reference/datasets/list.md +1 -3
  104. package/.docs/reference/datasets/listExperimentResults.md +1 -3
  105. package/.docs/reference/datasets/listExperiments.md +1 -3
  106. package/.docs/reference/datasets/listItems.md +1 -3
  107. package/.docs/reference/datasets/listVersions.md +1 -3
  108. package/.docs/reference/datasets/startExperiment.md +1 -3
  109. package/.docs/reference/datasets/startExperimentAsync.md +1 -3
  110. package/.docs/reference/datasets/update.md +1 -3
  111. package/.docs/reference/datasets/updateItem.md +1 -3
  112. package/.docs/reference/editor/mastra-editor.md +1 -3
  113. package/.docs/reference/evals/context-recall.md +205 -0
  114. package/.docs/reference/evals/create-scorer.md +3 -9
  115. package/.docs/reference/evals/mastra-scorer.md +1 -3
  116. package/.docs/reference/file-based-agents/tools.md +7 -6
  117. package/.docs/reference/index.md +5 -0
  118. package/.docs/reference/memory/observational-memory.md +21 -0
  119. package/.docs/reference/observability/tracing/exporters/posthog.md +39 -1
  120. package/.docs/reference/observability/tracing/processors/sensitive-data-filter.md +1 -3
  121. package/.docs/reference/processors/token-limiter-processor.md +1 -3
  122. package/.docs/reference/rag/database-config.md +12 -0
  123. package/.docs/reference/streaming/agents/stream.md +2 -0
  124. package/.docs/reference/templates/overview.md +6 -32
  125. package/.docs/reference/tools/create-tool.md +78 -52
  126. package/.docs/reference/tools/mcp-client.md +8 -24
  127. package/.docs/reference/tools/mcp-server.md +143 -44
  128. package/.docs/reference/tools/tavily.md +1 -1
  129. package/.docs/reference/tools/vector-query-tool.md +22 -0
  130. package/.docs/reference/vectors/mongodb.md +2 -0
  131. package/.docs/reference/vectors/turbopuffer.md +4 -0
  132. package/.docs/reference/voice/mistral.md +127 -0
  133. package/.docs/reference/workspace/daytona-sandbox.md +2 -6
  134. package/.docs/reference/workspace/platform-filesystem.md +182 -0
  135. package/.docs/reference/workspace/platform-sandbox.md +200 -0
  136. package/.docs/reference/workspace/railway-sandbox.md +37 -1
  137. package/CHANGELOG.md +71 -0
  138. package/dist/{chunk-GLPCVXXO.js → chunk-HGADBLKG.js} +2 -2
  139. package/dist/{chunk-GLPCVXXO.js.map → chunk-HGADBLKG.js.map} +1 -1
  140. package/dist/index.js +1 -1
  141. package/dist/stdio.js +1 -1
  142. package/dist/tools/docs.d.ts.map +1 -1
  143. package/package.json +8 -8
@@ -10,25 +10,29 @@ The `createTool()` function is used to define custom tools that your Mastra agen
10
10
  import { createTool } from '@mastra/core/tools'
11
11
  import { z } from 'zod'
12
12
 
13
- export const tool = createTool({
14
- id: 'test-tool',
15
- description: 'Reverse the input string',
13
+ export const weatherTool = createTool({
14
+ id: 'weather-tool',
15
+ description: 'Get the current weather for a location',
16
16
  inputSchema: z.object({
17
- input: z.string(),
17
+ location: z.string(),
18
18
  }),
19
19
  outputSchema: z.object({
20
- output: z.string(),
20
+ location: z.string(),
21
+ temperatureCelsius: z.number(),
22
+ conditions: z.string(),
21
23
  }),
22
- execute: async inputData => {
23
- const reversed = inputData.input.split('').reverse().join('')
24
-
24
+ execute: async ({ location }) => {
25
25
  return {
26
- output: reversed,
26
+ location,
27
+ temperatureCelsius: 21,
28
+ conditions: 'sunny',
27
29
  }
28
30
  },
29
31
  })
30
32
  ```
31
33
 
34
+ The first `execute` parameter is the validated value from `inputSchema`. Destructure schema fields directly in the function signature, as shown with `{ location }`. The optional second parameter contains the execution context.
35
+
32
36
  ## Parameters
33
37
 
34
38
  **id** (`string`): A unique identifier for the tool.
@@ -112,10 +116,12 @@ export const weatherTool = createTool({
112
116
  location: z.string(),
113
117
  }),
114
118
  outputSchema: z.object({
115
- weather: z.string(),
119
+ location: z.string(),
120
+ temperatureCelsius: z.number(),
121
+ conditions: z.string(),
116
122
  }),
117
- execute: async inputData => {
118
- // Fetch weather data
123
+ execute: async ({ location }) => {
124
+ return { location, temperatureCelsius: 21, conditions: 'sunny' }
119
125
  },
120
126
  })
121
127
  ```
@@ -137,11 +143,13 @@ export const weatherTool = createTool({
137
143
  ),
138
144
  outputSchema: toStandardJsonSchema(
139
145
  v.object({
140
- weather: v.string(),
146
+ location: v.string(),
147
+ temperatureCelsius: v.number(),
148
+ conditions: v.string(),
141
149
  }),
142
150
  ),
143
- execute: async inputData => {
144
- // Fetch weather data
151
+ execute: async ({ location }) => {
152
+ return { location, temperatureCelsius: 21, conditions: 'sunny' }
145
153
  },
146
154
  })
147
155
  ```
@@ -159,10 +167,12 @@ export const weatherTool = createTool({
159
167
  location: 'string',
160
168
  }),
161
169
  outputSchema: type({
162
- weather: 'string',
170
+ location: 'string',
171
+ temperatureCelsius: 'number',
172
+ conditions: 'string',
163
173
  }),
164
- execute: async inputData => {
165
- // Fetch weather data
174
+ execute: async ({ location }) => {
175
+ return { location, temperatureCelsius: 21, conditions: 'sunny' }
166
176
  },
167
177
  })
168
178
  ```
@@ -176,18 +186,22 @@ import { createTool } from '@mastra/core/tools'
176
186
  import { z } from 'zod'
177
187
 
178
188
  export const weatherTool = createTool({
179
- id: 'get-weather',
180
- description: 'Get weather for a city',
189
+ id: 'weather-tool',
190
+ description: 'Get the current weather for a location',
181
191
  strict: true,
182
192
  inputSchema: z.object({
183
- city: z.string(),
184
- units: z.enum(['metric', 'imperial']),
193
+ location: z.string(),
194
+ }),
195
+ outputSchema: z.object({
196
+ location: z.string(),
197
+ temperatureCelsius: z.number(),
198
+ conditions: z.string(),
185
199
  }),
186
- execute: async ({ city, units }) => {
200
+ execute: async ({ location }) => {
187
201
  return {
188
- city,
189
- units,
190
- forecast: 'sunny',
202
+ location,
203
+ temperatureCelsius: 21,
204
+ conditions: 'sunny',
191
205
  }
192
206
  },
193
207
  })
@@ -204,28 +218,31 @@ import { createTool } from '@mastra/core/tools'
204
218
  import { z } from 'zod'
205
219
 
206
220
  export const weatherTool = createTool({
207
- id: 'get-weather',
208
- description: 'Get weather for a city',
221
+ id: 'weather-tool',
222
+ description: 'Get the current weather for a location',
209
223
  inputSchema: z.object({
210
- city: z.string(),
224
+ location: z.string(),
211
225
  }),
212
226
  outputSchema: z.object({
213
- city: z.string(),
214
- temperature: z.number(),
215
- condition: z.string(),
227
+ location: z.string(),
228
+ temperatureCelsius: z.number(),
229
+ conditions: z.string(),
216
230
  radarImageUrl: z.string().url(),
217
231
  }),
218
- execute: async ({ city }) => ({
219
- city,
220
- temperature: 72,
221
- condition: 'sunny',
232
+ execute: async ({ location }) => ({
233
+ location,
234
+ temperatureCelsius: 21,
235
+ conditions: 'sunny',
222
236
  radarImageUrl: 'https://example.com/radar/seattle.png',
223
237
  }),
224
238
  toModelOutput: output => {
225
239
  return {
226
240
  type: 'content',
227
241
  value: [
228
- { type: 'text', text: `${output.city}: ${output.temperature}F and ${output.condition}` },
242
+ {
243
+ type: 'text',
244
+ text: `${output.location}: ${output.temperatureCelsius}°C and ${output.conditions}`,
245
+ },
229
246
  { type: 'image-url', url: output.radarImageUrl },
230
247
  ],
231
248
  }
@@ -294,11 +311,16 @@ import { createTool } from '@mastra/core/tools'
294
311
  import { z } from 'zod'
295
312
 
296
313
  export const weatherTool = createTool({
297
- id: 'get-weather',
298
- description: 'Get current weather for a location',
314
+ id: 'weather-tool',
315
+ description: 'Get the current weather for a location',
299
316
  inputSchema: z.object({
300
317
  location: z.string().describe('City name or coordinates'),
301
318
  }),
319
+ outputSchema: z.object({
320
+ location: z.string(),
321
+ temperatureCelsius: z.number(),
322
+ conditions: z.string(),
323
+ }),
302
324
  // MCP-specific properties
303
325
  mcp: {
304
326
  // Annotations for client behavior hints
@@ -315,9 +337,11 @@ export const weatherTool = createTool({
315
337
  category: 'weather',
316
338
  },
317
339
  },
318
- execute: async inputData => {
340
+ execute: async ({ location }) => {
319
341
  return {
320
- weather: `Current weather for ${inputData.location}: sunny`,
342
+ location,
343
+ temperatureCelsius: 21,
344
+ conditions: 'sunny',
321
345
  }
322
346
  },
323
347
  })
@@ -334,19 +358,21 @@ import { createTool } from '@mastra/core/tools'
334
358
  import { z } from 'zod'
335
359
 
336
360
  export const weatherTool = createTool({
337
- id: 'get-weather',
338
- description: 'Get weather for a city',
361
+ id: 'weather-tool',
362
+ description: 'Get the current weather for a location',
339
363
  inputSchema: z.object({
340
- city: z.string(),
364
+ location: z.string(),
341
365
  }),
342
366
  outputSchema: z.object({
343
- city: z.string(),
344
- forecast: z.string(),
367
+ location: z.string(),
368
+ temperatureCelsius: z.number(),
369
+ conditions: z.string(),
345
370
  }),
346
- execute: async ({ city }) => {
371
+ execute: async ({ location }) => {
347
372
  return {
348
- city,
349
- forecast: 'sunny',
373
+ location,
374
+ temperatureCelsius: 21,
375
+ conditions: 'sunny',
350
376
  }
351
377
  },
352
378
  onInputStart: ({ toolCallId }) => {
@@ -356,10 +382,10 @@ export const weatherTool = createTool({
356
382
  console.log(`Tool call ${toolCallId} received input chunk: ${inputTextDelta}`)
357
383
  },
358
384
  onInputAvailable: ({ input, toolCallId }) => {
359
- console.log(`Tool call ${toolCallId} received city: ${input.city}`)
385
+ console.log(`Tool call ${toolCallId} received location: ${input.location}`)
360
386
  },
361
387
  onOutput: ({ output, toolCallId, toolName }) => {
362
- console.log(`Tool ${toolName} call ${toolCallId} returned forecast: ${output.forecast}`)
388
+ console.log(`Tool ${toolName} call ${toolCallId} returned conditions: ${output.conditions}`)
363
389
  },
364
390
  })
365
391
  ```
@@ -403,7 +429,7 @@ export const tool = createTool({
403
429
  id: 'example-tool',
404
430
  description: 'Example tool with hooks',
405
431
  inputSchema: z.object({
406
- city: z.string(),
432
+ location: z.string(),
407
433
  }),
408
434
  onInputAvailable: ({ input, toolCallId, messages, abortSignal }) => {
409
435
  console.log(`Tool received complete input:`, input)
@@ -280,9 +280,7 @@ This is useful for connecting external MCP servers that implement the MCP Apps e
280
280
  The `MCPClient` instance has a `resources` property that provides access to resource-related operations.
281
281
 
282
282
  ```typescript
283
- const mcpClient = new MCPClient({
284
- /* ...servers configuration... */
285
- })
283
+ const mcpClient = new MCPClient({/* ...servers configuration... */})
286
284
 
287
285
  // Access resource methods via mcpClient.resources
288
286
  const allResourcesByServer = await mcpClient.resources.list()
@@ -411,9 +409,7 @@ mcpClient.resources.onListChanged('myWeatherServer', () => {
411
409
  The `MCPClient` instance has an `elicitation` property that provides access to elicitation-related operations. Elicitation allows MCP servers to request structured information from users.
412
410
 
413
411
  ```typescript
414
- const mcpClient = new MCPClient({
415
- /* ...servers configuration... */
416
- })
412
+ const mcpClient = new MCPClient({/* ...servers configuration... */})
417
413
 
418
414
  // Set up elicitation handler
419
415
  mcpClient.elicitation.onRequest('serverName', async request => {
@@ -552,9 +548,7 @@ await mcpClient.elicitation.onRequest('interactiveServer', async request => {
552
548
  The `MCPClient` instance has a `prompts` property that provides access to prompt-related operations.
553
549
 
554
550
  ```typescript
555
- const mcpClient = new MCPClient({
556
- /* ...servers configuration... */
557
- })
551
+ const mcpClient = new MCPClient({/* ...servers configuration... */})
558
552
 
559
553
  // Access prompt methods via mcpClient.prompts
560
554
  const allPromptsByServer = await mcpClient.prompts.list()
@@ -980,9 +974,7 @@ class DatabaseOAuthStorage implements OAuthStorage {
980
974
 
981
975
  const provider = new MCPOAuthClientProvider({
982
976
  redirectUrl: 'http://localhost:3000/callback',
983
- clientMetadata: {
984
- /* ... */
985
- },
977
+ clientMetadata: {/* ... */},
986
978
  storage: new DatabaseOAuthStorage(db, 'user-123'),
987
979
  })
988
980
  ```
@@ -1117,33 +1109,25 @@ For example, if you try to create multiple instances with the same configuration
1117
1109
  ```typescript
1118
1110
  // First instance - OK
1119
1111
  const mcp1 = new MCPClient({
1120
- servers: {
1121
- /* ... */
1122
- },
1112
+ servers: {/* ... */},
1123
1113
  })
1124
1114
 
1125
1115
  // Second instance with same config - Will throw an error
1126
1116
  const mcp2 = new MCPClient({
1127
- servers: {
1128
- /* ... */
1129
- },
1117
+ servers: {/* ... */},
1130
1118
  })
1131
1119
 
1132
1120
  // To fix, either:
1133
1121
  // 1. Add unique IDs
1134
1122
  const mcp3 = new MCPClient({
1135
1123
  id: 'instance-1',
1136
- servers: {
1137
- /* ... */
1138
- },
1124
+ servers: {/* ... */},
1139
1125
  })
1140
1126
 
1141
1127
  // 2. Or disconnect before recreating
1142
1128
  await mcp1.disconnect()
1143
1129
  const mcp4 = new MCPClient({
1144
- servers: {
1145
- /* ... */
1146
- },
1130
+ servers: {/* ... */},
1147
1131
  })
1148
1132
  ```
1149
1133
 
@@ -187,9 +187,7 @@ const server = new MCPServer({
187
187
  id: 'my-server',
188
188
  name: 'My Server',
189
189
  version: '1.0.0',
190
- tools: {
191
- /* ... */
192
- },
190
+ tools: {/* ... */},
193
191
  })
194
192
  await server.startStdio()
195
193
  ```
@@ -353,9 +351,7 @@ const server = new MCPServer({
353
351
  id: 'my-serverless-mcp',
354
352
  name: 'My Serverless MCP',
355
353
  version: '1.0.0',
356
- tools: {
357
- /* your tools */
358
- },
354
+ tools: {/* your tools */},
359
355
  })
360
356
 
361
357
  serve(async req => {
@@ -637,9 +633,7 @@ const serverWithResources = new MCPServer({
637
633
  id: 'resourceful-server',
638
634
  name: 'Resourceful Server',
639
635
  version: '1.0.0',
640
- tools: {
641
- /* ... your tools ... */
642
- },
636
+ tools: {/* ... your tools ... */},
643
637
  resources: myResourceHandlers,
644
638
  })
645
639
  ```
@@ -768,9 +762,7 @@ const serverWithPrompts = new MCPServer({
768
762
  id: 'promptful-server',
769
763
  name: 'Promptful Server',
770
764
  version: '1.0.0',
771
- tools: {
772
- /* ... */
773
- },
765
+ tools: {/* ... */},
774
766
  prompts: myPromptHandlers,
775
767
  })
776
768
  ```
@@ -966,9 +958,7 @@ execute: async (inputData, context) => {
966
958
  // Use elicitation capabilities
967
959
  const result = await context.mcp.elicitation.sendRequest({
968
960
  message: 'Please provide information',
969
- requestedSchema: {
970
- /* schema */
971
- },
961
+ requestedSchema: {/* schema */},
972
962
  })
973
963
 
974
964
  return result
@@ -1159,9 +1149,7 @@ const mcpServer = new MCPServer({
1159
1149
  id: 'protected-server',
1160
1150
  name: 'Protected MCP Server',
1161
1151
  version: '1.0.0',
1162
- tools: {
1163
- /* your tools */
1164
- },
1152
+ tools: {/* your tools */},
1165
1153
  })
1166
1154
 
1167
1155
  // Create OAuth middleware
@@ -1342,21 +1330,48 @@ To pass data to your tools, populate `req.auth` on the Node.js request object in
1342
1330
  ```typescript
1343
1331
  import express from 'express'
1344
1332
 
1333
+ type MCPAuthenticatedRequest = express.Request & {
1334
+ auth?: {
1335
+ token: string
1336
+ clientId: string
1337
+ scopes: string[]
1338
+ expiresAt?: number
1339
+ extra?: Record<string, unknown>
1340
+ }
1341
+ }
1342
+
1345
1343
  const app = express()
1346
1344
 
1347
1345
  // Auth middleware - set req.auth before the MCP handler
1348
- app.use('/mcp', (req, res, next) => {
1349
- const token = req.headers.authorization?.replace('Bearer ', '')
1350
- const user = verifyToken(token)
1351
-
1352
- // This entire object becomes context.mcp.extra.authInfo
1353
- // @ts-ignore - req.auth is read by the MCP SDK
1354
- req.auth = {
1355
- token,
1356
- userId: user.userId,
1357
- email: user.email,
1346
+ app.use('/mcp', async (req, res, next) => {
1347
+ const authorization = req.headers.authorization
1348
+
1349
+ if (!authorization?.startsWith('Bearer ')) {
1350
+ res.status(401).json({ error: 'Missing bearer token' })
1351
+ return
1352
+ }
1353
+
1354
+ const token = authorization.slice('Bearer '.length)
1355
+
1356
+ try {
1357
+ const user = await verifyToken(token)
1358
+
1359
+ // This entire object becomes context.mcp.extra.authInfo
1360
+ const authenticatedRequest = req as MCPAuthenticatedRequest
1361
+ authenticatedRequest.auth = {
1362
+ token,
1363
+ clientId: user.clientId,
1364
+ scopes: user.scopes,
1365
+ expiresAt: user.expiresAt,
1366
+ extra: {
1367
+ userId: user.userId,
1368
+ email: user.email,
1369
+ },
1370
+ }
1371
+ next()
1372
+ } catch {
1373
+ res.status(401).json({ error: 'Invalid or expired token' })
1358
1374
  }
1359
- next()
1360
1375
  })
1361
1376
 
1362
1377
  app.all('/mcp', async (req, res) => {
@@ -1434,19 +1449,86 @@ The full `context.mcp.extra` object contains:
1434
1449
 
1435
1450
  ### Complete Example
1436
1451
 
1437
- Here's a complete example showing the data flow from middleware to tool:
1452
+ Install [`jose`](https://github.com/panva/jose) to verify JSON Web Tokens (JWTs) against your identity provider's JSON Web Key Set (JWKS):
1453
+
1454
+ **npm**:
1455
+
1456
+ ```shell
1457
+ npm install jose
1458
+ ```
1459
+
1460
+ **pnpm**:
1461
+
1462
+ ```shell
1463
+ pnpm add jose
1464
+ ```
1465
+
1466
+ **Yarn**:
1467
+
1468
+ ```shell
1469
+ yarn add jose
1470
+ ```
1471
+
1472
+ **Bun**:
1473
+
1474
+ ```shell
1475
+ bun add jose
1476
+ ```
1477
+
1478
+ The following example validates the token's signature, issuer, audience, algorithm, expiration, and required claims before passing its user data to the tool:
1438
1479
 
1439
1480
  ```typescript
1440
1481
  import express from 'express'
1482
+ import { createRemoteJWKSet, jwtVerify } from 'jose'
1441
1483
  import { MCPServer } from '@mastra/mcp'
1442
1484
  import { createTool } from '@mastra/core/tools'
1443
1485
  import { z } from 'zod'
1444
1486
 
1445
- const verifyToken = (token: string) => {
1446
- // TODO: Implement token verification
1487
+ type MCPAuthenticatedRequest = express.Request & {
1488
+ auth?: {
1489
+ token: string
1490
+ clientId: string
1491
+ scopes: string[]
1492
+ expiresAt?: number
1493
+ extra?: Record<string, unknown>
1494
+ }
1495
+ }
1496
+
1497
+ const issuer = process.env.JWT_ISSUER
1498
+ const audience = process.env.JWT_AUDIENCE
1499
+ const jwksUri = process.env.JWT_JWKS_URI
1500
+
1501
+ if (!issuer || !audience || !jwksUri) {
1502
+ throw new Error('JWT_ISSUER, JWT_AUDIENCE, and JWT_JWKS_URI are required')
1503
+ }
1504
+
1505
+ const jwks = createRemoteJWKSet(new URL(jwksUri))
1506
+
1507
+ const verifyToken = async (token: string) => {
1508
+ const { payload } = await jwtVerify(token, jwks, {
1509
+ issuer,
1510
+ audience,
1511
+ algorithms: ['RS256'],
1512
+ requiredClaims: ['exp'],
1513
+ })
1514
+
1515
+ const clientId =
1516
+ typeof payload.client_id === 'string'
1517
+ ? payload.client_id
1518
+ : typeof payload.azp === 'string'
1519
+ ? payload.azp
1520
+ : undefined
1521
+
1522
+ if (!payload.sub || typeof payload.email !== 'string' || !clientId || !payload.exp) {
1523
+ throw new Error('Token must contain sub, email, exp, and client_id or azp claims')
1524
+ }
1525
+
1447
1526
  return {
1448
- userId: '123',
1449
- email: 'test@test.com',
1527
+ userId: payload.sub,
1528
+ clientId,
1529
+ email: payload.email,
1530
+ expiresAt: payload.exp,
1531
+ scopes: typeof payload.scope === 'string' ? payload.scope.split(' ') : [],
1450
1532
  }
1451
1533
  }
1452
1534
 
@@ -1481,18 +1563,35 @@ const server = new MCPServer({
1481
1563
  // 3. Set up Express with auth middleware
1482
1564
  const app = express()
1483
1565
 
1484
- app.use('/mcp', (req, res, next) => {
1485
- const token = req.headers.authorization?.replace('Bearer ', '')
1486
- const user = verifyToken(token)
1566
+ app.use('/mcp', async (req, res, next) => {
1567
+ const authorization = req.headers.authorization
1568
+
1569
+ if (!authorization?.startsWith('Bearer ')) {
1570
+ res.status(401).json({ error: 'Missing bearer token' })
1571
+ return
1572
+ }
1487
1573
 
1488
- // This entire object becomes context.mcp.extra.authInfo
1489
- // @ts-ignore - req.auth is read by the MCP SDK
1490
- req.auth = {
1491
- token,
1492
- userId: user.userId,
1493
- email: user.email,
1574
+ const token = authorization.slice('Bearer '.length)
1575
+
1576
+ try {
1577
+ const user = await verifyToken(token)
1578
+
1579
+ // This entire object becomes context.mcp.extra.authInfo
1580
+ const authenticatedRequest = req as MCPAuthenticatedRequest
1581
+ authenticatedRequest.auth = {
1582
+ token,
1583
+ clientId: user.clientId,
1584
+ scopes: user.scopes,
1585
+ expiresAt: user.expiresAt,
1586
+ extra: {
1587
+ userId: user.userId,
1588
+ email: user.email,
1589
+ },
1590
+ }
1591
+ next()
1592
+ } catch {
1593
+ res.status(401).json({ error: 'Invalid or expired token' })
1494
1594
  }
1495
- next()
1496
1595
  })
1497
1596
 
1498
1597
  app.all('/mcp', async (req, res) => {
@@ -59,7 +59,7 @@ All factory functions accept `TavilyClientOptions` from `@tavily/core`:
59
59
 
60
60
  **apiKey** (`string`): Tavily API key. Falls back to the TAVILY\_API\_KEY environment variable.
61
61
 
62
- **clientSource** (`string`): Attribution string sent with each request. (Default: `'mastra'`)
62
+ **clientName** (`string`): Attribution string sent with each request in the X-Client-Name header. (Default: `'mastra'`)
63
63
 
64
64
  **apiBaseURL** (`string`): Base URL for the Tavily API.
65
65
 
@@ -269,6 +269,28 @@ const chromaQueryTool = createVectorQueryTool({
269
269
  - **whereDocument**: Filter by document content
270
270
  - **Use Cases**: Advanced filtering, content-based search
271
271
 
272
+ **Turbopuffer**:
273
+
274
+ ### Turbopuffer Configuration
275
+
276
+ ```typescript
277
+ const turbopufferQueryTool = createVectorQueryTool({
278
+ vectorStoreName: 'turbopuffer',
279
+ indexName: 'docs',
280
+ model: new ModelRouterEmbeddingModel('openai/text-embedding-3-small'),
281
+ databaseConfig: {
282
+ turbopuffer: {
283
+ consistency: 'eventual', // Lower latency, recently written data may not be visible yet
284
+ },
285
+ },
286
+ })
287
+ ```
288
+
289
+ **Turbopuffer Features:**
290
+
291
+ - **consistency**: Choose between `strong` (default, read-your-writes) and `eventual` (lower latency)
292
+ - **Use Cases**: Latency-sensitive queries where slightly stale data is acceptable
293
+
272
294
  **Multiple Configs**:
273
295
 
274
296
  ### Multiple Database Configurations
@@ -89,6 +89,8 @@ Creates a new vector index (collection) in MongoDB.
89
89
 
90
90
  **metric** (`'cosine' | 'euclidean' | 'dotproduct'`): Distance metric for similarity search (Default: `cosine`)
91
91
 
92
+ **filterFields** (`string[]`): Metadata field names to declare as filter fields in the Atlas vectorSearch index (registered as metadata.\<field>). Queries that filter only on declared fields are pushed directly into $vectorSearch instead of pre-filtering candidate \_ids, avoiding the 16 MB BSON limit on large result sets. Filters that reference an undeclared field, or use an operator $vectorSearch does not support, fall back to the pre-filter automatically.
93
+
92
94
  ### `waitForIndexReady()`
93
95
 
94
96
  Waits for an index to become ready after creation. Useful when you need to ensure an index is ready before performing operations.
@@ -18,6 +18,8 @@ The TurbopufferVector class provides vector search using [Turbopuffer](https://t
18
18
 
19
19
  **compression** (`boolean`): Whether to compress requests and accept compressed responses. (Default: `true`)
20
20
 
21
+ **consistency** (`'strong' | 'eventual'`): The default consistency level for queries. Can be overridden per query. "strong" guarantees queries see all data written before the query started, at the cost of higher latency. "eventual" offers lower latency, but recently written data may not be visible yet. (Default: `strong`)
22
+
21
23
  **schemaConfigForIndex** (`function`): A callback function that takes an index name and returns a config object for that index. This allows you to define explicit schemas per index.
22
24
 
23
25
  ## Methods
@@ -50,6 +52,8 @@ The TurbopufferVector class provides vector search using [Turbopuffer](https://t
50
52
 
51
53
  **includeVector** (`boolean`): Whether to include vectors in the results (Default: `false`)
52
54
 
55
+ **consistency** (`'strong' | 'eventual'`): The consistency level for this query. Overrides the consistency level set in the constructor. Defaults to "strong".
56
+
53
57
  ### `listIndexes()`
54
58
 
55
59
  Returns an array of index names as strings.