Skip to content
46 changes: 44 additions & 2 deletions src/ModelContextProtocol.Core/Protocol/ElicitRequestParams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ public class Converter : JsonConverter<PrimitiveSchemaDefinition>
double? minimum = null;
double? maximum = null;
bool? defaultBool = null;
double? defaultNumber = null;
string? defaultString = null;
IList<string>? enumValues = null;
IList<string>? enumNames = null;

Expand Down Expand Up @@ -158,7 +160,20 @@ public class Converter : JsonConverter<PrimitiveSchemaDefinition>
break;

case "default":
defaultBool = reader.GetBoolean();
// We need to handle different types for default values
// Store the value based on the JSON token type
if (reader.TokenType == JsonTokenType.True || reader.TokenType == JsonTokenType.False)
{
defaultBool = reader.GetBoolean();
}
else if (reader.TokenType == JsonTokenType.Number)
{
defaultNumber = reader.GetDouble();
}
else if (reader.TokenType == JsonTokenType.String)
{
defaultString = reader.GetString();
}
break;

case "enum":
Expand Down Expand Up @@ -188,7 +203,8 @@ public class Converter : JsonConverter<PrimitiveSchemaDefinition>
psd = new EnumSchema
{
Enum = enumValues,
EnumNames = enumNames
EnumNames = enumNames,
Default = defaultString,
};
}
else
Expand All @@ -198,6 +214,7 @@ public class Converter : JsonConverter<PrimitiveSchemaDefinition>
MinLength = minLength,
MaxLength = maxLength,
Format = format,
Default = defaultString,
};
}
break;
Expand All @@ -208,6 +225,7 @@ public class Converter : JsonConverter<PrimitiveSchemaDefinition>
{
Minimum = minimum,
Maximum = maximum,
Default = defaultNumber,
};
break;

Expand Down Expand Up @@ -265,6 +283,10 @@ public override void Write(Utf8JsonWriter writer, PrimitiveSchemaDefinition valu
{
writer.WriteString("format", stringSchema.Format);
}
if (stringSchema.Default is not null)
{
writer.WriteString("default", stringSchema.Default);
}
break;

case NumberSchema numberSchema:
Expand All @@ -276,6 +298,10 @@ public override void Write(Utf8JsonWriter writer, PrimitiveSchemaDefinition valu
{
writer.WriteNumber("maximum", numberSchema.Maximum.Value);
}
if (numberSchema.Default.HasValue)
{
writer.WriteNumber("default", numberSchema.Default.Value);
}
break;

case BooleanSchema booleanSchema:
Expand All @@ -296,6 +322,10 @@ public override void Write(Utf8JsonWriter writer, PrimitiveSchemaDefinition valu
writer.WritePropertyName("enumNames");
JsonSerializer.Serialize(writer, enumSchema.EnumNames, McpJsonUtilities.JsonContext.Default.IListString);
}
if (enumSchema.Default is not null)
{
writer.WriteString("default", enumSchema.Default);
}
break;

default:
Expand Down Expand Up @@ -371,6 +401,10 @@ public string? Format
field = value;
}
}

/// <summary>Gets or sets the default value for the string.</summary>
[JsonPropertyName("default")]
public string? Default { get; set; }
}

/// <summary>Represents a schema for a number or integer type.</summary>
Expand Down Expand Up @@ -399,6 +433,10 @@ public override string Type
/// <summary>Gets or sets the maximum allowed value.</summary>
[JsonPropertyName("maximum")]
public double? Maximum { get; set; }

/// <summary>Gets or sets the default value for the number.</summary>
[JsonPropertyName("default")]
public double? Default { get; set; }
}

/// <summary>Represents a schema for a Boolean type.</summary>
Expand Down Expand Up @@ -456,5 +494,9 @@ public IList<string> Enum
/// <summary>Gets or sets optional display names corresponding to the enum values.</summary>
[JsonPropertyName("enumNames")]
public IList<string>? EnumNames { get; set; }

/// <summary>Gets or sets the default value for the enum.</summary>
[JsonPropertyName("default")]
public string? Default { get; set; }
}
}
Loading
Loading