using System.Diagnostics.CodeAnalysis;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
namespace ModelContextProtocol.Protocol;
///
/// Provides a base class for all request parameters.
///
///
/// See the schema for details.
///
public abstract class RequestParams
{
/// Prevent external derivations.
private protected RequestParams()
{
}
///
/// Gets or sets metadata reserved by MCP for protocol-level metadata.
///
///
/// Implementations must not make assumptions about its contents.
///
[JsonPropertyName("_meta")]
public JsonObject? Meta { get; set; }
///
/// Gets or sets the responses to server-initiated input requests from a previous .
///
///
///
/// This property is populated when retrying a request after receiving an .
/// Each key corresponds to a key from the map, and
/// the value is the client's response to that input request.
///
///
[Experimental(Experimentals.Mrtr_DiagnosticId, UrlFormat = Experimentals.Mrtr_Url)]
[JsonIgnore]
public IDictionary? InputResponses
{
get => InputResponsesCore;
set => InputResponsesCore = value;
}
// See ExperimentalInternalPropertyTests.cs before modifying this property.
[JsonInclude]
[JsonPropertyName("inputResponses")]
internal IDictionary? InputResponsesCore { get; set; }
///
/// Gets or sets opaque request state echoed back from a previous .
///
///
///
/// This property is populated when retrying a request after receiving an
/// that included a value. The client must echo back the
/// exact value without modification.
///
///
[Experimental(Experimentals.Mrtr_DiagnosticId, UrlFormat = Experimentals.Mrtr_Url)]
[JsonIgnore]
public string? RequestState
{
get => RequestStateCore;
set => RequestStateCore = value;
}
// See ExperimentalInternalPropertyTests.cs before modifying this property.
[JsonInclude]
[JsonPropertyName("requestState")]
internal string? RequestStateCore { get; set; }
///
/// Gets the opaque token that will be attached to any subsequent progress notifications.
///
[JsonIgnore]
public ProgressToken? ProgressToken
{
get
{
if (Meta?["progressToken"] is JsonValue progressToken)
{
if (progressToken.TryGetValue(out string? stringValue))
{
return new ProgressToken(stringValue);
}
if (progressToken.TryGetValue(out long longValue))
{
return new ProgressToken(longValue);
}
}
return null;
}
}
}