Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docs/concepts/elicitation/samples/client/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,16 @@ async ValueTask<ElicitResult> HandleElicitationAsync(ElicitRequestParams? reques
// Try standard boolean parsing first
if (bool.TryParse(clientInput, out parsedBool))
{
content[property.Key] = JsonSerializer.Deserialize<JsonElement>(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<JsonElement>(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<JsonElement>(JsonSerializer.Serialize(false));
content[property.Key] = JsonElement.Parse(JsonSerializer.Serialize(false));
}
}
else if (property.Value is ElicitRequestParams.NumberSchema numberSchema)
Expand All @@ -97,14 +97,14 @@ async ValueTask<ElicitResult> HandleElicitationAsync(ElicitRequestParams? reques
double parsedNumber;
if (double.TryParse(clientInput, out parsedNumber))
{
content[property.Key] = JsonSerializer.Deserialize<JsonElement>(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<JsonElement>(JsonSerializer.Serialize(clientInput));
content[property.Key] = JsonElement.Parse(JsonSerializer.Serialize(clientInput));
}
}

Expand Down
10 changes: 5 additions & 5 deletions tests/ModelContextProtocol.TestServer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ await server.SendMessageAsync(new JsonRpcNotification
Params = JsonSerializer.SerializeToNode(new LoggingMessageNotificationParams
{
Level = logLevel,
Data = JsonSerializer.Deserialize<JsonElement>("\"Random log message\"")
Data = JsonElement.Parse("\"Random log message\"")
})
}, cancellationToken);
}
Expand Down Expand Up @@ -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<JsonElement>("""
InputSchema = JsonElement.Parse("""
{
"type": "object",
"properties": {
Expand All @@ -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<JsonElement>("""
InputSchema = JsonElement.Parse("""
{
"type": "object"
}
""", McpJsonUtilities.DefaultOptions),
"""),
},
new Tool
{
Name = "sampleLLM",
Description = "Samples from an LLM using MCP's sampling feature.",
InputSchema = JsonSerializer.Deserialize<JsonElement>("""
InputSchema = JsonElement.Parse("""
{
"type": "object",
"properties": {
Expand Down
12 changes: 6 additions & 6 deletions tests/ModelContextProtocol.TestSseServer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ static CreateMessageRequestParams CreateRequestSamplingParams(string context, st
{
Name = "echo",
Description = "Echoes the input back to the client.",
InputSchema = JsonSerializer.Deserialize<JsonElement>("""
InputSchema = JsonElement.Parse("""
{
"type": "object",
"properties": {
Expand All @@ -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<JsonElement>("""
InputSchema = JsonElement.Parse("""
{
"type": "object"
}
""", McpJsonUtilities.DefaultOptions),
"""),
},
new Tool
{
Name = "sampleLLM",
Description = "Samples from an LLM using MCP's sampling feature.",
InputSchema = JsonSerializer.Deserialize<JsonElement>("""
InputSchema = JsonElement.Parse("""
{
"type": "object",
"properties": {
Expand All @@ -149,7 +149,7 @@ static CreateMessageRequestParams CreateRequestSamplingParams(string context, st
},
"required": ["prompt", "maxTokens"]
}
""", McpJsonUtilities.DefaultOptions),
"""),
}
]
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ protected override void ConfigureServices(ServiceCollection services, IMcpServer
{
Name = "FirstCustomTool",
Description = "First tool returned by custom handler",
InputSchema = JsonSerializer.Deserialize<JsonElement>("""
InputSchema = JsonElement.Parse("""
{
"type": "object",
"properties": {},
"required": []
}
""", McpJsonUtilities.DefaultOptions),
"""),
}],
};

Expand All @@ -61,13 +61,13 @@ protected override void ConfigureServices(ServiceCollection services, IMcpServer
{
Name = "SecondCustomTool",
Description = "Second tool returned by custom handler",
InputSchema = JsonSerializer.Deserialize<JsonElement>("""
InputSchema = JsonElement.Parse("""
{
"type": "object",
"properties": {},
"required": []
}
""", McpJsonUtilities.DefaultOptions),
"""),
}],
};

Expand All @@ -79,13 +79,13 @@ protected override void ConfigureServices(ServiceCollection services, IMcpServer
{
Name = "FinalCustomTool",
Description = "Third tool returned by custom handler",
InputSchema = JsonSerializer.Deserialize<JsonElement>("""
InputSchema = JsonElement.Parse("""
{
"type": "object",
"properties": {},
"required": []
}
""", McpJsonUtilities.DefaultOptions),
"""),
}],
};

Expand Down
16 changes: 8 additions & 8 deletions tests/ModelContextProtocol.Tests/Protocol/ElicitationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,18 @@ public async Task Can_Elicit_Information()
Action = "accept",
Content = new Dictionary<string, JsonElement>
{
["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)))!,
"""),
},
};
}
Expand Down
36 changes: 18 additions & 18 deletions tests/ModelContextProtocol.Tests/Protocol/ElicitationTypedTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,24 +177,24 @@ public async Task Can_Elicit_Typed_Information()
Action = "accept",
Content = new Dictionary<string, JsonElement>
{
[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)))!,
"""),
},
};
},
Expand Down Expand Up @@ -228,15 +228,15 @@ public async Task Elicit_Typed_Respects_NamingPolicy()
Action = "accept",
Content = new Dictionary<string, JsonElement>
{
["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)))!,
"""),
},
};
},
Expand Down
Loading