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.
This commit is contained in:
Sébastien Deleuze 2026-02-13 16:54:01 +01:00 • committed by GitHub
commit e60a0743a5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
31 changed files with 94 additions and 108 deletions

View file

@ -492,12 +492,9 @@ public interface McpClient {
McpClientFeatures.Async asyncFeatures = McpClientFeatures.Async.fromSync(syncFeatures);
return new McpSyncClient(
new McpAsyncClient(transport, this.requestTimeout, this.initializationTimeout,
jsonSchemaValidator != null ? jsonSchemaValidator
: McpJsonDefaults.getDefaultJsonSchemaValidator(),
asyncFeatures),
this.contextProvider);
return new McpSyncClient(new McpAsyncClient(transport, this.requestTimeout, this.initializationTimeout,
jsonSchemaValidator != null ? jsonSchemaValidator : McpJsonDefaults.getSchemaValidator(),
asyncFeatures), this.contextProvider);
}
}
@ -830,7 +827,7 @@ public interface McpClient {
*/
public McpAsyncClient build() {
var jsonSchemaValidator = (this.jsonSchemaValidator != null) ? this.jsonSchemaValidator
: McpJsonDefaults.getDefaultJsonSchemaValidator();
: McpJsonDefaults.getSchemaValidator();
return new McpAsyncClient(this.transport, this.requestTimeout, this.initializationTimeout,
jsonSchemaValidator,
new McpClientFeatures.Async(this.clientInfo, this.capabilities, this.roots,

View file

@ -328,7 +328,7 @@ public class HttpClientSseClientTransport implements McpClientTransport {
public HttpClientSseClientTransport build() {
HttpClient httpClient = this.clientBuilder.connectTimeout(this.connectTimeout).build();
return new HttpClientSseClientTransport(httpClient, requestBuilder, baseUri, sseEndpoint,
jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, httpRequestCustomizer);
jsonMapper == null ? McpJsonDefaults.getMapper() : jsonMapper, httpRequestCustomizer);
}
}

View file

@ -843,10 +843,9 @@ public class HttpClientStreamableHttpTransport implements McpClientTransport {
*/
public HttpClientStreamableHttpTransport build() {
HttpClient httpClient = this.clientBuilder.connectTimeout(this.connectTimeout).build();
return new HttpClientStreamableHttpTransport(
jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, httpClient,
requestBuilder, baseUri, endpoint, resumableStreams, openConnectionOnStartup, httpRequestCustomizer,
supportedProtocolVersions);
return new HttpClientStreamableHttpTransport(jsonMapper == null ? McpJsonDefaults.getMapper() : jsonMapper,
httpClient, requestBuilder, baseUri, endpoint, resumableStreams, openConnectionOnStartup,
httpRequestCustomizer, supportedProtocolVersions);
}
}

View file

@ -8,27 +8,29 @@ import io.modelcontextprotocol.json.schema.JsonSchemaValidatorSupplier;
import io.modelcontextprotocol.util.McpServiceLoader;
/**
* This class is to be used to provide access to the default McpJsonMapper and to the
* default JsonSchemaValidator instances via the static methods: getDefaultMcpJsonMapper
* and getDefaultJsonSchemaValidator.
* This class is to be used to provide access to the default {@link McpJsonMapper} and to
* the default {@link JsonSchemaValidator} instances via the static methods:
* {@link #getMapper()} and {@link #getSchemaValidator()}.
* <p>
* The initialization of (singleton) instances of this class is different in non-OSGi
* environments and OSGi environments. Specifically, in non-OSGi environments The
* McpJsonDefaults class will be loaded by whatever classloader is used to call one of the
* existing static get methods for the first time. For servers, this will usually be in
* response to the creation of the first McpServer instance. At that first time, the
* mcpMapperServiceLoader and mcpValidatorServiceLoader will be null, and the
* McpJsonDefaults constructor will be called, creating/initializing the
* mcpMapperServiceLoader and the mcpValidatorServiceLoader...which will then be used to
* call the ServiceLoader.load method.
* environments and OSGi environments. Specifically, in non-OSGi environments the
* {@code McpJsonDefaults} class will be loaded by whatever classloader is used to call
* one of the existing static get methods for the first time. For servers, this will
* usually be in response to the creation of the first {@code McpServer} instance. At that
* first time, the {@code mcpMapperServiceLoader} and {@code mcpValidatorServiceLoader}
* will be null, and the {@code McpJsonDefaults} constructor will be called,
* creating/initializing the {@code mcpMapperServiceLoader} and the
* {@code mcpValidatorServiceLoader}...which will then be used to call the
* {@code ServiceLoader.load} method.
* <p>
* In OSGi environments, upon bundle activation SCR will create a new (singleton) instance
* of McpJsonDefaults (via the constructor), and then inject suppliers via the
* setMcpJsonMapperSupplier and setJsonSchemaValidatorSupplier methods with the
* SCR-discovered instances of those services. This does depend upon the jars/bundles
* providing those suppliers to be started/activated. This SCR behavior is dictated by xml
* files in OSGi-INF directory of mcp-core (this project/jar/bundle), and the jsonmapper
* and jsonschemvalidator provider jars/bundles (e.g. mcp-json-jackson2, 3, or others).
* of {@code McpJsonDefaults} (via the constructor), and then inject suppliers via the
* {@code setMcpJsonMapperSupplier} and {@code setJsonSchemaValidatorSupplier} methods
* with the SCR-discovered instances of those services. This does depend upon the
* jars/bundles providing those suppliers to be started/activated. This SCR behavior is
* dictated by xml files in {@code OSGi-INF} directory of {@code mcp-core} (this
* project/jar/bundle), and the jsonmapper and jsonschemavalidator provider jars/bundles
* (e.g. {@code mcp-json-jackson2}, {@code mcp-json-jackson3}, or others).
*/
public class McpJsonDefaults {
@ -37,10 +39,8 @@ public class McpJsonDefaults {
protected static McpServiceLoader<JsonSchemaValidatorSupplier, JsonSchemaValidator> mcpValidatorServiceLoader;
public McpJsonDefaults() {
mcpMapperServiceLoader = new McpServiceLoader<McpJsonMapperSupplier, McpJsonMapper>(
McpJsonMapperSupplier.class);
mcpValidatorServiceLoader = new McpServiceLoader<JsonSchemaValidatorSupplier, JsonSchemaValidator>(
JsonSchemaValidatorSupplier.class);
mcpMapperServiceLoader = new McpServiceLoader<>(McpJsonMapperSupplier.class);
mcpValidatorServiceLoader = new McpServiceLoader<>(JsonSchemaValidatorSupplier.class);
}
void setMcpJsonMapperSupplier(McpJsonMapperSupplier supplier) {
@ -51,7 +51,7 @@ public class McpJsonDefaults {
mcpMapperServiceLoader.unsetSupplier(supplier);
}
public synchronized static McpJsonMapper getDefaultMcpJsonMapper() {
public synchronized static McpJsonMapper getMapper() {
if (mcpMapperServiceLoader == null) {
new McpJsonDefaults();
}
@ -66,7 +66,7 @@ public class McpJsonDefaults {
mcpValidatorServiceLoader.unsetSupplier(supplier);
}
public synchronized static JsonSchemaValidator getDefaultJsonSchemaValidator() {
public synchronized static JsonSchemaValidator getSchemaValidator() {
if (mcpValidatorServiceLoader == null) {
new McpJsonDefaults();
}

View file

@ -240,11 +240,10 @@ public interface McpServer {
this.instructions);
var jsonSchemaValidator = (this.jsonSchemaValidator != null) ? this.jsonSchemaValidator
: McpJsonDefaults.getDefaultJsonSchemaValidator();
: McpJsonDefaults.getSchemaValidator();
return new McpAsyncServer(transportProvider,
jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, features,
requestTimeout, uriTemplateManagerFactory, jsonSchemaValidator);
return new McpAsyncServer(transportProvider, jsonMapper == null ? McpJsonDefaults.getMapper() : jsonMapper,
features, requestTimeout, uriTemplateManagerFactory, jsonSchemaValidator);
}
}
@ -268,10 +267,9 @@ public interface McpServer {
this.resources, this.resourceTemplates, this.prompts, this.completions, this.rootsChangeHandlers,
this.instructions);
var jsonSchemaValidator = this.jsonSchemaValidator != null ? this.jsonSchemaValidator
: McpJsonDefaults.getDefaultJsonSchemaValidator();
return new McpAsyncServer(transportProvider,
jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, features,
requestTimeout, uriTemplateManagerFactory, jsonSchemaValidator);
: McpJsonDefaults.getSchemaValidator();
return new McpAsyncServer(transportProvider, jsonMapper == null ? McpJsonDefaults.getMapper() : jsonMapper,
features, requestTimeout, uriTemplateManagerFactory, jsonSchemaValidator);
}
}
@ -858,9 +856,9 @@ public interface McpServer {
this.immediateExecution);
var asyncServer = new McpAsyncServer(transportProvider,
jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, asyncFeatures,
requestTimeout, uriTemplateManagerFactory, jsonSchemaValidator != null ? jsonSchemaValidator
: McpJsonDefaults.getDefaultJsonSchemaValidator());
jsonMapper == null ? McpJsonDefaults.getMapper() : jsonMapper, asyncFeatures, requestTimeout,
uriTemplateManagerFactory,
jsonSchemaValidator != null ? jsonSchemaValidator : McpJsonDefaults.getSchemaValidator());
return new McpSyncServer(asyncServer, this.immediateExecution);
}
@ -888,10 +886,10 @@ public interface McpServer {
McpServerFeatures.Async asyncFeatures = McpServerFeatures.Async.fromSync(syncFeatures,
this.immediateExecution);
var jsonSchemaValidator = this.jsonSchemaValidator != null ? this.jsonSchemaValidator
: McpJsonDefaults.getDefaultJsonSchemaValidator();
: McpJsonDefaults.getSchemaValidator();
var asyncServer = new McpAsyncServer(transportProvider,
jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, asyncFeatures,
this.requestTimeout, this.uriTemplateManagerFactory, jsonSchemaValidator);
jsonMapper == null ? McpJsonDefaults.getMapper() : jsonMapper, asyncFeatures, this.requestTimeout,
this.uriTemplateManagerFactory, jsonSchemaValidator);
return new McpSyncServer(asyncServer, this.immediateExecution);
}
@ -1938,10 +1936,9 @@ public interface McpServer {
public McpStatelessAsyncServer build() {
var features = new McpStatelessServerFeatures.Async(this.serverInfo, this.serverCapabilities, this.tools,
this.resources, this.resourceTemplates, this.prompts, this.completions, this.instructions);
return new McpStatelessAsyncServer(transport,
jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, features,
requestTimeout, uriTemplateManagerFactory, jsonSchemaValidator != null ? jsonSchemaValidator
: McpJsonDefaults.getDefaultJsonSchemaValidator());
return new McpStatelessAsyncServer(transport, jsonMapper == null ? McpJsonDefaults.getMapper() : jsonMapper,
features, requestTimeout, uriTemplateManagerFactory,
jsonSchemaValidator != null ? jsonSchemaValidator : McpJsonDefaults.getSchemaValidator());
}
}
@ -2440,9 +2437,9 @@ public interface McpServer {
this.resources, this.resourceTemplates, this.prompts, this.completions, this.instructions);
var asyncFeatures = McpStatelessServerFeatures.Async.fromSync(syncFeatures, this.immediateExecution);
var asyncServer = new McpStatelessAsyncServer(transport,
jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, asyncFeatures,
requestTimeout, uriTemplateManagerFactory, this.jsonSchemaValidator != null
? this.jsonSchemaValidator : McpJsonDefaults.getDefaultJsonSchemaValidator());
jsonMapper == null ? McpJsonDefaults.getMapper() : jsonMapper, asyncFeatures, requestTimeout,
uriTemplateManagerFactory,
this.jsonSchemaValidator != null ? this.jsonSchemaValidator : McpJsonDefaults.getSchemaValidator());
return new McpStatelessSyncServer(asyncServer, this.immediateExecution);
}

View file

@ -672,8 +672,8 @@ public class HttpServletSseServerTransportProvider extends HttpServlet implement
throw new IllegalStateException("MessageEndpoint must be set");
}
return new HttpServletSseServerTransportProvider(
jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, baseUrl,
messageEndpoint, sseEndpoint, keepAliveInterval, contextExtractor, securityValidator);
jsonMapper == null ? McpJsonDefaults.getMapper() : jsonMapper, baseUrl, messageEndpoint,
sseEndpoint, keepAliveInterval, contextExtractor, securityValidator);
}
}

View file

@ -331,8 +331,8 @@ public class HttpServletStatelessServerTransport extends HttpServlet implements
public HttpServletStatelessServerTransport build() {
Assert.notNull(mcpEndpoint, "Message endpoint must be set");
return new HttpServletStatelessServerTransport(
jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, mcpEndpoint,
contextExtractor, securityValidator);
jsonMapper == null ? McpJsonDefaults.getMapper() : jsonMapper, mcpEndpoint, contextExtractor,
securityValidator);
}
}

View file

@ -895,8 +895,8 @@ public class HttpServletStreamableServerTransportProvider extends HttpServlet
public HttpServletStreamableServerTransportProvider build() {
Assert.notNull(this.mcpEndpoint, "MCP endpoint must be set");
return new HttpServletStreamableServerTransportProvider(
jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, mcpEndpoint,
disallowDelete, contextExtractor, keepAliveInterval, securityValidator);
jsonMapper == null ? McpJsonDefaults.getMapper() : jsonMapper, mcpEndpoint, disallowDelete,
contextExtractor, keepAliveInterval, securityValidator);
}
}

View file

@ -8,6 +8,6 @@ public final class McpJsonMapperUtils {
private McpJsonMapperUtils() {
}
public static final McpJsonMapper JSON_MAPPER = McpJsonDefaults.getDefaultMcpJsonMapper();
public static final McpJsonMapper JSON_MAPPER = McpJsonDefaults.getMapper();
}

View file

@ -14,7 +14,7 @@ class McpJsonMapperTest {
@Test
void shouldUseJackson2Mapper() {
assertThat(McpJsonDefaults.getDefaultMcpJsonMapper()).isInstanceOf(JacksonMcpJsonMapper.class);
assertThat(McpJsonDefaults.getMapper()).isInstanceOf(JacksonMcpJsonMapper.class);
}
}

View file

@ -15,7 +15,7 @@ class JsonSchemaValidatorTest {
@Test
void shouldUseJackson2Mapper() {
assertThat(McpJsonDefaults.getDefaultJsonSchemaValidator()).isInstanceOf(DefaultJsonSchemaValidator.class);
assertThat(McpJsonDefaults.getSchemaValidator()).isInstanceOf(DefaultJsonSchemaValidator.class);
}
}

View file

@ -14,7 +14,7 @@ class McpJsonMapperTest {
@Test
void shouldUseJackson2Mapper() {
assertThat(McpJsonDefaults.getDefaultMcpJsonMapper()).isInstanceOf(JacksonMcpJsonMapper.class);
assertThat(McpJsonDefaults.getMapper()).isInstanceOf(JacksonMcpJsonMapper.class);
}
}

View file

@ -15,7 +15,7 @@ class JsonSchemaValidatorTest {
@Test
void shouldUseJackson2Mapper() {
assertThat(McpJsonDefaults.getDefaultJsonSchemaValidator()).isInstanceOf(DefaultJsonSchemaValidator.class);
assertThat(McpJsonDefaults.getSchemaValidator()).isInstanceOf(DefaultJsonSchemaValidator.class);
}
}

View file

@ -616,9 +616,8 @@ public class WebClientStreamableHttpTransport implements McpClientTransport {
* @return a new instance of {@link WebClientStreamableHttpTransport}
*/
public WebClientStreamableHttpTransport build() {
return new WebClientStreamableHttpTransport(
jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, webClientBuilder,
endpoint, resumableStreams, openConnectionOnStartup, supportedProtocolVersions);
return new WebClientStreamableHttpTransport(jsonMapper == null ? McpJsonDefaults.getMapper() : jsonMapper,
webClientBuilder, endpoint, resumableStreams, openConnectionOnStartup, supportedProtocolVersions);
}
}

View file

@ -405,7 +405,7 @@ public class WebFluxSseClientTransport implements McpClientTransport {
*/
public WebFluxSseClientTransport build() {
return new WebFluxSseClientTransport(webClientBuilder,
jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, sseEndpoint);
jsonMapper == null ? McpJsonDefaults.getMapper() : jsonMapper, sseEndpoint);
}
}

View file

@ -562,9 +562,8 @@ public class WebFluxSseServerTransportProvider implements McpServerTransportProv
*/
public WebFluxSseServerTransportProvider build() {
Assert.notNull(messageEndpoint, "Message endpoint must be set");
return new WebFluxSseServerTransportProvider(
jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, baseUrl,
messageEndpoint, sseEndpoint, keepAliveInterval, contextExtractor, securityValidator);
return new WebFluxSseServerTransportProvider(jsonMapper == null ? McpJsonDefaults.getMapper() : jsonMapper,
baseUrl, messageEndpoint, sseEndpoint, keepAliveInterval, contextExtractor, securityValidator);
}
}

View file

@ -245,9 +245,8 @@ public class WebFluxStatelessServerTransport implements McpStatelessServerTransp
*/
public WebFluxStatelessServerTransport build() {
Assert.notNull(mcpEndpoint, "Message endpoint must be set");
return new WebFluxStatelessServerTransport(
jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, mcpEndpoint,
contextExtractor, securityValidator);
return new WebFluxStatelessServerTransport(jsonMapper == null ? McpJsonDefaults.getMapper() : jsonMapper,
mcpEndpoint, contextExtractor, securityValidator);
}
}

View file

@ -533,8 +533,8 @@ public class WebFluxStreamableServerTransportProvider implements McpStreamableSe
public WebFluxStreamableServerTransportProvider build() {
Assert.notNull(mcpEndpoint, "Message endpoint must be set");
return new WebFluxStreamableServerTransportProvider(
jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, mcpEndpoint,
contextExtractor, disallowDelete, keepAliveInterval, securityValidator);
jsonMapper == null ? McpJsonDefaults.getMapper() : jsonMapper, mcpEndpoint, contextExtractor,
disallowDelete, keepAliveInterval, securityValidator);
}
}

View file

@ -221,7 +221,7 @@ public class WebFluxServerTransportSecurityIntegrationTests {
public McpSyncClient createMcpClient(String baseUrl, TestHeaderExchangeFilterFunction exchangeFilterFunction) {
var transport = WebFluxSseClientTransport
.builder(WebClient.builder().baseUrl(baseUrl).filter(exchangeFilterFunction))
.jsonMapper(McpJsonDefaults.getDefaultMcpJsonMapper())
.jsonMapper(McpJsonDefaults.getMapper())
.build();
return McpClient.sync(transport).initializationTimeout(Duration.ofMillis(500)).build();
}
@ -254,7 +254,7 @@ public class WebFluxServerTransportSecurityIntegrationTests {
public McpSyncClient createMcpClient(String baseUrl, TestHeaderExchangeFilterFunction exchangeFilterFunction) {
var transport = WebClientStreamableHttpTransport
.builder(WebClient.builder().baseUrl(baseUrl).filter(exchangeFilterFunction))
.jsonMapper(McpJsonDefaults.getDefaultMcpJsonMapper())
.jsonMapper(McpJsonDefaults.getMapper())
.openConnectionOnStartup(true)
.build();
return McpClient.sync(transport).initializationTimeout(Duration.ofMillis(500)).build();
@ -288,7 +288,7 @@ public class WebFluxServerTransportSecurityIntegrationTests {
public McpSyncClient createMcpClient(String baseUrl, TestHeaderExchangeFilterFunction exchangeFilterFunction) {
var transport = WebClientStreamableHttpTransport
.builder(WebClient.builder().baseUrl(baseUrl).filter(exchangeFilterFunction))
.jsonMapper(McpJsonDefaults.getDefaultMcpJsonMapper())
.jsonMapper(McpJsonDefaults.getMapper())
.openConnectionOnStartup(true)
.build();
return McpClient.sync(transport).initializationTimeout(Duration.ofMillis(500)).build();

View file

@ -8,6 +8,6 @@ public final class McpJsonMapperUtils {
private McpJsonMapperUtils() {
}
public static final McpJsonMapper JSON_MAPPER = McpJsonDefaults.getDefaultMcpJsonMapper();
public static final McpJsonMapper JSON_MAPPER = McpJsonDefaults.getMapper();
}

Some files were not shown because too many files have changed in this diff Show more