forked from modelcontextprotocol/csharp-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateMessageResultDto.cs
More file actions
87 lines (74 loc) · 2.99 KB
/
CreateMessageResultDto.cs
File metadata and controls
87 lines (74 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
namespace ModelContextProtocol.Protocol;
internal sealed class CreateMessageResultDto_V2 // V1, V2, V3, etc. as a placeholder naming convention.
// Could also be the protocol version introducing the breaking change
{
[JsonPropertyName("content")]
public required List<ContentBlock> Content { get; init; }
[JsonPropertyName("model")]
public required string Model { get; init; }
[JsonPropertyName("stopReason")]
public string? StopReason { get; init; }
[JsonPropertyName("role")]
public required Role Role { get; init; }
[JsonPropertyName("_meta")]
public JsonObject? Meta { get; init; }
/// <summary>
/// The serializer for <see cref="CreateMessageResult"/> using this DTO.
/// </summary>
public static IMcpModelSerializer<CreateMessageResult> ModelSerializer { get; } =
McpModelSerializer.CreateDtoSerializer<CreateMessageResult, CreateMessageResultDto_V2>(
toDto: static model => new ()
{
Content = model.Contents,
Model = model.Model,
StopReason = model.StopReason,
Role = model.Role,
Meta = model.Meta
},
fromDto: static dto => new()
{
Contents = dto.Content,
Model = dto.Model,
StopReason = dto.StopReason,
Role = dto.Role,
Meta = dto.Meta
},
McpJsonUtilities.JsonContext.Default.CreateMessageResultDto_V2);
}
internal sealed class CreateMessageResultDto_V1 // V1, V2, V3, etc. as a placeholder naming convention.
{
[JsonPropertyName("content")]
public required ContentBlock Content { get; init; }
[JsonPropertyName("model")]
public required string Model { get; init; }
[JsonPropertyName("stopReason")]
public string? StopReason { get; init; }
[JsonPropertyName("role")]
public required Role Role { get; init; }
[JsonPropertyName("_meta")]
public JsonObject? Meta { get; init; }
/// <summary>
/// The serializer for <see cref="CreateMessageResult"/> using this DTO.
/// </summary>
public static IMcpModelSerializer<CreateMessageResult> ModelSerializer { get; } =
McpModelSerializer.CreateDtoSerializer<CreateMessageResult, CreateMessageResultDto_V1>(
toDto: static model => new()
{
Content = model.Content,
Model = model.Model,
StopReason = model.StopReason,
Role = model.Role,
Meta = model.Meta
},
fromDto: static dto => new()
{
Contents = [dto.Content],
Model = dto.Model,
StopReason = dto.StopReason,
Role = dto.Role,
Meta = dto.Meta
},
McpJsonUtilities.JsonContext.Default.CreateMessageResultDto_V1);
}