22using Microsoft . Extensions . Logging ;
33using ModelContextProtocol . Protocol ;
44using System . Collections . Concurrent ;
5- using System . ComponentModel ;
65using System . Diagnostics . CodeAnalysis ;
7- using System . Reflection ;
86using System . Runtime . CompilerServices ;
97using System . Text ;
108using System . Text . Json ;
@@ -259,9 +257,9 @@ public async ValueTask<ElicitResult<T>> ElicitAsync<T>(
259257 var dict = s_elicitResultSchemaCache . GetValue ( serializerOptions , _ => new ( ) ) ;
260258
261259#if NET
262- var schema = dict . GetOrAdd ( typeof ( T ) , static ( t , s ) => BuildRequestSchemaHelper ( t , s ) , serializerOptions ) ;
260+ var schema = dict . GetOrAdd ( typeof ( T ) , static ( t , s ) => BuildRequestSchema ( t , s ) , serializerOptions ) ;
263261#else
264- var schema = dict . GetOrAdd ( typeof ( T ) , type => BuildRequestSchemaHelper ( type , serializerOptions ) ) ;
262+ var schema = dict . GetOrAdd ( typeof ( T ) , type => BuildRequestSchema ( type , serializerOptions ) ) ;
265263#endif
266264
267265 var request = new ElicitRequestParams
@@ -287,21 +285,14 @@ public async ValueTask<ElicitResult<T>> ElicitAsync<T>(
287285 return new ElicitResult < T > { Action = raw . Action , Content = typed } ;
288286 }
289287
290- /// <summary>
291- /// Helper method for BuildRequestSchema that can be called from lambdas without annotation issues.
292- /// </summary>
293- [ UnconditionalSuppressMessage ( "Trimming" , "IL2067" , Justification = "Type T is preserved via JsonTypeInfo" ) ]
294- private static ElicitRequestParams . RequestSchema BuildRequestSchemaHelper ( Type type , JsonSerializerOptions serializerOptions )
295- => BuildRequestSchema ( type , serializerOptions ) ;
296-
297288 /// <summary>
298289 /// Builds a request schema for elicitation based on the public serializable properties of <paramref name="type"/>.
299290 /// </summary>
300291 /// <param name="type">The type of the schema being built.</param>
301292 /// <param name="serializerOptions">The serializer options to use.</param>
302293 /// <returns>The built request schema.</returns>
303294 /// <exception cref="McpProtocolException"></exception>
304- private static ElicitRequestParams . RequestSchema BuildRequestSchema ( [ DynamicallyAccessedMembers ( DynamicallyAccessedMemberTypes . PublicProperties ) ] Type type , JsonSerializerOptions serializerOptions )
295+ private static ElicitRequestParams . RequestSchema BuildRequestSchema ( Type type , JsonSerializerOptions serializerOptions )
305296 {
306297 var schema = new ElicitRequestParams . RequestSchema ( ) ;
307298 var props = schema . Properties ;
@@ -316,47 +307,11 @@ private static ElicitRequestParams.RequestSchema BuildRequestSchema([Dynamically
316307 foreach ( JsonPropertyInfo pi in typeInfo . Properties )
317308 {
318309 var def = CreatePrimitiveSchema ( pi . PropertyType , serializerOptions ) ;
319-
320- // Extract default value from DefaultValueAttribute if present
321- var propInfo = type . GetProperty ( pi . Name ) ;
322- if ( propInfo != null )
323- {
324- var defaultValueAttr = propInfo . GetCustomAttribute < System . ComponentModel . DefaultValueAttribute > ( ) ;
325- if ( defaultValueAttr ? . Value != null )
326- {
327- SetDefaultValue ( def , defaultValueAttr . Value ) ;
328- }
329- }
330-
331310 props [ pi . Name ] = def ;
332311 }
333312
334313 return schema ;
335314 }
336-
337- /// <summary>
338- /// Sets the default value on a primitive schema definition based on the value type.
339- /// </summary>
340- /// <param name="schema">The schema to set the default value on.</param>
341- /// <param name="value">The default value.</param>
342- private static void SetDefaultValue ( ElicitRequestParams . PrimitiveSchemaDefinition schema , object value )
343- {
344- switch ( schema )
345- {
346- case ElicitRequestParams . StringSchema stringSchema :
347- stringSchema . Default = value ? . ToString ( ) ;
348- break ;
349- case ElicitRequestParams . NumberSchema numberSchema :
350- numberSchema . Default = Convert . ToDouble ( value ) ;
351- break ;
352- case ElicitRequestParams . BooleanSchema booleanSchema :
353- booleanSchema . Default = Convert . ToBoolean ( value ) ;
354- break ;
355- case ElicitRequestParams . EnumSchema enumSchema :
356- enumSchema . Default = value ? . ToString ( ) ;
357- break ;
358- }
359- }
360315
361316 /// <summary>
362317 /// Creates a primitive schema definition for the specified type, if supported.
0 commit comments