Skip to content

Commit 4c0cdec

Browse files
committed
Fix: handle JsonSerializerOptions without TypeInfoResolver
Added a helper method which ensures that custom options are properly configured with required TypeInfoResolvers. Fixes #1150
1 parent 84dcfbc commit 4c0cdec

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

src/ModelContextProtocol.Core/Server/AIFunctionMcpServerTool.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,4 +580,22 @@ private static CallToolResult ConvertAIContentEnumerableToCallToolResult(IEnumer
580580
IsError = allErrorContent && hasAny
581581
};
582582
}
583+
584+
private static JsonSerializerOptions GetSerializerOptions(JsonSerializerOptions? customOptions)
585+
{
586+
if (customOptions is null)
587+
{
588+
return McpJsonUtilities.DefaultOptions;
589+
}
590+
591+
if (customOptions.TypeInfoResolver is not null)
592+
{
593+
return customOptions;
594+
}
595+
596+
customOptions.TypeInfoResolverChain.Add(McpJsonUtilities.JsonContext.Default);
597+
customOptions.TypeInfoResolverChain.Add(AIJsonUtilities.DefaultOptions.TypeInfoResolver!);
598+
599+
return customOptions;
600+
}
583601
}

0 commit comments

Comments
 (0)