Skip to main content
Glama
soriat

MCP Elicitations Demo Server

by soriat

startElicitation

Collect user preferences dynamically by prompting for favorite color, number, and pets using the MCP Elicitations Demo Server’s elicitation feature.

Instructions

Demonstrates the Elicitation feature by asking the user to provide information about their favorite color, number, and pets.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The core handler function for the startElicitation tool. It triggers an elicitation request for user preferences (color, number, pets), handles the response based on user action (accept/decline/cancel), formats content accordingly, and includes raw result for debugging.
    handler: async (args: any, request: any, server: Server) => { ElicitationSchema.parse(args); const elicitationResult = await requestElicitation( 'What are your favorite things?', { type: 'object', properties: { color: { type: 'string', description: 'Favorite color' }, number: { type: 'integer', description: 'Favorite number', minimum: 1, maximum: 100 }, pets: { type: 'string', enum: ['cats', 'dogs', 'birds', 'fish', 'reptiles'], description: 'Favorite pets' }, } }, server ); // Handle different response actions const content: any[] = []; if (elicitationResult.action === 'accept' && elicitationResult.content) { content.push({ type: "text" as const, text: `✅ User provided their favorite things!`, }); // Only access elicitationResult.content when action is accept const { color, number, pets } = elicitationResult.content; content.push({ type: "text" as const, text: `Their favorites are:\n- Color: ${color || 'not specified'}\n- Number: ${number || 'not specified'}\n- Pets: ${pets || 'not specified'}`, }); } else if (elicitationResult.action === 'decline') { content.push({ type: "text" as const, text: `❌ User declined to provide their favorite things.`, }); } else if (elicitationResult.action === 'cancel') { content.push({ type: "text" as const, text: `⚠️ User cancelled the elicitation dialog.`, }); } // Include raw result for debugging content.push({ type: "text" as const, text: `\nRaw result: ${JSON.stringify(elicitationResult, null, 2)}`, }); return { content }; },
  • Schema definition using Zod (empty object since no input arguments required) and its conversion to JSON schema for the tool's input validation.
    const ElicitationSchema = z.object({}); export const elicitationTool = { name: "startElicitation", description: "Demonstrates the Elicitation feature by asking the user to provide information about their favorite color, number, and pets.", inputSchema: zodToJsonSchema(ElicitationSchema),
  • The elicitationTool is registered by inclusion in the allTools array, which is used to provide tool metadata via getTools() and dispatch handlers via getToolHandler().
    elicitationTool,
  • Supporting utility function that sends an 'elicitation/create' request to the server to initiate user elicitation, used within the tool handler.
    export const requestElicitation = async ( message: string, requestedSchema: any, server: Server ) => { const request = { method: 'elicitation/create', params: { message, requestedSchema } }; return await server.request(request, z.any()); };

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/soriat/soria-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server