11using ModelContextProtocol . Protocol . Messages ;
22using ModelContextProtocol . Protocol . Types ;
33using System . Diagnostics . CodeAnalysis ;
4- using System . Text . Encodings . Web ;
54using System . Text . Json ;
65using System . Text . Json . Nodes ;
76using System . Text . Json . Serialization ;
@@ -26,11 +25,6 @@ public static partial class McpJsonUtilities
2625 /// <item>Enables string-based enum serialization as implemented by <see cref="JsonStringEnumConverter"/>.</item>
2726 /// <item>Enables <see cref="JsonIgnoreCondition.WhenWritingNull"/> as the default ignore condition for properties.</item>
2827 /// <item>Enables <see cref="JsonNumberHandling.AllowReadingFromString"/> as the default number handling for number types.</item>
29- /// <item>
30- /// Enables <see cref="JavaScriptEncoder.UnsafeRelaxedJsonEscaping"/> when escaping JSON strings.
31- /// Consuming applications must ensure that JSON outputs are adequately escaped before embedding in other document formats,
32- /// such as HTML and XML.
33- /// </item>
3428 /// </list>
3529 /// </para>
3630 /// </remarks>
@@ -58,15 +52,13 @@ private static JsonSerializerOptions CreateDefaultOptions()
5852 Converters = { new JsonStringEnumConverter ( ) } ,
5953 DefaultIgnoreCondition = JsonIgnoreCondition . WhenWritingNull ,
6054 NumberHandling = JsonNumberHandling . AllowReadingFromString ,
61- Encoder = JavaScriptEncoder . UnsafeRelaxedJsonEscaping ,
6255 } ;
6356 }
6457 else
6558 {
59+ // Keep in sync with any additional settings above beyond what's in JsonContext below.
6660 options = new ( JsonContext . Default . Options )
6761 {
68- // Compile-time encoder setting not yet available
69- Encoder = JavaScriptEncoder . UnsafeRelaxedJsonEscaping ,
7062 } ;
7163 }
7264
@@ -77,7 +69,8 @@ private static JsonSerializerOptions CreateDefaultOptions()
7769 internal static JsonTypeInfo < T > GetTypeInfo < T > ( this JsonSerializerOptions options ) =>
7870 ( JsonTypeInfo < T > ) options . GetTypeInfo ( typeof ( T ) ) ;
7971
80- internal static JsonElement DefaultMcpToolSchema = ParseJsonElement ( "{\" type\" :\" object\" }"u8 ) ;
72+ internal static JsonElement DefaultMcpToolSchema { get ; } = ParseJsonElement ( """{"type":"object"}"""u8 ) ;
73+
8174 internal static bool IsValidMcpToolSchema ( JsonElement element )
8275 {
8376 if ( element . ValueKind is not JsonValueKind . Object )
@@ -129,5 +122,4 @@ private static JsonElement ParseJsonElement(ReadOnlySpan<byte> utf8Json)
129122 Utf8JsonReader reader = new ( utf8Json ) ;
130123 return JsonElement . ParseValue ( ref reader ) ;
131124 }
132-
133125}
0 commit comments