Skip to content

Commit 5cf093f

Browse files
committed
Address my feedback
1 parent 50fe47a commit 5cf093f

File tree

1 file changed

+21
-26
lines changed

1 file changed

+21
-26
lines changed

src/ModelContextProtocol.Core/RequestOptions.cs

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,37 +27,31 @@ public RequestOptions()
2727
/// </summary>
2828
public JsonObject? Meta
2929
{
30-
get
31-
{
32-
_meta ??= new JsonObject();
33-
return _meta;
34-
}
30+
get => _meta ??= [];
3531
set
3632
{
3733
// Capture the existing progressToken value if set.
38-
var progressToken = _meta?["progressToken"];
39-
if (value is null)
34+
var existingProgressToken = _meta?["progressToken"];
35+
36+
if (value is not null)
4037
{
41-
if (progressToken is not null)
38+
if (existingProgressToken is not null)
4239
{
43-
_meta = new JsonObject
44-
{
45-
["progressToken"] = progressToken,
46-
};
40+
value["progressToken"] ??= existingProgressToken;
4741
}
48-
else
42+
43+
_meta = value;
44+
}
45+
else if (existingProgressToken is not null)
46+
{
47+
_meta = new()
4948
{
50-
_meta = null;
51-
}
49+
["progressToken"] = existingProgressToken,
50+
};
5251
}
5352
else
5453
{
55-
if (value["progressToken"] is null && progressToken is not null) {
56-
// Remove existing progressToken so it can be set into the new meta.
57-
_meta?.Remove("progressToken");
58-
value["progressToken"] = progressToken;
59-
}
60-
_meta = value;
54+
_meta = null;
6155
}
6256
}
6357
}
@@ -70,21 +64,22 @@ public JsonObject? Meta
7064
/// <summary>
7165
/// The progress token for tracking long-running operations.
7266
/// </summary>
73-
public ProgressToken? ProgressToken {
67+
public ProgressToken? ProgressToken
68+
{
7469
get
7570
{
7671
return _meta?["progressToken"] switch
7772
{
78-
JsonValue v when v.TryGetValue(out string? s) => new ProgressToken(s),
79-
JsonValue v when v.TryGetValue(out long l) => new ProgressToken(l),
73+
JsonValue v when v.TryGetValue(out string? s) => new(s),
74+
JsonValue v when v.TryGetValue(out long l) => new(l),
8075
_ => null
8176
};
8277
}
8378
set
8479
{
85-
if (value?.Token is {} token)
80+
if (value?.Token is { } token)
8681
{
87-
_meta ??= new JsonObject();
82+
_meta ??= [];
8883
_meta["progressToken"] = token switch
8984
{
9085
string s => s,

0 commit comments

Comments
 (0)