Skip to content

Commit 1a32217

Browse files
committed
Remove reduntant checks. #630
Refactor JSON schema type handling and add integer support This commit simplifies the validation logic for the `type` property in the JSON schema by removing unnecessary conditional checks. It directly retrieves the string value from `typeProperty` and assigns it to `typeKeyword`. Additionally, it enhances the `s_lazyElicitAllowedProperties` dictionary to include support for the `integer` type, allowing it to be recognized as a valid type with its corresponding allowed properties.
1 parent c5419c6 commit 1a32217

1 file changed

Lines changed: 3 additions & 14 deletions

File tree

src/ModelContextProtocol.Core/Server/McpServerExtensions.cs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -386,22 +386,13 @@ private static bool TryValidateElicitationPrimitiveSchema(JsonElement schema, Ty
386386
}
387387

388388
if (!schema.TryGetProperty("type", out JsonElement typeProperty)
389-
|| !(typeProperty.ValueKind is JsonValueKind.String or JsonValueKind.Array))
389+
|| typeProperty.ValueKind is not JsonValueKind.String)
390390
{
391391
error = $"Schema generated for type '{type.FullName}' is invalid: missing or invalid 'type' keyword.";
392392
return false;
393393
}
394394

395-
string? typeKeyword;
396-
if (typeProperty.ValueKind == JsonValueKind.String)
397-
{
398-
typeKeyword = typeProperty.GetString();
399-
}
400-
else
401-
{
402-
error = $"Schema generated for type '{type.FullName}' is invalid: unsupported 'type' array.";
403-
return false;
404-
}
395+
var typeKeyword = typeProperty.GetString();
405396

406397
if (string.IsNullOrEmpty(typeKeyword))
407398
{
@@ -415,13 +406,11 @@ private static bool TryValidateElicitationPrimitiveSchema(JsonElement schema, Ty
415406
return false;
416407
}
417408

418-
if (typeKeyword == "integer")
419-
typeKeyword = "number";
420-
421409
s_lazyElicitAllowedProperties ??= new()
422410
{
423411
["string"] = ["type", "title", "description", "minLength", "maxLength", "format", "enum", "enumNames"],
424412
["number"] = ["type", "title", "description", "minimum", "maximum"],
413+
["integer"] = ["type", "title", "description", "minimum", "maximum"],
425414
["boolean"] = ["type", "title", "description", "default"]
426415
};
427416

0 commit comments

Comments
 (0)