Fix CreateMessageRequestParams.Metadata type to JsonObject (#1354)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com> Co-authored-by: Stephen Toub <stoub@microsoft.com>
This commit is contained in:
parent
0a0a575a3d
commit
ce2a5e4a4b
2 changed files with 34 additions and 2 deletions
|
|
@ -1,5 +1,5 @@
|
|||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace ModelContextProtocol.Protocol;
|
||||
|
|
@ -68,7 +68,7 @@ public sealed class CreateMessageRequestParams : RequestParams
|
|||
/// </para>
|
||||
/// </remarks>
|
||||
[JsonPropertyName("metadata")]
|
||||
public JsonElement? Metadata { get; set; }
|
||||
public JsonObject? Metadata { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the server's preferences for which model to select.
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using ModelContextProtocol.Protocol;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
|
||||
namespace ModelContextProtocol.Tests.Protocol;
|
||||
|
||||
|
|
@ -166,6 +167,37 @@ public class CreateMessageRequestParamsTests
|
|||
Assert.NotNull(deserialized.ToolChoice);
|
||||
Assert.Equal("none", deserialized.ToolChoice.Mode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WithMetadata_SerializationRoundtrips()
|
||||
{
|
||||
CreateMessageRequestParams requestParams = new()
|
||||
{
|
||||
MaxTokens = 500,
|
||||
Messages =
|
||||
[
|
||||
new SamplingMessage
|
||||
{
|
||||
Role = Role.User,
|
||||
Content = [new TextContentBlock { Text = "Hello" }]
|
||||
}
|
||||
],
|
||||
Metadata = new JsonObject
|
||||
{
|
||||
["provider"] = "test-provider",
|
||||
["custom_setting"] = 42
|
||||
}
|
||||
};
|
||||
|
||||
var json = JsonSerializer.Serialize(requestParams, McpJsonUtilities.DefaultOptions);
|
||||
var deserialized = JsonSerializer.Deserialize<CreateMessageRequestParams>(json, McpJsonUtilities.DefaultOptions);
|
||||
|
||||
Assert.NotNull(deserialized);
|
||||
Assert.Equal(500, deserialized.MaxTokens);
|
||||
Assert.NotNull(deserialized.Metadata);
|
||||
Assert.Equal("test-provider", (string?)deserialized.Metadata["provider"]);
|
||||
Assert.Equal(42, (int)deserialized.Metadata["custom_setting"]!);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue