Skip to content

Commit e60a074

Browse files
authored
Refine McpJsonDefaults method names (#789)
As a follow-up of #779, this commit refines McpJsonDefaults method names by shortening them to not repeat the qualifiers already expressed at type level.
1 parent 8549e36 commit e60a074

File tree

31 files changed

+94
-108
lines changed

31 files changed

+94
-108
lines changed

mcp-core/src/main/java/io/modelcontextprotocol/client/McpClient.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -492,12 +492,9 @@ public McpSyncClient build() {
492492

493493
McpClientFeatures.Async asyncFeatures = McpClientFeatures.Async.fromSync(syncFeatures);
494494

495-
return new McpSyncClient(
496-
new McpAsyncClient(transport, this.requestTimeout, this.initializationTimeout,
497-
jsonSchemaValidator != null ? jsonSchemaValidator
498-
: McpJsonDefaults.getDefaultJsonSchemaValidator(),
499-
asyncFeatures),
500-
this.contextProvider);
495+
return new McpSyncClient(new McpAsyncClient(transport, this.requestTimeout, this.initializationTimeout,
496+
jsonSchemaValidator != null ? jsonSchemaValidator : McpJsonDefaults.getSchemaValidator(),
497+
asyncFeatures), this.contextProvider);
501498
}
502499

503500
}
@@ -830,7 +827,7 @@ public AsyncSpec enableCallToolSchemaCaching(boolean enableCallToolSchemaCaching
830827
*/
831828
public McpAsyncClient build() {
832829
var jsonSchemaValidator = (this.jsonSchemaValidator != null) ? this.jsonSchemaValidator
833-
: McpJsonDefaults.getDefaultJsonSchemaValidator();
830+
: McpJsonDefaults.getSchemaValidator();
834831
return new McpAsyncClient(this.transport, this.requestTimeout, this.initializationTimeout,
835832
jsonSchemaValidator,
836833
new McpClientFeatures.Async(this.clientInfo, this.capabilities, this.roots,

mcp-core/src/main/java/io/modelcontextprotocol/client/transport/HttpClientSseClientTransport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ public Builder connectTimeout(Duration connectTimeout) {
328328
public HttpClientSseClientTransport build() {
329329
HttpClient httpClient = this.clientBuilder.connectTimeout(this.connectTimeout).build();
330330
return new HttpClientSseClientTransport(httpClient, requestBuilder, baseUri, sseEndpoint,
331-
jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, httpRequestCustomizer);
331+
jsonMapper == null ? McpJsonDefaults.getMapper() : jsonMapper, httpRequestCustomizer);
332332
}
333333

334334
}

mcp-core/src/main/java/io/modelcontextprotocol/client/transport/HttpClientStreamableHttpTransport.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -843,10 +843,9 @@ public Builder supportedProtocolVersions(List<String> supportedProtocolVersions)
843843
*/
844844
public HttpClientStreamableHttpTransport build() {
845845
HttpClient httpClient = this.clientBuilder.connectTimeout(this.connectTimeout).build();
846-
return new HttpClientStreamableHttpTransport(
847-
jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, httpClient,
848-
requestBuilder, baseUri, endpoint, resumableStreams, openConnectionOnStartup, httpRequestCustomizer,
849-
supportedProtocolVersions);
846+
return new HttpClientStreamableHttpTransport(jsonMapper == null ? McpJsonDefaults.getMapper() : jsonMapper,
847+
httpClient, requestBuilder, baseUri, endpoint, resumableStreams, openConnectionOnStartup,
848+
httpRequestCustomizer, supportedProtocolVersions);
850849
}
851850

852851
}

mcp-core/src/main/java/io/modelcontextprotocol/json/McpJsonDefaults.java

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,29 @@
88
import io.modelcontextprotocol.util.McpServiceLoader;
99

1010
/**
11-
* This class is to be used to provide access to the default McpJsonMapper and to the
12-
* default JsonSchemaValidator instances via the static methods: getDefaultMcpJsonMapper
13-
* and getDefaultJsonSchemaValidator.
11+
* This class is to be used to provide access to the default {@link McpJsonMapper} and to
12+
* the default {@link JsonSchemaValidator} instances via the static methods:
13+
* {@link #getMapper()} and {@link #getSchemaValidator()}.
1414
* <p>
1515
* The initialization of (singleton) instances of this class is different in non-OSGi
16-
* environments and OSGi environments. Specifically, in non-OSGi environments The
17-
* McpJsonDefaults class will be loaded by whatever classloader is used to call one of the
18-
* existing static get methods for the first time. For servers, this will usually be in
19-
* response to the creation of the first McpServer instance. At that first time, the
20-
* mcpMapperServiceLoader and mcpValidatorServiceLoader will be null, and the
21-
* McpJsonDefaults constructor will be called, creating/initializing the
22-
* mcpMapperServiceLoader and the mcpValidatorServiceLoader...which will then be used to
23-
* call the ServiceLoader.load method.
16+
* environments and OSGi environments. Specifically, in non-OSGi environments the
17+
* {@code McpJsonDefaults} class will be loaded by whatever classloader is used to call
18+
* one of the existing static get methods for the first time. For servers, this will
19+
* usually be in response to the creation of the first {@code McpServer} instance. At that
20+
* first time, the {@code mcpMapperServiceLoader} and {@code mcpValidatorServiceLoader}
21+
* will be null, and the {@code McpJsonDefaults} constructor will be called,
22+
* creating/initializing the {@code mcpMapperServiceLoader} and the
23+
* {@code mcpValidatorServiceLoader}...which will then be used to call the
24+
* {@code ServiceLoader.load} method.
2425
* <p>
2526
* In OSGi environments, upon bundle activation SCR will create a new (singleton) instance
26-
* of McpJsonDefaults (via the constructor), and then inject suppliers via the
27-
* setMcpJsonMapperSupplier and setJsonSchemaValidatorSupplier methods with the
28-
* SCR-discovered instances of those services. This does depend upon the jars/bundles
29-
* providing those suppliers to be started/activated. This SCR behavior is dictated by xml
30-
* files in OSGi-INF directory of mcp-core (this project/jar/bundle), and the jsonmapper
31-
* and jsonschemvalidator provider jars/bundles (e.g. mcp-json-jackson2, 3, or others).
27+
* of {@code McpJsonDefaults} (via the constructor), and then inject suppliers via the
28+
* {@code setMcpJsonMapperSupplier} and {@code setJsonSchemaValidatorSupplier} methods
29+
* with the SCR-discovered instances of those services. This does depend upon the
30+
* jars/bundles providing those suppliers to be started/activated. This SCR behavior is
31+
* dictated by xml files in {@code OSGi-INF} directory of {@code mcp-core} (this
32+
* project/jar/bundle), and the jsonmapper and jsonschemavalidator provider jars/bundles
33+
* (e.g. {@code mcp-json-jackson2}, {@code mcp-json-jackson3}, or others).
3234
*/
3335
public class McpJsonDefaults {
3436

@@ -37,10 +39,8 @@ public class McpJsonDefaults {
3739
protected static McpServiceLoader<JsonSchemaValidatorSupplier, JsonSchemaValidator> mcpValidatorServiceLoader;
3840

3941
public McpJsonDefaults() {
40-
mcpMapperServiceLoader = new McpServiceLoader<McpJsonMapperSupplier, McpJsonMapper>(
41-
McpJsonMapperSupplier.class);
42-
mcpValidatorServiceLoader = new McpServiceLoader<JsonSchemaValidatorSupplier, JsonSchemaValidator>(
43-
JsonSchemaValidatorSupplier.class);
42+
mcpMapperServiceLoader = new McpServiceLoader<>(McpJsonMapperSupplier.class);
43+
mcpValidatorServiceLoader = new McpServiceLoader<>(JsonSchemaValidatorSupplier.class);
4444
}
4545

4646
void setMcpJsonMapperSupplier(McpJsonMapperSupplier supplier) {
@@ -51,7 +51,7 @@ void unsetMcpJsonMapperSupplier(McpJsonMapperSupplier supplier) {
5151
mcpMapperServiceLoader.unsetSupplier(supplier);
5252
}
5353

54-
public synchronized static McpJsonMapper getDefaultMcpJsonMapper() {
54+
public synchronized static McpJsonMapper getMapper() {
5555
if (mcpMapperServiceLoader == null) {
5656
new McpJsonDefaults();
5757
}
@@ -66,7 +66,7 @@ void unsetJsonSchemaValidatorSupplier(JsonSchemaValidatorSupplier supplier) {
6666
mcpValidatorServiceLoader.unsetSupplier(supplier);
6767
}
6868

69-
public synchronized static JsonSchemaValidator getDefaultJsonSchemaValidator() {
69+
public synchronized static JsonSchemaValidator getSchemaValidator() {
7070
if (mcpValidatorServiceLoader == null) {
7171
new McpJsonDefaults();
7272
}

mcp-core/src/main/java/io/modelcontextprotocol/server/McpServer.java

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,10 @@ public McpAsyncServer build() {
240240
this.instructions);
241241

242242
var jsonSchemaValidator = (this.jsonSchemaValidator != null) ? this.jsonSchemaValidator
243-
: McpJsonDefaults.getDefaultJsonSchemaValidator();
243+
: McpJsonDefaults.getSchemaValidator();
244244

245-
return new McpAsyncServer(transportProvider,
246-
jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, features,
247-
requestTimeout, uriTemplateManagerFactory, jsonSchemaValidator);
245+
return new McpAsyncServer(transportProvider, jsonMapper == null ? McpJsonDefaults.getMapper() : jsonMapper,
246+
features, requestTimeout, uriTemplateManagerFactory, jsonSchemaValidator);
248247
}
249248

250249
}
@@ -268,10 +267,9 @@ public McpAsyncServer build() {
268267
this.resources, this.resourceTemplates, this.prompts, this.completions, this.rootsChangeHandlers,
269268
this.instructions);
270269
var jsonSchemaValidator = this.jsonSchemaValidator != null ? this.jsonSchemaValidator
271-
: McpJsonDefaults.getDefaultJsonSchemaValidator();
272-
return new McpAsyncServer(transportProvider,
273-
jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, features,
274-
requestTimeout, uriTemplateManagerFactory, jsonSchemaValidator);
270+
: McpJsonDefaults.getSchemaValidator();
271+
return new McpAsyncServer(transportProvider, jsonMapper == null ? McpJsonDefaults.getMapper() : jsonMapper,
272+
features, requestTimeout, uriTemplateManagerFactory, jsonSchemaValidator);
275273
}
276274

277275
}
@@ -858,9 +856,9 @@ public McpSyncServer build() {
858856
this.immediateExecution);
859857

860858
var asyncServer = new McpAsyncServer(transportProvider,
861-
jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, asyncFeatures,
862-
requestTimeout, uriTemplateManagerFactory, jsonSchemaValidator != null ? jsonSchemaValidator
863-
: McpJsonDefaults.getDefaultJsonSchemaValidator());
859+
jsonMapper == null ? McpJsonDefaults.getMapper() : jsonMapper, asyncFeatures, requestTimeout,
860+
uriTemplateManagerFactory,
861+
jsonSchemaValidator != null ? jsonSchemaValidator : McpJsonDefaults.getSchemaValidator());
864862
return new McpSyncServer(asyncServer, this.immediateExecution);
865863
}
866864

@@ -888,10 +886,10 @@ public McpSyncServer build() {
888886
McpServerFeatures.Async asyncFeatures = McpServerFeatures.Async.fromSync(syncFeatures,
889887
this.immediateExecution);
890888
var jsonSchemaValidator = this.jsonSchemaValidator != null ? this.jsonSchemaValidator
891-
: McpJsonDefaults.getDefaultJsonSchemaValidator();
889+
: McpJsonDefaults.getSchemaValidator();
892890
var asyncServer = new McpAsyncServer(transportProvider,
893-
jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, asyncFeatures,
894-
this.requestTimeout, this.uriTemplateManagerFactory, jsonSchemaValidator);
891+
jsonMapper == null ? McpJsonDefaults.getMapper() : jsonMapper, asyncFeatures, this.requestTimeout,
892+
this.uriTemplateManagerFactory, jsonSchemaValidator);
895893
return new McpSyncServer(asyncServer, this.immediateExecution);
896894
}
897895

@@ -1938,10 +1936,9 @@ public StatelessAsyncSpecification jsonSchemaValidator(JsonSchemaValidator jsonS
19381936
public McpStatelessAsyncServer build() {
19391937
var features = new McpStatelessServerFeatures.Async(this.serverInfo, this.serverCapabilities, this.tools,
19401938
this.resources, this.resourceTemplates, this.prompts, this.completions, this.instructions);
1941-
return new McpStatelessAsyncServer(transport,
1942-
jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, features,
1943-
requestTimeout, uriTemplateManagerFactory, jsonSchemaValidator != null ? jsonSchemaValidator
1944-
: McpJsonDefaults.getDefaultJsonSchemaValidator());
1939+
return new McpStatelessAsyncServer(transport, jsonMapper == null ? McpJsonDefaults.getMapper() : jsonMapper,
1940+
features, requestTimeout, uriTemplateManagerFactory,
1941+
jsonSchemaValidator != null ? jsonSchemaValidator : McpJsonDefaults.getSchemaValidator());
19451942
}
19461943

19471944
}
@@ -2440,9 +2437,9 @@ public McpStatelessSyncServer build() {
24402437
this.resources, this.resourceTemplates, this.prompts, this.completions, this.instructions);
24412438
var asyncFeatures = McpStatelessServerFeatures.Async.fromSync(syncFeatures, this.immediateExecution);
24422439
var asyncServer = new McpStatelessAsyncServer(transport,
2443-
jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, asyncFeatures,
2444-
requestTimeout, uriTemplateManagerFactory, this.jsonSchemaValidator != null
2445-
? this.jsonSchemaValidator : McpJsonDefaults.getDefaultJsonSchemaValidator());
2440+
jsonMapper == null ? McpJsonDefaults.getMapper() : jsonMapper, asyncFeatures, requestTimeout,
2441+
uriTemplateManagerFactory,
2442+
this.jsonSchemaValidator != null ? this.jsonSchemaValidator : McpJsonDefaults.getSchemaValidator());
24462443
return new McpStatelessSyncServer(asyncServer, this.immediateExecution);
24472444
}
24482445

mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletSseServerTransportProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -672,8 +672,8 @@ public HttpServletSseServerTransportProvider build() {
672672
throw new IllegalStateException("MessageEndpoint must be set");
673673
}
674674
return new HttpServletSseServerTransportProvider(
675-
jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, baseUrl,
676-
messageEndpoint, sseEndpoint, keepAliveInterval, contextExtractor, securityValidator);
675+
jsonMapper == null ? McpJsonDefaults.getMapper() : jsonMapper, baseUrl, messageEndpoint,
676+
sseEndpoint, keepAliveInterval, contextExtractor, securityValidator);
677677
}
678678

679679
}

mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletStatelessServerTransport.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,8 @@ public Builder securityValidator(ServerTransportSecurityValidator securityValida
331331
public HttpServletStatelessServerTransport build() {
332332
Assert.notNull(mcpEndpoint, "Message endpoint must be set");
333333
return new HttpServletStatelessServerTransport(
334-
jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, mcpEndpoint,
335-
contextExtractor, securityValidator);
334+
jsonMapper == null ? McpJsonDefaults.getMapper() : jsonMapper, mcpEndpoint, contextExtractor,
335+
securityValidator);
336336
}
337337

338338
}

mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletStreamableServerTransportProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -895,8 +895,8 @@ public Builder securityValidator(ServerTransportSecurityValidator securityValida
895895
public HttpServletStreamableServerTransportProvider build() {
896896
Assert.notNull(this.mcpEndpoint, "MCP endpoint must be set");
897897
return new HttpServletStreamableServerTransportProvider(
898-
jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, mcpEndpoint,
899-
disallowDelete, contextExtractor, keepAliveInterval, securityValidator);
898+
jsonMapper == null ? McpJsonDefaults.getMapper() : jsonMapper, mcpEndpoint, disallowDelete,
899+
contextExtractor, keepAliveInterval, securityValidator);
900900
}
901901

902902
}

mcp-core/src/test/java/io/modelcontextprotocol/util/McpJsonMapperUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ public final class McpJsonMapperUtils {
88
private McpJsonMapperUtils() {
99
}
1010

11-
public static final McpJsonMapper JSON_MAPPER = McpJsonDefaults.getDefaultMcpJsonMapper();
11+
public static final McpJsonMapper JSON_MAPPER = McpJsonDefaults.getMapper();
1212

1313
}

mcp-json-jackson2/src/test/java/io/modelcontextprotocol/json/McpJsonMapperTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class McpJsonMapperTest {
1414

1515
@Test
1616
void shouldUseJackson2Mapper() {
17-
assertThat(McpJsonDefaults.getDefaultMcpJsonMapper()).isInstanceOf(JacksonMcpJsonMapper.class);
17+
assertThat(McpJsonDefaults.getMapper()).isInstanceOf(JacksonMcpJsonMapper.class);
1818
}
1919

2020
}

0 commit comments

Comments
 (0)