Skip to content
Merged
Changes from 1 commit
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
70 changes: 54 additions & 16 deletions src/ModelContextProtocol.Core/RequestOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,35 @@ public JsonObject? Meta
{
get
Comment thread
stephentoub marked this conversation as resolved.
Outdated
{
if (ProgressToken == null)
_meta ??= new JsonObject();
Comment thread
stephentoub marked this conversation as resolved.
Outdated
return _meta;
}
set
{
// Preserve the progress token if set.
var progressToken = _meta?["progressToken"];
if (value is null)
{
return _meta;
if (progressToken is not null)
{
_meta = new JsonObject
{
["progressToken"] = progressToken,
};
}
else
{
_meta = null;
}
}

// Clone existing metadata or create a new one
var meta = _meta?.DeepClone() as JsonObject ?? new JsonObject();

// Add progress token to metadata
meta["progressToken"] = ProgressToken.Value.Token switch
else
{
string s => s,
long l => l,
_ => null
};

return meta;
if (progressToken is not null) {
value["progressToken"] = progressToken;
Comment thread
stephentoub marked this conversation as resolved.
Outdated
}
_meta = value;
}
}
Comment thread
mikekistler marked this conversation as resolved.
set => _meta = value;
}

/// <summary>
Expand All @@ -58,5 +68,33 @@ public JsonObject? Meta
/// <summary>
/// The progress token for tracking long-running operations.
/// </summary>
public ProgressToken? ProgressToken { get; set; }
public ProgressToken? ProgressToken {
get
{
return _meta?["progressToken"] switch
{
JsonValue v when v.TryGetValue(out string? s) => new ProgressToken(s),
JsonValue v when v.TryGetValue(out long l) => new ProgressToken(l),
_ => null
};
}
set
{
if (value?.Token is {} token)
{
_meta ??= new JsonObject();
_meta["progressToken"] = token switch
{
null => _meta.Remove("progressToken"),
Comment thread
stephentoub marked this conversation as resolved.
Outdated
string s => s,
long l => l,
_ => throw new InvalidOperationException("ProgressToken must be a string or long"),
};
}
else
{
_meta?.Remove("progressToken");
}
}
}
Comment thread
mikekistler marked this conversation as resolved.
Comment thread
mikekistler marked this conversation as resolved.
}
Loading