Skip to content

Commit 39cdec7

Browse files
Yugi-2claude
andcommitted
refactor: drop per-entry extension() builder helper
Keep only the whole-map extensions(Map) setter on both capability builders, matching the existing experimental(Map) convention. The per-entry extension(id, settings) helper was a novel API for a single field, duplicated verbatim across both builders, with copy-on-write merge semantics no sibling setter has. Callers pass Map.of(id, Map.of()) for "supported, no settings". Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 77d6921 commit 39cdec7

2 files changed

Lines changed: 8 additions & 42 deletions

File tree

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

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -781,22 +781,6 @@ public Builder extensions(Map<String, Object> extensions) {
781781
return this;
782782
}
783783

784-
/**
785-
* Adds support for a single extension; {@code null} settings are sent as an
786-
* empty JSON object.
787-
* @param id the extension identifier
788-
* @param settings the per-extension settings, or {@code null}
789-
* @return this builder
790-
*/
791-
public Builder extension(String id, Map<String, Object> settings) {
792-
Assert.hasText(id, "id must not be null or empty");
793-
Map<String, Object> merged = (this.extensions != null) ? new HashMap<>(this.extensions)
794-
: new HashMap<>();
795-
merged.put(id, settings != null ? settings : Map.of());
796-
this.extensions = merged;
797-
return this;
798-
}
799-
800784
public ClientCapabilities build() {
801785
return new ClientCapabilities(experimental, roots, sampling, elicitation, extensions);
802786
}
@@ -1024,22 +1008,6 @@ public Builder extensions(Map<String, Object> extensions) {
10241008
return this;
10251009
}
10261010

1027-
/**
1028-
* Adds support for a single extension; {@code null} settings are sent as an
1029-
* empty JSON object.
1030-
* @param id the extension identifier
1031-
* @param settings the per-extension settings, or {@code null}
1032-
* @return this builder
1033-
*/
1034-
public Builder extension(String id, Map<String, Object> settings) {
1035-
Assert.hasText(id, "id must not be null or empty");
1036-
Map<String, Object> merged = (this.extensions != null) ? new HashMap<>(this.extensions)
1037-
: new HashMap<>();
1038-
merged.put(id, settings != null ? settings : Map.of());
1039-
this.extensions = merged;
1040-
return this;
1041-
}
1042-
10431011
public ServerCapabilities build() {
10441012
return new ServerCapabilities(completions, experimental, logging, prompts, resources, tools,
10451013
extensions);

mcp-test/src/test/java/io/modelcontextprotocol/spec/SchemaEvolutionTests.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -161,16 +161,15 @@ void serverCapabilitiesWithNullExtensionsOmitsFieldOnWire() throws IOException {
161161

162162
@Test
163163
void serverCapabilitiesExtensionsRoundTrip() throws IOException {
164-
McpSchema.ServerCapabilities caps = McpSchema.ServerCapabilities.builder()
165-
.extension("com.example/ext-with-settings", Map.of("maxDepth", 3))
166-
.extension("com.example/ext-without-settings", null)
167-
.build();
164+
Map<String, Object> extensions = Map.of("com.example/ext-with-settings", Map.of("maxDepth", 3),
165+
"com.example/ext-without-settings", Map.of());
166+
McpSchema.ServerCapabilities caps = McpSchema.ServerCapabilities.builder().extensions(extensions).build();
168167

169168
String json = mapper.writeValueAsString(caps);
170169
assertThat(json).contains("\"com.example/ext-without-settings\":{}");
171170

172171
McpSchema.ServerCapabilities parsed = mapper.readValue(json, McpSchema.ServerCapabilities.class);
173-
assertThat(parsed.extensions()).isEqualTo(caps.extensions());
172+
assertThat(parsed.extensions()).isEqualTo(extensions);
174173
}
175174

176175
// -----------------------------------------------------------------------
@@ -203,16 +202,15 @@ void clientCapabilitiesWithExtensionsUnknownFieldsIgnored() throws IOException {
203202

204203
@Test
205204
void clientCapabilitiesExtensionsRoundTrip() throws IOException {
206-
McpSchema.ClientCapabilities caps = McpSchema.ClientCapabilities.builder()
207-
.extension("com.example/ext-with-settings", Map.of("maxDepth", 3))
208-
.extension("com.example/ext-without-settings", null)
209-
.build();
205+
Map<String, Object> extensions = Map.of("com.example/ext-with-settings", Map.of("maxDepth", 3),
206+
"com.example/ext-without-settings", Map.of());
207+
McpSchema.ClientCapabilities caps = McpSchema.ClientCapabilities.builder().extensions(extensions).build();
210208

211209
String json = mapper.writeValueAsString(caps);
212210
assertThat(json).contains("\"com.example/ext-without-settings\":{}");
213211

214212
McpSchema.ClientCapabilities parsed = mapper.readValue(json, McpSchema.ClientCapabilities.class);
215-
assertThat(parsed.extensions()).isEqualTo(caps.extensions());
213+
assertThat(parsed.extensions()).isEqualTo(extensions);
216214
}
217215

218216
// -----------------------------------------------------------------------

0 commit comments

Comments
 (0)