| 
 | 1 | +using System.Diagnostics.CodeAnalysis;  | 
 | 2 | +using System.Text.Json.Serialization;  | 
 | 3 | + | 
 | 4 | +namespace ModelContextProtocol.Protocol;  | 
 | 5 | + | 
 | 6 | +/// <summary>  | 
 | 7 | +/// Represents a message issued from the server to elicit additional information from the user via the client.  | 
 | 8 | +/// </summary>  | 
 | 9 | +public class ElicitRequestParams  | 
 | 10 | +{  | 
 | 11 | +    /// <summary>  | 
 | 12 | +    /// Gets or sets the message to present to the user.  | 
 | 13 | +    /// </summary>  | 
 | 14 | +    [JsonPropertyName("message")]  | 
 | 15 | +    public string Message { get; set; } = string.Empty;  | 
 | 16 | + | 
 | 17 | +    /// <summary>  | 
 | 18 | +    /// Gets or sets the requested schema.  | 
 | 19 | +    /// </summary>  | 
 | 20 | +    /// <remarks>  | 
 | 21 | +    /// May be one of <see cref="StringSchema"/>, <see cref="NumberSchema"/>, <see cref="BooleanSchema"/>, or <see cref="EnumSchema"/>.  | 
 | 22 | +    /// </remarks>  | 
 | 23 | +    [JsonPropertyName("requestedSchema")]  | 
 | 24 | +    [field: MaybeNull]  | 
 | 25 | +    public RequestSchema RequestedSchema  | 
 | 26 | +    {  | 
 | 27 | +        get => field ??= new RequestSchema();  | 
 | 28 | +        set => field = value;  | 
 | 29 | +    }  | 
 | 30 | + | 
 | 31 | +    /// <summary>Represents a request schema used in an elicitation request.</summary>  | 
 | 32 | +    public class RequestSchema  | 
 | 33 | +    {  | 
 | 34 | +        /// <summary>Gets the type of the schema.</summary>  | 
 | 35 | +        /// <remarks>This is always "object".</remarks>  | 
 | 36 | +        [JsonPropertyName("type")]  | 
 | 37 | +        public string Type => "object";  | 
 | 38 | + | 
 | 39 | +        /// <summary>Gets or sets the properties of the schema.</summary>  | 
 | 40 | +        [JsonPropertyName("properties")]  | 
 | 41 | +        [field: MaybeNull]  | 
 | 42 | +        public IDictionary<string, PrimitiveSchemaDefinition> Properties  | 
 | 43 | +        {  | 
 | 44 | +            get => field ??= new Dictionary<string, PrimitiveSchemaDefinition>();  | 
 | 45 | +            set  | 
 | 46 | +            {  | 
 | 47 | +                Throw.IfNull(value);  | 
 | 48 | +                field = value;  | 
 | 49 | +            }  | 
 | 50 | +        }  | 
 | 51 | + | 
 | 52 | +        /// <summary>Gets or sets the required properties of the schema.</summary>  | 
 | 53 | +        [JsonPropertyName("required")]  | 
 | 54 | +        public IList<string>? Required { get; set; }  | 
 | 55 | +    }  | 
 | 56 | + | 
 | 57 | + | 
 | 58 | +    /// <summary>  | 
 | 59 | +    /// Represents restricted subset of JSON Schema:   | 
 | 60 | +    /// <see cref="StringSchema"/>, <see cref="NumberSchema"/>, <see cref="BooleanSchema"/>, or <see cref="EnumSchema"/>.  | 
 | 61 | +    /// </summary>  | 
 | 62 | +    [JsonDerivedType(typeof(BooleanSchema))]  | 
 | 63 | +    [JsonDerivedType(typeof(EnumSchema))]  | 
 | 64 | +    [JsonDerivedType(typeof(NumberSchema))]  | 
 | 65 | +    [JsonDerivedType(typeof(StringSchema))]  | 
 | 66 | +    public abstract class PrimitiveSchemaDefinition  | 
 | 67 | +    {  | 
 | 68 | +        protected private PrimitiveSchemaDefinition()  | 
 | 69 | +        {  | 
 | 70 | +        }  | 
 | 71 | +    }  | 
 | 72 | + | 
 | 73 | +    /// <summary>Represents a schema for a string type.</summary>  | 
 | 74 | +    public sealed class StringSchema : PrimitiveSchemaDefinition  | 
 | 75 | +    {  | 
 | 76 | +        /// <summary>Gets the type of the schema.</summary>  | 
 | 77 | +        /// <remarks>This is always "string".</remarks>  | 
 | 78 | +        [JsonPropertyName("type")]  | 
 | 79 | +        public string Type => "string";  | 
 | 80 | + | 
 | 81 | +        /// <summary>Gets or sets a title for the string.</summary>  | 
 | 82 | +        [JsonPropertyName("title")]  | 
 | 83 | +        public string? Title { get; set; }  | 
 | 84 | + | 
 | 85 | +        /// <summary>Gets or sets a description for the string.</summary>  | 
 | 86 | +        [JsonPropertyName("description")]  | 
 | 87 | +        public string? Description { get; set; }  | 
 | 88 | + | 
 | 89 | +        /// <summary>Gets or sets the minimum length for the string.</summary>  | 
 | 90 | +        [JsonPropertyName("minLength")]  | 
 | 91 | +        public int? MinLength  | 
 | 92 | +        {  | 
 | 93 | +            get => field;  | 
 | 94 | +            set  | 
 | 95 | +            {  | 
 | 96 | +                if (value < 0)  | 
 | 97 | +                {  | 
 | 98 | +                    throw new ArgumentOutOfRangeException(nameof(value), "Minimum length cannot be negative.");  | 
 | 99 | +                }  | 
 | 100 | + | 
 | 101 | +                field = value;  | 
 | 102 | +            }  | 
 | 103 | +        }  | 
 | 104 | + | 
 | 105 | +        /// <summary>Gets or sets the maximum length for the string.</summary>  | 
 | 106 | +        [JsonPropertyName("maxLength")]  | 
 | 107 | +        public int? MaxLength  | 
 | 108 | +        {  | 
 | 109 | +            get => field;  | 
 | 110 | +            set  | 
 | 111 | +            {  | 
 | 112 | +                if (value < 0)  | 
 | 113 | +                {  | 
 | 114 | +                    throw new ArgumentOutOfRangeException(nameof(value), "Maximum length cannot be negative.");  | 
 | 115 | +                }  | 
 | 116 | + | 
 | 117 | +                field = value;  | 
 | 118 | +            }  | 
 | 119 | +        }  | 
 | 120 | + | 
 | 121 | +        /// <summary>Gets or sets a specific format for the string ("email", "uri", "date", or "date-time").</summary>  | 
 | 122 | +        [JsonPropertyName("format")]  | 
 | 123 | +        public string? Format  | 
 | 124 | +        {  | 
 | 125 | +            get => field;  | 
 | 126 | +            set  | 
 | 127 | +            {  | 
 | 128 | +                if (value is not (null or "email" or "uri" or "date" or "date-time"))  | 
 | 129 | +                {  | 
 | 130 | +                    throw new ArgumentException("Format must be 'email', 'uri', 'date', or 'date-time'.", nameof(value));  | 
 | 131 | +                }  | 
 | 132 | + | 
 | 133 | +                field = value;  | 
 | 134 | +            }  | 
 | 135 | +        }  | 
 | 136 | +    }  | 
 | 137 | + | 
 | 138 | +    /// <summary>Represents a schema for a number or integer type.</summary>  | 
 | 139 | +    public sealed class NumberSchema : PrimitiveSchemaDefinition  | 
 | 140 | +    {  | 
 | 141 | +        /// <summary>Gets the type of the schema.</summary>  | 
 | 142 | +        /// <remarks>This should be "number" or "integer".</remarks>  | 
 | 143 | +        [JsonPropertyName("type")]  | 
 | 144 | +        [field: MaybeNull]  | 
 | 145 | +        public string Type  | 
 | 146 | +        {  | 
 | 147 | +            get => field ??= "number";  | 
 | 148 | +            set  | 
 | 149 | +            {  | 
 | 150 | +                if (value is not ("number" or "integer"))  | 
 | 151 | +                {  | 
 | 152 | +                    throw new ArgumentException("Type must be 'number' or 'integer'.", nameof(value));  | 
 | 153 | +                }  | 
 | 154 | + | 
 | 155 | +                field = value;  | 
 | 156 | +            }  | 
 | 157 | +        }  | 
 | 158 | + | 
 | 159 | +        /// <summary>Gets or sets a title for the number input.</summary>  | 
 | 160 | +        [JsonPropertyName("title")]  | 
 | 161 | +        public string? Title { get; set; }  | 
 | 162 | + | 
 | 163 | +        /// <summary>Gets or sets a description for the number input.</summary>  | 
 | 164 | +        [JsonPropertyName("description")]  | 
 | 165 | +        public string? Description { get; set; }  | 
 | 166 | + | 
 | 167 | +        /// <summary>Gets or sets the minimum allowed value.</summary>  | 
 | 168 | +        [JsonPropertyName("minimum")]  | 
 | 169 | +        public double? Minimum { get; set; }  | 
 | 170 | + | 
 | 171 | +        /// <summary>Gets or sets the maximum allowed value.</summary>  | 
 | 172 | +        [JsonPropertyName("maximum")]  | 
 | 173 | +        public double? Maximum { get; set; }  | 
 | 174 | +    }  | 
 | 175 | + | 
 | 176 | +    /// <summary>Represents a schema for a Boolean type.</summary>  | 
 | 177 | +    public sealed class BooleanSchema : PrimitiveSchemaDefinition  | 
 | 178 | +    {  | 
 | 179 | +        /// <summary>Gets the type of the schema.</summary>  | 
 | 180 | +        /// <remarks>This is always "boolean".</remarks>  | 
 | 181 | +        [JsonPropertyName("type")]  | 
 | 182 | +        public string Type => "boolean";  | 
 | 183 | + | 
 | 184 | +        /// <summary>Gets or sets a title for the Boolean.</summary>  | 
 | 185 | +        [JsonPropertyName("title")]  | 
 | 186 | +        public string? Title { get; set; }  | 
 | 187 | + | 
 | 188 | +        /// <summary>Gets or sets a description for the Boolean.</summary>  | 
 | 189 | +        [JsonPropertyName("description")]  | 
 | 190 | +        public string? Description { get; set; }  | 
 | 191 | + | 
 | 192 | +        /// <summary>Gets or sets the default value for the Boolean.</summary>  | 
 | 193 | +        [JsonPropertyName("default")]  | 
 | 194 | +        public bool? Default { get; set; }  | 
 | 195 | +    }  | 
 | 196 | + | 
 | 197 | +    /// <summary>Represents a schema for an enum type.</summary>  | 
 | 198 | +    public sealed class EnumSchema : PrimitiveSchemaDefinition  | 
 | 199 | +    {  | 
 | 200 | +        /// <summary>Gets the type of the schema.</summary>  | 
 | 201 | +        /// <remarks>This is always "string".</remarks>  | 
 | 202 | +        [JsonPropertyName("type")]  | 
 | 203 | +        public string Type => "string";  | 
 | 204 | + | 
 | 205 | +        /// <summary>Gets or sets a title for the enum.</summary>  | 
 | 206 | +        [JsonPropertyName("title")]  | 
 | 207 | +        public string? Title { get; set; }  | 
 | 208 | + | 
 | 209 | +        /// <summary>Gets or sets a description for the enum.</summary>  | 
 | 210 | +        [JsonPropertyName("description")]  | 
 | 211 | +        public string? Description { get; set; }  | 
 | 212 | + | 
 | 213 | +        /// <summary>Gets or sets the list of allowed string values for the enum.</summary>  | 
 | 214 | +        [JsonPropertyName("enum")]  | 
 | 215 | +        [field: MaybeNull]  | 
 | 216 | +        public IList<string> Enum  | 
 | 217 | +        {  | 
 | 218 | +            get => field ??= [];  | 
 | 219 | +            set  | 
 | 220 | +            {  | 
 | 221 | +                Throw.IfNull(value);  | 
 | 222 | +                field = value;  | 
 | 223 | +            }  | 
 | 224 | +        }  | 
 | 225 | + | 
 | 226 | +        /// <summary>Gets or sets optional display names corresponding to the enum values.</summary>  | 
 | 227 | +        [JsonPropertyName("enumNames")]  | 
 | 228 | +        public IList<string>? EnumNames { get; set; }  | 
 | 229 | +    }  | 
 | 230 | +}  | 
0 commit comments