|
4 | 4 | CompleteRequestSchema, |
5 | 5 | CreateMessageRequest, |
6 | 6 | CreateMessageResultSchema, |
| 7 | + ElicitResultSchema, |
7 | 8 | GetPromptRequestSchema, |
8 | 9 | ListPromptsRequestSchema, |
9 | 10 | ListResourcesRequestSchema, |
@@ -87,6 +88,7 @@ enum ToolName { |
87 | 88 | GET_TINY_IMAGE = "getTinyImage", |
88 | 89 | ANNOTATED_MESSAGE = "annotatedMessage", |
89 | 90 | GET_RESOURCE_REFERENCE = "getResourceReference", |
| 91 | + ELICIT_INPUTS = "elicitInputs", |
90 | 92 | } |
91 | 93 |
|
92 | 94 | enum PromptName { |
@@ -446,12 +448,18 @@ export const createMcpServer = (): McpServerWrapper => { |
446 | 448 | "Returns a resource reference that can be used by MCP clients", |
447 | 449 | inputSchema: zodToJsonSchema(GetResourceReferenceSchema) as ToolInput, |
448 | 450 | }, |
| 451 | + { |
| 452 | + name: ToolName.ELICIT_INPUTS, |
| 453 | + description: |
| 454 | + "Elicitation test tool that demonstrates how to request user input with various field types", |
| 455 | + inputSchema: { type: "object" , properties: {} }, |
| 456 | + }, |
449 | 457 | ]; |
450 | 458 |
|
451 | 459 | return { tools }; |
452 | 460 | }); |
453 | 461 |
|
454 | | - server.setRequestHandler(CallToolRequestSchema, async (request) => { |
| 462 | + server.setRequestHandler(CallToolRequestSchema, async (request, extra) => { |
455 | 463 | const { name, arguments: args } = request.params; |
456 | 464 |
|
457 | 465 | if (name === ToolName.ECHO) { |
@@ -624,6 +632,90 @@ export const createMcpServer = (): McpServerWrapper => { |
624 | 632 | return { content }; |
625 | 633 | } |
626 | 634 |
|
| 635 | + if (name === ToolName.ELICIT_INPUTS) { |
| 636 | + const result = await extra.sendRequest({ |
| 637 | + method: 'elicitation/create', |
| 638 | + params: { |
| 639 | + message: "Please provide inputs for the following fields:", |
| 640 | + requestedSchema: { |
| 641 | + type: "object", |
| 642 | + properties: { |
| 643 | + name: { |
| 644 | + title: "Full Name", |
| 645 | + type: "string", |
| 646 | + description: "Your full, legal name", |
| 647 | + }, |
| 648 | + check: { |
| 649 | + title: "Agree to terms", |
| 650 | + type: "boolean", |
| 651 | + description: "A boolean check", |
| 652 | + }, |
| 653 | + color: { |
| 654 | + title: "Favorite Color", |
| 655 | + type: "string", |
| 656 | + description: "Favorite color (open text)", |
| 657 | + default: "blue", |
| 658 | + }, |
| 659 | + email: { |
| 660 | + title: "Email Address", |
| 661 | + type: "string", |
| 662 | + format: "email", |
| 663 | + description: |
| 664 | + "Your email address (will be verified, and never shared with anyone else)", |
| 665 | + }, |
| 666 | + homepage: { |
| 667 | + type: "string", |
| 668 | + format: "uri", |
| 669 | + description: "Homepage / personal site", |
| 670 | + }, |
| 671 | + birthdate: { |
| 672 | + title: "Birthdate", |
| 673 | + type: "string", |
| 674 | + format: "date", |
| 675 | + description: |
| 676 | + "Your date of birth (will never be shared with anyone else)", |
| 677 | + }, |
| 678 | + integer: { |
| 679 | + title: "Favorite Integer", |
| 680 | + type: "integer", |
| 681 | + description: |
| 682 | + "Your favorite integer (do not give us your phone number, pin, or other sensitive info)", |
| 683 | + minimum: 1, |
| 684 | + maximum: 100, |
| 685 | + default: 42, |
| 686 | + }, |
| 687 | + number: { |
| 688 | + title: "Favorite Number", |
| 689 | + type: "number", |
| 690 | + description: "Favorite number (there are no wrong answers)", |
| 691 | + minimum: 0, |
| 692 | + maximum: 1000, |
| 693 | + default: 3.14, |
| 694 | + }, |
| 695 | + petType: { |
| 696 | + title: "Pet type", |
| 697 | + type: "string", |
| 698 | + enum: ["cats", "dogs", "birds", "fish", "reptiles"], |
| 699 | + enumNames: ["Cats", "Dogs", "Birds", "Fish", "Reptiles"], |
| 700 | + default: "dogs", |
| 701 | + description: "Your favorite pet type", |
| 702 | + }, |
| 703 | + }, |
| 704 | + required: ["name"], |
| 705 | + }, |
| 706 | + } |
| 707 | + }, ElicitResultSchema, {timeout: 10 * 60 * 1000 /* 10 minutes */}); |
| 708 | + |
| 709 | + return { |
| 710 | + content: [ |
| 711 | + { |
| 712 | + type: "text", |
| 713 | + text: `Elicitation result: ${JSON.stringify(result, null, 2)}`, |
| 714 | + }, |
| 715 | + ], |
| 716 | + }; |
| 717 | + } |
| 718 | + |
627 | 719 | throw new Error(`Unknown tool: ${name}`); |
628 | 720 | }); |
629 | 721 |
|
|
0 commit comments