Skip to content

Commit 2a6413d

Browse files
authored
Merge pull request #17 from modelcontextprotocol/ochafik/add-elicitation-tool
Add elicitInputs tool to MCP server
2 parents a0e0109 + 1547891 commit 2a6413d

File tree

1 file changed

+93
-1
lines changed
  • src/modules/mcp/services

1 file changed

+93
-1
lines changed

src/modules/mcp/services/mcp.ts

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
CompleteRequestSchema,
55
CreateMessageRequest,
66
CreateMessageResultSchema,
7+
ElicitResultSchema,
78
GetPromptRequestSchema,
89
ListPromptsRequestSchema,
910
ListResourcesRequestSchema,
@@ -87,6 +88,7 @@ enum ToolName {
8788
GET_TINY_IMAGE = "getTinyImage",
8889
ANNOTATED_MESSAGE = "annotatedMessage",
8990
GET_RESOURCE_REFERENCE = "getResourceReference",
91+
ELICIT_INPUTS = "elicitInputs",
9092
}
9193

9294
enum PromptName {
@@ -446,12 +448,18 @@ export const createMcpServer = (): McpServerWrapper => {
446448
"Returns a resource reference that can be used by MCP clients",
447449
inputSchema: zodToJsonSchema(GetResourceReferenceSchema) as ToolInput,
448450
},
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+
},
449457
];
450458

451459
return { tools };
452460
});
453461

454-
server.setRequestHandler(CallToolRequestSchema, async (request) => {
462+
server.setRequestHandler(CallToolRequestSchema, async (request, extra) => {
455463
const { name, arguments: args } = request.params;
456464

457465
if (name === ToolName.ECHO) {
@@ -624,6 +632,90 @@ export const createMcpServer = (): McpServerWrapper => {
624632
return { content };
625633
}
626634

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+
627719
throw new Error(`Unknown tool: ${name}`);
628720
});
629721

0 commit comments

Comments
 (0)