Fixed JSON serialization issue between Annotated base class and deriv… #12
+11
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
…ed classes due to 'Type' name conflict.
Experienced the following error during MCP server testing locally:
MCP error -32602: The type 'ModelContextProtocol.NET.Core.Models.Protocol.Shared.Content.TextContent' contains property 'type' that conflicts with an existing metadata property name.
Root Cause Determination:
In Annotated.cs, the base class has:
csharpCopy[JsonPolymorphic(TypeDiscriminatorPropertyName = "type")]
[JsonDerivedType(typeof(TextContent), "text")]
[JsonDerivedType(typeof(ImageContent), "image")]
[JsonDerivedType(typeof(EmbeddedResource), "resource")]
The base Annotated class uses [JsonPolymorphic] with TypeDiscriminatorPropertyName = "type" to handle polymorphic serialization. Each derived content class (TextContent, ImageContent, EmbeddedResource) defined a Type property that returned a string constant. During serialization, the system tried to use both the discriminator property "type" (from the JsonPolymorphic attribute) and the actual property "Type" from the class, causing a naming conflict
Changes Made:
Added [JsonIgnore] attribute to the Type property in:
TextContent.cs
ImageContent.cs
EmbeddedResource.cs
No unit tests found in the solution, but I tested the library with these changes locally and the error has been fixed.