@@ -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}
0 commit comments