Skip to content

Commit 87ef94e

Browse files
committed
Address PR comments
1 parent c6b7964 commit 87ef94e

3 files changed

Lines changed: 100 additions & 138 deletions

File tree

conformance-tests/server-servlet/src/main/java/io/modelcontextprotocol/conformance/server/ConformanceServlet.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -456,9 +456,9 @@ private static List<McpServerFeatures.SyncToolSpecification> createToolSpecs() {
456456
.build();
457457
// 2. Titled single-select using oneOf with const/title
458458
var titledSingle = TitledSingleSelectEnumSchema.builder()
459-
.oneOf(EnumSchemaOption.builder("value1", "First Option").build(),
460-
EnumSchemaOption.builder("value2", "Second Option").build(),
461-
EnumSchemaOption.builder("value3", "Third Option").build())
459+
.oneOf(new EnumSchemaOption("value1", "First Option"),
460+
new EnumSchemaOption("value2", "Second Option"),
461+
new EnumSchemaOption("value3", "Third Option"))
462462
.build();
463463
// 3. Legacy titled using enumNames (deprecated)
464464
var legacyEnum = LegacyTitledEnumSchema.builder()
@@ -472,9 +472,9 @@ private static List<McpServerFeatures.SyncToolSpecification> createToolSpecs() {
472472
// 5. Titled multi-select using items.anyOf with const/title
473473
var titledMulti = TitledMultiSelectEnumSchema
474474
.builder(TitledMultiSelectItems.builder()
475-
.anyOf(EnumSchemaOption.builder("value1", "First Choice").build(),
476-
EnumSchemaOption.builder("value2", "Second Choice").build(),
477-
EnumSchemaOption.builder("value3", "Third Choice").build())
475+
.anyOf(new EnumSchemaOption("value1", "First Choice"),
476+
new EnumSchemaOption("value2", "Second Choice"),
477+
new EnumSchemaOption("value3", "Third Choice"))
478478
.build())
479479
.build();
480480

mcp-core/src/main/java/io/modelcontextprotocol/spec/McpSchema.java

Lines changed: 53 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -3903,28 +3903,30 @@ public record EnumSchemaOption( // @formatter:off
39033903
@JsonProperty("const") String constValue,
39043904
@JsonProperty("title") String title) { // @formatter:on
39053905

3906-
public static Builder builder(String constValue, String title) {
3907-
return new Builder(constValue, title);
3906+
public EnumSchemaOption {
3907+
Assert.notNull(constValue, "constValue must not be null");
3908+
Assert.notNull(title, "title must not be null");
39083909
}
39093910

3910-
public static class Builder {
3911-
3912-
private final String constValue;
3913-
3914-
private final String title;
3915-
3916-
private Builder(String constValue, String title) {
3917-
Assert.notNull(constValue, "constValue must not be null");
3918-
Assert.notNull(title, "title must not be null");
3919-
this.constValue = constValue;
3920-
this.title = title;
3921-
}
3922-
3923-
public EnumSchemaOption build() {
3924-
return new EnumSchemaOption(constValue, title);
3911+
@JsonCreator
3912+
static EnumSchemaOption fromJson(@JsonProperty("const") String constValue,
3913+
@JsonProperty("title") String title) {
3914+
if (constValue == null || title == null) {
3915+
List<String> missing = new ArrayList<>();
3916+
if (constValue == null) {
3917+
missing.add("constValue -> ''");
3918+
constValue = "";
3919+
}
3920+
if (title == null) {
3921+
missing.add("title -> ''");
3922+
title = "";
3923+
}
3924+
logger.warn("EnumSchemaOption: missing required fields during deserialization: {}",
3925+
String.join(", ", missing));
39253926
}
3926-
3927+
return new EnumSchemaOption(constValue, title);
39273928
}
3929+
39283930
}
39293931

39303932
/**
@@ -3950,7 +3952,7 @@ public record LegacyTitledEnumSchema( // @formatter:off
39503952
@JsonProperty("default") String defaultValue) { // @formatter:on
39513953

39523954
public LegacyTitledEnumSchema {
3953-
Assert.notNull(enumValues, "enum must not be null");
3955+
Assert.notNull(enumValues, "enumValues must not be null");
39543956
}
39553957

39563958
@JsonProperty("type")
@@ -3988,40 +3990,26 @@ public Builder description(String description) {
39883990
}
39893991

39903992
public Builder enumValues(List<String> enumValues) {
3991-
Assert.notNull(enumValues, "enum must not be null");
3993+
Assert.notNull(enumValues, "enumValues must not be null");
39923994
this.enumValues = new ArrayList<>(enumValues);
39933995
return this;
39943996
}
39953997

39963998
public Builder enumValues(String... enumValues) {
3997-
Assert.notNull(enumValues, "enum must not be null");
3998-
this.enumValues = new ArrayList<>(Arrays.asList(enumValues));
3999-
return this;
4000-
}
4001-
4002-
public Builder enumValue(String enumValue) {
4003-
if (this.enumValues == null) {
4004-
this.enumValues = new ArrayList<>();
4005-
}
4006-
this.enumValues.add(enumValue);
3999+
Assert.notNull(enumValues, "enumValues must not be null");
4000+
this.enumValues = Arrays.asList(enumValues);
40074001
return this;
40084002
}
40094003

40104004
public Builder enumNames(List<String> enumNames) {
4011-
this.enumNames = enumNames == null ? null : new ArrayList<>(enumNames);
4005+
Assert.notNull(enumNames, "enumNames must not be null");
4006+
this.enumNames = new ArrayList<>(enumNames);
40124007
return this;
40134008
}
40144009

40154010
public Builder enumNames(String... enumNames) {
4016-
this.enumNames = enumNames == null ? null : new ArrayList<>(Arrays.asList(enumNames));
4017-
return this;
4018-
}
4019-
4020-
public Builder enumName(String enumName) {
4021-
if (this.enumNames == null) {
4022-
this.enumNames = new ArrayList<>();
4023-
}
4024-
this.enumNames.add(enumName);
4011+
Assert.notNull(enumNames, "enumNames must not be null");
4012+
this.enumNames = Arrays.asList(enumNames);
40254013
return this;
40264014
}
40274015

@@ -4031,7 +4019,7 @@ public Builder defaultValue(String defaultValue) {
40314019
}
40324020

40334021
public LegacyTitledEnumSchema build() {
4034-
Assert.notEmpty(enumValues, "enum must not be empty");
4022+
Assert.notEmpty(enumValues, "enumValues must not be empty");
40354023
return new LegacyTitledEnumSchema(title, description, enumValues, enumNames, defaultValue);
40364024
}
40374025

@@ -4055,7 +4043,7 @@ public record UntitledSingleSelectEnumSchema( // @formatter:off
40554043
@JsonProperty("default") String defaultValue) { // @formatter:on
40564044

40574045
public UntitledSingleSelectEnumSchema {
4058-
Assert.notNull(enumValues, "enum must not be null");
4046+
Assert.notNull(enumValues, "enumValues must not be null");
40594047
}
40604048

40614049
@JsonProperty("type")
@@ -4091,22 +4079,14 @@ public Builder description(String description) {
40914079
}
40924080

40934081
public Builder enumValues(List<String> enumValues) {
4094-
Assert.notNull(enumValues, "enum must not be null");
4082+
Assert.notNull(enumValues, "enumValues must not be null");
40954083
this.enumValues = new ArrayList<>(enumValues);
40964084
return this;
40974085
}
40984086

40994087
public Builder enumValues(String... enumValues) {
4100-
Assert.notNull(enumValues, "enum must not be null");
4101-
this.enumValues = new ArrayList<>(Arrays.asList(enumValues));
4102-
return this;
4103-
}
4104-
4105-
public Builder enumValue(String enumValue) {
4106-
if (this.enumValues == null) {
4107-
this.enumValues = new ArrayList<>();
4108-
}
4109-
this.enumValues.add(enumValue);
4088+
Assert.notNull(enumValues, "enumValues must not be null");
4089+
this.enumValues = Arrays.asList(enumValues);
41104090
return this;
41114091
}
41124092

@@ -4116,7 +4096,7 @@ public Builder defaultValue(String defaultValue) {
41164096
}
41174097

41184098
public UntitledSingleSelectEnumSchema build() {
4119-
Assert.notEmpty(enumValues, "enum must not be empty");
4099+
Assert.notEmpty(enumValues, "enumValues must not be empty");
41204100
return new UntitledSingleSelectEnumSchema(title, description, enumValues, defaultValue);
41214101
}
41224102

@@ -4184,15 +4164,7 @@ public Builder oneOf(List<EnumSchemaOption> oneOf) {
41844164

41854165
public Builder oneOf(EnumSchemaOption... oneOf) {
41864166
Assert.notNull(oneOf, "oneOf must not be null");
4187-
this.oneOf = new ArrayList<>(Arrays.asList(oneOf));
4188-
return this;
4189-
}
4190-
4191-
public Builder addOneOf(EnumSchemaOption option) {
4192-
if (this.oneOf == null) {
4193-
this.oneOf = new ArrayList<>();
4194-
}
4195-
this.oneOf.add(option);
4167+
this.oneOf = Arrays.asList(oneOf);
41964168
return this;
41974169
}
41984170

@@ -4221,7 +4193,7 @@ public record UntitledMultiSelectItems( // @formatter:off
42214193
@JsonProperty("enum") List<String> enumValues) { // @formatter:on
42224194

42234195
public UntitledMultiSelectItems {
4224-
Assert.notNull(enumValues, "enum must not be null");
4196+
Assert.notNull(enumValues, "enumValues must not be null");
42254197
}
42264198

42274199
@JsonProperty("type")
@@ -4241,27 +4213,19 @@ private Builder() {
42414213
}
42424214

42434215
public Builder enumValues(List<String> enumValues) {
4244-
Assert.notNull(enumValues, "enum must not be null");
4216+
Assert.notNull(enumValues, "enumValues must not be null");
42454217
this.enumValues = new ArrayList<>(enumValues);
42464218
return this;
42474219
}
42484220

42494221
public Builder enumValues(String... enumValues) {
4250-
Assert.notNull(enumValues, "enum must not be null");
4251-
this.enumValues = new ArrayList<>(Arrays.asList(enumValues));
4252-
return this;
4253-
}
4254-
4255-
public Builder enumValue(String enumValue) {
4256-
if (this.enumValues == null) {
4257-
this.enumValues = new ArrayList<>();
4258-
}
4259-
this.enumValues.add(enumValue);
4222+
Assert.notNull(enumValues, "enumValues must not be null");
4223+
this.enumValues = Arrays.asList(enumValues);
42604224
return this;
42614225
}
42624226

42634227
public UntitledMultiSelectItems build() {
4264-
Assert.notEmpty(enumValues, "enum must not be empty");
4228+
Assert.notEmpty(enumValues, "enumValues must not be empty");
42654229
return new UntitledMultiSelectItems(enumValues);
42664230
}
42674231

@@ -4346,16 +4310,15 @@ public Builder maxItems(Integer maxItems) {
43464310
return this;
43474311
}
43484312

4349-
public Builder defaultValue(List<String> defaultValue) {
4350-
this.defaultValue = defaultValue == null ? null : new ArrayList<>(defaultValue);
4313+
public Builder defaults(String... defaultValue) {
4314+
Assert.notNull(defaultValue, "defaultValue must not be null");
4315+
this.defaultValue = Arrays.asList(defaultValue);
43514316
return this;
43524317
}
43534318

4354-
public Builder addDefaultValue(String defaultValue) {
4355-
if (this.defaultValue == null) {
4356-
this.defaultValue = new ArrayList<>();
4357-
}
4358-
this.defaultValue.add(defaultValue);
4319+
public Builder defaults(List<String> defaultValue) {
4320+
Assert.notNull(defaultValue, "defaultValue must not be null");
4321+
this.defaultValue = new ArrayList<>(defaultValue);
43594322
return this;
43604323
}
43614324

@@ -4401,15 +4364,7 @@ public Builder anyOf(List<EnumSchemaOption> anyOf) {
44014364

44024365
public Builder anyOf(EnumSchemaOption... anyOf) {
44034366
Assert.notNull(anyOf, "anyOf must not be null");
4404-
this.anyOf = new ArrayList<>(Arrays.asList(anyOf));
4405-
return this;
4406-
}
4407-
4408-
public Builder addAnyOf(EnumSchemaOption option) {
4409-
if (this.anyOf == null) {
4410-
this.anyOf = new ArrayList<>();
4411-
}
4412-
this.anyOf.add(option);
4367+
this.anyOf = Arrays.asList(anyOf);
44134368
return this;
44144369
}
44154370

@@ -4499,16 +4454,15 @@ public Builder maxItems(Integer maxItems) {
44994454
return this;
45004455
}
45014456

4502-
public Builder defaultValue(List<String> defaultValue) {
4503-
this.defaultValue = defaultValue == null ? null : new ArrayList<>(defaultValue);
4457+
public Builder defaults(List<String> defaultValue) {
4458+
Assert.notNull(defaultValue, "defaultValue must not be null");
4459+
this.defaultValue = new ArrayList<>(defaultValue);
45044460
return this;
45054461
}
45064462

4507-
public Builder addDefaultValue(String defaultValue) {
4508-
if (this.defaultValue == null) {
4509-
this.defaultValue = new ArrayList<>();
4510-
}
4511-
this.defaultValue.add(defaultValue);
4463+
public Builder defaults(String... defaultValue) {
4464+
Assert.notNull(defaultValue, "defaultValue must not be null");
4465+
this.defaultValue = Arrays.asList(defaultValue);
45124466
return this;
45134467
}
45144468

0 commit comments

Comments
 (0)