From 77c8e95bc9ad6aa05041c77cf268bb3f2d07f81b Mon Sep 17 00:00:00 2001 From: cliffhall Date: Thu, 3 Jul 2025 14:05:44 -0400 Subject: [PATCH 1/2] In everything.ts - import ElicitRequest and ElicitResultSchema from SDK - refactor/rename GetTinyImageSchema to NoArgSchema - add ELICITATION to ToolName enum - add elicitUserInput function that sends an ElicitRequest and returns the result - in ListToolsRequest handler - add ToolName.ELICITATION entry - In CallToolRequest handler - add ToolName.ELICITATION handler which calls elicitUserInput returns the formatted result message - In GET_TINY_IMAGE handler, remove GetTinyImageSchema.parse(args) since it has no args (like elicitation tool, and doesn't need to be parsed) * In package.json - bump modelcontextprotocol/sdk to ^1.14.0 --- src/everything/everything.ts | 52 +++++++++++++++++++++++++++++++++--- src/everything/package.json | 2 +- 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/src/everything/everything.ts b/src/everything/everything.ts index 2abce9a075..dcff02fcc7 100644 --- a/src/everything/everything.ts +++ b/src/everything/everything.ts @@ -4,6 +4,8 @@ import { CompleteRequestSchema, CreateMessageRequest, CreateMessageResultSchema, + ElicitRequest, + ElicitResultSchema, GetPromptRequestSchema, ListPromptsRequestSchema, ListResourcesRequestSchema, @@ -66,7 +68,7 @@ const EXAMPLE_COMPLETIONS = { resourceId: ["1", "2", "3", "4", "5"], }; -const GetTinyImageSchema = z.object({}); +const NoArgSchema = z.object({}); const AnnotatedMessageSchema = z.object({ messageType: z @@ -92,6 +94,7 @@ enum ToolName { LONG_RUNNING_OPERATION = "longRunningOperation", PRINT_ENV = "printEnv", SAMPLE_LLM = "sampleLLM", + ELICITATION = "elicitationRequest", GET_TINY_IMAGE = "getTinyImage", ANNOTATED_MESSAGE = "annotatedMessage", GET_RESOURCE_REFERENCE = "getResourceReference", @@ -206,6 +209,36 @@ export const createServer = () => { return await server.request(request, CreateMessageResultSchema); }; + // Helper method to elicitation user input from client + const elicitUserInput = async () => { + const request: ElicitRequest = { + "method": "elicitation/create", + "params": { + "message": "Describe your upcoming travel plans.", + "requestedSchema": { + "type": "object", + "properties": { + "destination": { + "type": "string", + "description": "Your travel destination" + }, + "distance": { + "type": "number", + "description": "Distance you expect to travel in miles" + }, + "mixtape": { + "type": "string", + "description": "Name of mixtape you plan to listen to on the way" + } + }, + "required": ["destination", "distance"] + } + } + }; + + return await server.request(request, ElicitResultSchema); + }; + const ALL_RESOURCES: Resource[] = Array.from({ length: 100 }, (_, i) => { const uri = `test://static/resource/${i + 1}`; if (i % 2 === 0) { @@ -442,10 +475,15 @@ export const createServer = () => { description: "Samples from an LLM using MCP's sampling feature", inputSchema: zodToJsonSchema(SampleLLMSchema) as ToolInput, }, + { + name: ToolName.ELICITATION, + description: "Elicits input from the user", + inputSchema: zodToJsonSchema(NoArgSchema) as ToolInput, + }, { name: ToolName.GET_TINY_IMAGE, description: "Returns the MCP_TINY_IMAGE", - inputSchema: zodToJsonSchema(GetTinyImageSchema) as ToolInput, + inputSchema: zodToJsonSchema(NoArgSchema) as ToolInput, }, { name: ToolName.ANNOTATED_MESSAGE, @@ -547,8 +585,16 @@ export const createServer = () => { }; } + if (name === ToolName.ELICITATION) { + const result = await elicitUserInput(); + return { + content: [ + { type: "text", text: `Traveling ${result?.content?.distance} miles to ${result?.content?.destination}, listening to ${result?.content?.mixtape}` }, + ], + }; + } + if (name === ToolName.GET_TINY_IMAGE) { - GetTinyImageSchema.parse(args); return { content: [ { diff --git a/src/everything/package.json b/src/everything/package.json index 55777ac788..252a7f1d45 100644 --- a/src/everything/package.json +++ b/src/everything/package.json @@ -22,7 +22,7 @@ "start:streamableHttp": "node dist/streamableHttp.js" }, "dependencies": { - "@modelcontextprotocol/sdk": "^1.12.0", + "@modelcontextprotocol/sdk": "^1.14.0", "express": "^4.21.1", "zod": "^3.23.8", "zod-to-json-schema": "^3.23.5" From ff64d09120225d16914e5f300317f7a978330344 Mon Sep 17 00:00:00 2001 From: cliffhall Date: Thu, 3 Jul 2025 14:26:52 -0400 Subject: [PATCH 2/2] Updated package-lock.json --- package-lock.json | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index c785a237fe..e9bf190f86 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5817,7 +5817,7 @@ "version": "0.6.2", "license": "MIT", "dependencies": { - "@modelcontextprotocol/sdk": "^1.12.0", + "@modelcontextprotocol/sdk": "^1.14.0", "express": "^4.21.1", "zod": "^3.23.8", "zod-to-json-schema": "^3.23.5" @@ -5832,9 +5832,9 @@ } }, "src/everything/node_modules/@modelcontextprotocol/sdk": { - "version": "1.12.3", - "resolved": "https://registry.npmjs.org/@modelcontextprotocol/sdk/-/sdk-1.12.3.tgz", - "integrity": "sha512-DyVYSOafBvk3/j1Oka4z5BWT8o4AFmoNyZY9pALOm7Lh3GZglR71Co4r4dEUoqDWdDazIZQHBe7J2Nwkg6gHgQ==", + "version": "1.14.0", + "resolved": "https://registry.npmjs.org/@modelcontextprotocol/sdk/-/sdk-1.14.0.tgz", + "integrity": "sha512-f43SYQVRPGQcYDQMiL7T2qND4v9xCkBpunIVPhNT/K2vUe+R3kYw2FyOIlbPxZJIYnhBNjeaHFeKv/cOZZErNg==", "license": "MIT", "dependencies": { "ajv": "^6.12.6", @@ -5842,6 +5842,7 @@ "cors": "^2.8.5", "cross-spawn": "^7.0.5", "eventsource": "^3.0.2", + "eventsource-parser": "^3.0.0", "express": "^5.0.1", "express-rate-limit": "^7.5.0", "pkce-challenge": "^5.0.0",