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
Original file line numberDiff line numberDiff line change
@@ -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;
Expand DownExpand Up@@ -68,7 +68,7 @@ public sealed class CreateMessageRequestParams : RequestParams
/// </para>
/// </remarks>
[JsonPropertyName("metadata")]
public JsonElement? Metadata { get; set; }
public JsonObject? Metadata { get; set; }
Comment thread
stephentoub marked this conversation as resolved.

/// <summary>
/// Gets or sets the server's preferences for which model to select.
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
using ModelContextProtocol.Protocol;
using System.Text.Json;
using System.Text.Json.Nodes;

namespace ModelContextProtocol.Tests.Protocol;

Expand DownExpand Up@@ -166,6 +167,37 @@ public void WithToolChoiceNone_SerializationRoundtrips()
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"]!);
}
}


Expand Down