diff --git a/src/ModelContextProtocol.Core/Protocol/LoggingMessageNotificationParams.cs b/src/ModelContextProtocol.Core/Protocol/LoggingMessageNotificationParams.cs index 23e572791..600f620a5 100644 --- a/src/ModelContextProtocol.Core/Protocol/LoggingMessageNotificationParams.cs +++ b/src/ModelContextProtocol.Core/Protocol/LoggingMessageNotificationParams.cs @@ -45,8 +45,9 @@ public sealed class LoggingMessageNotificationParams : NotificationParams public string? Logger { get; set; } /// - /// Gets or sets the data to be logged, such as a string message. + /// Gets or sets the data to be logged, such as a string message or an object. + /// Any JSON serializable type is allowed here. /// [JsonPropertyName("data")] - public JsonElement? Data { get; set; } + public required JsonElement Data { get; set; } } diff --git a/tests/ModelContextProtocol.Tests/Client/McpClientTests.cs b/tests/ModelContextProtocol.Tests/Client/McpClientTests.cs index 26906f2e9..32e04da60 100644 --- a/tests/ModelContextProtocol.Tests/Client/McpClientTests.cs +++ b/tests/ModelContextProtocol.Tests/Client/McpClientTests.cs @@ -539,11 +539,9 @@ public async Task AsClientLoggerProvider_MessagesSentToClient() { var m = await channel.Reader.ReadAsync(TestContext.Current.CancellationToken); Assert.NotNull(m); - Assert.NotNull(m.Data); - Assert.Equal("TestLogger", m.Logger); - string? s = JsonSerializer.Deserialize(m.Data.Value, McpJsonUtilities.DefaultOptions); + string? s = JsonSerializer.Deserialize(m.Data, McpJsonUtilities.DefaultOptions); Assert.NotNull(s); if (s.Contains("Information")) diff --git a/tests/ModelContextProtocol.Tests/Protocol/LoggingMessageNotificationParamsTests.cs b/tests/ModelContextProtocol.Tests/Protocol/LoggingMessageNotificationParamsTests.cs index 449db3372..2e8e473ea 100644 --- a/tests/ModelContextProtocol.Tests/Protocol/LoggingMessageNotificationParamsTests.cs +++ b/tests/ModelContextProtocol.Tests/Protocol/LoggingMessageNotificationParamsTests.cs @@ -23,8 +23,7 @@ public static void LoggingMessageNotificationParams_SerializationRoundTrip_Prese Assert.NotNull(deserialized); Assert.Equal(LoggingLevel.Warning, deserialized.Level); Assert.Equal("MyApp.Services", deserialized.Logger); - Assert.NotNull(deserialized.Data); - Assert.Equal("Something went wrong", deserialized.Data.Value.GetString()); + Assert.Equal("Something went wrong", deserialized.Data.GetString()); Assert.NotNull(deserialized.Meta); Assert.Equal("value", (string)deserialized.Meta["key"]!); } @@ -34,7 +33,8 @@ public static void LoggingMessageNotificationParams_SerializationRoundTrip_WithM { var original = new LoggingMessageNotificationParams { - Level = LoggingLevel.Error + Level = LoggingLevel.Error, + Data = JsonDocument.Parse("\"error occurred\"").RootElement.Clone(), }; string json = JsonSerializer.Serialize(original, McpJsonUtilities.DefaultOptions); @@ -43,7 +43,7 @@ public static void LoggingMessageNotificationParams_SerializationRoundTrip_WithM Assert.NotNull(deserialized); Assert.Equal(LoggingLevel.Error, deserialized.Level); Assert.Null(deserialized.Logger); - Assert.Null(deserialized.Data); + Assert.Equal("error occurred", deserialized.Data.GetString()); Assert.Null(deserialized.Meta); } }