Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed JSON serialization issue between Annotated base class and deriv… #12

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

MisterDeee
Copy link

…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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants