Skip to content

Commit 27e403a

Browse files
Copilotstephentoub
andcommitted
Update ElicitResult documentation and add enum examples to sample code
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
1 parent 7103d14 commit 27e403a

2 files changed

Lines changed: 149 additions & 1 deletion

File tree

docs/concepts/elicitation/samples/server/Tools/InteractiveTools.cs

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,152 @@ CancellationToken token
123123
}
124124
}
125125
}
126+
127+
// <snippet_EnumExamples>
128+
[McpServerTool, Description("Example tool demonstrating various enum schema types")]
129+
public async Task<string> EnumExamples(
130+
McpServer server,
131+
CancellationToken token
132+
)
133+
{
134+
// Example 1: UntitledSingleSelectEnumSchema - Simple enum without display titles
135+
var prioritySchema = new RequestSchema
136+
{
137+
Properties =
138+
{
139+
["Priority"] = new UntitledSingleSelectEnumSchema
140+
{
141+
Title = "Priority Level",
142+
Description = "Select the priority level",
143+
Enum = ["low", "medium", "high", "critical"],
144+
Default = "medium"
145+
}
146+
}
147+
};
148+
149+
var priorityResponse = await server.ElicitAsync(new ElicitRequestParams
150+
{
151+
Message = "Select a priority level:",
152+
RequestedSchema = prioritySchema
153+
}, token);
154+
155+
if (priorityResponse.Action != "accept")
156+
{
157+
return "Operation cancelled";
158+
}
159+
160+
string? priority = priorityResponse.Content?["Priority"].GetString();
161+
162+
// Example 2: TitledSingleSelectEnumSchema - Enum with custom display titles
163+
var severitySchema = new RequestSchema
164+
{
165+
Properties =
166+
{
167+
["Severity"] = new TitledSingleSelectEnumSchema
168+
{
169+
Title = "Issue Severity",
170+
Description = "Select the issue severity level",
171+
OneOf =
172+
[
173+
new EnumOption { Const = "p0", Title = "P0 - Critical (Immediate attention required)" },
174+
new EnumOption { Const = "p1", Title = "P1 - High (Urgent, within 24 hours)" },
175+
new EnumOption { Const = "p2", Title = "P2 - Medium (Within a week)" },
176+
new EnumOption { Const = "p3", Title = "P3 - Low (As time permits)" }
177+
],
178+
Default = "p2"
179+
}
180+
}
181+
};
182+
183+
var severityResponse = await server.ElicitAsync(new ElicitRequestParams
184+
{
185+
Message = "Select the issue severity:",
186+
RequestedSchema = severitySchema
187+
}, token);
188+
189+
if (severityResponse.Action != "accept")
190+
{
191+
return "Operation cancelled";
192+
}
193+
194+
string? severity = severityResponse.Content?["Severity"].GetString();
195+
196+
// Example 3: UntitledMultiSelectEnumSchema - Select multiple values
197+
var tagsSchema = new RequestSchema
198+
{
199+
Properties =
200+
{
201+
["Tags"] = new UntitledMultiSelectEnumSchema
202+
{
203+
Title = "Tags",
204+
Description = "Select one or more tags",
205+
MinItems = 1,
206+
MaxItems = 3,
207+
Items = new EnumItemsSchema
208+
{
209+
Type = "string",
210+
Enum = ["bug", "feature", "documentation", "enhancement", "question"]
211+
},
212+
Default = ["bug"]
213+
}
214+
}
215+
};
216+
217+
var tagsResponse = await server.ElicitAsync(new ElicitRequestParams
218+
{
219+
Message = "Select up to 3 tags:",
220+
RequestedSchema = tagsSchema
221+
}, token);
222+
223+
if (tagsResponse.Action != "accept")
224+
{
225+
return "Operation cancelled";
226+
}
227+
228+
// For multi-select, the value is an array
229+
var tags = tagsResponse.Content?["Tags"].EnumerateArray()
230+
.Select(e => e.GetString())
231+
.ToArray();
232+
233+
// Example 4: TitledMultiSelectEnumSchema - Multi-select with custom titles
234+
var featuresSchema = new RequestSchema
235+
{
236+
Properties =
237+
{
238+
["Features"] = new TitledMultiSelectEnumSchema
239+
{
240+
Title = "Features",
241+
Description = "Select desired features",
242+
Items = new EnumItemsSchema
243+
{
244+
AnyOf =
245+
[
246+
new EnumOption { Const = "auth", Title = "Authentication & Authorization" },
247+
new EnumOption { Const = "api", Title = "RESTful API" },
248+
new EnumOption { Const = "ui", Title = "Modern UI Components" },
249+
new EnumOption { Const = "db", Title = "Database Integration" }
250+
]
251+
}
252+
}
253+
}
254+
};
255+
256+
var featuresResponse = await server.ElicitAsync(new ElicitRequestParams
257+
{
258+
Message = "Select desired features:",
259+
RequestedSchema = featuresSchema
260+
}, token);
261+
262+
if (featuresResponse.Action != "accept")
263+
{
264+
return "Operation cancelled";
265+
}
266+
267+
var features = featuresResponse.Content?["Features"].EnumerateArray()
268+
.Select(e => e.GetString())
269+
.ToArray();
270+
271+
return $"Selected: Priority={priority}, Severity={severity}, Tags=[{string.Join(", ", tags ?? [])}], Features=[{string.Join(", ", features ?? [])}]";
272+
}
273+
// </snippet_EnumExamples>
126274
}

src/ModelContextProtocol.Core/Protocol/ElicitResult.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public sealed class ElicitResult : Result
5151
/// </para>
5252
/// <para>
5353
/// Values in the dictionary should be of types <see cref="JsonValueKind.String"/>, <see cref="JsonValueKind.Number"/>,
54-
/// <see cref="JsonValueKind.True"/>, or <see cref="JsonValueKind.False"/>.
54+
/// <see cref="JsonValueKind.True"/>, <see cref="JsonValueKind.False"/>, or <see cref="JsonValueKind.Array"/> (for multi-select enums).
5555
/// </para>
5656
/// </remarks>
5757
[JsonPropertyName("content")]

0 commit comments

Comments
 (0)