@mastra/mcp-docs-server 0.13.2-alpha.0 → 0.13.2-alpha.2

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 (115) hide show
  1. package/.docs/organized/changelogs/%40mastra%2Fagui.md +12 -0
  2. package/.docs/organized/changelogs/%40mastra%2Fastra.md +25 -25
  3. package/.docs/organized/changelogs/%40mastra%2Fchroma.md +25 -25
  4. package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +26 -26
  5. package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +32 -32
  6. package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +25 -25
  7. package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +26 -26
  8. package/.docs/organized/changelogs/%40mastra%2Fcore.md +26 -26
  9. package/.docs/organized/changelogs/%40mastra%2Fcouchbase.md +14 -14
  10. package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +40 -40
  11. package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +44 -44
  12. package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +42 -42
  13. package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +45 -45
  14. package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +27 -27
  15. package/.docs/organized/changelogs/%40mastra%2Fevals.md +13 -13
  16. package/.docs/organized/changelogs/%40mastra%2Ffirecrawl.md +16 -16
  17. package/.docs/organized/changelogs/%40mastra%2Fgithub.md +13 -13
  18. package/.docs/organized/changelogs/%40mastra%2Flance.md +25 -0
  19. package/.docs/organized/changelogs/%40mastra%2Flibsql.md +28 -28
  20. package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +30 -30
  21. package/.docs/organized/changelogs/%40mastra%2Fmcp-registry-registry.md +16 -16
  22. package/.docs/organized/changelogs/%40mastra%2Fmcp.md +24 -24
  23. package/.docs/organized/changelogs/%40mastra%2Fmem0.md +13 -13
  24. package/.docs/organized/changelogs/%40mastra%2Fmemory.md +35 -35
  25. package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +28 -28
  26. package/.docs/organized/changelogs/%40mastra%2Fopensearch.md +24 -0
  27. package/.docs/organized/changelogs/%40mastra%2Fpg.md +28 -28
  28. package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +14 -14
  29. package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +38 -38
  30. package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +14 -14
  31. package/.docs/organized/changelogs/%40mastra%2Frag.md +14 -14
  32. package/.docs/organized/changelogs/%40mastra%2Fragie.md +13 -13
  33. package/.docs/organized/changelogs/%40mastra%2Fschema-compat.md +6 -0
  34. package/.docs/organized/changelogs/%40mastra%2Fserver.md +32 -32
  35. package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +14 -14
  36. package/.docs/organized/changelogs/%40mastra%2Fupstash.md +26 -26
  37. package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +14 -14
  38. package/.docs/organized/changelogs/%40mastra%2Fvoice-cloudflare.md +13 -13
  39. package/.docs/organized/changelogs/%40mastra%2Fvoice-deepgram.md +14 -14
  40. package/.docs/organized/changelogs/%40mastra%2Fvoice-elevenlabs.md +14 -14
  41. package/.docs/organized/changelogs/%40mastra%2Fvoice-gladia.md +12 -0
  42. package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +14 -14
  43. package/.docs/organized/changelogs/%40mastra%2Fvoice-murf.md +13 -13
  44. package/.docs/organized/changelogs/%40mastra%2Fvoice-openai.md +14 -14
  45. package/.docs/organized/changelogs/%40mastra%2Fvoice-playai.md +13 -13
  46. package/.docs/organized/changelogs/%40mastra%2Fvoice-sarvam.md +13 -13
  47. package/.docs/organized/changelogs/%40mastra%2Fvoice-speechify.md +14 -14
  48. package/.docs/organized/changelogs/create-mastra.md +7 -7
  49. package/.docs/organized/changelogs/mastra.md +48 -48
  50. package/.docs/organized/code-examples/a2a.md +1 -1
  51. package/.docs/organized/code-examples/agent-network.md +125 -7
  52. package/.docs/organized/code-examples/agent.md +183 -6
  53. package/.docs/organized/code-examples/agui.md +4 -4
  54. package/.docs/organized/code-examples/ai-sdk-useChat.md +6 -6
  55. package/.docs/organized/code-examples/assistant-ui.md +6 -6
  56. package/.docs/organized/code-examples/bird-checker-with-express.md +1 -1
  57. package/.docs/organized/code-examples/bird-checker-with-nextjs-and-eval.md +6 -6
  58. package/.docs/organized/code-examples/bird-checker-with-nextjs.md +6 -6
  59. package/.docs/organized/code-examples/client-side-tools.md +6 -6
  60. package/.docs/organized/code-examples/crypto-chatbot.md +6 -6
  61. package/.docs/organized/code-examples/experimental-auth-weather-agent.md +1 -1
  62. package/.docs/organized/code-examples/fireworks-r1.md +1 -1
  63. package/.docs/organized/code-examples/mcp-configuration.md +2 -2
  64. package/.docs/organized/code-examples/mcp-registry-registry.md +1 -1
  65. package/.docs/organized/code-examples/memory-per-resource-example.md +236 -0
  66. package/.docs/organized/code-examples/memory-with-mem0.md +1 -1
  67. package/.docs/organized/code-examples/memory-with-processors.md +1 -1
  68. package/.docs/organized/code-examples/openapi-spec-writer.md +6 -6
  69. package/.docs/organized/code-examples/quick-start.md +1 -1
  70. package/.docs/organized/code-examples/stock-price-tool.md +1 -1
  71. package/.docs/organized/code-examples/weather-agent.md +1 -1
  72. package/.docs/organized/code-examples/workflow-ai-recruiter.md +1 -1
  73. package/.docs/organized/code-examples/workflow-with-inline-steps.md +1 -1
  74. package/.docs/organized/code-examples/workflow-with-memory.md +1 -1
  75. package/.docs/organized/code-examples/workflow-with-separate-steps.md +1 -1
  76. package/.docs/raw/agents/using-tools-and-mcp.mdx +3 -2
  77. package/.docs/raw/deployment/cloud-providers/digital-ocean.mdx +111 -0
  78. package/.docs/raw/deployment/cloud-providers/index.mdx +15 -0
  79. package/.docs/raw/frameworks/agentic-uis/copilotkit.mdx +53 -10
  80. package/.docs/raw/mastra-cloud/dashboard.mdx +100 -0
  81. package/.docs/raw/mastra-cloud/observability.mdx +24 -138
  82. package/.docs/raw/mastra-cloud/overview.mdx +50 -42
  83. package/.docs/raw/mastra-cloud/setting-up.mdx +51 -87
  84. package/.docs/raw/memory/overview.mdx +4 -0
  85. package/.docs/raw/memory/working-memory.mdx +144 -1
  86. package/.docs/raw/networks-vnext/complex-task-execution.mdx +137 -0
  87. package/.docs/raw/networks-vnext/overview.mdx +85 -0
  88. package/.docs/raw/networks-vnext/single-task-execution.mdx +131 -0
  89. package/.docs/raw/observability/nextjs-tracing.mdx +2 -2
  90. package/.docs/raw/reference/client-js/agents.mdx +41 -0
  91. package/.docs/raw/reference/deployer/netlify.mdx +22 -68
  92. package/.docs/raw/reference/deployer/vercel.mdx +7 -77
  93. package/.docs/raw/reference/storage/libsql.mdx +1 -0
  94. package/.docs/raw/reference/tools/mcp-client.mdx +244 -0
  95. package/.docs/raw/reference/tools/mcp-server.mdx +186 -0
  96. package/.docs/raw/reference/tools/vector-query-tool.mdx +1 -0
  97. package/.docs/raw/reference/workflows/create-run.mdx +1 -1
  98. package/.docs/raw/reference/workflows/resume.mdx +1 -1
  99. package/.docs/raw/reference/workflows/sleep.mdx +43 -0
  100. package/.docs/raw/reference/workflows/sleepUntil.mdx +43 -0
  101. package/.docs/raw/reference/workflows/start.mdx +1 -1
  102. package/.docs/raw/reference/workflows/stream.mdx +1 -1
  103. package/.docs/raw/reference/workflows/waitForEvent.mdx +49 -0
  104. package/.docs/raw/reference/workflows/watch.mdx +1 -1
  105. package/.docs/raw/reference/workflows/workflow.mdx +6 -2
  106. package/.docs/raw/storage/overview.mdx +50 -1
  107. package/.docs/raw/tools-mcp/mcp-overview.mdx +52 -0
  108. package/.docs/raw/workflows/control-flow.mdx +42 -1
  109. package/.docs/raw/workflows/inngest-workflow.mdx +1 -1
  110. package/.docs/raw/workflows/overview.mdx +73 -5
  111. package/.docs/raw/workflows/pausing-execution.mdx +60 -0
  112. package/.docs/raw/workflows/suspend-and-resume.mdx +68 -23
  113. package/.docs/raw/workflows/using-with-agents-and-tools.mdx +1 -1
  114. package/package.json +6 -6
  115. package/.docs/raw/mastra-cloud/deploying.mdx +0 -142
@@ -21,50 +21,10 @@ import { NetlifyDeployer } from "@mastra/deployer-netlify";
21
21
 
22
22
  const mastra = new Mastra({
23
23
  // ...
24
- deployer: new NetlifyDeployer({
25
- scope: "your-team-slug",
26
- projectName: "your-project-name",
27
- token: "your-netlify-token",
28
- })
24
+ deployer: new NetlifyDeployer()
29
25
  });
30
26
  ```
31
27
 
32
- ## Parameters
33
-
34
- ### Constructor Parameters
35
-
36
- <PropertiesTable
37
- content={[
38
- {
39
- name: "scope",
40
- type: "string",
41
- description: "Your Netlify team slug or ID.",
42
- isOptional: false,
43
- },
44
- {
45
- name: "projectName",
46
- type: "string",
47
- description:
48
- "Name of your Netlify site (will be created if it doesn't exist).",
49
- isOptional: false,
50
- },
51
- {
52
- name: "token",
53
- type: "string",
54
- description: "Your Netlify authentication token.",
55
- isOptional: false,
56
- },
57
- ]}
58
- />
59
-
60
- ### Environment Variables
61
-
62
- The NetlifyDeployer handles environment variables from multiple sources:
63
-
64
- 1. **Environment Files**: Variables from `.env.production` and `.env` files.
65
- 2. **Configuration**: Variables passed through the Mastra configuration.
66
- 3. **Netlify Dashboard**: Variables can also be managed through Netlify's web interface.
67
-
68
28
  ## Lint Mastra Project
69
29
 
70
30
  Lint your Mastra project to make sure it's fine to build
@@ -84,28 +44,29 @@ npx mastra build
84
44
  The build process generates the following output structure in the `.mastra/output` directory:
85
45
 
86
46
  ```
87
- .mastra/output/
88
- ├── netlify/
89
- └── functions/
90
- └── api/
91
- └── index.mjs # Application entry point
92
- └── netlify.toml # Netlify configuration
47
+ .netlify/
48
+ ├── v1/
49
+ └── functions/
50
+ └── api/
51
+ └── index.mjs # Application entry point
52
+ config.json # Netlify configuration
93
53
  ```
94
54
 
95
55
  ### Netlify Configuration
96
56
 
97
- The NetlifyDeployer automatically generates a `netlify.toml` configuration file in `.mastra/output` with the following settings:
98
-
99
- ```toml
100
- [functions]
101
- node_bundler = "esbuild"
102
- directory = "netlify/functions"
57
+ The NetlifyDeployer automatically generates a `config.json` configuration file in `.netlify/v1` with the following settings:
103
58
 
104
- [[redirects]]
105
- force = true
106
- from = "/*"
107
- status = 200
108
- to = "/.netlify/functions/api/:splat"
59
+ ```json
60
+ {
61
+ "redirects": [
62
+ {
63
+ "force": true,
64
+ "from": "/*",
65
+ "to": "/.netlify/functions/api/:splat",
66
+ "status": 200
67
+ }
68
+ ]
69
+ }
109
70
  ```
110
71
 
111
72
  ## Deployment Options
@@ -115,9 +76,8 @@ After building, you can deploy your Mastra application `.mastra/output` to Netli
115
76
  1. **Netlify CLI**: Deploy directly using Netlify's official CLI tool
116
77
 
117
78
  - Install the CLI: `npm install -g netlify-cli`
118
- - Navigate to the output directory: `cd .mastra/output`
119
- - Deploy with functions directory specified: `netlify deploy --dir . --functions ./netlify/functions`
120
- - For production deployment add `--prod` flag: `netlify deploy --prod --dir . --functions ./netlify/functions`
79
+ - Deploy with functions directory specified: `netlify deploy`
80
+ - For production deployment add `--prod` flag: `netlify deploy --prod`
121
81
 
122
82
  2. **Netlify Dashboard**: Connect your Git repository or drag-and-drop the build output through the Netlify dashboard
123
83
 
@@ -126,19 +86,13 @@ After building, you can deploy your Mastra application `.mastra/output` to Netli
126
86
  ```bash
127
87
  # Build command
128
88
  npm run build
129
-
130
- # Publish directory
131
- .mastra/output
132
-
133
- # Functions directory
134
- .mastra/output/netlify/functions
135
89
  ```
136
90
 
137
91
 
138
92
 
139
93
  3. **Netlify Dev**: Run your Mastra application locally with Netlify's development environment
140
94
 
141
- > You can also run `netlify dev` in your output directory `.mastra/output` to test your Mastra application locally.
95
+ > You can also run `netlify dev` in your project root to test your Mastra application locally.
142
96
 
143
97
  ## Platform Documentation
144
98
 
@@ -21,52 +21,10 @@ import { VercelDeployer } from "@mastra/deployer-vercel";
21
21
 
22
22
  const mastra = new Mastra({
23
23
  // ...
24
- deployer: new VercelDeployer({
25
- teamSlug: "your-team-slug",
26
- projectName: "your-project-name",
27
- token: "your-vercel-token",
28
- })
24
+ deployer: new VercelDeployer()
29
25
  });
30
26
  ```
31
27
 
32
- ## Parameters
33
-
34
- ### Constructor Parameters
35
-
36
- <PropertiesTable
37
- content={[
38
- {
39
- name: "teamSlug",
40
- type: "string",
41
- description: "Your Vercel team slug",
42
- isOptional: false,
43
- },
44
- {
45
- name: "projectName",
46
- type: "string",
47
- description:
48
- "Name of your Vercel project (will be created if it doesn't exist).",
49
- isOptional: false,
50
- },
51
- {
52
- name: "token",
53
- type: "string",
54
- description: "Your Vercel authentication token.",
55
- isOptional: false,
56
- },
57
- ]}
58
- />
59
-
60
- ### Environment Variables
61
-
62
- The VercelDeployer handles environment variables from multiple sources:
63
-
64
- 1. **Environment Files**: Variables from `.env.production` and `.env` files.
65
- 2. **Configuration**: Variables passed through the Mastra configuration.
66
- 3. **Vercel Dashboard**: Variables can also be managed through Vercel's web interface.
67
-
68
- The deployer automatically synchronizes environment variables between your local development environment and Vercel's environment variable system, ensuring consistency across all deployment environments (production, preview, and development).
69
-
70
28
  ## Lint Mastra Project
71
29
 
72
30
  Lint your Mastra project to make sure it's fine to build
@@ -83,54 +41,26 @@ To build your Mastra project for Vercel deployment:
83
41
  npx mastra build
84
42
  ```
85
43
 
86
- The build process generates the following output structure in the `.mastra/output` directory:
44
+ The build process generates the following output structure in the `.vercel/output` directory:
87
45
 
88
46
  ```
89
- .mastra/output/
90
- ├── vercel.json # Vercel configuration
47
+ .vercel/output/functions/index.func
91
48
  └── index.mjs # Application entry point
92
49
  ```
93
50
 
94
- ### Vercel Configuration
95
-
96
- The VercelDeployer automatically generates a `vercel.json` configuration file in `.mastra/output` with the following settings:
97
-
98
- ```json
99
- {
100
- "version": 2,
101
- "installCommand": "npm install --omit=dev",
102
- "builds": [
103
- {
104
- "src": "index.mjs",
105
- "use": "@vercel/node",
106
- "config": {
107
- "includeFiles": ["**"]
108
- }
109
- }
110
- ],
111
- "routes": [
112
- {
113
- "src": "/(.*)",
114
- "dest": "index.mjs"
115
- }
116
- ]
117
- }
118
- ```
119
-
120
51
  ## Deployment Options
121
52
 
122
- After building, you can deploy your Mastra application `.mastra/output` to Vercel using any of these methods:
53
+ After building, you can deploy your Mastra application to Vercel using any of these methods:
123
54
 
124
55
  1. **Vercel CLI**: Deploy directly using Vercel's official CLI tool
125
56
 
126
57
  - Install the CLI: `npm install -g vercel`
127
- - Navigate to the output directory: `cd .mastra/output`
128
- - Deploy to preview environment: `vercel`
129
- - For production deployment: `vercel --prod`
58
+ - Deploy to preview environment: `vercel --prebuilt`
59
+ - For production deployment: `vercel --prod --prebuilt`
130
60
 
131
61
  2. **Vercel Dashboard**: Connect your Git repository or drag-and-drop the build output through the Vercel dashboard
132
62
 
133
- > You can also run `vercel dev` in your output directory `.mastra/output` to test your Mastra application locally.
63
+ > You can also run `vercel dev` in your project directory to test your Mastra application locally. (Make sure you configured your dev command to `mastra dev`)
134
64
 
135
65
  ## Platform Documentation
136
66
 
@@ -67,4 +67,5 @@ The storage implementation handles schema creation and updates automatically. It
67
67
 
68
68
  - `threads`: Stores conversation threads
69
69
  - `messages`: Stores individual messages
70
+ - `resources`: Stores user-specific data for resource-scoped working memory
70
71
  - `metadata`: Stores additional metadata for threads and messages
@@ -308,6 +308,145 @@ const { prompt, messages } = await mcpClient.prompts.get({
308
308
  });
309
309
  ```
310
310
 
311
+ ### `elicitation` Property
312
+
313
+ The `MCPClient` instance has an `elicitation` property that provides access to elicitation-related operations. Elicitation allows MCP servers to request structured information from users.
314
+
315
+ ```typescript
316
+ const mcpClient = new MCPClient({
317
+ /* ...servers configuration... */
318
+ });
319
+
320
+ // Set up elicitation handler
321
+ mcpClient.elicitation.onRequest('serverName', async (request) => {
322
+ // Handle elicitation request from server
323
+ console.log('Server requests:', request.message);
324
+ console.log('Schema:', request.requestedSchema);
325
+
326
+ // Return user response
327
+ return {
328
+ action: 'accept',
329
+ content: { name: 'John Doe', email: 'john@example.com' }
330
+ };
331
+ });
332
+ ```
333
+
334
+ #### `elicitation.onRequest(serverName: string, handler: ElicitationHandler)`
335
+
336
+ Sets up a handler function that will be called when any connected MCP server sends an elicitation request. The handler receives the request and must return a response.
337
+
338
+ **ElicitationHandler Function:**
339
+
340
+ The handler function receives a request object with:
341
+ - `message`: A human-readable message describing what information is needed
342
+ - `requestedSchema`: A JSON schema defining the structure of the expected response
343
+
344
+ The handler must return an `ElicitResult` with:
345
+ - `action`: One of `'accept'`, `'reject'`, or `'cancel'`
346
+ - `content`: The user's data (only when action is `'accept'`)
347
+
348
+ **Example:**
349
+
350
+ ```typescript
351
+ mcpClient.elicitation.onRequest('serverName', async (request) => {
352
+ console.log(`Server requests: ${request.message}`);
353
+
354
+ // Example: Simple user input collection
355
+ if (request.requestedSchema.properties.name) {
356
+ // Simulate user accepting and providing data
357
+ return {
358
+ action: 'accept',
359
+ content: {
360
+ name: 'Alice Smith',
361
+ email: 'alice@example.com'
362
+ }
363
+ };
364
+ }
365
+
366
+ // Simulate user rejecting the request
367
+ return { action: 'reject' };
368
+ });
369
+ ```
370
+
371
+ **Complete Interactive Example:**
372
+
373
+ ```typescript
374
+ import { MCPClient } from '@mastra/mcp';
375
+ import { createInterface } from 'readline';
376
+
377
+ const readline = createInterface({
378
+ input: process.stdin,
379
+ output: process.stdout,
380
+ });
381
+
382
+ function askQuestion(question: string): Promise<string> {
383
+ return new Promise(resolve => {
384
+ readline.question(question, answer => resolve(answer.trim()));
385
+ });
386
+ }
387
+
388
+ const mcpClient = new MCPClient({
389
+ servers: {
390
+ interactiveServer: {
391
+ url: new URL('http://localhost:3000/mcp'),
392
+ },
393
+ },
394
+ });
395
+
396
+ // Set up interactive elicitation handler
397
+ await mcpClient.elicitation.onRequest('interactiveServer', async (request) => {
398
+ console.log(`\n📋 Server Request: ${request.message}`);
399
+ console.log('Required information:');
400
+
401
+ const schema = request.requestedSchema;
402
+ const properties = schema.properties || {};
403
+ const required = schema.required || [];
404
+ const content: Record<string, any> = {};
405
+
406
+ // Collect input for each field
407
+ for (const [fieldName, fieldSchema] of Object.entries(properties)) {
408
+ const field = fieldSchema as any;
409
+ const isRequired = required.includes(fieldName);
410
+
411
+ let prompt = `${field.title || fieldName}`;
412
+ if (field.description) prompt += ` (${field.description})`;
413
+ if (isRequired) prompt += ' *required*';
414
+ prompt += ': ';
415
+
416
+ const answer = await askQuestion(prompt);
417
+
418
+ // Handle cancellation
419
+ if (answer.toLowerCase() === 'cancel') {
420
+ return { action: 'cancel' };
421
+ }
422
+
423
+ // Validate required fields
424
+ if (answer === '' && isRequired) {
425
+ console.log(`❌ ${fieldName} is required`);
426
+ return { action: 'reject' };
427
+ }
428
+
429
+ if (answer !== '') {
430
+ content[fieldName] = answer;
431
+ }
432
+ }
433
+
434
+ // Confirm submission
435
+ console.log('\n📝 You provided:');
436
+ console.log(JSON.stringify(content, null, 2));
437
+
438
+ const confirm = await askQuestion('\nSubmit this information? (yes/no/cancel): ');
439
+
440
+ if (confirm.toLowerCase() === 'yes' || confirm.toLowerCase() === 'y') {
441
+ return { action: 'accept', content };
442
+ } else if (confirm.toLowerCase() === 'cancel') {
443
+ return { action: 'cancel' };
444
+ } else {
445
+ return { action: 'reject' };
446
+ }
447
+ });
448
+ ```
449
+
311
450
  #### `prompts.list()`
312
451
 
313
452
  Retrieves all available prompts from all connected MCP servers, grouped by server name.
@@ -373,6 +512,111 @@ mcpClient.prompts.onListChanged("myWeatherServer", () => {
373
512
  });
374
513
  ```
375
514
 
515
+ ## Elicitation
516
+
517
+ Elicitation is a feature that allows MCP servers to request structured information from users. When a server needs additional data, it can send an elicitation request that the client handles by prompting the user. A common example is during a tool call.
518
+
519
+ ### How Elicitation Works
520
+
521
+ 1. **Server Request**: An MCP server tool calls `server.elicitation.sendRequest()` with a message and schema
522
+ 2. **Client Handler**: Your elicitation handler function is called with the request
523
+ 3. **User Interaction**: Your handler collects user input (via UI, CLI, etc.)
524
+ 4. **Response**: Your handler returns the user's response (accept/reject/cancel)
525
+ 5. **Tool Continuation**: The server tool receives the response and continues execution
526
+
527
+ ### Setting Up Elicitation
528
+
529
+ You must set up an elicitation handler before tools that use elicitation are called:
530
+
531
+ ```typescript
532
+ import { MCPClient } from '@mastra/mcp';
533
+
534
+ const mcpClient = new MCPClient({
535
+ servers: {
536
+ interactiveServer: {
537
+ url: new URL('http://localhost:3000/mcp'),
538
+ },
539
+ },
540
+ });
541
+
542
+ // Set up elicitation handler
543
+ mcpClient.elicitation.onRequest('interactiveServer', async (request) => {
544
+ // Handle the server's request for user input
545
+ console.log(`Server needs: ${request.message}`);
546
+
547
+ // Your logic to collect user input
548
+ const userData = await collectUserInput(request.requestedSchema);
549
+
550
+ return {
551
+ action: 'accept',
552
+ content: userData
553
+ };
554
+ });
555
+ ```
556
+
557
+ ### Response Types
558
+
559
+ Your elicitation handler must return one of three response types:
560
+
561
+ - **Accept**: User provided data and confirmed submission
562
+ ```typescript
563
+ return {
564
+ action: 'accept',
565
+ content: { name: 'John Doe', email: 'john@example.com' }
566
+ };
567
+ ```
568
+
569
+ - **Reject**: User explicitly declined to provide the information
570
+ ```typescript
571
+ return { action: 'reject' };
572
+ ```
573
+
574
+ - **Cancel**: User dismissed or cancelled the request
575
+ ```typescript
576
+ return { action: 'cancel' };
577
+ ```
578
+
579
+ ### Schema-Based Input Collection
580
+
581
+ The `requestedSchema` provides structure for the data the server needs:
582
+
583
+ ```typescript
584
+ await mcpClient.elicitation.onRequest('interactiveServer', async (request) => {
585
+ const { properties, required = [] } = request.requestedSchema;
586
+ const content: Record<string, any> = {};
587
+
588
+ for (const [fieldName, fieldSchema] of Object.entries(properties || {})) {
589
+ const field = fieldSchema as any;
590
+ const isRequired = required.includes(fieldName);
591
+
592
+ // Collect input based on field type and requirements
593
+ const value = await promptUser({
594
+ name: fieldName,
595
+ title: field.title,
596
+ description: field.description,
597
+ type: field.type,
598
+ required: isRequired,
599
+ format: field.format,
600
+ enum: field.enum,
601
+ });
602
+
603
+ if (value !== null) {
604
+ content[fieldName] = value;
605
+ }
606
+ }
607
+
608
+ return { action: 'accept', content };
609
+ });
610
+ ```
611
+
612
+ ### Best Practices
613
+
614
+ - **Always handle elicitation**: Set up your handler before calling tools that might use elicitation
615
+ - **Validate input**: Check that required fields are provided
616
+ - **Respect user choice**: Handle reject and cancel responses gracefully
617
+ - **Clear UI**: Make it obvious what information is being requested and why
618
+ - **Security**: Never auto-accept requests for sensitive information
619
+
376
620
  ## Examples
377
621
 
378
622
  ### Static Tool Configuration
@@ -833,6 +833,192 @@ For practical examples of setting up and deploying an MCPServer, see the [Deploy
833
833
 
834
834
  The example at the beginning of this page also demonstrates how to instantiate `MCPServer` with both tools and agents.
835
835
 
836
+ ## Elicitation
837
+
838
+ ### What is Elicitation?
839
+
840
+ Elicitation is a feature in the Model Context Protocol (MCP) that allows servers to request structured information from users. This enables interactive workflows where servers can collect additional data dynamically.
841
+
842
+ The `MCPServer` class automatically includes elicitation capabilities. Tools receive an `options` parameter in their `execute` function that includes an `elicitation.sendRequest()` method for requesting user input.
843
+
844
+ ### Tool Execution Signature
845
+
846
+ When tools are executed within an MCP server context, they receive an additional `options` parameter:
847
+
848
+ ```typescript
849
+ execute: async ({ context }, options) => {
850
+ // context contains the tool's input parameters
851
+ // options contains server capabilities like elicitation
852
+
853
+ const result = await options.elicitation.sendRequest({
854
+ message: "Please provide information",
855
+ requestedSchema: { /* schema */ }
856
+ });
857
+
858
+ return result;
859
+ }
860
+ ```
861
+
862
+ ### How Elicitation Works
863
+
864
+ A common use case is during tool execution. When a tool needs user input, it can use the elicitation functionality provided through the tool's execution options:
865
+
866
+ 1. The tool calls `options.elicitation.sendRequest()` with a message and schema
867
+ 2. The request is sent to the connected MCP client
868
+ 3. The client presents the request to the user (via UI, command line, etc.)
869
+ 4. The user provides input, rejects, or cancels the request
870
+ 5. The client sends the response back to the server
871
+ 6. The tool receives the response and continues execution
872
+
873
+ ### Using Elicitation in Tools
874
+
875
+ Here's an example of a tool that uses elicitation to collect user contact information:
876
+
877
+ ```typescript
878
+ import { MCPServer } from "@mastra/mcp";
879
+ import { createTool } from "@mastra/core/tools";
880
+ import { z } from "zod";
881
+
882
+ const server = new MCPServer({
883
+ name: "Interactive Server",
884
+ version: "1.0.0",
885
+ tools: {
886
+ collectContactInfo: createTool({
887
+ id: "collectContactInfo",
888
+ description: "Collects user contact information through elicitation",
889
+ inputSchema: z.object({
890
+ reason: z.string().optional().describe("Reason for collecting contact info"),
891
+ }),
892
+ execute: async ({ context }, options) => {
893
+ const { reason } = context;
894
+
895
+ try {
896
+ // Request user input via elicitation through the options parameter
897
+ const result = await options.elicitation.sendRequest({
898
+ message: reason
899
+ ? `Please provide your contact information. ${reason}`
900
+ : 'Please provide your contact information',
901
+ requestedSchema: {
902
+ type: 'object',
903
+ properties: {
904
+ name: {
905
+ type: 'string',
906
+ title: 'Full Name',
907
+ description: 'Your full name',
908
+ },
909
+ email: {
910
+ type: 'string',
911
+ title: 'Email Address',
912
+ description: 'Your email address',
913
+ format: 'email',
914
+ },
915
+ phone: {
916
+ type: 'string',
917
+ title: 'Phone Number',
918
+ description: 'Your phone number (optional)',
919
+ },
920
+ },
921
+ required: ['name', 'email'],
922
+ },
923
+ });
924
+
925
+ // Handle the user's response
926
+ if (result.action === 'accept') {
927
+ return `Contact information collected: ${JSON.stringify(result.content, null, 2)}`;
928
+ } else if (result.action === 'reject') {
929
+ return 'Contact information collection was declined by the user.';
930
+ } else {
931
+ return 'Contact information collection was cancelled by the user.';
932
+ }
933
+ } catch (error) {
934
+ return `Error collecting contact information: ${error}`;
935
+ }
936
+ },
937
+ }),
938
+ },
939
+ });
940
+ ```
941
+
942
+ ### Elicitation Request Schema
943
+
944
+ The `requestedSchema` must be a flat object with primitive properties only. Supported types include:
945
+
946
+ - **String**: `{ type: 'string', title: 'Display Name', description: 'Help text' }`
947
+ - **Number**: `{ type: 'number', minimum: 0, maximum: 100 }`
948
+ - **Boolean**: `{ type: 'boolean', default: false }`
949
+ - **Enum**: `{ type: 'string', enum: ['option1', 'option2'] }`
950
+
951
+ Example schema:
952
+
953
+ ```typescript
954
+ {
955
+ type: 'object',
956
+ properties: {
957
+ name: {
958
+ type: 'string',
959
+ title: 'Full Name',
960
+ description: 'Your complete name',
961
+ },
962
+ age: {
963
+ type: 'number',
964
+ title: 'Age',
965
+ minimum: 18,
966
+ maximum: 120,
967
+ },
968
+ newsletter: {
969
+ type: 'boolean',
970
+ title: 'Subscribe to Newsletter',
971
+ default: false,
972
+ },
973
+ },
974
+ required: ['name'],
975
+ }
976
+ ```
977
+
978
+ ### Response Actions
979
+
980
+ Users can respond to elicitation requests in three ways:
981
+
982
+ 1. **Accept** (`action: 'accept'`): User provided data and confirmed submission
983
+ - Contains `content` field with the submitted data
984
+ 2. **Reject** (`action: 'reject'`): User explicitly declined to provide information
985
+ - No content field
986
+ 3. **Cancel** (`action: 'cancel'`): User dismissed the request without deciding
987
+ - No content field
988
+
989
+ Tools should handle all three response types appropriately.
990
+
991
+ ### Security Considerations
992
+
993
+ - **Never request sensitive information** like passwords, SSNs, or credit card numbers
994
+ - Validate all user input against the provided schema
995
+ - Handle rejection and cancellation gracefully
996
+ - Provide clear reasons for data collection
997
+ - Respect user privacy and preferences
998
+
999
+ ### Tool Execution API
1000
+
1001
+ The elicitation functionality is available through the `options` parameter in tool execution:
1002
+
1003
+ ```typescript
1004
+ // Within a tool's execute function
1005
+ options.elicitation.sendRequest({
1006
+ message: string, // Message to display to user
1007
+ requestedSchema: object // JSON schema defining expected response structure
1008
+ }): Promise<ElicitResult>
1009
+ ```
1010
+
1011
+ Note that elicitation is **session-aware** when using HTTP-based transports (SSE or HTTP). This means that when multiple clients are connected to the same server, elicitation requests are routed to the correct client session that initiated the tool execution.
1012
+
1013
+ The `ElicitResult` type:
1014
+
1015
+ ```typescript
1016
+ type ElicitResult = {
1017
+ action: 'accept' | 'reject' | 'cancel';
1018
+ content?: any; // Only present when action is 'accept'
1019
+ }
1020
+ ```
1021
+
836
1022
  ## Related Information
837
1023
 
838
1024
  - For connecting to MCP servers in Mastra, see the [MCPClient documentation](./mcp-client).