@@ -563,6 +563,27 @@ public async Task StructuredOutput_Disabled_ReturnsExpectedSchema<T>(T value)
563563 Assert . Null ( result . StructuredContent ) ;
564564 }
565565
566+ [ Theory ]
567+ [ InlineData ( JsonNumberHandling . Strict ) ]
568+ [ InlineData ( JsonNumberHandling . AllowReadingFromString ) ]
569+ public async Task ToolWithNullableParameters_ReturnsExpectedSchema ( JsonNumberHandling nunmberHandling )
570+ {
571+ JsonSerializerOptions options = new ( JsonContext2 . Default . Options ) { NumberHandling = nunmberHandling } ;
572+ McpServerTool tool = McpServerTool . Create ( ( int ? x = 42 , DateTimeOffset ? y = null ) => { } , new ( ) { SerializerOptions = options } ) ;
573+
574+ JsonElement expectedSchema = JsonDocument . Parse ( """
575+ {
576+ "type": "object",
577+ "properties": {
578+ "x": { "type": ["integer", "null"], "default": 42 },
579+ "y": { "type": ["string", "null"], "format": "date-time", "default": null }
580+ }
581+ }
582+ """ ) . RootElement ;
583+
584+ Assert . True ( JsonElement . DeepEquals ( expectedSchema , tool . ProtocolTool . InputSchema ) ) ;
585+ }
586+
566587 public static IEnumerable < object [ ] > StructuredOutput_ReturnsExpectedSchema_Inputs ( )
567588 {
568589 yield return new object [ ] { "string" } ;
@@ -695,5 +716,7 @@ record Person(string Name, int Age);
695716 [ JsonSerializable ( typeof ( JsonSchema ) ) ]
696717 [ JsonSerializable ( typeof ( List < AIContent > ) ) ]
697718 [ JsonSerializable ( typeof ( List < string > ) ) ]
719+ [ JsonSerializable ( typeof ( int ? ) ) ]
720+ [ JsonSerializable ( typeof ( DateTimeOffset ? ) ) ]
698721 partial class JsonContext2 : JsonSerializerContext ;
699722}
0 commit comments