Bring up to 0.1.13 conformance (#1254)
This commit is contained in:
parent
9c1538fd98
commit
27b5eb8031
2 changed files with 1249 additions and 78 deletions
|
|
@ -143,6 +143,22 @@ public sealed class ElicitRequestParams : RequestParams
|
|||
{
|
||||
}
|
||||
|
||||
/// <summary>Gets the default value for this schema as a <see cref="JsonElement"/>, if one is defined.</summary>
|
||||
internal JsonElement? GetDefaultAsJsonElement() => this switch
|
||||
{
|
||||
StringSchema { Default: { } s } => JsonSerializer.SerializeToElement(s, McpJsonUtilities.JsonContext.Default.String),
|
||||
NumberSchema { Default: { } n } => JsonSerializer.SerializeToElement(n, McpJsonUtilities.JsonContext.Default.Double),
|
||||
BooleanSchema { Default: { } b } => JsonSerializer.SerializeToElement(b, McpJsonUtilities.JsonContext.Default.Boolean),
|
||||
UntitledSingleSelectEnumSchema { Default: { } s } => JsonSerializer.SerializeToElement(s, McpJsonUtilities.JsonContext.Default.String),
|
||||
TitledSingleSelectEnumSchema { Default: { } s } => JsonSerializer.SerializeToElement(s, McpJsonUtilities.JsonContext.Default.String),
|
||||
UntitledMultiSelectEnumSchema { Default: { } a } => JsonSerializer.SerializeToElement(a, McpJsonUtilities.JsonContext.Default.IListString),
|
||||
TitledMultiSelectEnumSchema { Default: { } a } => JsonSerializer.SerializeToElement(a, McpJsonUtilities.JsonContext.Default.IListString),
|
||||
#pragma warning disable MCP9001 // LegacyTitledEnumSchema is deprecated but supported for backward compatibility
|
||||
LegacyTitledEnumSchema { Default: { } s } => JsonSerializer.SerializeToElement(s, McpJsonUtilities.JsonContext.Default.String),
|
||||
#pragma warning restore MCP9001
|
||||
_ => null,
|
||||
};
|
||||
|
||||
/// <summary>Gets or sets the type of the schema.</summary>
|
||||
[JsonPropertyName("type")]
|
||||
public abstract string Type { get; set; }
|
||||
|
|
|
|||
|
|
@ -56,6 +56,36 @@ public sealed class ElicitResult : Result
|
|||
/// </remarks>
|
||||
[JsonPropertyName("content")]
|
||||
public IDictionary<string, JsonElement>? Content { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Applies default values from the elicitation request schema to any missing fields in the result content.
|
||||
/// </summary>
|
||||
internal static ElicitResult WithDefaults(ElicitRequestParams? requestParams, ElicitResult result)
|
||||
{
|
||||
if (result.IsAccepted && requestParams?.RequestedSchema?.Properties is { } properties)
|
||||
{
|
||||
Dictionary<string, JsonElement>? newContent = null;
|
||||
|
||||
foreach (KeyValuePair<string, ElicitRequestParams.PrimitiveSchemaDefinition> kvp in properties)
|
||||
{
|
||||
if ((result.Content is null || !result.Content.ContainsKey(kvp.Key)) &&
|
||||
kvp.Value.GetDefaultAsJsonElement() is { } element)
|
||||
{
|
||||
newContent ??= result.Content is not null ?
|
||||
new Dictionary<string, JsonElement>(result.Content) :
|
||||
[];
|
||||
newContent[kvp.Key] = element;
|
||||
}
|
||||
}
|
||||
|
||||
if (newContent is not null)
|
||||
{
|
||||
return new ElicitResult { Action = result.Action, Content = newContent, Meta = result.Meta };
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
Loading…
Reference in a new issue