From bdee4a8e6dc338ed5a0532929885148fe3ad83c3 Mon Sep 17 00:00:00 2001 From: Dean Mills Date: Wed, 19 Mar 2025 12:41:32 -0600 Subject: [PATCH] Fixed JSON serialization issue between Annotated base class and derived classes due to 'Type' name conflict. --- .../Models/Protocol/Shared/Content/EmbeddedResource.cs | 5 ++++- .../Models/Protocol/Shared/Content/ImageContent.cs | 5 ++++- .../Models/Protocol/Shared/Content/TextContent.cs | 3 +++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/ModelContextProtocol.NET.Core/Models/Protocol/Shared/Content/EmbeddedResource.cs b/src/ModelContextProtocol.NET.Core/Models/Protocol/Shared/Content/EmbeddedResource.cs index c61b89a..854b58c 100644 --- a/src/ModelContextProtocol.NET.Core/Models/Protocol/Shared/Content/EmbeddedResource.cs +++ b/src/ModelContextProtocol.NET.Core/Models/Protocol/Shared/Content/EmbeddedResource.cs @@ -1,7 +1,10 @@ -namespace ModelContextProtocol.NET.Core.Models.Protocol.Shared.Content; +using System.Text.Json.Serialization; + +namespace ModelContextProtocol.NET.Core.Models.Protocol.Shared.Content; public record EmbeddedResource : Annotated { + [JsonIgnore] public string Type => "resource"; public required ResourceContents Resource { get; init; } } diff --git a/src/ModelContextProtocol.NET.Core/Models/Protocol/Shared/Content/ImageContent.cs b/src/ModelContextProtocol.NET.Core/Models/Protocol/Shared/Content/ImageContent.cs index b0acdb8..6c28ec8 100644 --- a/src/ModelContextProtocol.NET.Core/Models/Protocol/Shared/Content/ImageContent.cs +++ b/src/ModelContextProtocol.NET.Core/Models/Protocol/Shared/Content/ImageContent.cs @@ -1,7 +1,10 @@ -namespace ModelContextProtocol.NET.Core.Models.Protocol.Shared.Content; +using System.Text.Json.Serialization; + +namespace ModelContextProtocol.NET.Core.Models.Protocol.Shared.Content; public record ImageContent : Annotated { + [JsonIgnore] public string Type => "image"; public required string Data { get; init; } public required string MimeType { get; init; } diff --git a/src/ModelContextProtocol.NET.Core/Models/Protocol/Shared/Content/TextContent.cs b/src/ModelContextProtocol.NET.Core/Models/Protocol/Shared/Content/TextContent.cs index fe508b7..58cf4ce 100644 --- a/src/ModelContextProtocol.NET.Core/Models/Protocol/Shared/Content/TextContent.cs +++ b/src/ModelContextProtocol.NET.Core/Models/Protocol/Shared/Content/TextContent.cs @@ -1,7 +1,10 @@ +using System.Text.Json.Serialization; + namespace ModelContextProtocol.NET.Core.Models.Protocol.Shared.Content; public record TextContent : Annotated { + [JsonIgnore] public string Type => "text"; public required string Text { get; init; }