You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
text: `Hello ${name}, welcome to the ${department} team!`
315
+
}
316
+
}]
317
+
})
318
+
);
319
+
```
320
+
321
+
### Completions
322
+
323
+
MCP supports argument completions to help users fill in prompt arguments and resource template parameters. See the examples above for [resource completions](#resources) and [prompt completions](#prompts).
324
+
325
+
#### Client Usage
326
+
327
+
```typescript
328
+
// Request completions for any argument
329
+
const result =awaitclient.complete({
330
+
ref: {
331
+
type: "ref/prompt", // or "ref/resource"
332
+
name: "example"// or uri: "template://..."
333
+
},
334
+
argument: {
335
+
name: "argumentName",
336
+
value: "partial"// What the user has typed so far
337
+
},
338
+
context: { // Optional: Include previously resolved arguments
339
+
arguments: {
340
+
previousArg: "value"
341
+
}
342
+
}
343
+
});
344
+
253
345
```
254
346
255
347
### Display Names and Metadata
@@ -772,6 +864,109 @@ const transport = new StdioServerTransport();
772
864
awaitserver.connect(transport);
773
865
```
774
866
867
+
### Eliciting User Input
868
+
869
+
MCP servers can request additional information from users through the elicitation feature. This is useful for interactive workflows where the server needs user input or confirmation:
870
+
871
+
```typescript
872
+
// Server-side: Restaurant booking tool that asks for alternatives
873
+
server.tool(
874
+
"book-restaurant",
875
+
{
876
+
restaurant: z.string(),
877
+
date: z.string(),
878
+
partySize: z.number()
879
+
},
880
+
async ({ restaurant, date, partySize }) => {
881
+
// Check availability
882
+
const available =awaitcheckAvailability(restaurant, date, partySize);
883
+
884
+
if (!available) {
885
+
// Ask user if they want to try alternative dates
886
+
const result =awaitserver.server.elicitInput({
887
+
message: `No tables available at ${restaurant} on ${date}. Would you like to check alternative dates?`,
888
+
requestedSchema: {
889
+
type: "object",
890
+
properties: {
891
+
checkAlternatives: {
892
+
type: "boolean",
893
+
title: "Check alternative dates",
894
+
description: "Would you like me to check other dates?"
895
+
},
896
+
flexibleDates: {
897
+
type: "string",
898
+
title: "Date flexibility",
899
+
description: "How flexible are your dates?",
900
+
enum: ["next_day", "same_week", "next_week"],
901
+
enumNames: ["Next day", "Same week", "Next week"]
902
+
}
903
+
},
904
+
required: ["checkAlternatives"]
905
+
}
906
+
});
907
+
908
+
if (result.action==="accept"&&result.content?.checkAlternatives) {
909
+
const alternatives =awaitfindAlternatives(
910
+
restaurant,
911
+
date,
912
+
partySize,
913
+
result.content.flexibleDatesasstring
914
+
);
915
+
return {
916
+
content: [{
917
+
type: "text",
918
+
text: `Found these alternatives: ${alternatives.join(", ")}`
919
+
}]
920
+
};
921
+
}
922
+
923
+
return {
924
+
content: [{
925
+
type: "text",
926
+
text: "No booking made. Original date not available."
927
+
}]
928
+
};
929
+
}
930
+
931
+
// Book the table
932
+
awaitmakeBooking(restaurant, date, partySize);
933
+
return {
934
+
content: [{
935
+
type: "text",
936
+
text: `Booked table for ${partySize} at ${restaurant} on ${date}`
937
+
}]
938
+
};
939
+
}
940
+
);
941
+
```
942
+
943
+
Client-side: Handle elicitation requests
944
+
945
+
```typescript
946
+
// This is a placeholder - implement based on your UI framework
0 commit comments