diff --git a/docs/concepts/elicitation/samples/client/Program.cs b/docs/concepts/elicitation/samples/client/Program.cs index b2a91ca4b..eeae99142 100644 --- a/docs/concepts/elicitation/samples/client/Program.cs +++ b/docs/concepts/elicitation/samples/client/Program.cs @@ -78,16 +78,16 @@ async ValueTask HandleElicitationAsync(ElicitRequestParams? reques // Try standard boolean parsing first if (bool.TryParse(clientInput, out parsedBool)) { - content[property.Key] = JsonSerializer.Deserialize(JsonSerializer.Serialize(parsedBool)); + content[property.Key] = JsonElement.Parse(JsonSerializer.Serialize(parsedBool)); } // Also accept "yes"/"no" as valid boolean inputs else if (string.Equals(clientInput?.Trim(), "yes", StringComparison.OrdinalIgnoreCase)) { - content[property.Key] = JsonSerializer.Deserialize(JsonSerializer.Serialize(true)); + content[property.Key] = JsonElement.Parse(JsonSerializer.Serialize(true)); } else if (string.Equals(clientInput?.Trim(), "no", StringComparison.OrdinalIgnoreCase)) { - content[property.Key] = JsonSerializer.Deserialize(JsonSerializer.Serialize(false)); + content[property.Key] = JsonElement.Parse(JsonSerializer.Serialize(false)); } } else if (property.Value is ElicitRequestParams.NumberSchema numberSchema) @@ -97,14 +97,14 @@ async ValueTask HandleElicitationAsync(ElicitRequestParams? reques double parsedNumber; if (double.TryParse(clientInput, out parsedNumber)) { - content[property.Key] = JsonSerializer.Deserialize(JsonSerializer.Serialize(parsedNumber)); + content[property.Key] = JsonElement.Parse(JsonSerializer.Serialize(parsedNumber)); } } else if (property.Value is ElicitRequestParams.StringSchema stringSchema) { Console.Write($"{stringSchema.Description}: "); var clientInput = Console.ReadLine(); - content[property.Key] = JsonSerializer.Deserialize(JsonSerializer.Serialize(clientInput)); + content[property.Key] = JsonElement.Parse(JsonSerializer.Serialize(clientInput)); } } diff --git a/tests/ModelContextProtocol.TestServer/Program.cs b/tests/ModelContextProtocol.TestServer/Program.cs index e4b797ee6..fe5c725ad 100644 --- a/tests/ModelContextProtocol.TestServer/Program.cs +++ b/tests/ModelContextProtocol.TestServer/Program.cs @@ -81,7 +81,7 @@ await server.SendMessageAsync(new JsonRpcNotification Params = JsonSerializer.SerializeToNode(new LoggingMessageNotificationParams { Level = logLevel, - Data = JsonSerializer.Deserialize("\"Random log message\"") + Data = JsonElement.Parse("\"Random log message\"") }) }, cancellationToken); } @@ -117,7 +117,7 @@ private static void ConfigureTools(McpServerOptions options, string? cliArg) { Name = "echo", Description = "Echoes the input back to the client.", - InputSchema = JsonSerializer.Deserialize(""" + InputSchema = JsonElement.Parse(""" { "type": "object", "properties": { @@ -134,17 +134,17 @@ private static void ConfigureTools(McpServerOptions options, string? cliArg) { Name = "echoSessionId", Description = "Echoes the session id back to the client.", - InputSchema = JsonSerializer.Deserialize(""" + InputSchema = JsonElement.Parse(""" { "type": "object" } - """, McpJsonUtilities.DefaultOptions), + """), }, new Tool { Name = "sampleLLM", Description = "Samples from an LLM using MCP's sampling feature.", - InputSchema = JsonSerializer.Deserialize(""" + InputSchema = JsonElement.Parse(""" { "type": "object", "properties": { diff --git a/tests/ModelContextProtocol.TestSseServer/Program.cs b/tests/ModelContextProtocol.TestSseServer/Program.cs index 53537c2b8..2b6c9b852 100644 --- a/tests/ModelContextProtocol.TestSseServer/Program.cs +++ b/tests/ModelContextProtocol.TestSseServer/Program.cs @@ -107,7 +107,7 @@ static CreateMessageRequestParams CreateRequestSamplingParams(string context, st { Name = "echo", Description = "Echoes the input back to the client.", - InputSchema = JsonSerializer.Deserialize(""" + InputSchema = JsonElement.Parse(""" { "type": "object", "properties": { @@ -118,23 +118,23 @@ static CreateMessageRequestParams CreateRequestSamplingParams(string context, st }, "required": ["message"] } - """, McpJsonUtilities.DefaultOptions), + """), }, new Tool { Name = "echoSessionId", Description = "Echoes the session id back to the client.", - InputSchema = JsonSerializer.Deserialize(""" + InputSchema = JsonElement.Parse(""" { "type": "object" } - """, McpJsonUtilities.DefaultOptions), + """), }, new Tool { Name = "sampleLLM", Description = "Samples from an LLM using MCP's sampling feature.", - InputSchema = JsonSerializer.Deserialize(""" + InputSchema = JsonElement.Parse(""" { "type": "object", "properties": { @@ -149,7 +149,7 @@ static CreateMessageRequestParams CreateRequestSamplingParams(string context, st }, "required": ["prompt", "maxTokens"] } - """, McpJsonUtilities.DefaultOptions), + """), } ] }; diff --git a/tests/ModelContextProtocol.Tests/Configuration/McpServerBuilderExtensionsToolsTests.cs b/tests/ModelContextProtocol.Tests/Configuration/McpServerBuilderExtensionsToolsTests.cs index 79bf6fe50..3739b7ae3 100644 --- a/tests/ModelContextProtocol.Tests/Configuration/McpServerBuilderExtensionsToolsTests.cs +++ b/tests/ModelContextProtocol.Tests/Configuration/McpServerBuilderExtensionsToolsTests.cs @@ -43,13 +43,13 @@ protected override void ConfigureServices(ServiceCollection services, IMcpServer { Name = "FirstCustomTool", Description = "First tool returned by custom handler", - InputSchema = JsonSerializer.Deserialize(""" + InputSchema = JsonElement.Parse(""" { "type": "object", "properties": {}, "required": [] } - """, McpJsonUtilities.DefaultOptions), + """), }], }; @@ -61,13 +61,13 @@ protected override void ConfigureServices(ServiceCollection services, IMcpServer { Name = "SecondCustomTool", Description = "Second tool returned by custom handler", - InputSchema = JsonSerializer.Deserialize(""" + InputSchema = JsonElement.Parse(""" { "type": "object", "properties": {}, "required": [] } - """, McpJsonUtilities.DefaultOptions), + """), }], }; @@ -79,13 +79,13 @@ protected override void ConfigureServices(ServiceCollection services, IMcpServer { Name = "FinalCustomTool", Description = "Third tool returned by custom handler", - InputSchema = JsonSerializer.Deserialize(""" + InputSchema = JsonElement.Parse(""" { "type": "object", "properties": {}, "required": [] } - """, McpJsonUtilities.DefaultOptions), + """), }], }; diff --git a/tests/ModelContextProtocol.Tests/Protocol/ElicitationTests.cs b/tests/ModelContextProtocol.Tests/Protocol/ElicitationTests.cs index fc4dacb78..92db42f72 100644 --- a/tests/ModelContextProtocol.Tests/Protocol/ElicitationTests.cs +++ b/tests/ModelContextProtocol.Tests/Protocol/ElicitationTests.cs @@ -120,18 +120,18 @@ public async Task Can_Elicit_Information() Action = "accept", Content = new Dictionary { - ["prop1"] = (JsonElement)JsonSerializer.Deserialize(""" + ["prop1"] = JsonElement.Parse(""" "string result" - """, McpJsonUtilities.DefaultOptions.GetTypeInfo(typeof(JsonElement)))!, - ["prop2"] = (JsonElement)JsonSerializer.Deserialize(""" + """), + ["prop2"] = JsonElement.Parse(""" 42 - """, McpJsonUtilities.DefaultOptions.GetTypeInfo(typeof(JsonElement)))!, - ["prop3"] = (JsonElement)JsonSerializer.Deserialize(""" + """), + ["prop3"] = JsonElement.Parse(""" true - """, McpJsonUtilities.DefaultOptions.GetTypeInfo(typeof(JsonElement)))!, - ["prop4"] = (JsonElement)JsonSerializer.Deserialize(""" + """), + ["prop4"] = JsonElement.Parse(""" "option2" - """, McpJsonUtilities.DefaultOptions.GetTypeInfo(typeof(JsonElement)))!, + """), }, }; } diff --git a/tests/ModelContextProtocol.Tests/Protocol/ElicitationTypedTests.cs b/tests/ModelContextProtocol.Tests/Protocol/ElicitationTypedTests.cs index b0cdbe3d9..ab0a5d4f4 100644 --- a/tests/ModelContextProtocol.Tests/Protocol/ElicitationTypedTests.cs +++ b/tests/ModelContextProtocol.Tests/Protocol/ElicitationTypedTests.cs @@ -177,24 +177,24 @@ public async Task Can_Elicit_Typed_Information() Action = "accept", Content = new Dictionary { - [nameof(SampleForm.Name)] = (JsonElement)JsonSerializer.Deserialize(""" + [nameof(SampleForm.Name)] = JsonElement.Parse(""" "Alice" - """, McpJsonUtilities.DefaultOptions.GetTypeInfo(typeof(JsonElement)))!, - [nameof(SampleForm.Age)] = (JsonElement)JsonSerializer.Deserialize(""" + """), + [nameof(SampleForm.Age)] = JsonElement.Parse(""" 30 - """, McpJsonUtilities.DefaultOptions.GetTypeInfo(typeof(JsonElement)))!, - [nameof(SampleForm.Active)] = (JsonElement)JsonSerializer.Deserialize(""" + """), + [nameof(SampleForm.Active)] = JsonElement.Parse(""" true - """, McpJsonUtilities.DefaultOptions.GetTypeInfo(typeof(JsonElement)))!, - [nameof(SampleForm.Role)] = (JsonElement)JsonSerializer.Deserialize(""" + """), + [nameof(SampleForm.Role)] = JsonElement.Parse(""" "Admin" - """, McpJsonUtilities.DefaultOptions.GetTypeInfo(typeof(JsonElement)))!, - [nameof(SampleForm.Score)] = (JsonElement)JsonSerializer.Deserialize(""" + """), + [nameof(SampleForm.Score)] = JsonElement.Parse(""" 99.5 - """, McpJsonUtilities.DefaultOptions.GetTypeInfo(typeof(JsonElement)))!, - [nameof(SampleForm.Created)] = (JsonElement)JsonSerializer.Deserialize(""" + """), + [nameof(SampleForm.Created)] = JsonElement.Parse(""" "2023-08-27T03:05:00" - """, McpJsonUtilities.DefaultOptions.GetTypeInfo(typeof(JsonElement)))!, + """), }, }; }, @@ -228,15 +228,15 @@ public async Task Elicit_Typed_Respects_NamingPolicy() Action = "accept", Content = new Dictionary { - ["firstName"] = (JsonElement)JsonSerializer.Deserialize(""" + ["firstName"] = JsonElement.Parse(""" "Bob" - """, McpJsonUtilities.DefaultOptions.GetTypeInfo(typeof(JsonElement)))!, - ["zipCode"] = (JsonElement)JsonSerializer.Deserialize(""" + """), + ["zipCode"] = JsonElement.Parse(""" 90210 - """, McpJsonUtilities.DefaultOptions.GetTypeInfo(typeof(JsonElement)))!, - ["isAdmin"] = (JsonElement)JsonSerializer.Deserialize(""" + """), + ["isAdmin"] = JsonElement.Parse(""" false - """, McpJsonUtilities.DefaultOptions.GetTypeInfo(typeof(JsonElement)))!, + """), }, }; },