using System.Text.Json; using System.Text.Json.Nodes; using ModelContextProtocol.Protocol; namespace ModelContextProtocol; /// /// Provides a bag of optional parameters for use with MCP requests. /// public sealed class RequestOptions { /// /// Initializes a new instance of the class. /// public RequestOptions() { } /// Creates a shallow clone of this options instance. /// A shallow clone of this options instance. internal RequestOptions Clone() => new() { JsonSerializerOptions = JsonSerializerOptions, Meta = Meta, ProgressToken = ProgressToken, }; /// /// Gets or sets optional metadata to include as the "_meta" property in a request. /// /// /// Although progress tokens are propagated in MCP "_meta" objects, the /// property and the property do not interact (setting /// does not affect , and the object returned from /// is not impacted by the value of ). To get the actual /// that contains state from both and , use the /// method. /// public JsonObject? Meta { get; set; } /// /// Gets or sets an optional progress token to use for tracking long-running operations. /// /// /// Although progress tokens are propagated in MCP "_meta" objects, the /// property and the property do not interact (setting /// does not affect , and getting does not read from /// ). To get the actual that contains state from both /// and , use the method. /// public ProgressToken? ProgressToken { get; set; } /// /// Gets or sets a to use for any serialization of arguments or results in the request. /// /// /// If , is used. /// public JsonSerializerOptions? JsonSerializerOptions { get; set; } /// /// Gets a to use in requests for the "_meta" property. /// /// /// A suitable for use in requests for the "_meta" property. /// /// /// Progress tokens are part of MCP's _meta property. As such, if /// is non- but is , will /// manufacture and return a new instance containing the token. If both /// and are non-, a new clone of will be created and its /// "progressToken" property overwritten with . Otherwise, /// will just return . /// public JsonObject? GetMetaForRequest() { JsonObject? meta = Meta; if (ProgressToken is not null) { meta = (JsonObject?)meta?.DeepClone() ?? []; meta["progressToken"] = ProgressToken.ToString(); } return meta; } }