Skip to content

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