@@ -173,44 +173,197 @@ public static string ErrorHandling()
173173 }
174174
175175 /// <summary>
176- /// Sampling tool - requests LLM completion from client (not implemented in this version)
176+ /// Sampling tool - requests LLM completion from client
177177 /// </summary>
178178 [ McpServerTool ( Name = "test_sampling" ) ]
179179 [ Description ( "Tests server-initiated sampling (LLM completion request)" ) ]
180- public static string Sampling ( [ Description ( "The prompt to send to the LLM" ) ] string prompt )
180+ public static async Task < string > Sampling (
181+ McpServer server ,
182+ [ Description ( "The prompt to send to the LLM" ) ] string prompt ,
183+ CancellationToken cancellationToken )
181184 {
182- // Note: Client-requested sampling is not yet implemented in the C# SDK
183- return "Sampling not supported or error: Sampling capability not implemented in C# SDK yet" ;
185+ try
186+ {
187+ var samplingParams = new CreateMessageRequestParams
188+ {
189+ Messages = [ new SamplingMessage
190+ {
191+ Role = Role . User ,
192+ Content = new TextContentBlock { Text = prompt } ,
193+ } ] ,
194+ MaxTokens = 100 ,
195+ Temperature = 0.7f
196+ } ;
197+
198+ var result = await server . SampleAsync ( samplingParams , cancellationToken ) ;
199+ return $ "Sampling result: { ( result . Content as TextContentBlock ) ? . Text ?? "No text content" } ";
200+ }
201+ catch ( Exception ex )
202+ {
203+ return $ "Sampling not supported or error: { ex . Message } ";
204+ }
184205 }
185206
186207 /// <summary>
187- /// Elicitation tool - requests user input from client (not implemented in this version)
208+ /// Elicitation tool - requests user input from client
188209 /// </summary>
189210 [ McpServerTool ( Name = "test_elicitation" ) ]
190211 [ Description ( "Tests elicitation (user input request from client)" ) ]
191- public static string Elicitation ( [ Description ( "Message to show to the user" ) ] string message )
212+ public static async Task < string > Elicitation (
213+ McpServer server ,
214+ [ Description ( "Message to show to the user" ) ] string message ,
215+ CancellationToken cancellationToken )
192216 {
193- // Note: Elicitation is not yet implemented in the C# SDK
194- return "Elicitation not supported or error: Elicitation capability not implemented in C# SDK yet" ;
217+ try
218+ {
219+ var schema = new ElicitRequestParams . RequestSchema
220+ {
221+ Properties =
222+ {
223+ [ "response" ] = new ElicitRequestParams . StringSchema ( )
224+ {
225+ Description = "User's response to the message"
226+ }
227+ }
228+ } ;
229+
230+ var result = await server . ElicitAsync ( new ElicitRequestParams
231+ {
232+ Message = message ,
233+ RequestedSchema = schema
234+ } , cancellationToken ) ;
235+
236+ if ( result . Action == "accept" && result . Content != null )
237+ {
238+ return $ "User responded: { result . Content [ "response" ] . GetString ( ) } ";
239+ }
240+ else
241+ {
242+ return $ "Elicitation { result . Action } ";
243+ }
244+ }
245+ catch ( Exception ex )
246+ {
247+ return $ "Elicitation not supported or error: { ex . Message } ";
248+ }
195249 }
196250
197251 /// <summary>
198- /// SEP-1034: Elicitation with default values for all primitive types (not implemented)
252+ /// SEP-1034: Elicitation with default values for all primitive types
199253 /// </summary>
200254 [ McpServerTool ( Name = "test_elicitation_sep1034_defaults" ) ]
201255 [ Description ( "Tests elicitation with default values per SEP-1034" ) ]
202- public static string ElicitationSep1034Defaults ( )
256+ public static async Task < string > ElicitationSep1034Defaults (
257+ McpServer server ,
258+ CancellationToken cancellationToken )
203259 {
204- return "Elicitation not supported or error: Elicitation capability not implemented in C# SDK yet" ;
260+ try
261+ {
262+ var schema = new ElicitRequestParams . RequestSchema
263+ {
264+ Properties =
265+ {
266+ [ "name" ] = new ElicitRequestParams . StringSchema ( )
267+ {
268+ Description = "Name" ,
269+ Default = "John Doe"
270+ } ,
271+ [ "age" ] = new ElicitRequestParams . NumberSchema ( )
272+ {
273+ Type = "integer" ,
274+ Description = "Age" ,
275+ Default = 30
276+ } ,
277+ [ "score" ] = new ElicitRequestParams . NumberSchema ( )
278+ {
279+ Description = "Score" ,
280+ Default = 95.5
281+ } ,
282+ [ "status" ] = new ElicitRequestParams . EnumSchema ( )
283+ {
284+ Description = "Status" ,
285+ Enum = [ "active" , "inactive" , "pending" ] ,
286+ Default = "active"
287+ } ,
288+ [ "verified" ] = new ElicitRequestParams . BooleanSchema ( )
289+ {
290+ Description = "Verified" ,
291+ Default = true
292+ }
293+ }
294+ } ;
295+
296+ var result = await server . ElicitAsync ( new ElicitRequestParams
297+ {
298+ Message = "Test elicitation with default values for primitive types" ,
299+ RequestedSchema = schema
300+ } , cancellationToken ) ;
301+
302+ if ( result . Action == "accept" && result . Content != null )
303+ {
304+ return $ "Accepted with values: string={ result . Content [ "stringField" ] . GetString ( ) } , " +
305+ $ "number={ result . Content [ "numberField" ] . GetInt32 ( ) } , " +
306+ $ "boolean={ result . Content [ "booleanField" ] . GetBoolean ( ) } ";
307+ }
308+ else
309+ {
310+ return $ "Elicitation { result . Action } ";
311+ }
312+ }
313+ catch ( Exception ex )
314+ {
315+ return $ "Elicitation not supported or error: { ex . Message } ";
316+ }
205317 }
206318
207319 /// <summary>
208- /// SEP-1330: Elicitation with enum schema improvements (not implemented)
320+ /// SEP-1330: Elicitation with enum schema improvements
209321 /// </summary>
210322 [ McpServerTool ( Name = "test_elicitation_sep1330_enums" ) ]
211323 [ Description ( "Tests elicitation with enum schema improvements per SEP-1330" ) ]
212- public static string ElicitationSep1330Enums ( )
324+ public static async Task < string > ElicitationSep1330Enums (
325+ McpServer server ,
326+ CancellationToken cancellationToken )
213327 {
214- return "Elicitation not supported or error: Elicitation capability not implemented in C# SDK yet" ;
328+ try
329+ {
330+ var schema = new ElicitRequestParams . RequestSchema
331+ {
332+ Properties =
333+ {
334+ [ "color" ] = new ElicitRequestParams . EnumSchema ( )
335+ {
336+ Description = "Choose a color" ,
337+ Enum = [ "red" , "green" , "blue" ]
338+ } ,
339+ [ "size" ] = new ElicitRequestParams . EnumSchema ( )
340+ {
341+ Description = "Choose a size" ,
342+ Enum = [ "small" , "medium" , "large" ] ,
343+ Default = "medium"
344+ }
345+ }
346+ } ;
347+
348+ var result = await server . ElicitAsync ( new ElicitRequestParams
349+ {
350+ Message = "Test elicitation with enum schema" ,
351+ RequestedSchema = schema
352+ } , cancellationToken ) ;
353+
354+ if ( result . Action == "accept" && result . Content != null )
355+ {
356+ return $ "Accepted with values: color={ result . Content [ "color" ] . GetString ( ) } , " +
357+ $ "size={ result . Content [ "size" ] . GetString ( ) } ";
358+ }
359+ else
360+ {
361+ return $ "Elicitation { result . Action } ";
362+ }
363+ }
364+ catch ( Exception ex )
365+ {
366+ return $ "Elicitation not supported or error: { ex . Message } ";
367+ }
215368 }
216369}
0 commit comments