-
Notifications
You must be signed in to change notification settings - Fork 5
Description
As per the PR.
2025-03-19T18:06:32.823Z [dashforge] [info] Message from client: {"method":"tools/call","params":{"name":"discover_metrics","arguments":{"Filter":null}},"jsonrpc":"2.0","id":27}
2025-03-19T18:06:32.951Z [dashforge] [info] Message from server: {"jsonrpc":"2.0","id":27,"error":{"code":-32602,"message":"The type 'ModelContextProtocol.NET.Core.Models.Protocol.Shared.Content.TextContent' contains property 'type' that conflicts with an existing metadata property name. Consider either renaming it or ignoring it with JsonIgnoreAttribute."}}
Issue Summary:
The library was experiencing a JSON serialization error when using MCP tool:
CopyMCP error -32602: The type 'ModelContextProtocol.NET.Core.Models.Protocol.Shared.Content.TextContent' contains property 'type' that conflicts with an existing metadata property name.
This error occurred because:
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.
The derived classes each defined a property with a name that conflicts with this discriminator:
csharpCopypublic string Type => "text"; // Same value, but property name conflicts
The error message suggests two solutions: renaming the property or using JsonIgnoreAttribute. I chose the later in the PR since it is less invasive/destructive.
No unit tests found in the solution, but I tested the library with the changes from the PR locally and the error has been fixed.