diff --git a/Directory.Packages.props b/Directory.Packages.props index 4df4ea73..6da9521f 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -3,7 +3,7 @@ true 9.0.5 10.0.0-preview.4.25258.110 - 9.7.0 + 9.7.1 diff --git a/tests/ModelContextProtocol.Tests/Server/McpServerToolTests.cs b/tests/ModelContextProtocol.Tests/Server/McpServerToolTests.cs index 5cc6fa78..bd0ca5ef 100644 --- a/tests/ModelContextProtocol.Tests/Server/McpServerToolTests.cs +++ b/tests/ModelContextProtocol.Tests/Server/McpServerToolTests.cs @@ -563,6 +563,27 @@ public async Task StructuredOutput_Disabled_ReturnsExpectedSchema(T value) Assert.Null(result.StructuredContent); } + [Theory] + [InlineData(JsonNumberHandling.Strict)] + [InlineData(JsonNumberHandling.AllowReadingFromString)] + public async Task ToolWithNullableParameters_ReturnsExpectedSchema(JsonNumberHandling nunmberHandling) + { + JsonSerializerOptions options = new(JsonContext2.Default.Options) { NumberHandling = nunmberHandling }; + McpServerTool tool = McpServerTool.Create((int? x = 42, DateTimeOffset? y = null) => { }, new() { SerializerOptions = options }); + + JsonElement expectedSchema = JsonDocument.Parse(""" + { + "type": "object", + "properties": { + "x": { "type": ["integer", "null"], "default": 42 }, + "y": { "type": ["string", "null"], "format": "date-time", "default": null } + } + } + """).RootElement; + + Assert.True(JsonElement.DeepEquals(expectedSchema, tool.ProtocolTool.InputSchema)); + } + public static IEnumerable StructuredOutput_ReturnsExpectedSchema_Inputs() { yield return new object[] { "string" }; @@ -695,5 +716,7 @@ record Person(string Name, int Age); [JsonSerializable(typeof(JsonSchema))] [JsonSerializable(typeof(List))] [JsonSerializable(typeof(List))] + [JsonSerializable(typeof(int?))] + [JsonSerializable(typeof(DateTimeOffset?))] partial class JsonContext2 : JsonSerializerContext; }