From 9c5a4d43359f0cc6f296d27a4344d90a5b072015 Mon Sep 17 00:00:00 2001 From: Olivier Chafik Date: Tue, 14 Oct 2025 17:40:19 +0100 Subject: [PATCH 1/3] Add elicitInputs tool to MCP server MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds a new elicitInputs tool that demonstrates how to use MCP's elicitation feature to request user input. The tool showcases various input field types including strings, booleans, emails, dates, numbers, and enums. This allows clients to interactively collect structured user input during tool execution. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- mcp-server/src/services/mcp.ts | 100 +++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) diff --git a/mcp-server/src/services/mcp.ts b/mcp-server/src/services/mcp.ts index 39192b5..cd14ab5 100644 --- a/mcp-server/src/services/mcp.ts +++ b/mcp-server/src/services/mcp.ts @@ -4,6 +4,7 @@ import { CompleteRequestSchema, CreateMessageRequest, CreateMessageResultSchema, + ElicitResultSchema, GetPromptRequestSchema, ListPromptsRequestSchema, ListResourcesRequestSchema, @@ -79,6 +80,8 @@ const GetResourceReferenceSchema = z.object({ .describe("ID of the resource to reference (1-100)"), }); +const ElicitInputsSchema = z.object({}); + enum ToolName { ECHO = "echo", ADD = "add", @@ -87,6 +90,7 @@ enum ToolName { GET_TINY_IMAGE = "getTinyImage", ANNOTATED_MESSAGE = "annotatedMessage", GET_RESOURCE_REFERENCE = "getResourceReference", + ELICIT_INPUTS = "elicitInputs", } enum PromptName { @@ -446,6 +450,12 @@ export const createMcpServer = (): McpServerWrapper => { "Returns a resource reference that can be used by MCP clients", inputSchema: zodToJsonSchema(GetResourceReferenceSchema) as ToolInput, }, + { + name: ToolName.ELICIT_INPUTS, + description: + "Elicitation test tool that demonstrates how to request user input with various field types", + inputSchema: zodToJsonSchema(ElicitInputsSchema) as ToolInput, + }, ]; return { tools }; @@ -624,6 +634,96 @@ export const createMcpServer = (): McpServerWrapper => { return { content }; } + if (name === ToolName.ELICIT_INPUTS) { + ElicitInputsSchema.parse(args); + + // Call elicitInput on the server to request user input + const result = await server.request( + { + method: "sampling/elicitInput", + params: { + message: "Please provide inputs for the following fields:", + requestedSchema: { + type: "object", + properties: { + name: { + title: "Full Name", + type: "string", + description: "Your full, legal name", + }, + check: { + title: "Agree to terms", + type: "boolean", + description: "A boolean check", + }, + color: { + title: "Favorite Color", + type: "string", + description: "Favorite color (open text)", + default: "blue", + }, + email: { + title: "Email Address", + type: "string", + format: "email", + description: + "Your email address (will be verified, and never shared with anyone else)", + }, + homepage: { + type: "string", + format: "uri", + description: "Homepage / personal site", + }, + birthdate: { + title: "Birthdate", + type: "string", + format: "date", + description: + "Your date of birth (will never be shared with anyone else)", + }, + integer: { + title: "Favorite Integer", + type: "integer", + description: + "Your favorite integer (do not give us your phone number, pin, or other sensitive info)", + minimum: 1, + maximum: 100, + default: 42, + }, + number: { + title: "Favorite Number", + type: "number", + description: "Favorite number (there are no wrong answers)", + minimum: 0, + maximum: 1000, + default: 3.14, + }, + petType: { + title: "Pet type", + type: "string", + enum: ["cats", "dogs", "birds", "fish", "reptiles"], + enumNames: ["Cats", "Dogs", "Birds", "Fish", "Reptiles"], + default: "dogs", + description: "Your favorite pet type", + }, + }, + required: ["name"], + }, + }, + }, + ElicitResultSchema + ); + + return { + content: [ + { + type: "text", + text: `Elicitation result: ${JSON.stringify(result, null, 2)}`, + }, + ], + }; + } + throw new Error(`Unknown tool: ${name}`); }); From 79b24447015363128c9fb5851333b86cf86bb59b Mon Sep 17 00:00:00 2001 From: Olivier Chafik Date: Wed, 15 Oct 2025 20:33:49 +0100 Subject: [PATCH 2/3] fix elicitation --- src/modules/mcp/services/mcp.ts | 147 +++++++++++++++----------------- 1 file changed, 71 insertions(+), 76 deletions(-) diff --git a/src/modules/mcp/services/mcp.ts b/src/modules/mcp/services/mcp.ts index cd14ab5..550acec 100644 --- a/src/modules/mcp/services/mcp.ts +++ b/src/modules/mcp/services/mcp.ts @@ -454,14 +454,14 @@ export const createMcpServer = (): McpServerWrapper => { name: ToolName.ELICIT_INPUTS, description: "Elicitation test tool that demonstrates how to request user input with various field types", - inputSchema: zodToJsonSchema(ElicitInputsSchema) as ToolInput, + inputSchema: { type: "object" , properties: {} }, }, ]; return { tools }; }); - server.setRequestHandler(CallToolRequestSchema, async (request) => { + server.setRequestHandler(CallToolRequestSchema, async (request, extra) => { const { name, arguments: args } = request.params; if (name === ToolName.ECHO) { @@ -635,84 +635,79 @@ export const createMcpServer = (): McpServerWrapper => { } if (name === ToolName.ELICIT_INPUTS) { - ElicitInputsSchema.parse(args); - // Call elicitInput on the server to request user input - const result = await server.request( - { - method: "sampling/elicitInput", - params: { - message: "Please provide inputs for the following fields:", - requestedSchema: { - type: "object", - properties: { - name: { - title: "Full Name", - type: "string", - description: "Your full, legal name", - }, - check: { - title: "Agree to terms", - type: "boolean", - description: "A boolean check", - }, - color: { - title: "Favorite Color", - type: "string", - description: "Favorite color (open text)", - default: "blue", - }, - email: { - title: "Email Address", - type: "string", - format: "email", - description: - "Your email address (will be verified, and never shared with anyone else)", - }, - homepage: { - type: "string", - format: "uri", - description: "Homepage / personal site", - }, - birthdate: { - title: "Birthdate", - type: "string", - format: "date", - description: - "Your date of birth (will never be shared with anyone else)", - }, - integer: { - title: "Favorite Integer", - type: "integer", - description: - "Your favorite integer (do not give us your phone number, pin, or other sensitive info)", - minimum: 1, - maximum: 100, - default: 42, - }, - number: { - title: "Favorite Number", - type: "number", - description: "Favorite number (there are no wrong answers)", - minimum: 0, - maximum: 1000, - default: 3.14, - }, - petType: { - title: "Pet type", - type: "string", - enum: ["cats", "dogs", "birds", "fish", "reptiles"], - enumNames: ["Cats", "Dogs", "Birds", "Fish", "Reptiles"], - default: "dogs", - description: "Your favorite pet type", - }, + const result = await extra.sendRequest({ + method: 'elicitation/create', + params: { + message: "Please provide inputs for the following fields:", + requestedSchema: { + type: "object", + properties: { + name: { + title: "Full Name", + type: "string", + description: "Your full, legal name", + }, + check: { + title: "Agree to terms", + type: "boolean", + description: "A boolean check", + }, + color: { + title: "Favorite Color", + type: "string", + description: "Favorite color (open text)", + default: "blue", + }, + email: { + title: "Email Address", + type: "string", + format: "email", + description: + "Your email address (will be verified, and never shared with anyone else)", + }, + homepage: { + type: "string", + format: "uri", + description: "Homepage / personal site", + }, + birthdate: { + title: "Birthdate", + type: "string", + format: "date", + description: + "Your date of birth (will never be shared with anyone else)", + }, + integer: { + title: "Favorite Integer", + type: "integer", + description: + "Your favorite integer (do not give us your phone number, pin, or other sensitive info)", + minimum: 1, + maximum: 100, + default: 42, + }, + number: { + title: "Favorite Number", + type: "number", + description: "Favorite number (there are no wrong answers)", + minimum: 0, + maximum: 1000, + default: 3.14, + }, + petType: { + title: "Pet type", + type: "string", + enum: ["cats", "dogs", "birds", "fish", "reptiles"], + enumNames: ["Cats", "Dogs", "Birds", "Fish", "Reptiles"], + default: "dogs", + description: "Your favorite pet type", }, - required: ["name"], }, + required: ["name"], }, - }, - ElicitResultSchema - ); + } + }, ElicitResultSchema, {timeout: 10 * 60 * 1000 /* 10 minutes */}); return { content: [ From 1547891443244d319ed505b1bc406503d08067ab Mon Sep 17 00:00:00 2001 From: Olivier Chafik Date: Wed, 15 Oct 2025 20:35:55 +0100 Subject: [PATCH 3/3] fix elicitation --- src/modules/mcp/services/mcp.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/modules/mcp/services/mcp.ts b/src/modules/mcp/services/mcp.ts index 550acec..8e77c64 100644 --- a/src/modules/mcp/services/mcp.ts +++ b/src/modules/mcp/services/mcp.ts @@ -80,8 +80,6 @@ const GetResourceReferenceSchema = z.object({ .describe("ID of the resource to reference (1-100)"), }); -const ElicitInputsSchema = z.object({}); - enum ToolName { ECHO = "echo", ADD = "add", @@ -635,7 +633,6 @@ export const createMcpServer = (): McpServerWrapper => { } if (name === ToolName.ELICIT_INPUTS) { - // Call elicitInput on the server to request user input const result = await extra.sendRequest({ method: 'elicitation/create', params: {