From d518303d65a7866f4fb2ee30112025cb1b13cd1f Mon Sep 17 00:00:00 2001 From: Scott Lewis Date: Wed, 19 Nov 2025 20:17:25 -0800 Subject: [PATCH 01/11] Initial refactor of json/json schema api. Moved classes in mcp-json into mcp-core. --- mcp-core/pom.xml | 12 ++- .../client/McpClient.java | 8 +- .../HttpClientSseClientTransport.java | 4 +- .../HttpClientStreamableHttpTransport.java | 4 +- .../json/McpJsonMapper.java | 90 +++++++++++++++++++ .../json/McpJsonMapperSupplier.java | 14 +++ .../io/modelcontextprotocol/json/TypeRef.java | 44 +++++++++ .../DefaultMcpJsonMapperSupplier.java | 40 +++++++++ ...DefaultMcpJsonSchemaValidatorSupplier.java | 42 +++++++++ .../json/schema/JsonSchemaValidator.java | 44 +++++++++ .../schema/JsonSchemaValidatorSupplier.java | 19 ++++ .../server/McpServer.java | 44 +++++---- ...HttpServletSseServerTransportProvider.java | 5 +- .../HttpServletStatelessServerTransport.java | 5 +- ...vletStreamableServerTransportProvider.java | 5 +- .../MockMcpClientTransport.java | 3 +- .../MockMcpServerTransport.java | 3 +- .../CompleteCompletionSerializationTest.java | 6 +- .../util/McpJsonMapperUtils.java | 3 +- mcp-json-jackson2/pom.xml | 10 +-- mcp-spring/mcp-spring-webflux/pom.xml | 2 +- .../WebClientStreamableHttpTransport.java | 4 +- .../transport/WebFluxSseClientTransport.java | 5 +- .../WebFluxSseServerTransportProvider.java | 6 +- .../WebFluxStatelessServerTransport.java | 4 +- ...FluxStreamableServerTransportProvider.java | 5 +- .../utils/McpJsonMapperUtils.java | 3 +- .../WebMvcSseServerTransportProvider.java | 6 +- .../WebMvcStatelessServerTransport.java | 4 +- ...bMvcStreamableServerTransportProvider.java | 6 +- ...WebMvcSseServerTransportProviderTests.java | 3 +- .../MockMcpTransport.java | 3 +- .../util/McpJsonMapperUtils.java | 3 +- pom.xml | 1 - 34 files changed, 393 insertions(+), 67 deletions(-) create mode 100644 mcp-core/src/main/java/io/modelcontextprotocol/json/McpJsonMapper.java create mode 100644 mcp-core/src/main/java/io/modelcontextprotocol/json/McpJsonMapperSupplier.java create mode 100644 mcp-core/src/main/java/io/modelcontextprotocol/json/TypeRef.java create mode 100644 mcp-core/src/main/java/io/modelcontextprotocol/json/internal/DefaultMcpJsonMapperSupplier.java create mode 100644 mcp-core/src/main/java/io/modelcontextprotocol/json/internal/DefaultMcpJsonSchemaValidatorSupplier.java create mode 100644 mcp-core/src/main/java/io/modelcontextprotocol/json/schema/JsonSchemaValidator.java create mode 100644 mcp-core/src/main/java/io/modelcontextprotocol/json/schema/JsonSchemaValidatorSupplier.java diff --git a/mcp-core/pom.xml b/mcp-core/pom.xml index 39b4c9dc7..a093860ed 100644 --- a/mcp-core/pom.xml +++ b/mcp-core/pom.xml @@ -65,12 +65,6 @@ - - io.modelcontextprotocol.sdk - mcp-json - 0.17.0-SNAPSHOT - - org.slf4j slf4j-api @@ -90,6 +84,11 @@ + + com.fasterxml.jackson.core + jackson-databind + ${jackson.version} + jakarta.servlet jakarta.servlet-api @@ -104,7 +103,6 @@ 0.17.0-SNAPSHOT test - org.springframework spring-webmvc diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/client/McpClient.java b/mcp-core/src/main/java/io/modelcontextprotocol/client/McpClient.java index 421f2fc7f..686fcb6aa 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/client/McpClient.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/client/McpClient.java @@ -13,8 +13,9 @@ import java.util.function.Function; import java.util.function.Supplier; -import io.modelcontextprotocol.json.schema.JsonSchemaValidator; import io.modelcontextprotocol.common.McpTransportContext; +import io.modelcontextprotocol.json.internal.DefaultMcpJsonSchemaValidatorSupplier; +import io.modelcontextprotocol.json.schema.JsonSchemaValidator; import io.modelcontextprotocol.spec.McpClientTransport; import io.modelcontextprotocol.spec.McpSchema; import io.modelcontextprotocol.spec.McpSchema.ClientCapabilities; @@ -475,7 +476,8 @@ public McpSyncClient build() { McpClientFeatures.Async asyncFeatures = McpClientFeatures.Async.fromSync(syncFeatures); return new McpSyncClient(new McpAsyncClient(transport, this.requestTimeout, this.initializationTimeout, - jsonSchemaValidator != null ? jsonSchemaValidator : JsonSchemaValidator.getDefault(), + jsonSchemaValidator != null ? jsonSchemaValidator + : DefaultMcpJsonSchemaValidatorSupplier.getDefaultJsonSchemaValidator(), asyncFeatures), this.contextProvider); } @@ -809,7 +811,7 @@ public AsyncSpec enableCallToolSchemaCaching(boolean enableCallToolSchemaCaching */ public McpAsyncClient build() { var jsonSchemaValidator = (this.jsonSchemaValidator != null) ? this.jsonSchemaValidator - : JsonSchemaValidator.getDefault(); + : DefaultMcpJsonSchemaValidatorSupplier.getDefaultJsonSchemaValidator(); return new McpAsyncClient(this.transport, this.requestTimeout, this.initializationTimeout, jsonSchemaValidator, new McpClientFeatures.Async(this.clientInfo, this.capabilities, this.roots, diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/HttpClientSseClientTransport.java b/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/HttpClientSseClientTransport.java index ae093316f..ba6964ec1 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/HttpClientSseClientTransport.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/HttpClientSseClientTransport.java @@ -24,6 +24,7 @@ import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.json.McpJsonMapper; import io.modelcontextprotocol.json.TypeRef; +import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; import io.modelcontextprotocol.spec.HttpHeaders; import io.modelcontextprotocol.spec.McpClientTransport; import io.modelcontextprotocol.spec.McpSchema; @@ -327,7 +328,8 @@ public Builder connectTimeout(Duration connectTimeout) { public HttpClientSseClientTransport build() { HttpClient httpClient = this.clientBuilder.connectTimeout(this.connectTimeout).build(); return new HttpClientSseClientTransport(httpClient, requestBuilder, baseUri, sseEndpoint, - jsonMapper == null ? McpJsonMapper.getDefault() : jsonMapper, httpRequestCustomizer); + jsonMapper == null ? DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper() : jsonMapper, + httpRequestCustomizer); } } diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/HttpClientStreamableHttpTransport.java b/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/HttpClientStreamableHttpTransport.java index c48aedbcf..7fe138ff7 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/HttpClientStreamableHttpTransport.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/HttpClientStreamableHttpTransport.java @@ -25,6 +25,7 @@ import io.modelcontextprotocol.client.transport.customizer.McpSyncHttpClientRequestCustomizer; import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.json.McpJsonMapper; +import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; import io.modelcontextprotocol.json.TypeRef; import io.modelcontextprotocol.spec.ClosedMcpTransportSession; import io.modelcontextprotocol.spec.DefaultMcpTransportSession; @@ -813,7 +814,8 @@ public Builder supportedProtocolVersions(List supportedProtocolVersions) */ public HttpClientStreamableHttpTransport build() { HttpClient httpClient = this.clientBuilder.connectTimeout(this.connectTimeout).build(); - return new HttpClientStreamableHttpTransport(jsonMapper == null ? McpJsonMapper.getDefault() : jsonMapper, + return new HttpClientStreamableHttpTransport( + jsonMapper == null ? DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper() : jsonMapper, httpClient, requestBuilder, baseUri, endpoint, resumableStreams, openConnectionOnStartup, httpRequestCustomizer, supportedProtocolVersions); } diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/json/McpJsonMapper.java b/mcp-core/src/main/java/io/modelcontextprotocol/json/McpJsonMapper.java new file mode 100644 index 000000000..8481d1703 --- /dev/null +++ b/mcp-core/src/main/java/io/modelcontextprotocol/json/McpJsonMapper.java @@ -0,0 +1,90 @@ +/* + * Copyright 2025 - 2025 the original author or authors. + */ + +package io.modelcontextprotocol.json; + +import java.io.IOException; + +/** + * Abstraction for JSON serialization/deserialization to decouple the SDK from any + * specific JSON library. A default implementation backed by Jackson is provided in + * io.modelcontextprotocol.spec.json.jackson.JacksonJsonMapper. + */ +public interface McpJsonMapper { + + /** + * Deserialize JSON string into a target type. + * @param content JSON as String + * @param type target class + * @return deserialized instance + * @param generic type + * @throws IOException on parse errors + */ + T readValue(String content, Class type) throws IOException; + + /** + * Deserialize JSON bytes into a target type. + * @param content JSON as bytes + * @param type target class + * @return deserialized instance + * @param generic type + * @throws IOException on parse errors + */ + T readValue(byte[] content, Class type) throws IOException; + + /** + * Deserialize JSON string into a parameterized target type. + * @param content JSON as String + * @param type parameterized type reference + * @return deserialized instance + * @param generic type + * @throws IOException on parse errors + */ + T readValue(String content, TypeRef type) throws IOException; + + /** + * Deserialize JSON bytes into a parameterized target type. + * @param content JSON as bytes + * @param type parameterized type reference + * @return deserialized instance + * @param generic type + * @throws IOException on parse errors + */ + T readValue(byte[] content, TypeRef type) throws IOException; + + /** + * Convert a value to a given type, useful for mapping nested JSON structures. + * @param fromValue source value + * @param type target class + * @return converted value + * @param generic type + */ + T convertValue(Object fromValue, Class type); + + /** + * Convert a value to a given parameterized type. + * @param fromValue source value + * @param type target type reference + * @return converted value + * @param generic type + */ + T convertValue(Object fromValue, TypeRef type); + + /** + * Serialize an object to JSON string. + * @param value object to serialize + * @return JSON as String + * @throws IOException on serialization errors + */ + String writeValueAsString(Object value) throws IOException; + + /** + * Serialize an object to JSON bytes. + * @param value object to serialize + * @return JSON as bytes + * @throws IOException on serialization errors + */ + byte[] writeValueAsBytes(Object value) throws IOException; + +} diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/json/McpJsonMapperSupplier.java b/mcp-core/src/main/java/io/modelcontextprotocol/json/McpJsonMapperSupplier.java new file mode 100644 index 000000000..619f96040 --- /dev/null +++ b/mcp-core/src/main/java/io/modelcontextprotocol/json/McpJsonMapperSupplier.java @@ -0,0 +1,14 @@ +/* + * Copyright 2025 - 2025 the original author or authors. + */ + +package io.modelcontextprotocol.json; + +import java.util.function.Supplier; + +/** + * Strategy interface for resolving a {@link McpJsonMapper}. + */ +public interface McpJsonMapperSupplier extends Supplier { + +} diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/json/TypeRef.java b/mcp-core/src/main/java/io/modelcontextprotocol/json/TypeRef.java new file mode 100644 index 000000000..725513c66 --- /dev/null +++ b/mcp-core/src/main/java/io/modelcontextprotocol/json/TypeRef.java @@ -0,0 +1,44 @@ +/* + * Copyright 2025 - 2025 the original author or authors. + */ + +package io.modelcontextprotocol.json; + +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; + +/** + * Captures generic type information at runtime for parameterized JSON (de)serialization. + * Usage: TypeRef> ref = new TypeRef<>(){}; + */ +public abstract class TypeRef { + + private final Type type; + + /** + * Constructs a new TypeRef instance, capturing the generic type information of the + * subclass. This constructor should be called from an anonymous subclass to capture + * the actual type arguments. For example:
+	 * TypeRef<List<Foo>> ref = new TypeRef<>(){};
+	 * 
+ * @throws IllegalStateException if TypeRef is not subclassed with actual type + * information + */ + protected TypeRef() { + Type superClass = getClass().getGenericSuperclass(); + if (superClass instanceof Class) { + throw new IllegalStateException("TypeRef constructed without actual type information"); + } + this.type = ((ParameterizedType) superClass).getActualTypeArguments()[0]; + } + + /** + * Returns the captured type information. + * @return the Type representing the actual type argument captured by this TypeRef + * instance + */ + public Type getType() { + return type; + } + +} diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/json/internal/DefaultMcpJsonMapperSupplier.java b/mcp-core/src/main/java/io/modelcontextprotocol/json/internal/DefaultMcpJsonMapperSupplier.java new file mode 100644 index 000000000..b44cadc62 --- /dev/null +++ b/mcp-core/src/main/java/io/modelcontextprotocol/json/internal/DefaultMcpJsonMapperSupplier.java @@ -0,0 +1,40 @@ +package io.modelcontextprotocol.json.internal; + +import java.util.Optional; +import java.util.ServiceConfigurationError; +import java.util.ServiceLoader; + +import io.modelcontextprotocol.json.McpJsonMapper; +import io.modelcontextprotocol.json.McpJsonMapperSupplier; + +public class DefaultMcpJsonMapperSupplier { + + private static McpJsonMapperSupplier jsonMapperSupplier; + + private static McpJsonMapper defaultJsonMapper; + + void setMcpJsonMapperSupplier(McpJsonMapperSupplier supplier) { + jsonMapperSupplier = supplier; + } + + void unsetMcpJsonMapperSupplier(McpJsonMapperSupplier supplier) { + jsonMapperSupplier = null; + defaultJsonMapper = null; + } + + public synchronized static McpJsonMapper getDefaultMcpJsonMapper() { + if (defaultJsonMapper == null) { + if (jsonMapperSupplier == null) { + // Use serviceloader + Optional sl = ServiceLoader.load(McpJsonMapperSupplier.class).findFirst(); + if (sl.isEmpty()) { + throw new ServiceConfigurationError("No JsonMapperSupplier available for creating McpJsonMapper"); + } + jsonMapperSupplier = sl.get(); + } + defaultJsonMapper = jsonMapperSupplier.get(); + } + return defaultJsonMapper; + } + +} diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/json/internal/DefaultMcpJsonSchemaValidatorSupplier.java b/mcp-core/src/main/java/io/modelcontextprotocol/json/internal/DefaultMcpJsonSchemaValidatorSupplier.java new file mode 100644 index 000000000..cb9d46029 --- /dev/null +++ b/mcp-core/src/main/java/io/modelcontextprotocol/json/internal/DefaultMcpJsonSchemaValidatorSupplier.java @@ -0,0 +1,42 @@ +package io.modelcontextprotocol.json.internal; + +import java.util.Optional; +import java.util.ServiceConfigurationError; +import java.util.ServiceLoader; + +import io.modelcontextprotocol.json.schema.JsonSchemaValidator; +import io.modelcontextprotocol.json.schema.JsonSchemaValidatorSupplier; + +public class DefaultMcpJsonSchemaValidatorSupplier { + + private static JsonSchemaValidatorSupplier jsonSchemaValidatorSupplier; + + private static JsonSchemaValidator defaultJsonSchemaValidator; + + void setJsonSchemaValidatorSupplier(JsonSchemaValidatorSupplier supplier) { + jsonSchemaValidatorSupplier = supplier; + } + + void unsetJsonSchemaValidatorSupplier(JsonSchemaValidatorSupplier supplier) { + jsonSchemaValidatorSupplier = null; + defaultJsonSchemaValidator = null; + } + + public synchronized static JsonSchemaValidator getDefaultJsonSchemaValidator() { + if (defaultJsonSchemaValidator == null) { + if (jsonSchemaValidatorSupplier == null) { + // Use serviceloader + Optional sl = ServiceLoader.load(JsonSchemaValidatorSupplier.class) + .findFirst(); + if (sl.isEmpty()) { + throw new ServiceConfigurationError( + "No JsonSchemaValidatorSupplier available for creating JsonSchemaValidator"); + } + jsonSchemaValidatorSupplier = sl.get(); + } + defaultJsonSchemaValidator = jsonSchemaValidatorSupplier.get(); + } + return defaultJsonSchemaValidator; + } + +} diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/json/schema/JsonSchemaValidator.java b/mcp-core/src/main/java/io/modelcontextprotocol/json/schema/JsonSchemaValidator.java new file mode 100644 index 000000000..09fe604f4 --- /dev/null +++ b/mcp-core/src/main/java/io/modelcontextprotocol/json/schema/JsonSchemaValidator.java @@ -0,0 +1,44 @@ +/* + * Copyright 2024-2024 the original author or authors. + */ +package io.modelcontextprotocol.json.schema; + +import java.util.Map; + +/** + * Interface for validating structured content against a JSON schema. This interface + * defines a method to validate structured content based on the provided output schema. + * + * @author Christian Tzolov + */ +public interface JsonSchemaValidator { + + /** + * Represents the result of a validation operation. + * + * @param valid Indicates whether the validation was successful. + * @param errorMessage An error message if the validation failed, otherwise null. + * @param jsonStructuredOutput The text structured content in JSON format if the + * validation was successful, otherwise null. + */ + record ValidationResponse(boolean valid, String errorMessage, String jsonStructuredOutput) { + + public static ValidationResponse asValid(String jsonStructuredOutput) { + return new ValidationResponse(true, null, jsonStructuredOutput); + } + + public static ValidationResponse asInvalid(String message) { + return new ValidationResponse(false, message, null); + } + } + + /** + * Validates the structured content against the provided JSON schema. + * @param schema The JSON schema to validate against. + * @param structuredContent The structured content to validate. + * @return A ValidationResponse indicating whether the validation was successful or + * not. + */ + ValidationResponse validate(Map schema, Object structuredContent); + +} diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/json/schema/JsonSchemaValidatorSupplier.java b/mcp-core/src/main/java/io/modelcontextprotocol/json/schema/JsonSchemaValidatorSupplier.java new file mode 100644 index 000000000..6f69169a0 --- /dev/null +++ b/mcp-core/src/main/java/io/modelcontextprotocol/json/schema/JsonSchemaValidatorSupplier.java @@ -0,0 +1,19 @@ +/* + * Copyright 2025 - 2025 the original author or authors. + */ + +package io.modelcontextprotocol.json.schema; + +import java.util.function.Supplier; + +/** + * A supplier interface that provides a {@link JsonSchemaValidator} instance. + * Implementations of this interface are expected to return a new or cached instance of + * {@link JsonSchemaValidator} when {@link #get()} is invoked. + * + * @see JsonSchemaValidator + * @see Supplier + */ +public interface JsonSchemaValidatorSupplier extends Supplier { + +} diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/server/McpServer.java b/mcp-core/src/main/java/io/modelcontextprotocol/server/McpServer.java index 87c84ba1b..c88d021fa 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/server/McpServer.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/server/McpServer.java @@ -15,7 +15,8 @@ import java.util.function.BiFunction; import io.modelcontextprotocol.json.McpJsonMapper; - +import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; +import io.modelcontextprotocol.json.internal.DefaultMcpJsonSchemaValidatorSupplier; import io.modelcontextprotocol.json.schema.JsonSchemaValidator; import io.modelcontextprotocol.spec.McpSchema; import io.modelcontextprotocol.spec.McpSchema.CallToolResult; @@ -228,10 +229,11 @@ public McpAsyncServer build() { this.instructions); var jsonSchemaValidator = (this.jsonSchemaValidator != null) ? this.jsonSchemaValidator - : JsonSchemaValidator.getDefault(); + : DefaultMcpJsonSchemaValidatorSupplier.getDefaultJsonSchemaValidator(); - return new McpAsyncServer(transportProvider, jsonMapper == null ? McpJsonMapper.getDefault() : jsonMapper, - features, requestTimeout, uriTemplateManagerFactory, jsonSchemaValidator); + return new McpAsyncServer(transportProvider, + jsonMapper == null ? DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper() : jsonMapper, features, + requestTimeout, uriTemplateManagerFactory, jsonSchemaValidator); } } @@ -255,9 +257,10 @@ public McpAsyncServer build() { this.resources, this.resourceTemplates, this.prompts, this.completions, this.rootsChangeHandlers, this.instructions); var jsonSchemaValidator = this.jsonSchemaValidator != null ? this.jsonSchemaValidator - : JsonSchemaValidator.getDefault(); - return new McpAsyncServer(transportProvider, jsonMapper == null ? McpJsonMapper.getDefault() : jsonMapper, - features, requestTimeout, uriTemplateManagerFactory, jsonSchemaValidator); + : DefaultMcpJsonSchemaValidatorSupplier.getDefaultJsonSchemaValidator(); + return new McpAsyncServer(transportProvider, + jsonMapper == null ? DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper() : jsonMapper, features, + requestTimeout, uriTemplateManagerFactory, jsonSchemaValidator); } } @@ -819,9 +822,10 @@ public McpSyncServer build() { this.immediateExecution); var asyncServer = new McpAsyncServer(transportProvider, - jsonMapper == null ? McpJsonMapper.getDefault() : jsonMapper, asyncFeatures, requestTimeout, - uriTemplateManagerFactory, - jsonSchemaValidator != null ? jsonSchemaValidator : JsonSchemaValidator.getDefault()); + jsonMapper == null ? DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper() : jsonMapper, + asyncFeatures, requestTimeout, uriTemplateManagerFactory, + jsonSchemaValidator != null ? jsonSchemaValidator + : DefaultMcpJsonSchemaValidatorSupplier.getDefaultJsonSchemaValidator()); return new McpSyncServer(asyncServer, this.immediateExecution); } @@ -849,10 +853,10 @@ public McpSyncServer build() { McpServerFeatures.Async asyncFeatures = McpServerFeatures.Async.fromSync(syncFeatures, this.immediateExecution); var jsonSchemaValidator = this.jsonSchemaValidator != null ? this.jsonSchemaValidator - : JsonSchemaValidator.getDefault(); + : DefaultMcpJsonSchemaValidatorSupplier.getDefaultJsonSchemaValidator(); var asyncServer = new McpAsyncServer(transportProvider, - jsonMapper == null ? McpJsonMapper.getDefault() : jsonMapper, asyncFeatures, this.requestTimeout, - this.uriTemplateManagerFactory, jsonSchemaValidator); + jsonMapper == null ? DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper() : jsonMapper, + asyncFeatures, this.requestTimeout, this.uriTemplateManagerFactory, jsonSchemaValidator); return new McpSyncServer(asyncServer, this.immediateExecution); } @@ -1853,9 +1857,10 @@ public StatelessAsyncSpecification jsonSchemaValidator(JsonSchemaValidator jsonS 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 ? McpJsonMapper.getDefault() : jsonMapper, - features, requestTimeout, uriTemplateManagerFactory, - jsonSchemaValidator != null ? jsonSchemaValidator : JsonSchemaValidator.getDefault()); + return new McpStatelessAsyncServer(transport, + jsonMapper == null ? DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper() : jsonMapper, features, + requestTimeout, uriTemplateManagerFactory, jsonSchemaValidator != null ? jsonSchemaValidator + : DefaultMcpJsonSchemaValidatorSupplier.getDefaultJsonSchemaValidator()); } } @@ -2333,9 +2338,10 @@ public McpStatelessSyncServer build() { 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 ? McpJsonMapper.getDefault() : jsonMapper, asyncFeatures, requestTimeout, - uriTemplateManagerFactory, - this.jsonSchemaValidator != null ? this.jsonSchemaValidator : JsonSchemaValidator.getDefault()); + jsonMapper == null ? DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper() : jsonMapper, + asyncFeatures, requestTimeout, uriTemplateManagerFactory, + this.jsonSchemaValidator != null ? this.jsonSchemaValidator + : DefaultMcpJsonSchemaValidatorSupplier.getDefaultJsonSchemaValidator()); return new McpStatelessSyncServer(asyncServer, this.immediateExecution); } diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletSseServerTransportProvider.java b/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletSseServerTransportProvider.java index 96cebb74a..2bfc3d2e2 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletSseServerTransportProvider.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletSseServerTransportProvider.java @@ -17,6 +17,7 @@ import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.json.McpJsonMapper; import io.modelcontextprotocol.json.TypeRef; +import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; import io.modelcontextprotocol.server.McpTransportContextExtractor; import io.modelcontextprotocol.spec.McpError; import io.modelcontextprotocol.spec.McpSchema; @@ -632,8 +633,8 @@ public HttpServletSseServerTransportProvider build() { throw new IllegalStateException("MessageEndpoint must be set"); } return new HttpServletSseServerTransportProvider( - jsonMapper == null ? McpJsonMapper.getDefault() : jsonMapper, baseUrl, messageEndpoint, sseEndpoint, - keepAliveInterval, contextExtractor); + jsonMapper == null ? DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper() : jsonMapper, baseUrl, + messageEndpoint, sseEndpoint, keepAliveInterval, contextExtractor); } } diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletStatelessServerTransport.java b/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletStatelessServerTransport.java index 40767f416..6e8a1c2f8 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletStatelessServerTransport.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletStatelessServerTransport.java @@ -12,7 +12,7 @@ import org.slf4j.LoggerFactory; import io.modelcontextprotocol.json.McpJsonMapper; - +import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.server.McpStatelessServerHandler; import io.modelcontextprotocol.server.McpTransportContextExtractor; @@ -296,7 +296,8 @@ public Builder contextExtractor(McpTransportContextExtractor */ public HttpServletStatelessServerTransport build() { Assert.notNull(mcpEndpoint, "Message endpoint must be set"); - return new HttpServletStatelessServerTransport(jsonMapper == null ? McpJsonMapper.getDefault() : jsonMapper, + return new HttpServletStatelessServerTransport( + jsonMapper == null ? DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper() : jsonMapper, mcpEndpoint, contextExtractor); } diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletStreamableServerTransportProvider.java b/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletStreamableServerTransportProvider.java index 34671c105..714d65bde 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletStreamableServerTransportProvider.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletStreamableServerTransportProvider.java @@ -29,6 +29,7 @@ import io.modelcontextprotocol.spec.ProtocolVersions; import io.modelcontextprotocol.util.Assert; import io.modelcontextprotocol.json.McpJsonMapper; +import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; import io.modelcontextprotocol.util.KeepAliveScheduler; import jakarta.servlet.AsyncContext; import jakarta.servlet.ServletException; @@ -842,8 +843,8 @@ public Builder keepAliveInterval(Duration keepAliveInterval) { public HttpServletStreamableServerTransportProvider build() { Assert.notNull(this.mcpEndpoint, "MCP endpoint must be set"); return new HttpServletStreamableServerTransportProvider( - jsonMapper == null ? McpJsonMapper.getDefault() : jsonMapper, mcpEndpoint, disallowDelete, - contextExtractor, keepAliveInterval); + jsonMapper == null ? DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper() : jsonMapper, + mcpEndpoint, disallowDelete, contextExtractor, keepAliveInterval); } } diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/MockMcpClientTransport.java b/mcp-core/src/test/java/io/modelcontextprotocol/MockMcpClientTransport.java index 9854de210..77d91b5bc 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/MockMcpClientTransport.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/MockMcpClientTransport.java @@ -11,6 +11,7 @@ import io.modelcontextprotocol.json.McpJsonMapper; import io.modelcontextprotocol.json.TypeRef; +import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; import io.modelcontextprotocol.spec.McpClientTransport; import io.modelcontextprotocol.spec.McpSchema; import io.modelcontextprotocol.spec.McpSchema.JSONRPCNotification; @@ -100,7 +101,7 @@ public Mono closeGracefully() { @Override public T unmarshalFrom(Object data, TypeRef typeRef) { - return McpJsonMapper.getDefault().convertValue(data, typeRef); + return DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper().convertValue(data, typeRef); } } diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/MockMcpServerTransport.java b/mcp-core/src/test/java/io/modelcontextprotocol/MockMcpServerTransport.java index f3d6b77a7..8da486d1d 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/MockMcpServerTransport.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/MockMcpServerTransport.java @@ -10,6 +10,7 @@ import io.modelcontextprotocol.json.McpJsonMapper; import io.modelcontextprotocol.json.TypeRef; +import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; import io.modelcontextprotocol.spec.McpSchema; import io.modelcontextprotocol.spec.McpSchema.JSONRPCNotification; import io.modelcontextprotocol.spec.McpSchema.JSONRPCRequest; @@ -68,7 +69,7 @@ public Mono closeGracefully() { @Override public T unmarshalFrom(Object data, TypeRef typeRef) { - return McpJsonMapper.getDefault().convertValue(data, typeRef); + return DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper().convertValue(data, typeRef); } } diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/spec/CompleteCompletionSerializationTest.java b/mcp-core/src/test/java/io/modelcontextprotocol/spec/CompleteCompletionSerializationTest.java index 55f71fea4..1974f2bde 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/spec/CompleteCompletionSerializationTest.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/spec/CompleteCompletionSerializationTest.java @@ -1,16 +1,18 @@ package io.modelcontextprotocol.spec; -import io.modelcontextprotocol.json.McpJsonMapper; import org.junit.jupiter.api.Test; import java.io.IOException; import java.util.Collections; import static org.junit.jupiter.api.Assertions.assertEquals; +import io.modelcontextprotocol.json.McpJsonMapper; +import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; + class CompleteCompletionSerializationTest { @Test void codeCompletionSerialization() throws IOException { - McpJsonMapper jsonMapper = McpJsonMapper.getDefault(); + McpJsonMapper jsonMapper = DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper(); McpSchema.CompleteResult.CompleteCompletion codeComplete = new McpSchema.CompleteResult.CompleteCompletion( Collections.emptyList(), 0, false); String json = jsonMapper.writeValueAsString(codeComplete); diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/util/McpJsonMapperUtils.java b/mcp-core/src/test/java/io/modelcontextprotocol/util/McpJsonMapperUtils.java index 911506e01..f2b574a45 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/util/McpJsonMapperUtils.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/util/McpJsonMapperUtils.java @@ -1,12 +1,13 @@ package io.modelcontextprotocol.util; import io.modelcontextprotocol.json.McpJsonMapper; +import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; public final class McpJsonMapperUtils { private McpJsonMapperUtils() { } - public static final McpJsonMapper JSON_MAPPER = McpJsonMapper.getDefault(); + public static final McpJsonMapper JSON_MAPPER = DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper(); } diff --git a/mcp-json-jackson2/pom.xml b/mcp-json-jackson2/pom.xml index 8ea1fa7d2..9698385be 100644 --- a/mcp-json-jackson2/pom.xml +++ b/mcp-json-jackson2/pom.xml @@ -34,16 +34,16 @@ - - io.modelcontextprotocol.sdk - mcp-json - 0.17.0-SNAPSHOT - com.fasterxml.jackson.core jackson-databind ${jackson.version} + + io.modelcontextprotocol.sdk + mcp-core + 0.15.0-SNAPSHOT + com.networknt json-schema-validator diff --git a/mcp-spring/mcp-spring-webflux/pom.xml b/mcp-spring/mcp-spring-webflux/pom.xml index 594d95750..271000f35 100644 --- a/mcp-spring/mcp-spring-webflux/pom.xml +++ b/mcp-spring/mcp-spring-webflux/pom.xml @@ -30,7 +30,7 @@ io.modelcontextprotocol.sdk - mcp + mcp-core 0.17.0-SNAPSHOT diff --git a/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/client/transport/WebClientStreamableHttpTransport.java b/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/client/transport/WebClientStreamableHttpTransport.java index 6b1d6ba8a..616c09859 100644 --- a/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/client/transport/WebClientStreamableHttpTransport.java +++ b/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/client/transport/WebClientStreamableHttpTransport.java @@ -26,6 +26,7 @@ import io.modelcontextprotocol.json.McpJsonMapper; import io.modelcontextprotocol.json.TypeRef; +import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; import io.modelcontextprotocol.spec.ClosedMcpTransportSession; import io.modelcontextprotocol.spec.DefaultMcpTransportSession; import io.modelcontextprotocol.spec.DefaultMcpTransportStream; @@ -594,7 +595,8 @@ public Builder supportedProtocolVersions(List supportedProtocolVersions) * @return a new instance of {@link WebClientStreamableHttpTransport} */ public WebClientStreamableHttpTransport build() { - return new WebClientStreamableHttpTransport(jsonMapper == null ? McpJsonMapper.getDefault() : jsonMapper, + return new WebClientStreamableHttpTransport( + jsonMapper == null ? DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper() : jsonMapper, webClientBuilder, endpoint, resumableStreams, openConnectionOnStartup, supportedProtocolVersions); } diff --git a/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/client/transport/WebFluxSseClientTransport.java b/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/client/transport/WebFluxSseClientTransport.java index 91b89d6d2..2a9c0e202 100644 --- a/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/client/transport/WebFluxSseClientTransport.java +++ b/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/client/transport/WebFluxSseClientTransport.java @@ -11,7 +11,7 @@ import io.modelcontextprotocol.json.McpJsonMapper; import io.modelcontextprotocol.json.TypeRef; - +import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; import io.modelcontextprotocol.spec.HttpHeaders; import io.modelcontextprotocol.spec.McpClientTransport; import io.modelcontextprotocol.spec.McpSchema; @@ -404,7 +404,8 @@ public Builder jsonMapper(McpJsonMapper jsonMapper) { */ public WebFluxSseClientTransport build() { return new WebFluxSseClientTransport(webClientBuilder, - jsonMapper == null ? McpJsonMapper.getDefault() : jsonMapper, sseEndpoint); + jsonMapper == null ? DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper() : jsonMapper, + sseEndpoint); } } diff --git a/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/server/transport/WebFluxSseServerTransportProvider.java b/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/server/transport/WebFluxSseServerTransportProvider.java index 0c80c5b8b..a01261e04 100644 --- a/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/server/transport/WebFluxSseServerTransportProvider.java +++ b/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/server/transport/WebFluxSseServerTransportProvider.java @@ -12,6 +12,7 @@ import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.json.McpJsonMapper; import io.modelcontextprotocol.json.TypeRef; +import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; import io.modelcontextprotocol.server.McpTransportContextExtractor; import io.modelcontextprotocol.spec.McpError; import io.modelcontextprotocol.spec.McpSchema; @@ -521,8 +522,9 @@ public Builder contextExtractor(McpTransportContextExtractor cont */ public WebFluxSseServerTransportProvider build() { Assert.notNull(messageEndpoint, "Message endpoint must be set"); - return new WebFluxSseServerTransportProvider(jsonMapper == null ? McpJsonMapper.getDefault() : jsonMapper, - baseUrl, messageEndpoint, sseEndpoint, keepAliveInterval, contextExtractor); + return new WebFluxSseServerTransportProvider( + jsonMapper == null ? DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper() : jsonMapper, baseUrl, + messageEndpoint, sseEndpoint, keepAliveInterval, contextExtractor); } } diff --git a/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/server/transport/WebFluxStatelessServerTransport.java b/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/server/transport/WebFluxStatelessServerTransport.java index 400be341e..ef95bb8b2 100644 --- a/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/server/transport/WebFluxStatelessServerTransport.java +++ b/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/server/transport/WebFluxStatelessServerTransport.java @@ -5,6 +5,7 @@ package io.modelcontextprotocol.server.transport; import io.modelcontextprotocol.json.McpJsonMapper; +import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.server.McpStatelessServerHandler; import io.modelcontextprotocol.server.McpTransportContextExtractor; @@ -213,7 +214,8 @@ public Builder contextExtractor(McpTransportContextExtractor cont */ public WebFluxStatelessServerTransport build() { Assert.notNull(mcpEndpoint, "Message endpoint must be set"); - return new WebFluxStatelessServerTransport(jsonMapper == null ? McpJsonMapper.getDefault() : jsonMapper, + return new WebFluxStatelessServerTransport( + jsonMapper == null ? DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper() : jsonMapper, mcpEndpoint, contextExtractor); } diff --git a/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/server/transport/WebFluxStreamableServerTransportProvider.java b/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/server/transport/WebFluxStreamableServerTransportProvider.java index deebfc616..b9e47f8a7 100644 --- a/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/server/transport/WebFluxStreamableServerTransportProvider.java +++ b/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/server/transport/WebFluxStreamableServerTransportProvider.java @@ -6,6 +6,7 @@ import io.modelcontextprotocol.json.McpJsonMapper; import io.modelcontextprotocol.json.TypeRef; +import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.server.McpTransportContextExtractor; import io.modelcontextprotocol.spec.HttpHeaders; @@ -486,8 +487,8 @@ public Builder keepAliveInterval(Duration keepAliveInterval) { public WebFluxStreamableServerTransportProvider build() { Assert.notNull(mcpEndpoint, "Message endpoint must be set"); return new WebFluxStreamableServerTransportProvider( - jsonMapper == null ? McpJsonMapper.getDefault() : jsonMapper, mcpEndpoint, contextExtractor, - disallowDelete, keepAliveInterval); + jsonMapper == null ? DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper() : jsonMapper, + mcpEndpoint, contextExtractor, disallowDelete, keepAliveInterval); } } diff --git a/mcp-spring/mcp-spring-webflux/src/test/java/io/modelcontextprotocol/utils/McpJsonMapperUtils.java b/mcp-spring/mcp-spring-webflux/src/test/java/io/modelcontextprotocol/utils/McpJsonMapperUtils.java index 67347573c..c7ad34048 100644 --- a/mcp-spring/mcp-spring-webflux/src/test/java/io/modelcontextprotocol/utils/McpJsonMapperUtils.java +++ b/mcp-spring/mcp-spring-webflux/src/test/java/io/modelcontextprotocol/utils/McpJsonMapperUtils.java @@ -1,12 +1,13 @@ package io.modelcontextprotocol.utils; import io.modelcontextprotocol.json.McpJsonMapper; +import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; public final class McpJsonMapperUtils { private McpJsonMapperUtils() { } - public static final McpJsonMapper JSON_MAPPER = McpJsonMapper.createDefault(); + public static final McpJsonMapper JSON_MAPPER = DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper(); } \ No newline at end of file diff --git a/mcp-spring/mcp-spring-webmvc/src/main/java/io/modelcontextprotocol/server/transport/WebMvcSseServerTransportProvider.java b/mcp-spring/mcp-spring-webmvc/src/main/java/io/modelcontextprotocol/server/transport/WebMvcSseServerTransportProvider.java index dfaee64b5..b8eb27708 100644 --- a/mcp-spring/mcp-spring-webmvc/src/main/java/io/modelcontextprotocol/server/transport/WebMvcSseServerTransportProvider.java +++ b/mcp-spring/mcp-spring-webmvc/src/main/java/io/modelcontextprotocol/server/transport/WebMvcSseServerTransportProvider.java @@ -14,6 +14,7 @@ import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.json.McpJsonMapper; import io.modelcontextprotocol.json.TypeRef; +import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; import io.modelcontextprotocol.server.McpTransportContextExtractor; import io.modelcontextprotocol.spec.McpError; import io.modelcontextprotocol.spec.McpSchema; @@ -577,8 +578,9 @@ public WebMvcSseServerTransportProvider build() { if (messageEndpoint == null) { throw new IllegalStateException("MessageEndpoint must be set"); } - return new WebMvcSseServerTransportProvider(jsonMapper == null ? McpJsonMapper.getDefault() : jsonMapper, - baseUrl, messageEndpoint, sseEndpoint, keepAliveInterval, contextExtractor); + return new WebMvcSseServerTransportProvider( + jsonMapper == null ? DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper() : jsonMapper, baseUrl, + messageEndpoint, sseEndpoint, keepAliveInterval, contextExtractor); } } diff --git a/mcp-spring/mcp-spring-webmvc/src/main/java/io/modelcontextprotocol/server/transport/WebMvcStatelessServerTransport.java b/mcp-spring/mcp-spring-webmvc/src/main/java/io/modelcontextprotocol/server/transport/WebMvcStatelessServerTransport.java index 4223084ff..07b6565e2 100644 --- a/mcp-spring/mcp-spring-webmvc/src/main/java/io/modelcontextprotocol/server/transport/WebMvcStatelessServerTransport.java +++ b/mcp-spring/mcp-spring-webmvc/src/main/java/io/modelcontextprotocol/server/transport/WebMvcStatelessServerTransport.java @@ -6,6 +6,7 @@ import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.json.McpJsonMapper; +import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; import io.modelcontextprotocol.server.McpStatelessServerHandler; import io.modelcontextprotocol.server.McpTransportContextExtractor; import io.modelcontextprotocol.spec.McpError; @@ -231,7 +232,8 @@ public Builder contextExtractor(McpTransportContextExtractor cont */ public WebMvcStatelessServerTransport build() { Assert.notNull(mcpEndpoint, "Message endpoint must be set"); - return new WebMvcStatelessServerTransport(jsonMapper == null ? McpJsonMapper.getDefault() : jsonMapper, + return new WebMvcStatelessServerTransport( + jsonMapper == null ? DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper() : jsonMapper, mcpEndpoint, contextExtractor); } diff --git a/mcp-spring/mcp-spring-webmvc/src/main/java/io/modelcontextprotocol/server/transport/WebMvcStreamableServerTransportProvider.java b/mcp-spring/mcp-spring-webmvc/src/main/java/io/modelcontextprotocol/server/transport/WebMvcStreamableServerTransportProvider.java index f2a58d4d8..003548ad6 100644 --- a/mcp-spring/mcp-spring-webmvc/src/main/java/io/modelcontextprotocol/server/transport/WebMvcStreamableServerTransportProvider.java +++ b/mcp-spring/mcp-spring-webmvc/src/main/java/io/modelcontextprotocol/server/transport/WebMvcStreamableServerTransportProvider.java @@ -22,7 +22,7 @@ import org.springframework.web.servlet.function.ServerResponse.SseBuilder; import io.modelcontextprotocol.json.TypeRef; - +import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.server.McpTransportContextExtractor; import io.modelcontextprotocol.spec.HttpHeaders; @@ -681,8 +681,8 @@ public Builder keepAliveInterval(Duration keepAliveInterval) { public WebMvcStreamableServerTransportProvider build() { Assert.notNull(this.mcpEndpoint, "MCP endpoint must be set"); return new WebMvcStreamableServerTransportProvider( - jsonMapper == null ? McpJsonMapper.getDefault() : jsonMapper, mcpEndpoint, disallowDelete, - contextExtractor, keepAliveInterval); + jsonMapper == null ? DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper() : jsonMapper, + mcpEndpoint, disallowDelete, contextExtractor, keepAliveInterval); } } diff --git a/mcp-spring/mcp-spring-webmvc/src/test/java/io/modelcontextprotocol/server/transport/WebMvcSseServerTransportProviderTests.java b/mcp-spring/mcp-spring-webmvc/src/test/java/io/modelcontextprotocol/server/transport/WebMvcSseServerTransportProviderTests.java index 1074e8a35..c4d415ead 100644 --- a/mcp-spring/mcp-spring-webmvc/src/test/java/io/modelcontextprotocol/server/transport/WebMvcSseServerTransportProviderTests.java +++ b/mcp-spring/mcp-spring-webmvc/src/test/java/io/modelcontextprotocol/server/transport/WebMvcSseServerTransportProviderTests.java @@ -8,6 +8,7 @@ import io.modelcontextprotocol.client.transport.HttpClientSseClientTransport; import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.json.McpJsonMapper; +import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; import io.modelcontextprotocol.server.McpServer; import io.modelcontextprotocol.server.TestUtil; import io.modelcontextprotocol.server.TomcatTestUtil; @@ -104,7 +105,7 @@ public WebMvcSseServerTransportProvider webMvcSseServerTransportProvider() { .baseUrl("http://localhost:" + PORT + "/") .messageEndpoint(MESSAGE_ENDPOINT) .sseEndpoint(WebMvcSseServerTransportProvider.DEFAULT_SSE_ENDPOINT) - .jsonMapper(McpJsonMapper.getDefault()) + .jsonMapper(DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper()) .contextExtractor(req -> McpTransportContext.EMPTY) .build(); } diff --git a/mcp-test/src/main/java/io/modelcontextprotocol/MockMcpTransport.java b/mcp-test/src/main/java/io/modelcontextprotocol/MockMcpTransport.java index cd8458311..5beb7fc8b 100644 --- a/mcp-test/src/main/java/io/modelcontextprotocol/MockMcpTransport.java +++ b/mcp-test/src/main/java/io/modelcontextprotocol/MockMcpTransport.java @@ -11,6 +11,7 @@ import io.modelcontextprotocol.json.McpJsonMapper; import io.modelcontextprotocol.json.TypeRef; +import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; import io.modelcontextprotocol.spec.McpClientTransport; import io.modelcontextprotocol.spec.McpSchema; import io.modelcontextprotocol.spec.McpSchema.JSONRPCNotification; @@ -94,7 +95,7 @@ public Mono closeGracefully() { @Override public T unmarshalFrom(Object data, TypeRef typeRef) { - return McpJsonMapper.getDefault().convertValue(data, typeRef); + return DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper().convertValue(data, typeRef); } } diff --git a/mcp-test/src/main/java/io/modelcontextprotocol/util/McpJsonMapperUtils.java b/mcp-test/src/main/java/io/modelcontextprotocol/util/McpJsonMapperUtils.java index 723965519..3c58f9cfe 100644 --- a/mcp-test/src/main/java/io/modelcontextprotocol/util/McpJsonMapperUtils.java +++ b/mcp-test/src/main/java/io/modelcontextprotocol/util/McpJsonMapperUtils.java @@ -1,12 +1,13 @@ package io.modelcontextprotocol.util; import io.modelcontextprotocol.json.McpJsonMapper; +import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; public final class McpJsonMapperUtils { private McpJsonMapperUtils() { } - public static final McpJsonMapper JSON_MAPPER = McpJsonMapper.getDefault(); + public static final McpJsonMapper JSON_MAPPER = DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper(); } \ No newline at end of file diff --git a/pom.xml b/pom.xml index ca9ce7be4..eb4c8c6ef 100644 --- a/pom.xml +++ b/pom.xml @@ -105,7 +105,6 @@ mcp mcp-core mcp-json-jackson2 - mcp-json mcp-spring/mcp-spring-webflux mcp-spring/mcp-spring-webmvc mcp-test From 7762e2e88d9824fb5016bbc81cffc25be75ad843 Mon Sep 17 00:00:00 2001 From: Scott Lewis Date: Thu, 20 Nov 2025 13:19:30 -0800 Subject: [PATCH 02/11] Added test changes --- .../client/LifecycleInitializer.java | 5 ++- .../client/McpAsyncClient.java | 5 ++- .../HttpClientSseClientTransport.java | 2 + .../HttpClientStreamableHttpTransport.java | 9 ++-- .../client/transport/ServerParameters.java | 1 + .../transport/StdioClientTransport.java | 7 +-- ...ngMcpAsyncHttpClientRequestCustomizer.java | 1 - .../McpAsyncHttpClientRequestCustomizer.java | 4 +- .../McpSyncHttpClientRequestCustomizer.java | 3 +- .../DefaultMcpStatelessServerHandler.java | 9 ++-- .../server/McpAsyncServer.java | 10 ++--- .../server/McpAsyncServerExchange.java | 2 +- .../server/McpServer.java | 3 +- .../server/McpStatelessAsyncServer.java | 34 +++++++------- .../server/McpStatelessSyncServer.java | 7 +-- ...HttpServletSseServerTransportProvider.java | 5 ++- .../HttpServletStatelessServerTransport.java | 2 +- ...vletStreamableServerTransportProvider.java | 7 ++- .../StdioServerTransportProvider.java | 7 +-- .../spec/ClosedMcpTransportSession.java | 1 + ...aultMcpStreamableServerSessionFactory.java | 6 +-- .../spec/DefaultMcpTransportSession.java | 11 ++--- .../spec/DefaultMcpTransportStream.java | 11 ++--- .../spec/McpClientSession.java | 17 +++---- .../modelcontextprotocol/spec/McpError.java | 6 +-- .../modelcontextprotocol/spec/McpSchema.java | 6 ++- .../spec/McpServerSession.java | 7 +-- .../spec/McpStreamableServerSession.java | 3 +- .../spec/McpTransport.java | 2 +- .../spec/McpTransportSession.java | 4 +- .../spec/McpTransportStream.java | 5 ++- .../util/KeepAliveScheduler.java | 1 - .../McpUriTemplateManagerTests.java | 5 ++- .../MockMcpClientTransport.java | 1 - .../MockMcpServerTransport.java | 1 - ...AbstractMcpAsyncClientResiliencyTests.java | 33 +++++++------- ...pClientStreamableHttpAsyncClientTests.java | 5 ++- ...tpClientStreamableHttpSyncClientTests.java | 12 ++--- .../client/HttpSseMcpSyncClientTests.java | 14 +++--- ...nitializerPostInitializationHookTests.java | 25 ++++++----- .../client/LifecycleInitializerTests.java | 27 ++++++------ .../McpAsyncClientResponseHandlerTests.java | 19 ++++---- .../client/McpAsyncClientTests.java | 11 ++--- .../client/McpClientProtocolVersionTests.java | 7 +-- .../client/StdioMcpAsyncClientTests.java | 10 ++--- .../client/StdioMcpSyncClientTests.java | 13 +++--- .../HttpClientSseClientTransportTests.java | 39 ++++++++-------- ...HttpClientStreamableHttpTransportTest.java | 24 +++++----- ...pAsyncHttpClientRequestCustomizerTest.java | 17 +++---- ...cpSyncHttpClientRequestCustomizerTest.java | 9 ++-- ...erMcpTransportContextIntegrationTests.java | 17 +++---- ...ttpVersionNegotiationIntegrationTests.java | 15 ++++--- ...erMcpTransportContextIntegrationTests.java | 24 +++++----- .../server/AbstractMcpAsyncServerTests.java | 18 ++++---- ...stractMcpClientServerIntegrationTests.java | 25 ++++++----- .../server/AbstractMcpSyncServerTests.java | 18 ++++---- .../AsyncToolSpecificationBuilderTest.java | 2 +- .../HttpServletSseIntegrationTests.java | 19 ++++---- .../HttpServletStatelessIntegrationTests.java | 44 +++++++++---------- ...HttpServletStreamableIntegrationTests.java | 19 ++++---- .../server/McpAsyncServerExchangeTests.java | 29 ++++++------ .../server/McpCompletionTests.java | 10 ++--- .../server/McpServerProtocolVersionTests.java | 7 +-- .../server/McpSyncServerExchangeTests.java | 27 ++++++------ .../server/ResourceTemplateListingTest.java | 7 +-- .../ResourceTemplateManagementTests.java | 13 +++--- .../server/ServletSseMcpAsyncServerTests.java | 3 +- .../server/ServletSseMcpSyncServerTests.java | 3 +- .../server/StdioMcpAsyncServerTests.java | 7 +-- .../server/StdioMcpSyncServerTests.java | 7 +-- ...ervletSseServerCustomContextPathTests.java | 11 ++--- .../StdioServerTransportProviderTests.java | 23 +++++----- .../server/transport/TomcatTestUtil.java | 5 ++- .../CompleteCompletionSerializationTest.java | 6 ++- .../spec/JSONRPCRequestMcpValidationTest.java | 3 +- .../spec/McpClientSessionTests.java | 9 ++-- .../spec/McpErrorTest.java | 6 +-- .../spec/PromptReferenceEqualsTest.java | 9 ++-- .../spec/json/gson/GsonMcpJsonMapper.java | 7 +-- .../json/gson/GsonMcpJsonMapperTests.java | 15 ++++--- .../util/AssertTests.java | 8 ++-- .../util/KeepAliveSchedulerTests.java | 1 - .../modelcontextprotocol/util/ToolsUtils.java | 4 +- .../modelcontextprotocol/util/UtilsTests.java | 10 ++--- 84 files changed, 477 insertions(+), 429 deletions(-) diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/client/LifecycleInitializer.java b/mcp-core/src/main/java/io/modelcontextprotocol/client/LifecycleInitializer.java index f56c79a6d..2356961c6 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/client/LifecycleInitializer.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/client/LifecycleInitializer.java @@ -11,13 +11,14 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.function.Function; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import io.modelcontextprotocol.spec.McpClientSession; import io.modelcontextprotocol.spec.McpError; import io.modelcontextprotocol.spec.McpSchema; import io.modelcontextprotocol.spec.McpTransportSessionNotFoundException; import io.modelcontextprotocol.util.Assert; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import reactor.core.publisher.Mono; import reactor.core.publisher.Sinks; import reactor.util.context.ContextView; diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/client/McpAsyncClient.java b/mcp-core/src/main/java/io/modelcontextprotocol/client/McpAsyncClient.java index 2d1f4b43c..f1410da33 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/client/McpAsyncClient.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/client/McpAsyncClient.java @@ -15,6 +15,9 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.function.Function; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import io.modelcontextprotocol.client.LifecycleInitializer.Initialization; import io.modelcontextprotocol.json.TypeRef; import io.modelcontextprotocol.json.schema.JsonSchemaValidator; @@ -37,8 +40,6 @@ import io.modelcontextprotocol.spec.McpSchema.Root; import io.modelcontextprotocol.util.Assert; import io.modelcontextprotocol.util.Utils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/HttpClientSseClientTransport.java b/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/HttpClientSseClientTransport.java index ba6964ec1..3f8307b9e 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/HttpClientSseClientTransport.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/HttpClientSseClientTransport.java @@ -18,6 +18,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import io.modelcontextprotocol.client.transport.ResponseSubscribers.ResponseEvent; import io.modelcontextprotocol.client.transport.customizer.McpAsyncHttpClientRequestCustomizer; import io.modelcontextprotocol.client.transport.customizer.McpSyncHttpClientRequestCustomizer; @@ -27,6 +28,7 @@ import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; import io.modelcontextprotocol.spec.HttpHeaders; import io.modelcontextprotocol.spec.McpClientTransport; +import io.modelcontextprotocol.spec.McpError; import io.modelcontextprotocol.spec.McpSchema; import io.modelcontextprotocol.spec.McpSchema.JSONRPCMessage; import io.modelcontextprotocol.spec.McpTransportException; diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/HttpClientStreamableHttpTransport.java b/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/HttpClientStreamableHttpTransport.java index 7fe138ff7..58365106b 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/HttpClientStreamableHttpTransport.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/HttpClientStreamableHttpTransport.java @@ -20,13 +20,17 @@ import java.util.function.Consumer; import java.util.function.Function; +import org.reactivestreams.Publisher; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import io.modelcontextprotocol.client.transport.ResponseSubscribers.ResponseEvent; import io.modelcontextprotocol.client.transport.customizer.McpAsyncHttpClientRequestCustomizer; import io.modelcontextprotocol.client.transport.customizer.McpSyncHttpClientRequestCustomizer; import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.json.McpJsonMapper; -import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; import io.modelcontextprotocol.json.TypeRef; +import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; import io.modelcontextprotocol.spec.ClosedMcpTransportSession; import io.modelcontextprotocol.spec.DefaultMcpTransportSession; import io.modelcontextprotocol.spec.DefaultMcpTransportStream; @@ -40,9 +44,6 @@ import io.modelcontextprotocol.spec.ProtocolVersions; import io.modelcontextprotocol.util.Assert; import io.modelcontextprotocol.util.Utils; -import org.reactivestreams.Publisher; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import reactor.core.Disposable; import reactor.core.publisher.Flux; import reactor.core.publisher.FluxSink; diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/ServerParameters.java b/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/ServerParameters.java index 25a02279f..62929755a 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/ServerParameters.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/ServerParameters.java @@ -13,6 +13,7 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; + import io.modelcontextprotocol.util.Assert; /** diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/StdioClientTransport.java b/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/StdioClientTransport.java index 1b4eaca97..340d81e66 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/StdioClientTransport.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/StdioClientTransport.java @@ -15,14 +15,15 @@ import java.util.function.Consumer; import java.util.function.Function; -import io.modelcontextprotocol.json.TypeRef; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import io.modelcontextprotocol.json.McpJsonMapper; +import io.modelcontextprotocol.json.TypeRef; import io.modelcontextprotocol.spec.McpClientTransport; import io.modelcontextprotocol.spec.McpSchema; import io.modelcontextprotocol.spec.McpSchema.JSONRPCMessage; import io.modelcontextprotocol.util.Assert; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.core.publisher.Sinks; diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/customizer/DelegatingMcpAsyncHttpClientRequestCustomizer.java b/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/customizer/DelegatingMcpAsyncHttpClientRequestCustomizer.java index 2492efe18..b89dbe84f 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/customizer/DelegatingMcpAsyncHttpClientRequestCustomizer.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/customizer/DelegatingMcpAsyncHttpClientRequestCustomizer.java @@ -11,7 +11,6 @@ import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.util.Assert; - import reactor.core.publisher.Mono; /** diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/customizer/McpAsyncHttpClientRequestCustomizer.java b/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/customizer/McpAsyncHttpClientRequestCustomizer.java index 756b39c35..bd197be48 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/customizer/McpAsyncHttpClientRequestCustomizer.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/customizer/McpAsyncHttpClientRequestCustomizer.java @@ -8,12 +8,12 @@ import java.net.http.HttpRequest; import org.reactivestreams.Publisher; + +import io.modelcontextprotocol.common.McpTransportContext; import reactor.core.publisher.Mono; import reactor.core.scheduler.Schedulers; import reactor.util.annotation.Nullable; -import io.modelcontextprotocol.common.McpTransportContext; - /** * Customize {@link HttpRequest.Builder} before executing the request, in either SSE or * Streamable HTTP transport. diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/customizer/McpSyncHttpClientRequestCustomizer.java b/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/customizer/McpSyncHttpClientRequestCustomizer.java index e22e3aa62..03b9ec181 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/customizer/McpSyncHttpClientRequestCustomizer.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/customizer/McpSyncHttpClientRequestCustomizer.java @@ -7,10 +7,9 @@ import java.net.URI; import java.net.http.HttpRequest; -import reactor.util.annotation.Nullable; - import io.modelcontextprotocol.client.McpClient.SyncSpec; import io.modelcontextprotocol.common.McpTransportContext; +import reactor.util.annotation.Nullable; /** * Customize {@link HttpRequest.Builder} before executing the request, either in SSE or diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/server/DefaultMcpStatelessServerHandler.java b/mcp-core/src/main/java/io/modelcontextprotocol/server/DefaultMcpStatelessServerHandler.java index d1b55f594..46b1f600e 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/server/DefaultMcpStatelessServerHandler.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/server/DefaultMcpStatelessServerHandler.java @@ -4,15 +4,16 @@ package io.modelcontextprotocol.server; +import java.util.Map; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.spec.McpError; import io.modelcontextprotocol.spec.McpSchema; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import reactor.core.publisher.Mono; -import java.util.Map; - class DefaultMcpStatelessServerHandler implements McpStatelessServerHandler { private static final Logger logger = LoggerFactory.getLogger(DefaultMcpStatelessServerHandler.class); diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/server/McpAsyncServer.java b/mcp-core/src/main/java/io/modelcontextprotocol/server/McpAsyncServer.java index ac4b36990..3cfe31d58 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/server/McpAsyncServer.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/server/McpAsyncServer.java @@ -4,6 +4,8 @@ package io.modelcontextprotocol.server; +import static io.modelcontextprotocol.spec.McpError.RESOURCE_NOT_FOUND; + import java.time.Duration; import java.util.HashMap; import java.util.List; @@ -14,6 +16,9 @@ import java.util.concurrent.CopyOnWriteArrayList; import java.util.function.BiFunction; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import io.modelcontextprotocol.json.McpJsonMapper; import io.modelcontextprotocol.json.TypeRef; import io.modelcontextprotocol.json.schema.JsonSchemaValidator; @@ -24,7 +29,6 @@ import io.modelcontextprotocol.spec.McpSchema.CallToolResult; import io.modelcontextprotocol.spec.McpSchema.CompleteResult.CompleteCompletion; import io.modelcontextprotocol.spec.McpSchema.ErrorCodes; -import io.modelcontextprotocol.spec.McpSchema.JSONRPCResponse; import io.modelcontextprotocol.spec.McpSchema.LoggingLevel; import io.modelcontextprotocol.spec.McpSchema.LoggingMessageNotification; import io.modelcontextprotocol.spec.McpSchema.PromptReference; @@ -39,13 +43,9 @@ import io.modelcontextprotocol.util.DefaultMcpUriTemplateManagerFactory; import io.modelcontextprotocol.util.McpUriTemplateManagerFactory; import io.modelcontextprotocol.util.Utils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; -import static io.modelcontextprotocol.spec.McpError.RESOURCE_NOT_FOUND; - /** * The Model Context Protocol (MCP) server implementation that provides asynchronous * communication using Project Reactor's Mono and Flux types. diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/server/McpAsyncServerExchange.java b/mcp-core/src/main/java/io/modelcontextprotocol/server/McpAsyncServerExchange.java index a15c58cd5..95e0c35bc 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/server/McpAsyncServerExchange.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/server/McpAsyncServerExchange.java @@ -4,10 +4,10 @@ package io.modelcontextprotocol.server; -import io.modelcontextprotocol.common.McpTransportContext; import java.util.ArrayList; import java.util.Collections; +import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.json.TypeRef; import io.modelcontextprotocol.spec.McpError; import io.modelcontextprotocol.spec.McpLoggableSession; diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/server/McpServer.java b/mcp-core/src/main/java/io/modelcontextprotocol/server/McpServer.java index c88d021fa..284f203c3 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/server/McpServer.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/server/McpServer.java @@ -4,7 +4,6 @@ package io.modelcontextprotocol.server; -import io.modelcontextprotocol.common.McpTransportContext; import java.time.Duration; import java.util.ArrayList; import java.util.Arrays; @@ -14,13 +13,13 @@ import java.util.function.BiConsumer; import java.util.function.BiFunction; +import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.json.McpJsonMapper; import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; import io.modelcontextprotocol.json.internal.DefaultMcpJsonSchemaValidatorSupplier; import io.modelcontextprotocol.json.schema.JsonSchemaValidator; import io.modelcontextprotocol.spec.McpSchema; import io.modelcontextprotocol.spec.McpSchema.CallToolResult; -import io.modelcontextprotocol.spec.McpSchema.ResourceTemplate; import io.modelcontextprotocol.spec.McpServerTransportProvider; import io.modelcontextprotocol.spec.McpStatelessServerTransport; import io.modelcontextprotocol.spec.McpStreamableServerTransportProvider; diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/server/McpStatelessAsyncServer.java b/mcp-core/src/main/java/io/modelcontextprotocol/server/McpStatelessAsyncServer.java index 997df7225..8d278d613 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/server/McpStatelessAsyncServer.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/server/McpStatelessAsyncServer.java @@ -4,9 +4,24 @@ package io.modelcontextprotocol.server; -import io.modelcontextprotocol.json.TypeRef; -import io.modelcontextprotocol.json.McpJsonMapper; +import static io.modelcontextprotocol.spec.McpError.RESOURCE_NOT_FOUND; + +import java.time.Duration; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.function.BiFunction; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import io.modelcontextprotocol.common.McpTransportContext; +import io.modelcontextprotocol.json.McpJsonMapper; +import io.modelcontextprotocol.json.TypeRef; import io.modelcontextprotocol.json.schema.JsonSchemaValidator; import io.modelcontextprotocol.server.McpStatelessServerFeatures.AsyncResourceTemplateSpecification; import io.modelcontextprotocol.spec.McpError; @@ -14,7 +29,6 @@ import io.modelcontextprotocol.spec.McpSchema.CallToolResult; import io.modelcontextprotocol.spec.McpSchema.CompleteResult.CompleteCompletion; import io.modelcontextprotocol.spec.McpSchema.ErrorCodes; -import io.modelcontextprotocol.spec.McpSchema.JSONRPCResponse; import io.modelcontextprotocol.spec.McpSchema.PromptReference; import io.modelcontextprotocol.spec.McpSchema.ResourceReference; import io.modelcontextprotocol.spec.McpSchema.Tool; @@ -23,23 +37,9 @@ import io.modelcontextprotocol.util.DefaultMcpUriTemplateManagerFactory; import io.modelcontextprotocol.util.McpUriTemplateManagerFactory; import io.modelcontextprotocol.util.Utils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; -import java.time.Duration; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.CopyOnWriteArrayList; -import java.util.function.BiFunction; - -import static io.modelcontextprotocol.spec.McpError.RESOURCE_NOT_FOUND; - /** * A stateless MCP server implementation for use with Streamable HTTP transport types. It * allows simple horizontal scalability since it does not maintain a session and does not diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/server/McpStatelessSyncServer.java b/mcp-core/src/main/java/io/modelcontextprotocol/server/McpStatelessSyncServer.java index 6849eb8ed..17d66a3d5 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/server/McpStatelessSyncServer.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/server/McpStatelessSyncServer.java @@ -4,12 +4,13 @@ package io.modelcontextprotocol.server; -import io.modelcontextprotocol.spec.McpSchema; +import java.util.List; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import reactor.core.publisher.Mono; -import java.util.List; +import io.modelcontextprotocol.spec.McpSchema; +import reactor.core.publisher.Mono; /** * A stateless MCP server implementation for use with Streamable HTTP transport types. It diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletSseServerTransportProvider.java b/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletSseServerTransportProvider.java index 2bfc3d2e2..fe5842953 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletSseServerTransportProvider.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletSseServerTransportProvider.java @@ -14,6 +14,9 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicBoolean; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.json.McpJsonMapper; import io.modelcontextprotocol.json.TypeRef; @@ -33,8 +36,6 @@ import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletStatelessServerTransport.java b/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletStatelessServerTransport.java index 6e8a1c2f8..a4449615d 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletStatelessServerTransport.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletStatelessServerTransport.java @@ -11,9 +11,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.json.McpJsonMapper; import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; -import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.server.McpStatelessServerHandler; import io.modelcontextprotocol.server.McpTransportContextExtractor; import io.modelcontextprotocol.spec.McpError; diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletStreamableServerTransportProvider.java b/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletStreamableServerTransportProvider.java index 714d65bde..fb30f0005 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletStreamableServerTransportProvider.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletStreamableServerTransportProvider.java @@ -16,9 +16,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import io.modelcontextprotocol.json.TypeRef; - import io.modelcontextprotocol.common.McpTransportContext; +import io.modelcontextprotocol.json.McpJsonMapper; +import io.modelcontextprotocol.json.TypeRef; +import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; import io.modelcontextprotocol.server.McpTransportContextExtractor; import io.modelcontextprotocol.spec.HttpHeaders; import io.modelcontextprotocol.spec.McpError; @@ -28,8 +29,6 @@ import io.modelcontextprotocol.spec.McpStreamableServerTransportProvider; import io.modelcontextprotocol.spec.ProtocolVersions; import io.modelcontextprotocol.util.Assert; -import io.modelcontextprotocol.json.McpJsonMapper; -import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; import io.modelcontextprotocol.util.KeepAliveScheduler; import jakarta.servlet.AsyncContext; import jakarta.servlet.ServletException; diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/StdioServerTransportProvider.java b/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/StdioServerTransportProvider.java index 68be62931..eb2a143d3 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/StdioServerTransportProvider.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/StdioServerTransportProvider.java @@ -15,6 +15,10 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Function; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import io.modelcontextprotocol.json.McpJsonMapper; import io.modelcontextprotocol.json.TypeRef; import io.modelcontextprotocol.spec.McpError; import io.modelcontextprotocol.spec.McpSchema; @@ -24,9 +28,6 @@ import io.modelcontextprotocol.spec.McpServerTransportProvider; import io.modelcontextprotocol.spec.ProtocolVersions; import io.modelcontextprotocol.util.Assert; -import io.modelcontextprotocol.json.McpJsonMapper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.core.publisher.Sinks; diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/spec/ClosedMcpTransportSession.java b/mcp-core/src/main/java/io/modelcontextprotocol/spec/ClosedMcpTransportSession.java index b18364abb..212ba82f9 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/spec/ClosedMcpTransportSession.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/spec/ClosedMcpTransportSession.java @@ -6,6 +6,7 @@ import java.util.Optional; import org.reactivestreams.Publisher; + import reactor.core.publisher.Mono; import reactor.util.annotation.Nullable; diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/spec/DefaultMcpStreamableServerSessionFactory.java b/mcp-core/src/main/java/io/modelcontextprotocol/spec/DefaultMcpStreamableServerSessionFactory.java index f497afd43..1892c48f7 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/spec/DefaultMcpStreamableServerSessionFactory.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/spec/DefaultMcpStreamableServerSessionFactory.java @@ -4,13 +4,13 @@ package io.modelcontextprotocol.spec; -import io.modelcontextprotocol.server.McpNotificationHandler; -import io.modelcontextprotocol.server.McpRequestHandler; - import java.time.Duration; import java.util.Map; import java.util.UUID; +import io.modelcontextprotocol.server.McpNotificationHandler; +import io.modelcontextprotocol.server.McpRequestHandler; + /** * A default implementation of {@link McpStreamableServerSession.Factory}. * diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/spec/DefaultMcpTransportSession.java b/mcp-core/src/main/java/io/modelcontextprotocol/spec/DefaultMcpTransportSession.java index fdb7bfd89..d3f6b9a2f 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/spec/DefaultMcpTransportSession.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/spec/DefaultMcpTransportSession.java @@ -4,18 +4,19 @@ package io.modelcontextprotocol.spec; +import java.util.Optional; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Function; + import org.reactivestreams.Publisher; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import reactor.core.Disposable; import reactor.core.Disposables; import reactor.core.publisher.Mono; -import java.util.Optional; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicReference; -import java.util.function.Function; - /** * Default implementation of {@link McpTransportSession} which manages the open * connections using tye {@link Disposable} type and allows to perform clean up using the diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/spec/DefaultMcpTransportStream.java b/mcp-core/src/main/java/io/modelcontextprotocol/spec/DefaultMcpTransportStream.java index 8d63fb50d..6db8eabfe 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/spec/DefaultMcpTransportStream.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/spec/DefaultMcpTransportStream.java @@ -4,18 +4,19 @@ package io.modelcontextprotocol.spec; +import java.util.Optional; +import java.util.concurrent.atomic.AtomicLong; +import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Function; + import org.reactivestreams.Publisher; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.util.function.Tuple2; -import java.util.Optional; -import java.util.concurrent.atomic.AtomicLong; -import java.util.concurrent.atomic.AtomicReference; -import java.util.function.Function; - /** * An implementation of {@link McpTransportStream} using Project Reactor types. * diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpClientSession.java b/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpClientSession.java index 0ba7ab3b8..70bd46df3 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpClientSession.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpClientSession.java @@ -4,14 +4,6 @@ package io.modelcontextprotocol.spec; -import io.modelcontextprotocol.json.TypeRef; -import io.modelcontextprotocol.util.Assert; -import org.reactivestreams.Publisher; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import reactor.core.publisher.Mono; -import reactor.core.publisher.MonoSink; - import java.time.Duration; import java.util.Map; import java.util.UUID; @@ -19,6 +11,15 @@ import java.util.concurrent.atomic.AtomicLong; import java.util.function.Function; +import org.reactivestreams.Publisher; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import io.modelcontextprotocol.json.TypeRef; +import io.modelcontextprotocol.util.Assert; +import reactor.core.publisher.Mono; +import reactor.core.publisher.MonoSink; + /** * Default implementation of the MCP (Model Context Protocol) session that manages * bidirectional JSON-RPC communication between clients and servers. This implementation diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpError.java b/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpError.java index d6e549fdc..2492e8992 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpError.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpError.java @@ -4,12 +4,12 @@ package io.modelcontextprotocol.spec; -import io.modelcontextprotocol.spec.McpSchema.JSONRPCResponse.JSONRPCError; -import io.modelcontextprotocol.util.Assert; - import java.util.Map; import java.util.function.Function; +import io.modelcontextprotocol.spec.McpSchema.JSONRPCResponse.JSONRPCError; +import io.modelcontextprotocol.util.Assert; + public class McpError extends RuntimeException { /** diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpSchema.java b/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpSchema.java index 342fc5347..535241e7d 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpSchema.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpSchema.java @@ -11,17 +11,19 @@ import java.util.List; import java.util.Map; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; + import io.modelcontextprotocol.json.McpJsonMapper; import io.modelcontextprotocol.json.TypeRef; import io.modelcontextprotocol.util.Assert; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * Based on the JSON-RPC 2.0 diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpServerSession.java b/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpServerSession.java index 241f7d8b5..584086143 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpServerSession.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpServerSession.java @@ -11,15 +11,16 @@ import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicReference; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import io.modelcontextprotocol.common.McpTransportContext; +import io.modelcontextprotocol.json.TypeRef; import io.modelcontextprotocol.server.McpAsyncServerExchange; import io.modelcontextprotocol.server.McpInitRequestHandler; import io.modelcontextprotocol.server.McpNotificationHandler; import io.modelcontextprotocol.server.McpRequestHandler; -import io.modelcontextprotocol.json.TypeRef; import io.modelcontextprotocol.util.Assert; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import reactor.core.publisher.Mono; import reactor.core.publisher.MonoSink; import reactor.core.publisher.Sinks; diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpStreamableServerSession.java b/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpStreamableServerSession.java index 95f8959f5..cdc251208 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpStreamableServerSession.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpStreamableServerSession.java @@ -15,9 +15,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import io.modelcontextprotocol.json.TypeRef; - import io.modelcontextprotocol.common.McpTransportContext; +import io.modelcontextprotocol.json.TypeRef; import io.modelcontextprotocol.server.McpAsyncServerExchange; import io.modelcontextprotocol.server.McpNotificationHandler; import io.modelcontextprotocol.server.McpRequestHandler; diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpTransport.java b/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpTransport.java index 0a732bab6..140039685 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpTransport.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpTransport.java @@ -6,8 +6,8 @@ import java.util.List; -import io.modelcontextprotocol.spec.McpSchema.JSONRPCMessage; import io.modelcontextprotocol.json.TypeRef; +import io.modelcontextprotocol.spec.McpSchema.JSONRPCMessage; import reactor.core.publisher.Mono; /** diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpTransportSession.java b/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpTransportSession.java index 716ff0d16..68f0fc5bb 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpTransportSession.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpTransportSession.java @@ -4,10 +4,10 @@ package io.modelcontextprotocol.spec; -import org.reactivestreams.Publisher; - import java.util.Optional; +import org.reactivestreams.Publisher; + /** * An abstraction of the session as perceived from the MCP transport layer. Not to be * confused with the {@link McpSession} type that operates at the level of the JSON-RPC diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpTransportStream.java b/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpTransportStream.java index 322afda63..7b1d834d0 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpTransportStream.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpTransportStream.java @@ -4,10 +4,11 @@ package io.modelcontextprotocol.spec; +import java.util.Optional; + import org.reactivestreams.Publisher; -import reactor.util.function.Tuple2; -import java.util.Optional; +import reactor.util.function.Tuple2; /** * A representation of a stream at the transport layer of the MCP protocol. In particular, diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/util/KeepAliveScheduler.java b/mcp-core/src/main/java/io/modelcontextprotocol/util/KeepAliveScheduler.java index 6d53ed516..658eb2fc3 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/util/KeepAliveScheduler.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/util/KeepAliveScheduler.java @@ -12,7 +12,6 @@ import org.slf4j.LoggerFactory; import io.modelcontextprotocol.json.TypeRef; - import io.modelcontextprotocol.spec.McpSchema; import io.modelcontextprotocol.spec.McpSession; import reactor.core.Disposable; diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/McpUriTemplateManagerTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/McpUriTemplateManagerTests.java index 8f68f0d6e..fb467601c 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/McpUriTemplateManagerTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/McpUriTemplateManagerTests.java @@ -12,11 +12,12 @@ import java.util.List; import java.util.Map; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + import io.modelcontextprotocol.util.DefaultMcpUriTemplateManagerFactory; import io.modelcontextprotocol.util.McpUriTemplateManager; import io.modelcontextprotocol.util.McpUriTemplateManagerFactory; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; /** * Tests for {@link McpUriTemplateManager} and its implementations. diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/MockMcpClientTransport.java b/mcp-core/src/test/java/io/modelcontextprotocol/MockMcpClientTransport.java index 77d91b5bc..2f8e4601c 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/MockMcpClientTransport.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/MockMcpClientTransport.java @@ -9,7 +9,6 @@ import java.util.function.BiConsumer; import java.util.function.Function; -import io.modelcontextprotocol.json.McpJsonMapper; import io.modelcontextprotocol.json.TypeRef; import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; import io.modelcontextprotocol.spec.McpClientTransport; diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/MockMcpServerTransport.java b/mcp-core/src/test/java/io/modelcontextprotocol/MockMcpServerTransport.java index 8da486d1d..7231ad45d 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/MockMcpServerTransport.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/MockMcpServerTransport.java @@ -8,7 +8,6 @@ import java.util.List; import java.util.function.BiConsumer; -import io.modelcontextprotocol.json.McpJsonMapper; import io.modelcontextprotocol.json.TypeRef; import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; import io.modelcontextprotocol.spec.McpSchema; diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/client/AbstractMcpAsyncClientResiliencyTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/client/AbstractMcpAsyncClientResiliencyTests.java index 183b8a365..cb74d6f50 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/client/AbstractMcpAsyncClientResiliencyTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/client/AbstractMcpAsyncClientResiliencyTests.java @@ -4,21 +4,7 @@ package io.modelcontextprotocol.client; -import eu.rekawek.toxiproxy.Proxy; -import eu.rekawek.toxiproxy.ToxiproxyClient; -import eu.rekawek.toxiproxy.model.ToxicDirection; -import io.modelcontextprotocol.spec.McpClientTransport; -import io.modelcontextprotocol.spec.McpSchema; -import io.modelcontextprotocol.spec.McpTransport; -import io.modelcontextprotocol.spec.McpTransportSessionClosedException; -import org.junit.jupiter.api.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testcontainers.containers.GenericContainer; -import org.testcontainers.containers.Network; -import org.testcontainers.containers.ToxiproxyContainer; -import org.testcontainers.containers.wait.strategy.Wait; -import reactor.test.StepVerifier; +import static org.assertj.core.api.Assertions.assertThatCode; import java.io.IOException; import java.time.Duration; @@ -28,7 +14,22 @@ import java.util.function.Consumer; import java.util.function.Function; -import static org.assertj.core.api.Assertions.assertThatCode; +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.Network; +import org.testcontainers.containers.ToxiproxyContainer; +import org.testcontainers.containers.wait.strategy.Wait; + +import eu.rekawek.toxiproxy.Proxy; +import eu.rekawek.toxiproxy.ToxiproxyClient; +import eu.rekawek.toxiproxy.model.ToxicDirection; +import io.modelcontextprotocol.spec.McpClientTransport; +import io.modelcontextprotocol.spec.McpSchema; +import io.modelcontextprotocol.spec.McpTransport; +import io.modelcontextprotocol.spec.McpTransportSessionClosedException; +import reactor.test.StepVerifier; /** * Resiliency test suite for the {@link McpAsyncClient} that can be used with different diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/client/HttpClientStreamableHttpAsyncClientTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/client/HttpClientStreamableHttpAsyncClientTests.java index c4157bc37..1e015ca5e 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/client/HttpClientStreamableHttpAsyncClientTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/client/HttpClientStreamableHttpAsyncClientTests.java @@ -4,14 +4,15 @@ package io.modelcontextprotocol.client; -import io.modelcontextprotocol.client.transport.HttpClientStreamableHttpTransport; -import io.modelcontextprotocol.spec.McpClientTransport; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Timeout; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.wait.strategy.Wait; +import io.modelcontextprotocol.client.transport.HttpClientStreamableHttpTransport; +import io.modelcontextprotocol.spec.McpClientTransport; + @Timeout(15) public class HttpClientStreamableHttpAsyncClientTests extends AbstractMcpAsyncClientTests { diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/client/HttpClientStreamableHttpSyncClientTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/client/HttpClientStreamableHttpSyncClientTests.java index d59ae35b4..d7b8c0121 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/client/HttpClientStreamableHttpSyncClientTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/client/HttpClientStreamableHttpSyncClientTests.java @@ -4,6 +4,12 @@ package io.modelcontextprotocol.client; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.atLeastOnce; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + import java.net.URI; import java.util.Map; @@ -19,12 +25,6 @@ import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.spec.McpClientTransport; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.atLeastOnce; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; - @Timeout(15) public class HttpClientStreamableHttpSyncClientTests extends AbstractMcpSyncClientTests { diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/client/HttpSseMcpSyncClientTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/client/HttpSseMcpSyncClientTests.java index 483d38669..672c4f64c 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/client/HttpSseMcpSyncClientTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/client/HttpSseMcpSyncClientTests.java @@ -4,6 +4,13 @@ package io.modelcontextprotocol.client; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isNull; +import static org.mockito.Mockito.atLeastOnce; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + import java.net.URI; import java.util.Map; @@ -19,13 +26,6 @@ import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.spec.McpClientTransport; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.ArgumentMatchers.isNull; -import static org.mockito.Mockito.atLeastOnce; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; - /** * Tests for the {@link McpSyncClient} with {@link HttpClientSseClientTransport}. * diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/client/LifecycleInitializerPostInitializationHookTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/client/LifecycleInitializerPostInitializationHookTests.java index 6f7390f19..6bb4915b4 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/client/LifecycleInitializerPostInitializationHookTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/client/LifecycleInitializerPostInitializationHookTests.java @@ -4,33 +4,34 @@ package io.modelcontextprotocol.client; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + import java.time.Duration; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Function; -import io.modelcontextprotocol.client.LifecycleInitializer.Initialization; -import io.modelcontextprotocol.spec.McpClientSession; -import io.modelcontextprotocol.spec.McpSchema; -import io.modelcontextprotocol.spec.McpTransportSessionNotFoundException; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; + +import io.modelcontextprotocol.client.LifecycleInitializer.Initialization; +import io.modelcontextprotocol.spec.McpClientSession; +import io.modelcontextprotocol.spec.McpSchema; +import io.modelcontextprotocol.spec.McpTransportSessionNotFoundException; import reactor.core.publisher.Mono; import reactor.core.scheduler.Schedulers; import reactor.test.StepVerifier; import reactor.util.context.ContextView; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - /** * Tests for {@link LifecycleInitializer} postInitializationHook functionality. * diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/client/LifecycleInitializerTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/client/LifecycleInitializerTests.java index 787ee9480..fd9837207 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/client/LifecycleInitializerTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/client/LifecycleInitializerTests.java @@ -4,20 +4,30 @@ package io.modelcontextprotocol.client; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + import java.time.Duration; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Function; -import io.modelcontextprotocol.client.LifecycleInitializer.Initialization; -import io.modelcontextprotocol.spec.McpClientSession; -import io.modelcontextprotocol.spec.McpSchema; -import io.modelcontextprotocol.spec.McpTransportSessionNotFoundException; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; + +import io.modelcontextprotocol.client.LifecycleInitializer.Initialization; +import io.modelcontextprotocol.spec.McpClientSession; +import io.modelcontextprotocol.spec.McpSchema; +import io.modelcontextprotocol.spec.McpTransportSessionNotFoundException; import reactor.core.publisher.Mono; import reactor.core.scheduler.Schedulers; import reactor.test.StepVerifier; @@ -25,15 +35,6 @@ import reactor.util.context.Context; import reactor.util.context.ContextView; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - /** * Tests for {@link LifecycleInitializer}. */ diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/client/McpAsyncClientResponseHandlerTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/client/McpAsyncClientResponseHandlerTests.java index 612a65898..1bd1c4b6b 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/client/McpAsyncClientResponseHandlerTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/client/McpAsyncClientResponseHandlerTests.java @@ -4,29 +4,30 @@ package io.modelcontextprotocol.client; +import static io.modelcontextprotocol.spec.McpSchema.METHOD_INITIALIZE; +import static io.modelcontextprotocol.util.McpJsonMapperUtils.JSON_MAPPER; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.function.Function; -import io.modelcontextprotocol.json.TypeRef; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; + import io.modelcontextprotocol.MockMcpClientTransport; +import io.modelcontextprotocol.json.TypeRef; import io.modelcontextprotocol.spec.McpSchema; import io.modelcontextprotocol.spec.McpSchema.ClientCapabilities; import io.modelcontextprotocol.spec.McpSchema.InitializeResult; import io.modelcontextprotocol.spec.McpSchema.PaginatedRequest; import io.modelcontextprotocol.spec.McpSchema.Root; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.EnumSource; import reactor.core.publisher.Mono; -import static io.modelcontextprotocol.spec.McpSchema.METHOD_INITIALIZE; -import static io.modelcontextprotocol.util.McpJsonMapperUtils.JSON_MAPPER; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - class McpAsyncClientResponseHandlerTests { private static final McpSchema.Implementation SERVER_INFO = new McpSchema.Implementation("test-server", "1.0.0"); diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/client/McpAsyncClientTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/client/McpAsyncClientTests.java index 48bf1da5b..6a306ead2 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/client/McpAsyncClientTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/client/McpAsyncClientTests.java @@ -4,6 +4,10 @@ package io.modelcontextprotocol.client; +import static io.modelcontextprotocol.util.McpJsonMapperUtils.JSON_MAPPER; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatCode; + import java.util.List; import java.util.Map; import java.util.Objects; @@ -12,18 +16,15 @@ import java.util.function.Function; import java.util.stream.Collectors; +import org.junit.jupiter.api.Test; + import io.modelcontextprotocol.json.TypeRef; import io.modelcontextprotocol.spec.McpClientTransport; import io.modelcontextprotocol.spec.McpSchema; import io.modelcontextprotocol.spec.ProtocolVersions; -import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import static io.modelcontextprotocol.util.McpJsonMapperUtils.JSON_MAPPER; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatCode; - class McpAsyncClientTests { public static final McpSchema.Implementation MOCK_SERVER_INFO = new McpSchema.Implementation("test-server", diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/client/McpClientProtocolVersionTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/client/McpClientProtocolVersionTests.java index a94b9b6a7..42c98418a 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/client/McpClientProtocolVersionTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/client/McpClientProtocolVersionTests.java @@ -4,19 +4,20 @@ package io.modelcontextprotocol.client; +import static org.assertj.core.api.Assertions.assertThat; + import java.time.Duration; import java.util.List; +import org.junit.jupiter.api.Test; + import io.modelcontextprotocol.MockMcpClientTransport; import io.modelcontextprotocol.spec.McpSchema; import io.modelcontextprotocol.spec.McpSchema.InitializeResult; import io.modelcontextprotocol.spec.McpSchema.ServerCapabilities; -import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import static org.assertj.core.api.Assertions.assertThat; - /** * Tests for MCP protocol version negotiation and compatibility. */ diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/client/StdioMcpAsyncClientTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/client/StdioMcpAsyncClientTests.java index aa8aaa397..751e2a57c 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/client/StdioMcpAsyncClientTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/client/StdioMcpAsyncClientTests.java @@ -4,15 +4,15 @@ package io.modelcontextprotocol.client; +import static io.modelcontextprotocol.client.ServerParameterUtils.createServerParameters; +import static io.modelcontextprotocol.util.McpJsonMapperUtils.JSON_MAPPER; + import java.time.Duration; -import io.modelcontextprotocol.client.transport.ServerParameters; -import io.modelcontextprotocol.client.transport.StdioClientTransport; -import io.modelcontextprotocol.spec.McpClientTransport; import org.junit.jupiter.api.Timeout; -import static io.modelcontextprotocol.client.ServerParameterUtils.createServerParameters; -import static io.modelcontextprotocol.util.McpJsonMapperUtils.JSON_MAPPER; +import io.modelcontextprotocol.client.transport.StdioClientTransport; +import io.modelcontextprotocol.spec.McpClientTransport; /** * Tests for the {@link McpAsyncClient} with {@link StdioClientTransport}. diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/client/StdioMcpSyncClientTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/client/StdioMcpSyncClientTests.java index b1e567989..7087b2d3c 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/client/StdioMcpSyncClientTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/client/StdioMcpSyncClientTests.java @@ -4,23 +4,24 @@ package io.modelcontextprotocol.client; +import static io.modelcontextprotocol.client.ServerParameterUtils.createServerParameters; +import static io.modelcontextprotocol.util.McpJsonMapperUtils.JSON_MAPPER; +import static org.assertj.core.api.Assertions.assertThat; + import java.time.Duration; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; + import io.modelcontextprotocol.client.transport.ServerParameters; import io.modelcontextprotocol.client.transport.StdioClientTransport; import io.modelcontextprotocol.spec.McpClientTransport; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.Timeout; import reactor.core.publisher.Sinks; import reactor.test.StepVerifier; -import static io.modelcontextprotocol.client.ServerParameterUtils.createServerParameters; -import static io.modelcontextprotocol.util.McpJsonMapperUtils.JSON_MAPPER; -import static org.assertj.core.api.Assertions.assertThat; - /** * Tests for the {@link McpSyncClient} with {@link StdioClientTransport}. * diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/client/transport/HttpClientSseClientTransportTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/client/transport/HttpClientSseClientTransportTests.java index c5c365798..71ade20ef 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/client/transport/HttpClientSseClientTransportTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/client/transport/HttpClientSseClientTransportTests.java @@ -4,6 +4,17 @@ package io.modelcontextprotocol.client.transport; +import static io.modelcontextprotocol.util.McpJsonMapperUtils.JSON_MAPPER; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatCode; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isNull; +import static org.mockito.Mockito.clearInvocations; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; @@ -14,12 +25,6 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.function.Function; -import io.modelcontextprotocol.client.transport.customizer.McpAsyncHttpClientRequestCustomizer; -import io.modelcontextprotocol.client.transport.customizer.McpSyncHttpClientRequestCustomizer; -import io.modelcontextprotocol.common.McpTransportContext; -import io.modelcontextprotocol.spec.McpSchema; -import io.modelcontextprotocol.spec.McpSchema.JSONRPCRequest; - import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; @@ -27,26 +32,20 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; import org.mockito.ArgumentCaptor; +import org.springframework.http.codec.ServerSentEvent; +import org.springframework.web.util.UriComponentsBuilder; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.wait.strategy.Wait; + +import io.modelcontextprotocol.client.transport.customizer.McpAsyncHttpClientRequestCustomizer; +import io.modelcontextprotocol.client.transport.customizer.McpSyncHttpClientRequestCustomizer; +import io.modelcontextprotocol.common.McpTransportContext; +import io.modelcontextprotocol.spec.McpSchema; +import io.modelcontextprotocol.spec.McpSchema.JSONRPCRequest; import reactor.core.publisher.Mono; import reactor.core.publisher.Sinks; import reactor.test.StepVerifier; -import org.springframework.http.codec.ServerSentEvent; -import org.springframework.web.util.UriComponentsBuilder; - -import static io.modelcontextprotocol.util.McpJsonMapperUtils.JSON_MAPPER; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatCode; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.ArgumentMatchers.isNull; -import static org.mockito.Mockito.clearInvocations; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - /** * Tests for the {@link HttpClientSseClientTransport} class. * diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/client/transport/HttpClientStreamableHttpTransportTest.java b/mcp-core/src/test/java/io/modelcontextprotocol/client/transport/HttpClientStreamableHttpTransportTest.java index f9536b690..ef0d7ecc8 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/client/transport/HttpClientStreamableHttpTransportTest.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/client/transport/HttpClientStreamableHttpTransportTest.java @@ -4,29 +4,31 @@ package io.modelcontextprotocol.client.transport; -import io.modelcontextprotocol.client.transport.customizer.McpAsyncHttpClientRequestCustomizer; -import io.modelcontextprotocol.client.transport.customizer.McpSyncHttpClientRequestCustomizer; -import io.modelcontextprotocol.common.McpTransportContext; -import io.modelcontextprotocol.spec.McpSchema; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.atLeastOnce; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + import java.net.URI; import java.net.URISyntaxException; import java.util.Map; import java.util.function.Consumer; + import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.wait.strategy.Wait; + +import io.modelcontextprotocol.client.transport.customizer.McpAsyncHttpClientRequestCustomizer; +import io.modelcontextprotocol.client.transport.customizer.McpSyncHttpClientRequestCustomizer; +import io.modelcontextprotocol.common.McpTransportContext; +import io.modelcontextprotocol.spec.McpSchema; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.atLeastOnce; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - /** * Tests for the {@link HttpClientStreamableHttpTransport} class. * diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/client/transport/customizer/DelegatingMcpAsyncHttpClientRequestCustomizerTest.java b/mcp-core/src/test/java/io/modelcontextprotocol/client/transport/customizer/DelegatingMcpAsyncHttpClientRequestCustomizerTest.java index a04787aa3..f47d02a66 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/client/transport/customizer/DelegatingMcpAsyncHttpClientRequestCustomizerTest.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/client/transport/customizer/DelegatingMcpAsyncHttpClientRequestCustomizerTest.java @@ -4,20 +4,21 @@ package io.modelcontextprotocol.client.transport.customizer; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + import java.net.URI; import java.net.http.HttpRequest; import java.util.List; + import org.junit.jupiter.api.Test; -import reactor.core.publisher.Mono; -import reactor.test.StepVerifier; import io.modelcontextprotocol.common.McpTransportContext; - -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import reactor.core.publisher.Mono; +import reactor.test.StepVerifier; /** * Tests for {@link DelegatingMcpAsyncHttpClientRequestCustomizer}. diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/client/transport/customizer/DelegatingMcpSyncHttpClientRequestCustomizerTest.java b/mcp-core/src/test/java/io/modelcontextprotocol/client/transport/customizer/DelegatingMcpSyncHttpClientRequestCustomizerTest.java index 6c51a3d12..f48167550 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/client/transport/customizer/DelegatingMcpSyncHttpClientRequestCustomizerTest.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/client/transport/customizer/DelegatingMcpSyncHttpClientRequestCustomizerTest.java @@ -4,18 +4,19 @@ package io.modelcontextprotocol.client.transport.customizer; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.Mockito.verify; + import java.net.URI; import java.net.http.HttpRequest; import java.util.List; + import org.junit.jupiter.api.Test; import org.mockito.Mockito; import io.modelcontextprotocol.common.McpTransportContext; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.Mockito.verify; - /** * Tests for {@link DelegatingMcpSyncHttpClientRequestCustomizer}. * diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/common/AsyncServerMcpTransportContextIntegrationTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/common/AsyncServerMcpTransportContextIntegrationTests.java index 8b2dea462..600f93491 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/common/AsyncServerMcpTransportContextIntegrationTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/common/AsyncServerMcpTransportContextIntegrationTests.java @@ -4,9 +4,18 @@ package io.modelcontextprotocol.common; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.Map; import java.util.function.BiFunction; +import org.apache.catalina.LifecycleException; +import org.apache.catalina.LifecycleState; +import org.apache.catalina.startup.Tomcat; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; + import io.modelcontextprotocol.client.McpAsyncClient; import io.modelcontextprotocol.client.McpClient; import io.modelcontextprotocol.client.transport.HttpClientSseClientTransport; @@ -25,17 +34,9 @@ import io.modelcontextprotocol.spec.McpSchema; import jakarta.servlet.Servlet; import jakarta.servlet.http.HttpServletRequest; -import org.apache.catalina.LifecycleException; -import org.apache.catalina.LifecycleState; -import org.apache.catalina.startup.Tomcat; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.Timeout; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import static org.assertj.core.api.Assertions.assertThat; - /** * Integration tests for {@link McpTransportContext} propagation between MCP clients and * async servers. diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/common/HttpClientStreamableHttpVersionNegotiationIntegrationTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/common/HttpClientStreamableHttpVersionNegotiationIntegrationTests.java index 12a3ef9c6..547e9af87 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/common/HttpClientStreamableHttpVersionNegotiationIntegrationTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/common/HttpClientStreamableHttpVersionNegotiationIntegrationTests.java @@ -4,10 +4,18 @@ package io.modelcontextprotocol.common; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.List; import java.util.Map; import java.util.function.BiFunction; +import org.apache.catalina.LifecycleException; +import org.apache.catalina.LifecycleState; +import org.apache.catalina.startup.Tomcat; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; + import io.modelcontextprotocol.client.McpClient; import io.modelcontextprotocol.client.transport.HttpClientStreamableHttpTransport; import io.modelcontextprotocol.server.McpServer; @@ -19,13 +27,6 @@ import io.modelcontextprotocol.server.transport.TomcatTestUtil; import io.modelcontextprotocol.spec.McpSchema; import io.modelcontextprotocol.spec.ProtocolVersions; -import org.apache.catalina.LifecycleException; -import org.apache.catalina.LifecycleState; -import org.apache.catalina.startup.Tomcat; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; class HttpClientStreamableHttpVersionNegotiationIntegrationTests { diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/common/SyncServerMcpTransportContextIntegrationTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/common/SyncServerMcpTransportContextIntegrationTests.java index cc8f4c4be..eaede29ad 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/common/SyncServerMcpTransportContextIntegrationTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/common/SyncServerMcpTransportContextIntegrationTests.java @@ -4,6 +4,19 @@ package io.modelcontextprotocol.common; +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.Map; +import java.util.function.BiFunction; +import java.util.function.Supplier; + +import org.apache.catalina.LifecycleException; +import org.apache.catalina.LifecycleState; +import org.apache.catalina.startup.Tomcat; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; + import io.modelcontextprotocol.client.McpClient; import io.modelcontextprotocol.client.McpClient.SyncSpec; import io.modelcontextprotocol.client.McpSyncClient; @@ -22,17 +35,6 @@ import io.modelcontextprotocol.spec.McpSchema; import jakarta.servlet.Servlet; import jakarta.servlet.http.HttpServletRequest; -import java.util.Map; -import java.util.function.BiFunction; -import java.util.function.Supplier; -import org.apache.catalina.LifecycleException; -import org.apache.catalina.LifecycleState; -import org.apache.catalina.startup.Tomcat; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.Timeout; - -import static org.assertj.core.api.Assertions.assertThat; /** * Test both Client and Server {@link McpTransportContext} integration, in two steps. diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/server/AbstractMcpAsyncServerTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/server/AbstractMcpAsyncServerTests.java index aa68203dd..8febcd45f 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/server/AbstractMcpAsyncServerTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/server/AbstractMcpAsyncServerTests.java @@ -4,10 +4,18 @@ package io.modelcontextprotocol.server; +import static io.modelcontextprotocol.util.ToolsUtils.EMPTY_JSON_SCHEMA; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatCode; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + import java.time.Duration; import java.util.List; -import io.modelcontextprotocol.spec.McpError; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + import io.modelcontextprotocol.spec.McpSchema; import io.modelcontextprotocol.spec.McpSchema.CallToolResult; import io.modelcontextprotocol.spec.McpSchema.GetPromptResult; @@ -18,17 +26,9 @@ import io.modelcontextprotocol.spec.McpSchema.ServerCapabilities; import io.modelcontextprotocol.spec.McpSchema.Tool; import io.modelcontextprotocol.spec.McpServerTransportProvider; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import static io.modelcontextprotocol.util.ToolsUtils.EMPTY_JSON_SCHEMA; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatCode; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - /** * Test suite for the {@link McpAsyncServer} that can be used with different * {@link io.modelcontextprotocol.spec.McpServerTransportProvider} implementations. diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/server/AbstractMcpClientServerIntegrationTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/server/AbstractMcpClientServerIntegrationTests.java index 603324631..41a378ae9 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/server/AbstractMcpClientServerIntegrationTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/server/AbstractMcpClientServerIntegrationTests.java @@ -4,6 +4,15 @@ package io.modelcontextprotocol.server; +import static io.modelcontextprotocol.util.ToolsUtils.EMPTY_JSON_SCHEMA; +import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson; +import static net.javacrumbs.jsonunit.assertj.JsonAssertions.json; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.assertj.core.api.Assertions.assertWith; +import static org.awaitility.Awaitility.await; +import static org.mockito.Mockito.mock; + import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; @@ -21,6 +30,10 @@ import java.util.function.Function; import java.util.stream.Collectors; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.ValueSource; + import io.modelcontextprotocol.client.McpClient; import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.spec.McpError; @@ -45,21 +58,9 @@ import io.modelcontextprotocol.spec.McpSchema.Tool; import io.modelcontextprotocol.util.Utils; import net.javacrumbs.jsonunit.core.Option; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import static io.modelcontextprotocol.util.ToolsUtils.EMPTY_JSON_SCHEMA; -import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson; -import static net.javacrumbs.jsonunit.assertj.JsonAssertions.json; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.assertj.core.api.Assertions.assertWith; -import static org.awaitility.Awaitility.await; -import static org.mockito.Mockito.mock; - public abstract class AbstractMcpClientServerIntegrationTests { protected ConcurrentHashMap clientBuilders = new ConcurrentHashMap<>(); diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/server/AbstractMcpSyncServerTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/server/AbstractMcpSyncServerTests.java index 976eb8c2c..54d93066f 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/server/AbstractMcpSyncServerTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/server/AbstractMcpSyncServerTests.java @@ -4,9 +4,17 @@ package io.modelcontextprotocol.server; +import static io.modelcontextprotocol.util.ToolsUtils.EMPTY_JSON_SCHEMA; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatCode; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + import java.util.List; -import io.modelcontextprotocol.spec.McpError; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + import io.modelcontextprotocol.spec.McpSchema; import io.modelcontextprotocol.spec.McpSchema.CallToolResult; import io.modelcontextprotocol.spec.McpSchema.GetPromptResult; @@ -17,14 +25,6 @@ import io.modelcontextprotocol.spec.McpSchema.ServerCapabilities; import io.modelcontextprotocol.spec.McpSchema.Tool; import io.modelcontextprotocol.spec.McpServerTransportProvider; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import static io.modelcontextprotocol.util.ToolsUtils.EMPTY_JSON_SCHEMA; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatCode; -import static org.assertj.core.api.Assertions.assertThatThrownBy; /** * Test suite for the {@link McpSyncServer} that can be used with different diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/server/AsyncToolSpecificationBuilderTest.java b/mcp-core/src/test/java/io/modelcontextprotocol/server/AsyncToolSpecificationBuilderTest.java index 8fe8e6fb0..4d4964963 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/server/AsyncToolSpecificationBuilderTest.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/server/AsyncToolSpecificationBuilderTest.java @@ -11,9 +11,9 @@ import java.util.List; import java.util.Map; -import io.modelcontextprotocol.spec.McpSchema; import org.junit.jupiter.api.Test; +import io.modelcontextprotocol.spec.McpSchema; import io.modelcontextprotocol.spec.McpSchema.CallToolRequest; import io.modelcontextprotocol.spec.McpSchema.CallToolResult; import io.modelcontextprotocol.spec.McpSchema.TextContent; diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/server/HttpServletSseIntegrationTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/server/HttpServletSseIntegrationTests.java index d2b9d14d0..f3a1a8c8a 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/server/HttpServletSseIntegrationTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/server/HttpServletSseIntegrationTests.java @@ -4,18 +4,12 @@ package io.modelcontextprotocol.server; +import static org.assertj.core.api.Assertions.assertThat; + import java.time.Duration; import java.util.Map; import java.util.stream.Stream; -import io.modelcontextprotocol.client.McpClient; -import io.modelcontextprotocol.client.transport.HttpClientSseClientTransport; -import io.modelcontextprotocol.common.McpTransportContext; -import io.modelcontextprotocol.server.McpServer.AsyncSpecification; -import io.modelcontextprotocol.server.McpServer.SyncSpecification; -import io.modelcontextprotocol.server.transport.HttpServletSseServerTransportProvider; -import io.modelcontextprotocol.server.transport.TomcatTestUtil; -import jakarta.servlet.http.HttpServletRequest; import org.apache.catalina.LifecycleException; import org.apache.catalina.LifecycleState; import org.apache.catalina.startup.Tomcat; @@ -24,7 +18,14 @@ import org.junit.jupiter.api.Timeout; import org.junit.jupiter.params.provider.Arguments; -import static org.assertj.core.api.Assertions.assertThat; +import io.modelcontextprotocol.client.McpClient; +import io.modelcontextprotocol.client.transport.HttpClientSseClientTransport; +import io.modelcontextprotocol.common.McpTransportContext; +import io.modelcontextprotocol.server.McpServer.AsyncSpecification; +import io.modelcontextprotocol.server.McpServer.SyncSpecification; +import io.modelcontextprotocol.server.transport.HttpServletSseServerTransportProvider; +import io.modelcontextprotocol.server.transport.TomcatTestUtil; +import jakarta.servlet.http.HttpServletRequest; @Timeout(15) class HttpServletSseIntegrationTests extends AbstractMcpClientServerIntegrationTests { diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/server/HttpServletStatelessIntegrationTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/server/HttpServletStatelessIntegrationTests.java index de74bafc1..129caec9c 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/server/HttpServletStatelessIntegrationTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/server/HttpServletStatelessIntegrationTests.java @@ -4,6 +4,15 @@ package io.modelcontextprotocol.server; +import static io.modelcontextprotocol.server.transport.HttpServletStatelessServerTransport.APPLICATION_JSON; +import static io.modelcontextprotocol.server.transport.HttpServletStatelessServerTransport.TEXT_EVENT_STREAM; +import static io.modelcontextprotocol.util.McpJsonMapperUtils.JSON_MAPPER; +import static io.modelcontextprotocol.util.ToolsUtils.EMPTY_JSON_SCHEMA; +import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson; +import static net.javacrumbs.jsonunit.assertj.JsonAssertions.json; +import static org.assertj.core.api.Assertions.assertThat; +import static org.awaitility.Awaitility.await; + import java.time.Duration; import java.util.List; import java.util.Map; @@ -11,6 +20,19 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.function.BiFunction; +import org.apache.catalina.LifecycleException; +import org.apache.catalina.LifecycleState; +import org.apache.catalina.startup.Tomcat; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; +import org.springframework.mock.web.MockHttpServletRequest; +import org.springframework.mock.web.MockHttpServletResponse; +import org.springframework.web.client.RestClient; + import io.modelcontextprotocol.client.McpClient; import io.modelcontextprotocol.client.transport.HttpClientStreamableHttpTransport; import io.modelcontextprotocol.common.McpTransportContext; @@ -31,28 +53,6 @@ import io.modelcontextprotocol.spec.McpSchema.Tool; import io.modelcontextprotocol.spec.ProtocolVersions; import net.javacrumbs.jsonunit.core.Option; -import org.apache.catalina.LifecycleException; -import org.apache.catalina.LifecycleState; -import org.apache.catalina.startup.Tomcat; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.Timeout; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; - -import org.springframework.mock.web.MockHttpServletRequest; -import org.springframework.mock.web.MockHttpServletResponse; -import org.springframework.web.client.RestClient; - -import static io.modelcontextprotocol.server.transport.HttpServletStatelessServerTransport.APPLICATION_JSON; -import static io.modelcontextprotocol.server.transport.HttpServletStatelessServerTransport.TEXT_EVENT_STREAM; -import static io.modelcontextprotocol.util.McpJsonMapperUtils.JSON_MAPPER; -import static io.modelcontextprotocol.util.ToolsUtils.EMPTY_JSON_SCHEMA; -import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson; -import static net.javacrumbs.jsonunit.assertj.JsonAssertions.json; -import static org.assertj.core.api.Assertions.assertThat; -import static org.awaitility.Awaitility.await; @Timeout(15) class HttpServletStatelessIntegrationTests { diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/server/HttpServletStreamableIntegrationTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/server/HttpServletStreamableIntegrationTests.java index 81423e0c5..76073fa3b 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/server/HttpServletStreamableIntegrationTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/server/HttpServletStreamableIntegrationTests.java @@ -4,18 +4,12 @@ package io.modelcontextprotocol.server; +import static org.assertj.core.api.Assertions.assertThat; + import java.time.Duration; import java.util.Map; import java.util.stream.Stream; -import io.modelcontextprotocol.client.McpClient; -import io.modelcontextprotocol.client.transport.HttpClientStreamableHttpTransport; -import io.modelcontextprotocol.common.McpTransportContext; -import io.modelcontextprotocol.server.McpServer.AsyncSpecification; -import io.modelcontextprotocol.server.McpServer.SyncSpecification; -import io.modelcontextprotocol.server.transport.HttpServletStreamableServerTransportProvider; -import io.modelcontextprotocol.server.transport.TomcatTestUtil; -import jakarta.servlet.http.HttpServletRequest; import org.apache.catalina.LifecycleException; import org.apache.catalina.LifecycleState; import org.apache.catalina.startup.Tomcat; @@ -24,7 +18,14 @@ import org.junit.jupiter.api.Timeout; import org.junit.jupiter.params.provider.Arguments; -import static org.assertj.core.api.Assertions.assertThat; +import io.modelcontextprotocol.client.McpClient; +import io.modelcontextprotocol.client.transport.HttpClientStreamableHttpTransport; +import io.modelcontextprotocol.common.McpTransportContext; +import io.modelcontextprotocol.server.McpServer.AsyncSpecification; +import io.modelcontextprotocol.server.McpServer.SyncSpecification; +import io.modelcontextprotocol.server.transport.HttpServletStreamableServerTransportProvider; +import io.modelcontextprotocol.server.transport.TomcatTestUtil; +import jakarta.servlet.http.HttpServletRequest; @Timeout(15) class HttpServletStreamableIntegrationTests extends AbstractMcpClientServerIntegrationTests { diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/server/McpAsyncServerExchangeTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/server/McpAsyncServerExchangeTests.java index 640d34c9c..c8f2aed77 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/server/McpAsyncServerExchangeTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/server/McpAsyncServerExchangeTests.java @@ -4,32 +4,33 @@ package io.modelcontextprotocol.server; -import io.modelcontextprotocol.common.McpTransportContext; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; -import io.modelcontextprotocol.spec.McpError; -import io.modelcontextprotocol.spec.McpSchema; -import io.modelcontextprotocol.spec.McpServerSession; -import io.modelcontextprotocol.json.TypeRef; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; + +import io.modelcontextprotocol.common.McpTransportContext; +import io.modelcontextprotocol.json.TypeRef; +import io.modelcontextprotocol.spec.McpError; +import io.modelcontextprotocol.spec.McpSchema; +import io.modelcontextprotocol.spec.McpServerSession; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - /** * Tests for {@link McpAsyncServerExchange}. * diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/server/McpCompletionTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/server/McpCompletionTests.java index 54fb80a78..fa4e7e7ee 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/server/McpCompletionTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/server/McpCompletionTests.java @@ -4,6 +4,9 @@ package io.modelcontextprotocol.server; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicReference; @@ -12,17 +15,15 @@ import org.apache.catalina.LifecycleException; import org.apache.catalina.LifecycleState; import org.apache.catalina.startup.Tomcat; - -import static org.assertj.core.api.Assertions.assertThat; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import io.modelcontextprotocol.client.McpClient; import io.modelcontextprotocol.client.transport.HttpClientSseClientTransport; import io.modelcontextprotocol.server.transport.HttpServletSseServerTransportProvider; import io.modelcontextprotocol.server.transport.TomcatTestUtil; +import io.modelcontextprotocol.spec.McpError; import io.modelcontextprotocol.spec.McpSchema; import io.modelcontextprotocol.spec.McpSchema.CompleteRequest; import io.modelcontextprotocol.spec.McpSchema.CompleteResult; @@ -30,12 +31,11 @@ import io.modelcontextprotocol.spec.McpSchema.InitializeResult; import io.modelcontextprotocol.spec.McpSchema.Prompt; import io.modelcontextprotocol.spec.McpSchema.PromptArgument; +import io.modelcontextprotocol.spec.McpSchema.PromptReference; import io.modelcontextprotocol.spec.McpSchema.ReadResourceResult; import io.modelcontextprotocol.spec.McpSchema.Resource; import io.modelcontextprotocol.spec.McpSchema.ResourceReference; -import io.modelcontextprotocol.spec.McpSchema.PromptReference; import io.modelcontextprotocol.spec.McpSchema.ServerCapabilities; -import io.modelcontextprotocol.spec.McpError; /** * Tests for completion functionality with context support. diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/server/McpServerProtocolVersionTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/server/McpServerProtocolVersionTests.java index cdd2bacb7..84dc24650 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/server/McpServerProtocolVersionTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/server/McpServerProtocolVersionTests.java @@ -4,15 +4,16 @@ package io.modelcontextprotocol.server; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.List; import java.util.UUID; +import org.junit.jupiter.api.Test; + import io.modelcontextprotocol.MockMcpServerTransport; import io.modelcontextprotocol.MockMcpServerTransportProvider; import io.modelcontextprotocol.spec.McpSchema; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; /** * Tests for MCP server protocol version negotiation and compatibility. diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/server/McpSyncServerExchangeTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/server/McpSyncServerExchangeTests.java index 069d0f896..79b84600a 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/server/McpSyncServerExchangeTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/server/McpSyncServerExchangeTests.java @@ -4,29 +4,30 @@ package io.modelcontextprotocol.server; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; -import io.modelcontextprotocol.spec.McpError; -import io.modelcontextprotocol.spec.McpSchema; -import io.modelcontextprotocol.spec.McpServerSession; -import io.modelcontextprotocol.json.TypeRef; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import reactor.core.publisher.Mono; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import io.modelcontextprotocol.json.TypeRef; +import io.modelcontextprotocol.spec.McpError; +import io.modelcontextprotocol.spec.McpSchema; +import io.modelcontextprotocol.spec.McpServerSession; +import reactor.core.publisher.Mono; /** * Tests for {@link McpSyncServerExchange}. diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/server/ResourceTemplateListingTest.java b/mcp-core/src/test/java/io/modelcontextprotocol/server/ResourceTemplateListingTest.java index 61703c306..1f1fb09d9 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/server/ResourceTemplateListingTest.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/server/ResourceTemplateListingTest.java @@ -4,13 +4,14 @@ package io.modelcontextprotocol.server; -import io.modelcontextprotocol.spec.McpSchema; -import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; import java.util.List; import java.util.stream.Collectors; -import static org.assertj.core.api.Assertions.assertThat; +import org.junit.jupiter.api.Test; + +import io.modelcontextprotocol.spec.McpSchema; /** * Test to verify the separation of regular resources and resource templates. Regular diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/server/ResourceTemplateManagementTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/server/ResourceTemplateManagementTests.java index b7d46a967..5e1403ace 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/server/ResourceTemplateManagementTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/server/ResourceTemplateManagementTests.java @@ -4,23 +4,24 @@ package io.modelcontextprotocol.server; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatCode; + import java.time.Duration; import java.util.List; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + import io.modelcontextprotocol.MockMcpServerTransport; import io.modelcontextprotocol.MockMcpServerTransportProvider; import io.modelcontextprotocol.spec.McpSchema.ReadResourceResult; import io.modelcontextprotocol.spec.McpSchema.ResourceTemplate; import io.modelcontextprotocol.spec.McpSchema.ServerCapabilities; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatCode; - /** * Test suite for Resource Template Management functionality. Tests the new * addResourceTemplate() and removeResourceTemplate() methods, as well as the Map-based diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/server/ServletSseMcpAsyncServerTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/server/ServletSseMcpAsyncServerTests.java index 8906adfe0..cd69bee07 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/server/ServletSseMcpAsyncServerTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/server/ServletSseMcpAsyncServerTests.java @@ -4,9 +4,10 @@ package io.modelcontextprotocol.server; +import org.junit.jupiter.api.Timeout; + import io.modelcontextprotocol.server.transport.HttpServletSseServerTransportProvider; import io.modelcontextprotocol.spec.McpServerTransportProvider; -import org.junit.jupiter.api.Timeout; /** * Tests for {@link McpAsyncServer} using {@link HttpServletSseServerTransportProvider}. diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/server/ServletSseMcpSyncServerTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/server/ServletSseMcpSyncServerTests.java index 7b77f9241..cc96cefb7 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/server/ServletSseMcpSyncServerTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/server/ServletSseMcpSyncServerTests.java @@ -4,9 +4,10 @@ package io.modelcontextprotocol.server; +import org.junit.jupiter.api.Timeout; + import io.modelcontextprotocol.server.transport.HttpServletSseServerTransportProvider; import io.modelcontextprotocol.spec.McpServerTransportProvider; -import org.junit.jupiter.api.Timeout; /** * Tests for {@link McpSyncServer} using {@link HttpServletSseServerTransportProvider}. diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/server/StdioMcpAsyncServerTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/server/StdioMcpAsyncServerTests.java index b2dfbea25..f20f7cf9f 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/server/StdioMcpAsyncServerTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/server/StdioMcpAsyncServerTests.java @@ -4,11 +4,12 @@ package io.modelcontextprotocol.server; -import io.modelcontextprotocol.server.transport.StdioServerTransportProvider; -import io.modelcontextprotocol.spec.McpServerTransportProvider; +import static io.modelcontextprotocol.util.McpJsonMapperUtils.JSON_MAPPER; + import org.junit.jupiter.api.Timeout; -import static io.modelcontextprotocol.util.McpJsonMapperUtils.JSON_MAPPER; +import io.modelcontextprotocol.server.transport.StdioServerTransportProvider; +import io.modelcontextprotocol.spec.McpServerTransportProvider; /** * Tests for {@link McpAsyncServer} using {@link StdioServerTransport}. diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/server/StdioMcpSyncServerTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/server/StdioMcpSyncServerTests.java index c97c75d38..68acead68 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/server/StdioMcpSyncServerTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/server/StdioMcpSyncServerTests.java @@ -4,11 +4,12 @@ package io.modelcontextprotocol.server; -import io.modelcontextprotocol.server.transport.StdioServerTransportProvider; -import io.modelcontextprotocol.spec.McpServerTransportProvider; +import static io.modelcontextprotocol.util.McpJsonMapperUtils.JSON_MAPPER; + import org.junit.jupiter.api.Timeout; -import static io.modelcontextprotocol.util.McpJsonMapperUtils.JSON_MAPPER; +import io.modelcontextprotocol.server.transport.StdioServerTransportProvider; +import io.modelcontextprotocol.spec.McpServerTransportProvider; /** * Tests for {@link McpSyncServer} using {@link StdioServerTransportProvider}. diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/server/transport/HttpServletSseServerCustomContextPathTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/server/transport/HttpServletSseServerCustomContextPathTests.java index be88097b3..916fdc627 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/server/transport/HttpServletSseServerCustomContextPathTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/server/transport/HttpServletSseServerCustomContextPathTests.java @@ -4,10 +4,8 @@ package io.modelcontextprotocol.server.transport; -import io.modelcontextprotocol.client.McpClient; -import io.modelcontextprotocol.client.transport.HttpClientSseClientTransport; -import io.modelcontextprotocol.server.McpServer; -import io.modelcontextprotocol.spec.McpSchema; +import static org.assertj.core.api.Assertions.assertThat; + import org.apache.catalina.LifecycleException; import org.apache.catalina.LifecycleState; import org.apache.catalina.startup.Tomcat; @@ -15,7 +13,10 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.assertj.core.api.Assertions.assertThat; +import io.modelcontextprotocol.client.McpClient; +import io.modelcontextprotocol.client.transport.HttpClientSseClientTransport; +import io.modelcontextprotocol.server.McpServer; +import io.modelcontextprotocol.spec.McpSchema; class HttpServletSseServerCustomContextPathTests { diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/server/transport/StdioServerTransportProviderTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/server/transport/StdioServerTransportProviderTests.java index 6a70af33d..381e9a7f1 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/server/transport/StdioServerTransportProviderTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/server/transport/StdioServerTransportProviderTests.java @@ -4,6 +4,13 @@ package io.modelcontextprotocol.server.transport; +import static io.modelcontextprotocol.util.McpJsonMapperUtils.JSON_MAPPER; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.InputStream; @@ -14,24 +21,18 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; -import io.modelcontextprotocol.spec.McpError; -import io.modelcontextprotocol.spec.McpSchema; -import io.modelcontextprotocol.spec.McpServerSession; -import io.modelcontextprotocol.spec.McpServerTransport; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + +import io.modelcontextprotocol.spec.McpError; +import io.modelcontextprotocol.spec.McpSchema; +import io.modelcontextprotocol.spec.McpServerSession; +import io.modelcontextprotocol.spec.McpServerTransport; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import static io.modelcontextprotocol.util.McpJsonMapperUtils.JSON_MAPPER; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - /** * Tests for {@link StdioServerTransportProvider}. * diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/server/transport/TomcatTestUtil.java b/mcp-core/src/test/java/io/modelcontextprotocol/server/transport/TomcatTestUtil.java index 490e29838..d7e4fb865 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/server/transport/TomcatTestUtil.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/server/transport/TomcatTestUtil.java @@ -8,13 +8,14 @@ import java.net.InetSocketAddress; import java.net.ServerSocket; -import jakarta.servlet.Filter; -import jakarta.servlet.Servlet; import org.apache.catalina.Context; import org.apache.catalina.startup.Tomcat; import org.apache.tomcat.util.descriptor.web.FilterDef; import org.apache.tomcat.util.descriptor.web.FilterMap; +import jakarta.servlet.Filter; +import jakarta.servlet.Servlet; + /** * @author Christian Tzolov * @author Daniel Garnier-Moiroux diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/spec/CompleteCompletionSerializationTest.java b/mcp-core/src/test/java/io/modelcontextprotocol/spec/CompleteCompletionSerializationTest.java index 1974f2bde..8374c28ea 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/spec/CompleteCompletionSerializationTest.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/spec/CompleteCompletionSerializationTest.java @@ -1,9 +1,11 @@ package io.modelcontextprotocol.spec; -import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; + import java.io.IOException; import java.util.Collections; -import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; import io.modelcontextprotocol.json.McpJsonMapper; import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/spec/JSONRPCRequestMcpValidationTest.java b/mcp-core/src/test/java/io/modelcontextprotocol/spec/JSONRPCRequestMcpValidationTest.java index fbe17d464..4d62ef567 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/spec/JSONRPCRequestMcpValidationTest.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/spec/JSONRPCRequestMcpValidationTest.java @@ -4,12 +4,13 @@ package io.modelcontextprotocol.spec; -import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; + /** * Tests for MCP-specific validation of JSONRPCRequest ID requirements. * diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/spec/McpClientSessionTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/spec/McpClientSessionTests.java index 3de06f503..2cb79b425 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/spec/McpClientSessionTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/spec/McpClientSessionTests.java @@ -4,21 +4,22 @@ package io.modelcontextprotocol.spec; +import static org.assertj.core.api.Assertions.assertThat; + import java.time.Duration; import java.util.Map; import java.util.function.Function; -import io.modelcontextprotocol.MockMcpClientTransport; -import io.modelcontextprotocol.json.TypeRef; import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + +import io.modelcontextprotocol.MockMcpClientTransport; +import io.modelcontextprotocol.json.TypeRef; import reactor.core.publisher.Mono; import reactor.core.publisher.Sinks; import reactor.test.StepVerifier; -import static org.assertj.core.api.Assertions.assertThat; - /** * Test suite for {@link McpClientSession} that verifies its JSON-RPC message handling, * request-response correlation, and notification processing. diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/spec/McpErrorTest.java b/mcp-core/src/test/java/io/modelcontextprotocol/spec/McpErrorTest.java index 0978ffe0b..f4d13a630 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/spec/McpErrorTest.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/spec/McpErrorTest.java @@ -1,11 +1,11 @@ package io.modelcontextprotocol.spec; -import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import java.util.Map; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.Test; class McpErrorTest { diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/spec/PromptReferenceEqualsTest.java b/mcp-core/src/test/java/io/modelcontextprotocol/spec/PromptReferenceEqualsTest.java index 1d7be0b51..03da264d0 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/spec/PromptReferenceEqualsTest.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/spec/PromptReferenceEqualsTest.java @@ -4,12 +4,13 @@ package io.modelcontextprotocol.spec; -import io.modelcontextprotocol.spec.McpSchema.PromptReference; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertEquals; +import io.modelcontextprotocol.spec.McpSchema.PromptReference; /** * Test class to verify the equals method implementation for PromptReference. diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/spec/json/gson/GsonMcpJsonMapper.java b/mcp-core/src/test/java/io/modelcontextprotocol/spec/json/gson/GsonMcpJsonMapper.java index ef7cd2737..e1ab905a1 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/spec/json/gson/GsonMcpJsonMapper.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/spec/json/gson/GsonMcpJsonMapper.java @@ -1,14 +1,15 @@ package io.modelcontextprotocol.spec.json.gson; +import java.io.IOException; +import java.nio.charset.StandardCharsets; + import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.ToNumberPolicy; + import io.modelcontextprotocol.json.McpJsonMapper; import io.modelcontextprotocol.json.TypeRef; -import java.io.IOException; -import java.nio.charset.StandardCharsets; - /** * Test-only Gson-based implementation of McpJsonMapper. This lives under src/test/java so * it doesn't affect production code or dependencies. diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/spec/json/gson/GsonMcpJsonMapperTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/spec/json/gson/GsonMcpJsonMapperTests.java index 498194d17..e2e7e8b1a 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/spec/json/gson/GsonMcpJsonMapperTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/spec/json/gson/GsonMcpJsonMapperTests.java @@ -1,17 +1,18 @@ package io.modelcontextprotocol.spec.json.gson; -import io.modelcontextprotocol.spec.McpSchema; -import io.modelcontextprotocol.json.TypeRef; -import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.util.List; import java.util.Map; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import org.junit.jupiter.api.Test; + +import io.modelcontextprotocol.json.TypeRef; +import io.modelcontextprotocol.spec.McpSchema; class GsonMcpJsonMapperTests { diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/util/AssertTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/util/AssertTests.java index 0038d4e1b..6c2254853 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/util/AssertTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/util/AssertTests.java @@ -4,13 +4,13 @@ package io.modelcontextprotocol.util; -import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.util.List; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import org.junit.jupiter.api.Test; class AssertTests { diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/util/KeepAliveSchedulerTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/util/KeepAliveSchedulerTests.java index d5ef8a91c..752f30b38 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/util/KeepAliveSchedulerTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/util/KeepAliveSchedulerTests.java @@ -17,7 +17,6 @@ import org.junit.jupiter.api.Test; import io.modelcontextprotocol.json.TypeRef; - import io.modelcontextprotocol.spec.McpSchema; import io.modelcontextprotocol.spec.McpSession; import reactor.core.Disposable; diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/util/ToolsUtils.java b/mcp-core/src/test/java/io/modelcontextprotocol/util/ToolsUtils.java index ce8755223..5df692941 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/util/ToolsUtils.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/util/ToolsUtils.java @@ -1,9 +1,9 @@ package io.modelcontextprotocol.util; -import io.modelcontextprotocol.spec.McpSchema; - import java.util.Collections; +import io.modelcontextprotocol.spec.McpSchema; + public final class ToolsUtils { private ToolsUtils() { diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/util/UtilsTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/util/UtilsTests.java index 0f2e689b5..904ea7f49 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/util/UtilsTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/util/UtilsTests.java @@ -4,17 +4,17 @@ package io.modelcontextprotocol.util; -import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.net.URI; import java.util.Collection; import java.util.List; import java.util.Map; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; From 28edf6512952219b1f87afcae29555bcba8ba616 Mon Sep 17 00:00:00 2001 From: Scott Lewis Date: Thu, 20 Nov 2025 17:36:52 -0800 Subject: [PATCH 03/11] Added osgi (declarative) services and build metadata for mcp-core (DefaultMcpJsonMapperSupplier,DefaultMcpJsonSchemaValidator) and mcp-json-jackson2 (JacksonMcpJsonMapperSupplier, JacksonJsonSchemaValidatorSupplier) --- mcp-core/pom.xml | 1 + ....internal.DefaultMcpJsonMapperSupplier.xml | 5 +++ ....DefaultMcpJsonSchemaValidatorSupplier.xml | 5 +++ mcp-json-jackson2/pom.xml | 34 +++++++++++++++++-- ...n.jackson.JacksonMcpJsonMapperSupplier.xml | 7 ++++ ...son.JacksonJsonSchemaValidatorSupplier.xml | 7 ++++ 6 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 mcp-core/src/main/resources/OSGI-INF/io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier.xml create mode 100644 mcp-core/src/main/resources/OSGI-INF/io.modelcontextprotocol.json.internal.DefaultMcpJsonSchemaValidatorSupplier.xml create mode 100644 mcp-json-jackson2/src/main/resources/OSGI-INF/io.modelcontextprotocol.json.jackson.JacksonMcpJsonMapperSupplier.xml create mode 100644 mcp-json-jackson2/src/main/resources/OSGI-INF/io.modelcontextprotocol.json.schema.jackson.JacksonJsonSchemaValidatorSupplier.xml diff --git a/mcp-core/pom.xml b/mcp-core/pom.xml index a093860ed..e9cb5de8f 100644 --- a/mcp-core/pom.xml +++ b/mcp-core/pom.xml @@ -42,6 +42,7 @@ Import-Package: jakarta.*;resolution:=optional, \ *; Export-Package: io.modelcontextprotocol.*;version="${version}";-noimport:=true + Service-Component: OSGI-INF/io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier.xml,OSGI-INF/io.modelcontextprotocol.json.internal.DefaultMcpJsonSchemaValidatorSupplier.xml -noimportjava: true; -nouses: true; -removeheaders: Private-Package diff --git a/mcp-core/src/main/resources/OSGI-INF/io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier.xml b/mcp-core/src/main/resources/OSGI-INF/io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier.xml new file mode 100644 index 000000000..5129cacad --- /dev/null +++ b/mcp-core/src/main/resources/OSGI-INF/io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/mcp-core/src/main/resources/OSGI-INF/io.modelcontextprotocol.json.internal.DefaultMcpJsonSchemaValidatorSupplier.xml b/mcp-core/src/main/resources/OSGI-INF/io.modelcontextprotocol.json.internal.DefaultMcpJsonSchemaValidatorSupplier.xml new file mode 100644 index 000000000..19a8acc9e --- /dev/null +++ b/mcp-core/src/main/resources/OSGI-INF/io.modelcontextprotocol.json.internal.DefaultMcpJsonSchemaValidatorSupplier.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/mcp-json-jackson2/pom.xml b/mcp-json-jackson2/pom.xml index 9698385be..b2c9bace4 100644 --- a/mcp-json-jackson2/pom.xml +++ b/mcp-json-jackson2/pom.xml @@ -20,14 +20,42 @@ + + biz.aQute.bnd + bnd-maven-plugin + ${bnd-maven-plugin.version} + + + bnd-process + + bnd-process + + + + + + + + + org.apache.maven.plugins maven-jar-plugin - - true - + ${project.build.outputDirectory}/META-INF/MANIFEST.MF diff --git a/mcp-json-jackson2/src/main/resources/OSGI-INF/io.modelcontextprotocol.json.jackson.JacksonMcpJsonMapperSupplier.xml b/mcp-json-jackson2/src/main/resources/OSGI-INF/io.modelcontextprotocol.json.jackson.JacksonMcpJsonMapperSupplier.xml new file mode 100644 index 000000000..4db58d344 --- /dev/null +++ b/mcp-json-jackson2/src/main/resources/OSGI-INF/io.modelcontextprotocol.json.jackson.JacksonMcpJsonMapperSupplier.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/mcp-json-jackson2/src/main/resources/OSGI-INF/io.modelcontextprotocol.json.schema.jackson.JacksonJsonSchemaValidatorSupplier.xml b/mcp-json-jackson2/src/main/resources/OSGI-INF/io.modelcontextprotocol.json.schema.jackson.JacksonJsonSchemaValidatorSupplier.xml new file mode 100644 index 000000000..6e45d4277 --- /dev/null +++ b/mcp-json-jackson2/src/main/resources/OSGI-INF/io.modelcontextprotocol.json.schema.jackson.JacksonJsonSchemaValidatorSupplier.xml @@ -0,0 +1,7 @@ + + + + + + + From 332af620cbf1222c1d8a48d6cbc56865ebeb9f2c Mon Sep 17 00:00:00 2001 From: Scott Lewis Date: Fri, 21 Nov 2025 17:49:07 -0800 Subject: [PATCH 04/11] Introduced McpServiceLoader class to handle all types of service loading in common way. --- .../DefaultMcpJsonMapperSupplier.java | 29 ++----- ...DefaultMcpJsonSchemaValidatorSupplier.java | 31 ++------ .../util/McpServiceLoader.java | 79 +++++++++++++++++++ 3 files changed, 95 insertions(+), 44 deletions(-) create mode 100644 mcp-core/src/main/java/io/modelcontextprotocol/util/McpServiceLoader.java diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/json/internal/DefaultMcpJsonMapperSupplier.java b/mcp-core/src/main/java/io/modelcontextprotocol/json/internal/DefaultMcpJsonMapperSupplier.java index b44cadc62..325ba2293 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/json/internal/DefaultMcpJsonMapperSupplier.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/json/internal/DefaultMcpJsonMapperSupplier.java @@ -1,40 +1,27 @@ package io.modelcontextprotocol.json.internal; -import java.util.Optional; -import java.util.ServiceConfigurationError; -import java.util.ServiceLoader; - import io.modelcontextprotocol.json.McpJsonMapper; import io.modelcontextprotocol.json.McpJsonMapperSupplier; +import io.modelcontextprotocol.util.McpServiceLoader; public class DefaultMcpJsonMapperSupplier { - private static McpJsonMapperSupplier jsonMapperSupplier; + private static McpServiceLoader mcpServiceLoader; - private static McpJsonMapper defaultJsonMapper; + public DefaultMcpJsonMapperSupplier() { + mcpServiceLoader = new McpServiceLoader(); + } void setMcpJsonMapperSupplier(McpJsonMapperSupplier supplier) { - jsonMapperSupplier = supplier; + mcpServiceLoader.setSupplier(supplier); } void unsetMcpJsonMapperSupplier(McpJsonMapperSupplier supplier) { - jsonMapperSupplier = null; - defaultJsonMapper = null; + mcpServiceLoader.unsetSupplier(supplier); } public synchronized static McpJsonMapper getDefaultMcpJsonMapper() { - if (defaultJsonMapper == null) { - if (jsonMapperSupplier == null) { - // Use serviceloader - Optional sl = ServiceLoader.load(McpJsonMapperSupplier.class).findFirst(); - if (sl.isEmpty()) { - throw new ServiceConfigurationError("No JsonMapperSupplier available for creating McpJsonMapper"); - } - jsonMapperSupplier = sl.get(); - } - defaultJsonMapper = jsonMapperSupplier.get(); - } - return defaultJsonMapper; + return mcpServiceLoader.getDefault(); } } diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/json/internal/DefaultMcpJsonSchemaValidatorSupplier.java b/mcp-core/src/main/java/io/modelcontextprotocol/json/internal/DefaultMcpJsonSchemaValidatorSupplier.java index cb9d46029..a1f45e2b1 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/json/internal/DefaultMcpJsonSchemaValidatorSupplier.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/json/internal/DefaultMcpJsonSchemaValidatorSupplier.java @@ -1,42 +1,27 @@ package io.modelcontextprotocol.json.internal; -import java.util.Optional; -import java.util.ServiceConfigurationError; -import java.util.ServiceLoader; - import io.modelcontextprotocol.json.schema.JsonSchemaValidator; import io.modelcontextprotocol.json.schema.JsonSchemaValidatorSupplier; +import io.modelcontextprotocol.util.McpServiceLoader; public class DefaultMcpJsonSchemaValidatorSupplier { - private static JsonSchemaValidatorSupplier jsonSchemaValidatorSupplier; + private static McpServiceLoader mcpServiceLoader; - private static JsonSchemaValidator defaultJsonSchemaValidator; + public DefaultMcpJsonSchemaValidatorSupplier() { + mcpServiceLoader = new McpServiceLoader(); + } void setJsonSchemaValidatorSupplier(JsonSchemaValidatorSupplier supplier) { - jsonSchemaValidatorSupplier = supplier; + mcpServiceLoader.setSupplier(supplier); } void unsetJsonSchemaValidatorSupplier(JsonSchemaValidatorSupplier supplier) { - jsonSchemaValidatorSupplier = null; - defaultJsonSchemaValidator = null; + mcpServiceLoader.unsetSupplier(supplier); } public synchronized static JsonSchemaValidator getDefaultJsonSchemaValidator() { - if (defaultJsonSchemaValidator == null) { - if (jsonSchemaValidatorSupplier == null) { - // Use serviceloader - Optional sl = ServiceLoader.load(JsonSchemaValidatorSupplier.class) - .findFirst(); - if (sl.isEmpty()) { - throw new ServiceConfigurationError( - "No JsonSchemaValidatorSupplier available for creating JsonSchemaValidator"); - } - jsonSchemaValidatorSupplier = sl.get(); - } - defaultJsonSchemaValidator = jsonSchemaValidatorSupplier.get(); - } - return defaultJsonSchemaValidator; + return mcpServiceLoader.getDefault(); } } diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/util/McpServiceLoader.java b/mcp-core/src/main/java/io/modelcontextprotocol/util/McpServiceLoader.java new file mode 100644 index 000000000..7eee25861 --- /dev/null +++ b/mcp-core/src/main/java/io/modelcontextprotocol/util/McpServiceLoader.java @@ -0,0 +1,79 @@ +package io.modelcontextprotocol.util; + +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.util.Optional; +import java.util.ServiceConfigurationError; +import java.util.ServiceLoader; +import java.util.function.Supplier; + +public class McpServiceLoader, R> { + + private Type supplierType; + + private S supplier; + + private R supplierResult; + + protected abstract class TypeToken { + + private Type type; + + protected TypeToken() { + Type superClass = getClass().getGenericSuperclass(); + this.type = ((ParameterizedType) superClass).getActualTypeArguments()[0]; + } + + public Type getType() { + return type; + } + + } + + protected class SupplierTypeToken extends TypeToken { + + }; + + public void setSupplier(S supplier) { + this.supplier = supplier; + this.supplierResult = null; + } + + public void unsetSupplier(S supplier) { + this.supplier = null; + this.supplierResult = null; + } + + public McpServiceLoader() { + this.supplierType = new SupplierTypeToken().getType(); + } + + protected Optional serviceLoad(Class type) { + return ServiceLoader.load(type).findFirst(); + } + + @SuppressWarnings("unchecked") + public synchronized R getDefault() { + if (this.supplierResult == null) { + if (this.supplier == null) { + // Use serviceloader + Optional sl; + try { + sl = serviceLoad((Class) Class.forName(this.supplierType.getTypeName())); + if (sl.isEmpty()) { + throw new ServiceConfigurationError( + "No JsonMapperSupplier available for creating McpJsonMapper"); + } + } + catch (ClassNotFoundException e) { + throw new ServiceConfigurationError( + "ClassNotFoundException for Type=" + this.supplierType.getTypeName()); + } + this.supplier = (S) sl.get(); + } + this.supplierResult = this.supplier.get(); + } + return supplierResult; + } + +} From d4bf65ef159a7212c1ba853e73d57526bf62b024 Mon Sep 17 00:00:00 2001 From: Scott Lewis Date: Sun, 23 Nov 2025 16:49:07 -0800 Subject: [PATCH 05/11] Simplification of DefaultMcpJson* classes by creating a single DefaultMcpJson class that provides access to both the DefaultMcpJsonMapper and the DefaultMcpJson Validator --- mcp-core/pom.xml | 3 +- .../client/McpClient.java | 14 +++--- .../HttpClientSseClientTransport.java | 5 +-- .../HttpClientStreamableHttpTransport.java | 8 ++-- .../json/internal/DefaultMcpJson.java | 44 +++++++++++++++++++ .../DefaultMcpJsonMapperSupplier.java | 27 ------------ ...DefaultMcpJsonSchemaValidatorSupplier.java | 27 ------------ .../server/McpServer.java | 37 +++++++--------- ...HttpServletSseServerTransportProvider.java | 4 +- .../HttpServletStatelessServerTransport.java | 6 +-- ...vletStreamableServerTransportProvider.java | 6 +-- ...protocol.json.internal.DefaultMcpJson.xml} | 5 ++- ....internal.DefaultMcpJsonMapperSupplier.xml | 5 --- .../MockMcpClientTransport.java | 3 +- .../MockMcpServerTransport.java | 3 +- .../CompleteCompletionSerializationTest.java | 3 +- .../util/McpJsonMapperUtils.java | 3 +- mcp-json-jackson2/pom.xml | 1 + .../WebClientStreamableHttpTransport.java | 6 +-- .../transport/WebFluxSseClientTransport.java | 5 +-- .../WebFluxSseServerTransportProvider.java | 4 +- .../WebFluxStatelessServerTransport.java | 6 +-- ...FluxStreamableServerTransportProvider.java | 6 +-- .../utils/McpJsonMapperUtils.java | 4 +- mcp-spring/mcp-spring-webmvc/pom.xml | 2 +- .../WebMvcSseServerTransportProvider.java | 4 +- .../WebMvcStatelessServerTransport.java | 6 +-- ...bMvcStreamableServerTransportProvider.java | 6 +-- ...WebMvcSseServerTransportProviderTests.java | 4 +- .../MockMcpTransport.java | 4 +- .../util/McpJsonMapperUtils.java | 4 +- 31 files changed, 127 insertions(+), 138 deletions(-) create mode 100644 mcp-core/src/main/java/io/modelcontextprotocol/json/internal/DefaultMcpJson.java delete mode 100644 mcp-core/src/main/java/io/modelcontextprotocol/json/internal/DefaultMcpJsonMapperSupplier.java delete mode 100644 mcp-core/src/main/java/io/modelcontextprotocol/json/internal/DefaultMcpJsonSchemaValidatorSupplier.java rename mcp-core/src/main/resources/OSGI-INF/{io.modelcontextprotocol.json.internal.DefaultMcpJsonSchemaValidatorSupplier.xml => io.modelcontextprotocol.json.internal.DefaultMcpJson.xml} (59%) delete mode 100644 mcp-core/src/main/resources/OSGI-INF/io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier.xml diff --git a/mcp-core/pom.xml b/mcp-core/pom.xml index e9cb5de8f..b48b5e140 100644 --- a/mcp-core/pom.xml +++ b/mcp-core/pom.xml @@ -39,10 +39,11 @@ Bundle-SymbolicName: ${project.groupId}.${project.artifactId} Bundle-Version: ${version} Automatic-Module-Name: ${project.groupId}.${project.artifactId} + Bundle-ActivationPolicy: lazy Import-Package: jakarta.*;resolution:=optional, \ *; Export-Package: io.modelcontextprotocol.*;version="${version}";-noimport:=true - Service-Component: OSGI-INF/io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier.xml,OSGI-INF/io.modelcontextprotocol.json.internal.DefaultMcpJsonSchemaValidatorSupplier.xml + Service-Component: OSGI-INF/io.modelcontextprotocol.json.internal.DefaultMcpJson.xml -noimportjava: true; -nouses: true; -removeheaders: Private-Package diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/client/McpClient.java b/mcp-core/src/main/java/io/modelcontextprotocol/client/McpClient.java index 686fcb6aa..485c03fb0 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/client/McpClient.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/client/McpClient.java @@ -14,7 +14,7 @@ import java.util.function.Supplier; import io.modelcontextprotocol.common.McpTransportContext; -import io.modelcontextprotocol.json.internal.DefaultMcpJsonSchemaValidatorSupplier; +import io.modelcontextprotocol.json.internal.DefaultMcpJson; import io.modelcontextprotocol.json.schema.JsonSchemaValidator; import io.modelcontextprotocol.spec.McpClientTransport; import io.modelcontextprotocol.spec.McpSchema; @@ -475,10 +475,12 @@ public McpSyncClient build() { McpClientFeatures.Async asyncFeatures = McpClientFeatures.Async.fromSync(syncFeatures); - return new McpSyncClient(new McpAsyncClient(transport, this.requestTimeout, this.initializationTimeout, - jsonSchemaValidator != null ? jsonSchemaValidator - : DefaultMcpJsonSchemaValidatorSupplier.getDefaultJsonSchemaValidator(), - asyncFeatures), this.contextProvider); + return new McpSyncClient( + new McpAsyncClient(transport, this.requestTimeout, this.initializationTimeout, + jsonSchemaValidator != null ? jsonSchemaValidator + : DefaultMcpJson.getDefaultJsonSchemaValidator(), + asyncFeatures), + this.contextProvider); } } @@ -811,7 +813,7 @@ public AsyncSpec enableCallToolSchemaCaching(boolean enableCallToolSchemaCaching */ public McpAsyncClient build() { var jsonSchemaValidator = (this.jsonSchemaValidator != null) ? this.jsonSchemaValidator - : DefaultMcpJsonSchemaValidatorSupplier.getDefaultJsonSchemaValidator(); + : DefaultMcpJson.getDefaultJsonSchemaValidator(); return new McpAsyncClient(this.transport, this.requestTimeout, this.initializationTimeout, jsonSchemaValidator, new McpClientFeatures.Async(this.clientInfo, this.capabilities, this.roots, diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/HttpClientSseClientTransport.java b/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/HttpClientSseClientTransport.java index 3f8307b9e..5f1df2aee 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/HttpClientSseClientTransport.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/HttpClientSseClientTransport.java @@ -25,7 +25,7 @@ import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.json.McpJsonMapper; import io.modelcontextprotocol.json.TypeRef; -import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; +import io.modelcontextprotocol.json.internal.DefaultMcpJson; import io.modelcontextprotocol.spec.HttpHeaders; import io.modelcontextprotocol.spec.McpClientTransport; import io.modelcontextprotocol.spec.McpError; @@ -330,8 +330,7 @@ public Builder connectTimeout(Duration connectTimeout) { public HttpClientSseClientTransport build() { HttpClient httpClient = this.clientBuilder.connectTimeout(this.connectTimeout).build(); return new HttpClientSseClientTransport(httpClient, requestBuilder, baseUri, sseEndpoint, - jsonMapper == null ? DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper() : jsonMapper, - httpRequestCustomizer); + jsonMapper == null ? DefaultMcpJson.getDefaultMcpJsonMapper() : jsonMapper, httpRequestCustomizer); } } diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/HttpClientStreamableHttpTransport.java b/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/HttpClientStreamableHttpTransport.java index 58365106b..6cff190d2 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/HttpClientStreamableHttpTransport.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/HttpClientStreamableHttpTransport.java @@ -30,7 +30,7 @@ import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.json.McpJsonMapper; import io.modelcontextprotocol.json.TypeRef; -import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; +import io.modelcontextprotocol.json.internal.DefaultMcpJson; import io.modelcontextprotocol.spec.ClosedMcpTransportSession; import io.modelcontextprotocol.spec.DefaultMcpTransportSession; import io.modelcontextprotocol.spec.DefaultMcpTransportStream; @@ -816,9 +816,9 @@ public Builder supportedProtocolVersions(List supportedProtocolVersions) public HttpClientStreamableHttpTransport build() { HttpClient httpClient = this.clientBuilder.connectTimeout(this.connectTimeout).build(); return new HttpClientStreamableHttpTransport( - jsonMapper == null ? DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper() : jsonMapper, - httpClient, requestBuilder, baseUri, endpoint, resumableStreams, openConnectionOnStartup, - httpRequestCustomizer, supportedProtocolVersions); + jsonMapper == null ? DefaultMcpJson.getDefaultMcpJsonMapper() : jsonMapper, httpClient, + requestBuilder, baseUri, endpoint, resumableStreams, openConnectionOnStartup, httpRequestCustomizer, + supportedProtocolVersions); } } diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/json/internal/DefaultMcpJson.java b/mcp-core/src/main/java/io/modelcontextprotocol/json/internal/DefaultMcpJson.java new file mode 100644 index 000000000..2e4be4b58 --- /dev/null +++ b/mcp-core/src/main/java/io/modelcontextprotocol/json/internal/DefaultMcpJson.java @@ -0,0 +1,44 @@ +package io.modelcontextprotocol.json.internal; + +import io.modelcontextprotocol.json.McpJsonMapper; +import io.modelcontextprotocol.json.McpJsonMapperSupplier; +import io.modelcontextprotocol.json.schema.JsonSchemaValidator; +import io.modelcontextprotocol.json.schema.JsonSchemaValidatorSupplier; +import io.modelcontextprotocol.util.McpServiceLoader; + +public class DefaultMcpJson { + + protected static McpServiceLoader mcpMapperServiceLoader; + + protected static McpServiceLoader mcpValidatorServiceLoader; + + public DefaultMcpJson() { + mcpMapperServiceLoader = new McpServiceLoader(); + mcpValidatorServiceLoader = new McpServiceLoader(); + } + + void setMcpJsonMapperSupplier(McpJsonMapperSupplier supplier) { + mcpMapperServiceLoader.setSupplier(supplier); + } + + void unsetMcpJsonMapperSupplier(McpJsonMapperSupplier supplier) { + mcpMapperServiceLoader.unsetSupplier(supplier); + } + + public synchronized static McpJsonMapper getDefaultMcpJsonMapper() { + return mcpMapperServiceLoader.getDefault(); + } + + void setJsonSchemaValidatorSupplier(JsonSchemaValidatorSupplier supplier) { + mcpValidatorServiceLoader.setSupplier(supplier); + } + + void unsetJsonSchemaValidatorSupplier(JsonSchemaValidatorSupplier supplier) { + mcpValidatorServiceLoader.unsetSupplier(supplier); + } + + public synchronized static JsonSchemaValidator getDefaultJsonSchemaValidator() { + return mcpValidatorServiceLoader.getDefault(); + } + +} diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/json/internal/DefaultMcpJsonMapperSupplier.java b/mcp-core/src/main/java/io/modelcontextprotocol/json/internal/DefaultMcpJsonMapperSupplier.java deleted file mode 100644 index 325ba2293..000000000 --- a/mcp-core/src/main/java/io/modelcontextprotocol/json/internal/DefaultMcpJsonMapperSupplier.java +++ /dev/null @@ -1,27 +0,0 @@ -package io.modelcontextprotocol.json.internal; - -import io.modelcontextprotocol.json.McpJsonMapper; -import io.modelcontextprotocol.json.McpJsonMapperSupplier; -import io.modelcontextprotocol.util.McpServiceLoader; - -public class DefaultMcpJsonMapperSupplier { - - private static McpServiceLoader mcpServiceLoader; - - public DefaultMcpJsonMapperSupplier() { - mcpServiceLoader = new McpServiceLoader(); - } - - void setMcpJsonMapperSupplier(McpJsonMapperSupplier supplier) { - mcpServiceLoader.setSupplier(supplier); - } - - void unsetMcpJsonMapperSupplier(McpJsonMapperSupplier supplier) { - mcpServiceLoader.unsetSupplier(supplier); - } - - public synchronized static McpJsonMapper getDefaultMcpJsonMapper() { - return mcpServiceLoader.getDefault(); - } - -} diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/json/internal/DefaultMcpJsonSchemaValidatorSupplier.java b/mcp-core/src/main/java/io/modelcontextprotocol/json/internal/DefaultMcpJsonSchemaValidatorSupplier.java deleted file mode 100644 index a1f45e2b1..000000000 --- a/mcp-core/src/main/java/io/modelcontextprotocol/json/internal/DefaultMcpJsonSchemaValidatorSupplier.java +++ /dev/null @@ -1,27 +0,0 @@ -package io.modelcontextprotocol.json.internal; - -import io.modelcontextprotocol.json.schema.JsonSchemaValidator; -import io.modelcontextprotocol.json.schema.JsonSchemaValidatorSupplier; -import io.modelcontextprotocol.util.McpServiceLoader; - -public class DefaultMcpJsonSchemaValidatorSupplier { - - private static McpServiceLoader mcpServiceLoader; - - public DefaultMcpJsonSchemaValidatorSupplier() { - mcpServiceLoader = new McpServiceLoader(); - } - - void setJsonSchemaValidatorSupplier(JsonSchemaValidatorSupplier supplier) { - mcpServiceLoader.setSupplier(supplier); - } - - void unsetJsonSchemaValidatorSupplier(JsonSchemaValidatorSupplier supplier) { - mcpServiceLoader.unsetSupplier(supplier); - } - - public synchronized static JsonSchemaValidator getDefaultJsonSchemaValidator() { - return mcpServiceLoader.getDefault(); - } - -} diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/server/McpServer.java b/mcp-core/src/main/java/io/modelcontextprotocol/server/McpServer.java index 284f203c3..550630059 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/server/McpServer.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/server/McpServer.java @@ -15,8 +15,7 @@ import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.json.McpJsonMapper; -import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; -import io.modelcontextprotocol.json.internal.DefaultMcpJsonSchemaValidatorSupplier; +import io.modelcontextprotocol.json.internal.DefaultMcpJson; import io.modelcontextprotocol.json.schema.JsonSchemaValidator; import io.modelcontextprotocol.spec.McpSchema; import io.modelcontextprotocol.spec.McpSchema.CallToolResult; @@ -228,10 +227,10 @@ public McpAsyncServer build() { this.instructions); var jsonSchemaValidator = (this.jsonSchemaValidator != null) ? this.jsonSchemaValidator - : DefaultMcpJsonSchemaValidatorSupplier.getDefaultJsonSchemaValidator(); + : DefaultMcpJson.getDefaultJsonSchemaValidator(); return new McpAsyncServer(transportProvider, - jsonMapper == null ? DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper() : jsonMapper, features, + jsonMapper == null ? DefaultMcpJson.getDefaultMcpJsonMapper() : jsonMapper, features, requestTimeout, uriTemplateManagerFactory, jsonSchemaValidator); } @@ -256,9 +255,9 @@ public McpAsyncServer build() { this.resources, this.resourceTemplates, this.prompts, this.completions, this.rootsChangeHandlers, this.instructions); var jsonSchemaValidator = this.jsonSchemaValidator != null ? this.jsonSchemaValidator - : DefaultMcpJsonSchemaValidatorSupplier.getDefaultJsonSchemaValidator(); + : DefaultMcpJson.getDefaultJsonSchemaValidator(); return new McpAsyncServer(transportProvider, - jsonMapper == null ? DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper() : jsonMapper, features, + jsonMapper == null ? DefaultMcpJson.getDefaultMcpJsonMapper() : jsonMapper, features, requestTimeout, uriTemplateManagerFactory, jsonSchemaValidator); } @@ -821,10 +820,9 @@ public McpSyncServer build() { this.immediateExecution); var asyncServer = new McpAsyncServer(transportProvider, - jsonMapper == null ? DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper() : jsonMapper, - asyncFeatures, requestTimeout, uriTemplateManagerFactory, - jsonSchemaValidator != null ? jsonSchemaValidator - : DefaultMcpJsonSchemaValidatorSupplier.getDefaultJsonSchemaValidator()); + jsonMapper == null ? DefaultMcpJson.getDefaultMcpJsonMapper() : jsonMapper, asyncFeatures, + requestTimeout, uriTemplateManagerFactory, + jsonSchemaValidator != null ? jsonSchemaValidator : DefaultMcpJson.getDefaultJsonSchemaValidator()); return new McpSyncServer(asyncServer, this.immediateExecution); } @@ -852,10 +850,10 @@ public McpSyncServer build() { McpServerFeatures.Async asyncFeatures = McpServerFeatures.Async.fromSync(syncFeatures, this.immediateExecution); var jsonSchemaValidator = this.jsonSchemaValidator != null ? this.jsonSchemaValidator - : DefaultMcpJsonSchemaValidatorSupplier.getDefaultJsonSchemaValidator(); + : DefaultMcpJson.getDefaultJsonSchemaValidator(); var asyncServer = new McpAsyncServer(transportProvider, - jsonMapper == null ? DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper() : jsonMapper, - asyncFeatures, this.requestTimeout, this.uriTemplateManagerFactory, jsonSchemaValidator); + jsonMapper == null ? DefaultMcpJson.getDefaultMcpJsonMapper() : jsonMapper, asyncFeatures, + this.requestTimeout, this.uriTemplateManagerFactory, jsonSchemaValidator); return new McpSyncServer(asyncServer, this.immediateExecution); } @@ -1857,9 +1855,9 @@ 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 ? DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper() : jsonMapper, features, - requestTimeout, uriTemplateManagerFactory, jsonSchemaValidator != null ? jsonSchemaValidator - : DefaultMcpJsonSchemaValidatorSupplier.getDefaultJsonSchemaValidator()); + jsonMapper == null ? DefaultMcpJson.getDefaultMcpJsonMapper() : jsonMapper, features, + requestTimeout, uriTemplateManagerFactory, + jsonSchemaValidator != null ? jsonSchemaValidator : DefaultMcpJson.getDefaultJsonSchemaValidator()); } } @@ -2337,10 +2335,9 @@ public McpStatelessSyncServer build() { 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 ? DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper() : jsonMapper, - asyncFeatures, requestTimeout, uriTemplateManagerFactory, - this.jsonSchemaValidator != null ? this.jsonSchemaValidator - : DefaultMcpJsonSchemaValidatorSupplier.getDefaultJsonSchemaValidator()); + jsonMapper == null ? DefaultMcpJson.getDefaultMcpJsonMapper() : jsonMapper, asyncFeatures, + requestTimeout, uriTemplateManagerFactory, this.jsonSchemaValidator != null + ? this.jsonSchemaValidator : DefaultMcpJson.getDefaultJsonSchemaValidator()); return new McpStatelessSyncServer(asyncServer, this.immediateExecution); } diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletSseServerTransportProvider.java b/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletSseServerTransportProvider.java index fe5842953..ba959ccfc 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletSseServerTransportProvider.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletSseServerTransportProvider.java @@ -20,7 +20,7 @@ import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.json.McpJsonMapper; import io.modelcontextprotocol.json.TypeRef; -import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; +import io.modelcontextprotocol.json.internal.DefaultMcpJson; import io.modelcontextprotocol.server.McpTransportContextExtractor; import io.modelcontextprotocol.spec.McpError; import io.modelcontextprotocol.spec.McpSchema; @@ -634,7 +634,7 @@ public HttpServletSseServerTransportProvider build() { throw new IllegalStateException("MessageEndpoint must be set"); } return new HttpServletSseServerTransportProvider( - jsonMapper == null ? DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper() : jsonMapper, baseUrl, + jsonMapper == null ? DefaultMcpJson.getDefaultMcpJsonMapper() : jsonMapper, baseUrl, messageEndpoint, sseEndpoint, keepAliveInterval, contextExtractor); } diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletStatelessServerTransport.java b/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletStatelessServerTransport.java index a4449615d..900203da5 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletStatelessServerTransport.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletStatelessServerTransport.java @@ -13,7 +13,7 @@ import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.json.McpJsonMapper; -import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; +import io.modelcontextprotocol.json.internal.DefaultMcpJson; import io.modelcontextprotocol.server.McpStatelessServerHandler; import io.modelcontextprotocol.server.McpTransportContextExtractor; import io.modelcontextprotocol.spec.McpError; @@ -297,8 +297,8 @@ public Builder contextExtractor(McpTransportContextExtractor public HttpServletStatelessServerTransport build() { Assert.notNull(mcpEndpoint, "Message endpoint must be set"); return new HttpServletStatelessServerTransport( - jsonMapper == null ? DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper() : jsonMapper, - mcpEndpoint, contextExtractor); + jsonMapper == null ? DefaultMcpJson.getDefaultMcpJsonMapper() : jsonMapper, mcpEndpoint, + contextExtractor); } } diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletStreamableServerTransportProvider.java b/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletStreamableServerTransportProvider.java index fb30f0005..66647f07a 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletStreamableServerTransportProvider.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletStreamableServerTransportProvider.java @@ -19,7 +19,7 @@ import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.json.McpJsonMapper; import io.modelcontextprotocol.json.TypeRef; -import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; +import io.modelcontextprotocol.json.internal.DefaultMcpJson; import io.modelcontextprotocol.server.McpTransportContextExtractor; import io.modelcontextprotocol.spec.HttpHeaders; import io.modelcontextprotocol.spec.McpError; @@ -842,8 +842,8 @@ public Builder keepAliveInterval(Duration keepAliveInterval) { public HttpServletStreamableServerTransportProvider build() { Assert.notNull(this.mcpEndpoint, "MCP endpoint must be set"); return new HttpServletStreamableServerTransportProvider( - jsonMapper == null ? DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper() : jsonMapper, - mcpEndpoint, disallowDelete, contextExtractor, keepAliveInterval); + jsonMapper == null ? DefaultMcpJson.getDefaultMcpJsonMapper() : jsonMapper, mcpEndpoint, + disallowDelete, contextExtractor, keepAliveInterval); } } diff --git a/mcp-core/src/main/resources/OSGI-INF/io.modelcontextprotocol.json.internal.DefaultMcpJsonSchemaValidatorSupplier.xml b/mcp-core/src/main/resources/OSGI-INF/io.modelcontextprotocol.json.internal.DefaultMcpJson.xml similarity index 59% rename from mcp-core/src/main/resources/OSGI-INF/io.modelcontextprotocol.json.internal.DefaultMcpJsonSchemaValidatorSupplier.xml rename to mcp-core/src/main/resources/OSGI-INF/io.modelcontextprotocol.json.internal.DefaultMcpJson.xml index 19a8acc9e..ab9934d79 100644 --- a/mcp-core/src/main/resources/OSGI-INF/io.modelcontextprotocol.json.internal.DefaultMcpJsonSchemaValidatorSupplier.xml +++ b/mcp-core/src/main/resources/OSGI-INF/io.modelcontextprotocol.json.internal.DefaultMcpJson.xml @@ -1,5 +1,6 @@ - + + - + diff --git a/mcp-core/src/main/resources/OSGI-INF/io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier.xml b/mcp-core/src/main/resources/OSGI-INF/io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier.xml deleted file mode 100644 index 5129cacad..000000000 --- a/mcp-core/src/main/resources/OSGI-INF/io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/MockMcpClientTransport.java b/mcp-core/src/test/java/io/modelcontextprotocol/MockMcpClientTransport.java index 2f8e4601c..1ec15c614 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/MockMcpClientTransport.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/MockMcpClientTransport.java @@ -10,6 +10,7 @@ import java.util.function.Function; import io.modelcontextprotocol.json.TypeRef; +import io.modelcontextprotocol.json.internal.DefaultMcpJson; import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; import io.modelcontextprotocol.spec.McpClientTransport; import io.modelcontextprotocol.spec.McpSchema; @@ -100,7 +101,7 @@ public Mono closeGracefully() { @Override public T unmarshalFrom(Object data, TypeRef typeRef) { - return DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper().convertValue(data, typeRef); + return DefaultMcpJson.getDefaultMcpJsonMapper().convertValue(data, typeRef); } } diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/MockMcpServerTransport.java b/mcp-core/src/test/java/io/modelcontextprotocol/MockMcpServerTransport.java index 7231ad45d..5e06c1831 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/MockMcpServerTransport.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/MockMcpServerTransport.java @@ -9,6 +9,7 @@ import java.util.function.BiConsumer; import io.modelcontextprotocol.json.TypeRef; +import io.modelcontextprotocol.json.internal.DefaultMcpJson; import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; import io.modelcontextprotocol.spec.McpSchema; import io.modelcontextprotocol.spec.McpSchema.JSONRPCNotification; @@ -68,7 +69,7 @@ public Mono closeGracefully() { @Override public T unmarshalFrom(Object data, TypeRef typeRef) { - return DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper().convertValue(data, typeRef); + return DefaultMcpJson.getDefaultMcpJsonMapper().convertValue(data, typeRef); } } diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/spec/CompleteCompletionSerializationTest.java b/mcp-core/src/test/java/io/modelcontextprotocol/spec/CompleteCompletionSerializationTest.java index 8374c28ea..693802699 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/spec/CompleteCompletionSerializationTest.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/spec/CompleteCompletionSerializationTest.java @@ -8,13 +8,14 @@ import org.junit.jupiter.api.Test; import io.modelcontextprotocol.json.McpJsonMapper; +import io.modelcontextprotocol.json.internal.DefaultMcpJson; import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; class CompleteCompletionSerializationTest { @Test void codeCompletionSerialization() throws IOException { - McpJsonMapper jsonMapper = DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper(); + McpJsonMapper jsonMapper = DefaultMcpJson.getDefaultMcpJsonMapper(); McpSchema.CompleteResult.CompleteCompletion codeComplete = new McpSchema.CompleteResult.CompleteCompletion( Collections.emptyList(), 0, false); String json = jsonMapper.writeValueAsString(codeComplete); diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/util/McpJsonMapperUtils.java b/mcp-core/src/test/java/io/modelcontextprotocol/util/McpJsonMapperUtils.java index f2b574a45..b29ac9b0a 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/util/McpJsonMapperUtils.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/util/McpJsonMapperUtils.java @@ -1,6 +1,7 @@ package io.modelcontextprotocol.util; import io.modelcontextprotocol.json.McpJsonMapper; +import io.modelcontextprotocol.json.internal.DefaultMcpJson; import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; public final class McpJsonMapperUtils { @@ -8,6 +9,6 @@ public final class McpJsonMapperUtils { private McpJsonMapperUtils() { } - public static final McpJsonMapper JSON_MAPPER = DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper(); + public static final McpJsonMapper JSON_MAPPER = DefaultMcpJson.getDefaultMcpJsonMapper(); } diff --git a/mcp-json-jackson2/pom.xml b/mcp-json-jackson2/pom.xml index b2c9bace4..4c67f7bc7 100644 --- a/mcp-json-jackson2/pom.xml +++ b/mcp-json-jackson2/pom.xml @@ -37,6 +37,7 @@ Bundle-SymbolicName: ${project.groupId}.${project.artifactId} Bundle-Version: ${version} Automatic-Module-Name: ${project.groupId}.${project.artifactId} + Bundle-ActivationPolicy: lazy Import-Package: io.modelcontextprotocol.json,io.modelcontextprotocol.json.schema, \ *; Service-Component: OSGI-INF/io.modelcontextprotocol.json.jackson.JacksonMcpJsonMapperSupplier.xml,OSGI-INF/io.modelcontextprotocol.json.schema.jackson.JacksonJsonSchemaValidatorSupplier.xml diff --git a/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/client/transport/WebClientStreamableHttpTransport.java b/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/client/transport/WebClientStreamableHttpTransport.java index 616c09859..78e88db84 100644 --- a/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/client/transport/WebClientStreamableHttpTransport.java +++ b/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/client/transport/WebClientStreamableHttpTransport.java @@ -26,7 +26,7 @@ import io.modelcontextprotocol.json.McpJsonMapper; import io.modelcontextprotocol.json.TypeRef; -import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; +import io.modelcontextprotocol.json.internal.DefaultMcpJson; import io.modelcontextprotocol.spec.ClosedMcpTransportSession; import io.modelcontextprotocol.spec.DefaultMcpTransportSession; import io.modelcontextprotocol.spec.DefaultMcpTransportStream; @@ -596,8 +596,8 @@ public Builder supportedProtocolVersions(List supportedProtocolVersions) */ public WebClientStreamableHttpTransport build() { return new WebClientStreamableHttpTransport( - jsonMapper == null ? DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper() : jsonMapper, - webClientBuilder, endpoint, resumableStreams, openConnectionOnStartup, supportedProtocolVersions); + jsonMapper == null ? DefaultMcpJson.getDefaultMcpJsonMapper() : jsonMapper, webClientBuilder, + endpoint, resumableStreams, openConnectionOnStartup, supportedProtocolVersions); } } diff --git a/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/client/transport/WebFluxSseClientTransport.java b/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/client/transport/WebFluxSseClientTransport.java index 2a9c0e202..45ee67449 100644 --- a/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/client/transport/WebFluxSseClientTransport.java +++ b/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/client/transport/WebFluxSseClientTransport.java @@ -11,7 +11,7 @@ import io.modelcontextprotocol.json.McpJsonMapper; import io.modelcontextprotocol.json.TypeRef; -import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; +import io.modelcontextprotocol.json.internal.DefaultMcpJson; import io.modelcontextprotocol.spec.HttpHeaders; import io.modelcontextprotocol.spec.McpClientTransport; import io.modelcontextprotocol.spec.McpSchema; @@ -404,8 +404,7 @@ public Builder jsonMapper(McpJsonMapper jsonMapper) { */ public WebFluxSseClientTransport build() { return new WebFluxSseClientTransport(webClientBuilder, - jsonMapper == null ? DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper() : jsonMapper, - sseEndpoint); + jsonMapper == null ? DefaultMcpJson.getDefaultMcpJsonMapper() : jsonMapper, sseEndpoint); } } diff --git a/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/server/transport/WebFluxSseServerTransportProvider.java b/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/server/transport/WebFluxSseServerTransportProvider.java index a01261e04..128a47bb9 100644 --- a/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/server/transport/WebFluxSseServerTransportProvider.java +++ b/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/server/transport/WebFluxSseServerTransportProvider.java @@ -12,7 +12,7 @@ import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.json.McpJsonMapper; import io.modelcontextprotocol.json.TypeRef; -import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; +import io.modelcontextprotocol.json.internal.DefaultMcpJson; import io.modelcontextprotocol.server.McpTransportContextExtractor; import io.modelcontextprotocol.spec.McpError; import io.modelcontextprotocol.spec.McpSchema; @@ -523,7 +523,7 @@ public Builder contextExtractor(McpTransportContextExtractor cont public WebFluxSseServerTransportProvider build() { Assert.notNull(messageEndpoint, "Message endpoint must be set"); return new WebFluxSseServerTransportProvider( - jsonMapper == null ? DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper() : jsonMapper, baseUrl, + jsonMapper == null ? DefaultMcpJson.getDefaultMcpJsonMapper() : jsonMapper, baseUrl, messageEndpoint, sseEndpoint, keepAliveInterval, contextExtractor); } diff --git a/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/server/transport/WebFluxStatelessServerTransport.java b/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/server/transport/WebFluxStatelessServerTransport.java index ef95bb8b2..afc3ff17e 100644 --- a/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/server/transport/WebFluxStatelessServerTransport.java +++ b/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/server/transport/WebFluxStatelessServerTransport.java @@ -5,7 +5,7 @@ package io.modelcontextprotocol.server.transport; import io.modelcontextprotocol.json.McpJsonMapper; -import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; +import io.modelcontextprotocol.json.internal.DefaultMcpJson; import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.server.McpStatelessServerHandler; import io.modelcontextprotocol.server.McpTransportContextExtractor; @@ -215,8 +215,8 @@ public Builder contextExtractor(McpTransportContextExtractor cont public WebFluxStatelessServerTransport build() { Assert.notNull(mcpEndpoint, "Message endpoint must be set"); return new WebFluxStatelessServerTransport( - jsonMapper == null ? DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper() : jsonMapper, - mcpEndpoint, contextExtractor); + jsonMapper == null ? DefaultMcpJson.getDefaultMcpJsonMapper() : jsonMapper, mcpEndpoint, + contextExtractor); } } diff --git a/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/server/transport/WebFluxStreamableServerTransportProvider.java b/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/server/transport/WebFluxStreamableServerTransportProvider.java index b9e47f8a7..321331541 100644 --- a/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/server/transport/WebFluxStreamableServerTransportProvider.java +++ b/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/server/transport/WebFluxStreamableServerTransportProvider.java @@ -6,7 +6,7 @@ import io.modelcontextprotocol.json.McpJsonMapper; import io.modelcontextprotocol.json.TypeRef; -import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; +import io.modelcontextprotocol.json.internal.DefaultMcpJson; import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.server.McpTransportContextExtractor; import io.modelcontextprotocol.spec.HttpHeaders; @@ -487,8 +487,8 @@ public Builder keepAliveInterval(Duration keepAliveInterval) { public WebFluxStreamableServerTransportProvider build() { Assert.notNull(mcpEndpoint, "Message endpoint must be set"); return new WebFluxStreamableServerTransportProvider( - jsonMapper == null ? DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper() : jsonMapper, - mcpEndpoint, contextExtractor, disallowDelete, keepAliveInterval); + jsonMapper == null ? DefaultMcpJson.getDefaultMcpJsonMapper() : jsonMapper, mcpEndpoint, + contextExtractor, disallowDelete, keepAliveInterval); } } diff --git a/mcp-spring/mcp-spring-webflux/src/test/java/io/modelcontextprotocol/utils/McpJsonMapperUtils.java b/mcp-spring/mcp-spring-webflux/src/test/java/io/modelcontextprotocol/utils/McpJsonMapperUtils.java index c7ad34048..fa27a794d 100644 --- a/mcp-spring/mcp-spring-webflux/src/test/java/io/modelcontextprotocol/utils/McpJsonMapperUtils.java +++ b/mcp-spring/mcp-spring-webflux/src/test/java/io/modelcontextprotocol/utils/McpJsonMapperUtils.java @@ -1,13 +1,13 @@ package io.modelcontextprotocol.utils; import io.modelcontextprotocol.json.McpJsonMapper; -import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; +import io.modelcontextprotocol.json.internal.DefaultMcpJson; public final class McpJsonMapperUtils { private McpJsonMapperUtils() { } - public static final McpJsonMapper JSON_MAPPER = DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper(); + public static final McpJsonMapper JSON_MAPPER = DefaultMcpJson.getDefaultMcpJsonMapper(); } \ No newline at end of file diff --git a/mcp-spring/mcp-spring-webmvc/pom.xml b/mcp-spring/mcp-spring-webmvc/pom.xml index 6460f652f..3e77e6333 100644 --- a/mcp-spring/mcp-spring-webmvc/pom.xml +++ b/mcp-spring/mcp-spring-webmvc/pom.xml @@ -30,7 +30,7 @@ io.modelcontextprotocol.sdk - mcp + mcp-core 0.17.0-SNAPSHOT diff --git a/mcp-spring/mcp-spring-webmvc/src/main/java/io/modelcontextprotocol/server/transport/WebMvcSseServerTransportProvider.java b/mcp-spring/mcp-spring-webmvc/src/main/java/io/modelcontextprotocol/server/transport/WebMvcSseServerTransportProvider.java index b8eb27708..f20bdaeb0 100644 --- a/mcp-spring/mcp-spring-webmvc/src/main/java/io/modelcontextprotocol/server/transport/WebMvcSseServerTransportProvider.java +++ b/mcp-spring/mcp-spring-webmvc/src/main/java/io/modelcontextprotocol/server/transport/WebMvcSseServerTransportProvider.java @@ -14,7 +14,7 @@ import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.json.McpJsonMapper; import io.modelcontextprotocol.json.TypeRef; -import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; +import io.modelcontextprotocol.json.internal.DefaultMcpJson; import io.modelcontextprotocol.server.McpTransportContextExtractor; import io.modelcontextprotocol.spec.McpError; import io.modelcontextprotocol.spec.McpSchema; @@ -579,7 +579,7 @@ public WebMvcSseServerTransportProvider build() { throw new IllegalStateException("MessageEndpoint must be set"); } return new WebMvcSseServerTransportProvider( - jsonMapper == null ? DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper() : jsonMapper, baseUrl, + jsonMapper == null ? DefaultMcpJson.getDefaultMcpJsonMapper() : jsonMapper, baseUrl, messageEndpoint, sseEndpoint, keepAliveInterval, contextExtractor); } diff --git a/mcp-spring/mcp-spring-webmvc/src/main/java/io/modelcontextprotocol/server/transport/WebMvcStatelessServerTransport.java b/mcp-spring/mcp-spring-webmvc/src/main/java/io/modelcontextprotocol/server/transport/WebMvcStatelessServerTransport.java index 07b6565e2..2c8c92acd 100644 --- a/mcp-spring/mcp-spring-webmvc/src/main/java/io/modelcontextprotocol/server/transport/WebMvcStatelessServerTransport.java +++ b/mcp-spring/mcp-spring-webmvc/src/main/java/io/modelcontextprotocol/server/transport/WebMvcStatelessServerTransport.java @@ -6,7 +6,7 @@ import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.json.McpJsonMapper; -import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; +import io.modelcontextprotocol.json.internal.DefaultMcpJson; import io.modelcontextprotocol.server.McpStatelessServerHandler; import io.modelcontextprotocol.server.McpTransportContextExtractor; import io.modelcontextprotocol.spec.McpError; @@ -233,8 +233,8 @@ public Builder contextExtractor(McpTransportContextExtractor cont public WebMvcStatelessServerTransport build() { Assert.notNull(mcpEndpoint, "Message endpoint must be set"); return new WebMvcStatelessServerTransport( - jsonMapper == null ? DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper() : jsonMapper, - mcpEndpoint, contextExtractor); + jsonMapper == null ? DefaultMcpJson.getDefaultMcpJsonMapper() : jsonMapper, mcpEndpoint, + contextExtractor); } } diff --git a/mcp-spring/mcp-spring-webmvc/src/main/java/io/modelcontextprotocol/server/transport/WebMvcStreamableServerTransportProvider.java b/mcp-spring/mcp-spring-webmvc/src/main/java/io/modelcontextprotocol/server/transport/WebMvcStreamableServerTransportProvider.java index 003548ad6..5d0be7509 100644 --- a/mcp-spring/mcp-spring-webmvc/src/main/java/io/modelcontextprotocol/server/transport/WebMvcStreamableServerTransportProvider.java +++ b/mcp-spring/mcp-spring-webmvc/src/main/java/io/modelcontextprotocol/server/transport/WebMvcStreamableServerTransportProvider.java @@ -22,7 +22,7 @@ import org.springframework.web.servlet.function.ServerResponse.SseBuilder; import io.modelcontextprotocol.json.TypeRef; -import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; +import io.modelcontextprotocol.json.internal.DefaultMcpJson; import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.server.McpTransportContextExtractor; import io.modelcontextprotocol.spec.HttpHeaders; @@ -681,8 +681,8 @@ public Builder keepAliveInterval(Duration keepAliveInterval) { public WebMvcStreamableServerTransportProvider build() { Assert.notNull(this.mcpEndpoint, "MCP endpoint must be set"); return new WebMvcStreamableServerTransportProvider( - jsonMapper == null ? DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper() : jsonMapper, - mcpEndpoint, disallowDelete, contextExtractor, keepAliveInterval); + jsonMapper == null ? DefaultMcpJson.getDefaultMcpJsonMapper() : jsonMapper, mcpEndpoint, + disallowDelete, contextExtractor, keepAliveInterval); } } diff --git a/mcp-spring/mcp-spring-webmvc/src/test/java/io/modelcontextprotocol/server/transport/WebMvcSseServerTransportProviderTests.java b/mcp-spring/mcp-spring-webmvc/src/test/java/io/modelcontextprotocol/server/transport/WebMvcSseServerTransportProviderTests.java index c4d415ead..93b50b66f 100644 --- a/mcp-spring/mcp-spring-webmvc/src/test/java/io/modelcontextprotocol/server/transport/WebMvcSseServerTransportProviderTests.java +++ b/mcp-spring/mcp-spring-webmvc/src/test/java/io/modelcontextprotocol/server/transport/WebMvcSseServerTransportProviderTests.java @@ -8,7 +8,7 @@ import io.modelcontextprotocol.client.transport.HttpClientSseClientTransport; import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.json.McpJsonMapper; -import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; +import io.modelcontextprotocol.json.internal.DefaultMcpJson; import io.modelcontextprotocol.server.McpServer; import io.modelcontextprotocol.server.TestUtil; import io.modelcontextprotocol.server.TomcatTestUtil; @@ -105,7 +105,7 @@ public WebMvcSseServerTransportProvider webMvcSseServerTransportProvider() { .baseUrl("http://localhost:" + PORT + "/") .messageEndpoint(MESSAGE_ENDPOINT) .sseEndpoint(WebMvcSseServerTransportProvider.DEFAULT_SSE_ENDPOINT) - .jsonMapper(DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper()) + .jsonMapper(DefaultMcpJson.getDefaultMcpJsonMapper()) .contextExtractor(req -> McpTransportContext.EMPTY) .build(); } diff --git a/mcp-test/src/main/java/io/modelcontextprotocol/MockMcpTransport.java b/mcp-test/src/main/java/io/modelcontextprotocol/MockMcpTransport.java index 5beb7fc8b..e5e005932 100644 --- a/mcp-test/src/main/java/io/modelcontextprotocol/MockMcpTransport.java +++ b/mcp-test/src/main/java/io/modelcontextprotocol/MockMcpTransport.java @@ -11,7 +11,7 @@ import io.modelcontextprotocol.json.McpJsonMapper; import io.modelcontextprotocol.json.TypeRef; -import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; +import io.modelcontextprotocol.json.internal.DefaultMcpJson; import io.modelcontextprotocol.spec.McpClientTransport; import io.modelcontextprotocol.spec.McpSchema; import io.modelcontextprotocol.spec.McpSchema.JSONRPCNotification; @@ -95,7 +95,7 @@ public Mono closeGracefully() { @Override public T unmarshalFrom(Object data, TypeRef typeRef) { - return DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper().convertValue(data, typeRef); + return DefaultMcpJson.getDefaultMcpJsonMapper().convertValue(data, typeRef); } } diff --git a/mcp-test/src/main/java/io/modelcontextprotocol/util/McpJsonMapperUtils.java b/mcp-test/src/main/java/io/modelcontextprotocol/util/McpJsonMapperUtils.java index 3c58f9cfe..261288dee 100644 --- a/mcp-test/src/main/java/io/modelcontextprotocol/util/McpJsonMapperUtils.java +++ b/mcp-test/src/main/java/io/modelcontextprotocol/util/McpJsonMapperUtils.java @@ -1,13 +1,13 @@ package io.modelcontextprotocol.util; import io.modelcontextprotocol.json.McpJsonMapper; -import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; +import io.modelcontextprotocol.json.internal.DefaultMcpJson; public final class McpJsonMapperUtils { private McpJsonMapperUtils() { } - public static final McpJsonMapper JSON_MAPPER = DefaultMcpJsonMapperSupplier.getDefaultMcpJsonMapper(); + public static final McpJsonMapper JSON_MAPPER = DefaultMcpJson.getDefaultMcpJsonMapper(); } \ No newline at end of file From 1384a8f920f44fcf3da0bb6af3196c1efc9ca4aa Mon Sep 17 00:00:00 2001 From: Scott Lewis Date: Sun, 23 Nov 2025 17:02:30 -0800 Subject: [PATCH 06/11] Fix for initialization in non-osgi environment case --- .../modelcontextprotocol/json/internal/DefaultMcpJson.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/json/internal/DefaultMcpJson.java b/mcp-core/src/main/java/io/modelcontextprotocol/json/internal/DefaultMcpJson.java index 2e4be4b58..b0fbe46b9 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/json/internal/DefaultMcpJson.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/json/internal/DefaultMcpJson.java @@ -26,6 +26,9 @@ void unsetMcpJsonMapperSupplier(McpJsonMapperSupplier supplier) { } public synchronized static McpJsonMapper getDefaultMcpJsonMapper() { + if (mcpMapperServiceLoader == null) { + new DefaultMcpJson(); + } return mcpMapperServiceLoader.getDefault(); } @@ -38,6 +41,9 @@ void unsetJsonSchemaValidatorSupplier(JsonSchemaValidatorSupplier supplier) { } public synchronized static JsonSchemaValidator getDefaultJsonSchemaValidator() { + if (mcpValidatorServiceLoader == null) { + new DefaultMcpJson(); + } return mcpValidatorServiceLoader.getDefault(); } From a17175d5b536f4878c057819fe9d898a5e658c68 Mon Sep 17 00:00:00 2001 From: Scott Lewis Date: Mon, 24 Nov 2025 17:45:31 -0800 Subject: [PATCH 07/11] Refactor of DefaultMcpJson to McpJsonDefaults class for entry point for access to default mapper and defaul validator services. --- mcp-core/pom.xml | 2 +- .../client/McpClient.java | 6 ++-- .../HttpClientSseClientTransport.java | 4 +-- .../HttpClientStreamableHttpTransport.java | 4 +-- ...faultMcpJson.java => McpJsonDefaults.java} | 12 ++++---- .../server/McpServer.java | 30 +++++++++---------- ...HttpServletSseServerTransportProvider.java | 4 +-- .../HttpServletStatelessServerTransport.java | 4 +-- ...vletStreamableServerTransportProvider.java | 4 +-- ...elcontextprotocol.json.McpJsonDefaults.xml | 9 ++++++ .../MockMcpClientTransport.java | 4 +-- .../MockMcpServerTransport.java | 4 +-- .../CompleteCompletionSerializationTest.java | 4 +-- .../util/McpJsonMapperUtils.java | 4 +-- .../WebClientStreamableHttpTransport.java | 4 +-- .../transport/WebFluxSseClientTransport.java | 4 +-- .../WebFluxSseServerTransportProvider.java | 4 +-- .../WebFluxStatelessServerTransport.java | 4 +-- ...FluxStreamableServerTransportProvider.java | 4 +-- .../utils/McpJsonMapperUtils.java | 4 +-- .../WebMvcSseServerTransportProvider.java | 4 +-- .../WebMvcStatelessServerTransport.java | 4 +-- ...bMvcStreamableServerTransportProvider.java | 4 +-- ...WebMvcSseServerTransportProviderTests.java | 4 +-- .../MockMcpTransport.java | 4 +-- .../util/McpJsonMapperUtils.java | 4 +-- 26 files changed, 75 insertions(+), 68 deletions(-) rename mcp-core/src/main/java/io/modelcontextprotocol/json/{internal/DefaultMcpJson.java => McpJsonDefaults.java} (84%) create mode 100644 mcp-core/src/main/resources/OSGI-INF/io.modelcontextprotocol.json.McpJsonDefaults.xml diff --git a/mcp-core/pom.xml b/mcp-core/pom.xml index b48b5e140..d47b8011a 100644 --- a/mcp-core/pom.xml +++ b/mcp-core/pom.xml @@ -43,7 +43,7 @@ Import-Package: jakarta.*;resolution:=optional, \ *; Export-Package: io.modelcontextprotocol.*;version="${version}";-noimport:=true - Service-Component: OSGI-INF/io.modelcontextprotocol.json.internal.DefaultMcpJson.xml + Service-Component: OSGI-INF/io.modelcontextprotocol.json.McpJsonDefaults.xml -noimportjava: true; -nouses: true; -removeheaders: Private-Package diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/client/McpClient.java b/mcp-core/src/main/java/io/modelcontextprotocol/client/McpClient.java index 485c03fb0..ad851c0c4 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/client/McpClient.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/client/McpClient.java @@ -14,7 +14,7 @@ import java.util.function.Supplier; import io.modelcontextprotocol.common.McpTransportContext; -import io.modelcontextprotocol.json.internal.DefaultMcpJson; +import io.modelcontextprotocol.json.McpJsonDefaults; import io.modelcontextprotocol.json.schema.JsonSchemaValidator; import io.modelcontextprotocol.spec.McpClientTransport; import io.modelcontextprotocol.spec.McpSchema; @@ -478,7 +478,7 @@ public McpSyncClient build() { return new McpSyncClient( new McpAsyncClient(transport, this.requestTimeout, this.initializationTimeout, jsonSchemaValidator != null ? jsonSchemaValidator - : DefaultMcpJson.getDefaultJsonSchemaValidator(), + : McpJsonDefaults.getDefaultJsonSchemaValidator(), asyncFeatures), this.contextProvider); } @@ -813,7 +813,7 @@ public AsyncSpec enableCallToolSchemaCaching(boolean enableCallToolSchemaCaching */ public McpAsyncClient build() { var jsonSchemaValidator = (this.jsonSchemaValidator != null) ? this.jsonSchemaValidator - : DefaultMcpJson.getDefaultJsonSchemaValidator(); + : McpJsonDefaults.getDefaultJsonSchemaValidator(); return new McpAsyncClient(this.transport, this.requestTimeout, this.initializationTimeout, jsonSchemaValidator, new McpClientFeatures.Async(this.clientInfo, this.capabilities, this.roots, diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/HttpClientSseClientTransport.java b/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/HttpClientSseClientTransport.java index 5f1df2aee..4665bed7e 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/HttpClientSseClientTransport.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/HttpClientSseClientTransport.java @@ -23,9 +23,9 @@ import io.modelcontextprotocol.client.transport.customizer.McpAsyncHttpClientRequestCustomizer; import io.modelcontextprotocol.client.transport.customizer.McpSyncHttpClientRequestCustomizer; import io.modelcontextprotocol.common.McpTransportContext; +import io.modelcontextprotocol.json.McpJsonDefaults; import io.modelcontextprotocol.json.McpJsonMapper; import io.modelcontextprotocol.json.TypeRef; -import io.modelcontextprotocol.json.internal.DefaultMcpJson; import io.modelcontextprotocol.spec.HttpHeaders; import io.modelcontextprotocol.spec.McpClientTransport; import io.modelcontextprotocol.spec.McpError; @@ -330,7 +330,7 @@ public Builder connectTimeout(Duration connectTimeout) { public HttpClientSseClientTransport build() { HttpClient httpClient = this.clientBuilder.connectTimeout(this.connectTimeout).build(); return new HttpClientSseClientTransport(httpClient, requestBuilder, baseUri, sseEndpoint, - jsonMapper == null ? DefaultMcpJson.getDefaultMcpJsonMapper() : jsonMapper, httpRequestCustomizer); + jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, httpRequestCustomizer); } } diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/HttpClientStreamableHttpTransport.java b/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/HttpClientStreamableHttpTransport.java index 6cff190d2..ed32b93c6 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/HttpClientStreamableHttpTransport.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/HttpClientStreamableHttpTransport.java @@ -28,9 +28,9 @@ import io.modelcontextprotocol.client.transport.customizer.McpAsyncHttpClientRequestCustomizer; import io.modelcontextprotocol.client.transport.customizer.McpSyncHttpClientRequestCustomizer; import io.modelcontextprotocol.common.McpTransportContext; +import io.modelcontextprotocol.json.McpJsonDefaults; import io.modelcontextprotocol.json.McpJsonMapper; import io.modelcontextprotocol.json.TypeRef; -import io.modelcontextprotocol.json.internal.DefaultMcpJson; import io.modelcontextprotocol.spec.ClosedMcpTransportSession; import io.modelcontextprotocol.spec.DefaultMcpTransportSession; import io.modelcontextprotocol.spec.DefaultMcpTransportStream; @@ -816,7 +816,7 @@ public Builder supportedProtocolVersions(List supportedProtocolVersions) public HttpClientStreamableHttpTransport build() { HttpClient httpClient = this.clientBuilder.connectTimeout(this.connectTimeout).build(); return new HttpClientStreamableHttpTransport( - jsonMapper == null ? DefaultMcpJson.getDefaultMcpJsonMapper() : jsonMapper, httpClient, + jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, httpClient, requestBuilder, baseUri, endpoint, resumableStreams, openConnectionOnStartup, httpRequestCustomizer, supportedProtocolVersions); } diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/json/internal/DefaultMcpJson.java b/mcp-core/src/main/java/io/modelcontextprotocol/json/McpJsonDefaults.java similarity index 84% rename from mcp-core/src/main/java/io/modelcontextprotocol/json/internal/DefaultMcpJson.java rename to mcp-core/src/main/java/io/modelcontextprotocol/json/McpJsonDefaults.java index b0fbe46b9..3538ad333 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/json/internal/DefaultMcpJson.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/json/McpJsonDefaults.java @@ -1,18 +1,16 @@ -package io.modelcontextprotocol.json.internal; +package io.modelcontextprotocol.json; -import io.modelcontextprotocol.json.McpJsonMapper; -import io.modelcontextprotocol.json.McpJsonMapperSupplier; import io.modelcontextprotocol.json.schema.JsonSchemaValidator; import io.modelcontextprotocol.json.schema.JsonSchemaValidatorSupplier; import io.modelcontextprotocol.util.McpServiceLoader; -public class DefaultMcpJson { +public class McpJsonDefaults { protected static McpServiceLoader mcpMapperServiceLoader; protected static McpServiceLoader mcpValidatorServiceLoader; - public DefaultMcpJson() { + public McpJsonDefaults() { mcpMapperServiceLoader = new McpServiceLoader(); mcpValidatorServiceLoader = new McpServiceLoader(); } @@ -27,7 +25,7 @@ void unsetMcpJsonMapperSupplier(McpJsonMapperSupplier supplier) { public synchronized static McpJsonMapper getDefaultMcpJsonMapper() { if (mcpMapperServiceLoader == null) { - new DefaultMcpJson(); + new McpJsonDefaults(); } return mcpMapperServiceLoader.getDefault(); } @@ -42,7 +40,7 @@ void unsetJsonSchemaValidatorSupplier(JsonSchemaValidatorSupplier supplier) { public synchronized static JsonSchemaValidator getDefaultJsonSchemaValidator() { if (mcpValidatorServiceLoader == null) { - new DefaultMcpJson(); + new McpJsonDefaults(); } return mcpValidatorServiceLoader.getDefault(); } diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/server/McpServer.java b/mcp-core/src/main/java/io/modelcontextprotocol/server/McpServer.java index 550630059..267a0b40c 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/server/McpServer.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/server/McpServer.java @@ -14,8 +14,8 @@ import java.util.function.BiFunction; import io.modelcontextprotocol.common.McpTransportContext; +import io.modelcontextprotocol.json.McpJsonDefaults; import io.modelcontextprotocol.json.McpJsonMapper; -import io.modelcontextprotocol.json.internal.DefaultMcpJson; import io.modelcontextprotocol.json.schema.JsonSchemaValidator; import io.modelcontextprotocol.spec.McpSchema; import io.modelcontextprotocol.spec.McpSchema.CallToolResult; @@ -227,10 +227,10 @@ public McpAsyncServer build() { this.instructions); var jsonSchemaValidator = (this.jsonSchemaValidator != null) ? this.jsonSchemaValidator - : DefaultMcpJson.getDefaultJsonSchemaValidator(); + : McpJsonDefaults.getDefaultJsonSchemaValidator(); return new McpAsyncServer(transportProvider, - jsonMapper == null ? DefaultMcpJson.getDefaultMcpJsonMapper() : jsonMapper, features, + jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, features, requestTimeout, uriTemplateManagerFactory, jsonSchemaValidator); } @@ -255,9 +255,9 @@ public McpAsyncServer build() { this.resources, this.resourceTemplates, this.prompts, this.completions, this.rootsChangeHandlers, this.instructions); var jsonSchemaValidator = this.jsonSchemaValidator != null ? this.jsonSchemaValidator - : DefaultMcpJson.getDefaultJsonSchemaValidator(); + : McpJsonDefaults.getDefaultJsonSchemaValidator(); return new McpAsyncServer(transportProvider, - jsonMapper == null ? DefaultMcpJson.getDefaultMcpJsonMapper() : jsonMapper, features, + jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, features, requestTimeout, uriTemplateManagerFactory, jsonSchemaValidator); } @@ -820,9 +820,9 @@ public McpSyncServer build() { this.immediateExecution); var asyncServer = new McpAsyncServer(transportProvider, - jsonMapper == null ? DefaultMcpJson.getDefaultMcpJsonMapper() : jsonMapper, asyncFeatures, - requestTimeout, uriTemplateManagerFactory, - jsonSchemaValidator != null ? jsonSchemaValidator : DefaultMcpJson.getDefaultJsonSchemaValidator()); + jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, asyncFeatures, + requestTimeout, uriTemplateManagerFactory, jsonSchemaValidator != null ? jsonSchemaValidator + : McpJsonDefaults.getDefaultJsonSchemaValidator()); return new McpSyncServer(asyncServer, this.immediateExecution); } @@ -850,9 +850,9 @@ public McpSyncServer build() { McpServerFeatures.Async asyncFeatures = McpServerFeatures.Async.fromSync(syncFeatures, this.immediateExecution); var jsonSchemaValidator = this.jsonSchemaValidator != null ? this.jsonSchemaValidator - : DefaultMcpJson.getDefaultJsonSchemaValidator(); + : McpJsonDefaults.getDefaultJsonSchemaValidator(); var asyncServer = new McpAsyncServer(transportProvider, - jsonMapper == null ? DefaultMcpJson.getDefaultMcpJsonMapper() : jsonMapper, asyncFeatures, + jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, asyncFeatures, this.requestTimeout, this.uriTemplateManagerFactory, jsonSchemaValidator); return new McpSyncServer(asyncServer, this.immediateExecution); } @@ -1855,9 +1855,9 @@ 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 ? DefaultMcpJson.getDefaultMcpJsonMapper() : jsonMapper, features, - requestTimeout, uriTemplateManagerFactory, - jsonSchemaValidator != null ? jsonSchemaValidator : DefaultMcpJson.getDefaultJsonSchemaValidator()); + jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, features, + requestTimeout, uriTemplateManagerFactory, jsonSchemaValidator != null ? jsonSchemaValidator + : McpJsonDefaults.getDefaultJsonSchemaValidator()); } } @@ -2335,9 +2335,9 @@ public McpStatelessSyncServer build() { 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 ? DefaultMcpJson.getDefaultMcpJsonMapper() : jsonMapper, asyncFeatures, + jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, asyncFeatures, requestTimeout, uriTemplateManagerFactory, this.jsonSchemaValidator != null - ? this.jsonSchemaValidator : DefaultMcpJson.getDefaultJsonSchemaValidator()); + ? this.jsonSchemaValidator : McpJsonDefaults.getDefaultJsonSchemaValidator()); return new McpStatelessSyncServer(asyncServer, this.immediateExecution); } diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletSseServerTransportProvider.java b/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletSseServerTransportProvider.java index ba959ccfc..bf1d2863a 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletSseServerTransportProvider.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletSseServerTransportProvider.java @@ -18,9 +18,9 @@ import org.slf4j.LoggerFactory; import io.modelcontextprotocol.common.McpTransportContext; +import io.modelcontextprotocol.json.McpJsonDefaults; import io.modelcontextprotocol.json.McpJsonMapper; import io.modelcontextprotocol.json.TypeRef; -import io.modelcontextprotocol.json.internal.DefaultMcpJson; import io.modelcontextprotocol.server.McpTransportContextExtractor; import io.modelcontextprotocol.spec.McpError; import io.modelcontextprotocol.spec.McpSchema; @@ -634,7 +634,7 @@ public HttpServletSseServerTransportProvider build() { throw new IllegalStateException("MessageEndpoint must be set"); } return new HttpServletSseServerTransportProvider( - jsonMapper == null ? DefaultMcpJson.getDefaultMcpJsonMapper() : jsonMapper, baseUrl, + jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, baseUrl, messageEndpoint, sseEndpoint, keepAliveInterval, contextExtractor); } diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletStatelessServerTransport.java b/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletStatelessServerTransport.java index 900203da5..eba7ba976 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletStatelessServerTransport.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletStatelessServerTransport.java @@ -12,8 +12,8 @@ import org.slf4j.LoggerFactory; import io.modelcontextprotocol.common.McpTransportContext; +import io.modelcontextprotocol.json.McpJsonDefaults; import io.modelcontextprotocol.json.McpJsonMapper; -import io.modelcontextprotocol.json.internal.DefaultMcpJson; import io.modelcontextprotocol.server.McpStatelessServerHandler; import io.modelcontextprotocol.server.McpTransportContextExtractor; import io.modelcontextprotocol.spec.McpError; @@ -297,7 +297,7 @@ public Builder contextExtractor(McpTransportContextExtractor public HttpServletStatelessServerTransport build() { Assert.notNull(mcpEndpoint, "Message endpoint must be set"); return new HttpServletStatelessServerTransport( - jsonMapper == null ? DefaultMcpJson.getDefaultMcpJsonMapper() : jsonMapper, mcpEndpoint, + jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, mcpEndpoint, contextExtractor); } diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletStreamableServerTransportProvider.java b/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletStreamableServerTransportProvider.java index 66647f07a..5581e6bcd 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletStreamableServerTransportProvider.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletStreamableServerTransportProvider.java @@ -17,9 +17,9 @@ import org.slf4j.LoggerFactory; import io.modelcontextprotocol.common.McpTransportContext; +import io.modelcontextprotocol.json.McpJsonDefaults; import io.modelcontextprotocol.json.McpJsonMapper; import io.modelcontextprotocol.json.TypeRef; -import io.modelcontextprotocol.json.internal.DefaultMcpJson; import io.modelcontextprotocol.server.McpTransportContextExtractor; import io.modelcontextprotocol.spec.HttpHeaders; import io.modelcontextprotocol.spec.McpError; @@ -842,7 +842,7 @@ public Builder keepAliveInterval(Duration keepAliveInterval) { public HttpServletStreamableServerTransportProvider build() { Assert.notNull(this.mcpEndpoint, "MCP endpoint must be set"); return new HttpServletStreamableServerTransportProvider( - jsonMapper == null ? DefaultMcpJson.getDefaultMcpJsonMapper() : jsonMapper, mcpEndpoint, + jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, mcpEndpoint, disallowDelete, contextExtractor, keepAliveInterval); } diff --git a/mcp-core/src/main/resources/OSGI-INF/io.modelcontextprotocol.json.McpJsonDefaults.xml b/mcp-core/src/main/resources/OSGI-INF/io.modelcontextprotocol.json.McpJsonDefaults.xml new file mode 100644 index 000000000..1a10fdfb3 --- /dev/null +++ b/mcp-core/src/main/resources/OSGI-INF/io.modelcontextprotocol.json.McpJsonDefaults.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/MockMcpClientTransport.java b/mcp-core/src/test/java/io/modelcontextprotocol/MockMcpClientTransport.java index 1ec15c614..027c80602 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/MockMcpClientTransport.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/MockMcpClientTransport.java @@ -9,8 +9,8 @@ import java.util.function.BiConsumer; import java.util.function.Function; +import io.modelcontextprotocol.json.McpJsonDefaults; import io.modelcontextprotocol.json.TypeRef; -import io.modelcontextprotocol.json.internal.DefaultMcpJson; import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; import io.modelcontextprotocol.spec.McpClientTransport; import io.modelcontextprotocol.spec.McpSchema; @@ -101,7 +101,7 @@ public Mono closeGracefully() { @Override public T unmarshalFrom(Object data, TypeRef typeRef) { - return DefaultMcpJson.getDefaultMcpJsonMapper().convertValue(data, typeRef); + return McpJsonDefaults.getDefaultMcpJsonMapper().convertValue(data, typeRef); } } diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/MockMcpServerTransport.java b/mcp-core/src/test/java/io/modelcontextprotocol/MockMcpServerTransport.java index 5e06c1831..e729c24b3 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/MockMcpServerTransport.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/MockMcpServerTransport.java @@ -8,8 +8,8 @@ import java.util.List; import java.util.function.BiConsumer; +import io.modelcontextprotocol.json.McpJsonDefaults; import io.modelcontextprotocol.json.TypeRef; -import io.modelcontextprotocol.json.internal.DefaultMcpJson; import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; import io.modelcontextprotocol.spec.McpSchema; import io.modelcontextprotocol.spec.McpSchema.JSONRPCNotification; @@ -69,7 +69,7 @@ public Mono closeGracefully() { @Override public T unmarshalFrom(Object data, TypeRef typeRef) { - return DefaultMcpJson.getDefaultMcpJsonMapper().convertValue(data, typeRef); + return McpJsonDefaults.getDefaultMcpJsonMapper().convertValue(data, typeRef); } } diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/spec/CompleteCompletionSerializationTest.java b/mcp-core/src/test/java/io/modelcontextprotocol/spec/CompleteCompletionSerializationTest.java index 693802699..e4f2d8aac 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/spec/CompleteCompletionSerializationTest.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/spec/CompleteCompletionSerializationTest.java @@ -7,15 +7,15 @@ import org.junit.jupiter.api.Test; +import io.modelcontextprotocol.json.McpJsonDefaults; import io.modelcontextprotocol.json.McpJsonMapper; -import io.modelcontextprotocol.json.internal.DefaultMcpJson; import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; class CompleteCompletionSerializationTest { @Test void codeCompletionSerialization() throws IOException { - McpJsonMapper jsonMapper = DefaultMcpJson.getDefaultMcpJsonMapper(); + McpJsonMapper jsonMapper = McpJsonDefaults.getDefaultMcpJsonMapper(); McpSchema.CompleteResult.CompleteCompletion codeComplete = new McpSchema.CompleteResult.CompleteCompletion( Collections.emptyList(), 0, false); String json = jsonMapper.writeValueAsString(codeComplete); diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/util/McpJsonMapperUtils.java b/mcp-core/src/test/java/io/modelcontextprotocol/util/McpJsonMapperUtils.java index b29ac9b0a..459701b11 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/util/McpJsonMapperUtils.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/util/McpJsonMapperUtils.java @@ -1,7 +1,7 @@ package io.modelcontextprotocol.util; +import io.modelcontextprotocol.json.McpJsonDefaults; import io.modelcontextprotocol.json.McpJsonMapper; -import io.modelcontextprotocol.json.internal.DefaultMcpJson; import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; public final class McpJsonMapperUtils { @@ -9,6 +9,6 @@ public final class McpJsonMapperUtils { private McpJsonMapperUtils() { } - public static final McpJsonMapper JSON_MAPPER = DefaultMcpJson.getDefaultMcpJsonMapper(); + public static final McpJsonMapper JSON_MAPPER = McpJsonDefaults.getDefaultMcpJsonMapper(); } diff --git a/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/client/transport/WebClientStreamableHttpTransport.java b/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/client/transport/WebClientStreamableHttpTransport.java index 78e88db84..58cc20a7d 100644 --- a/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/client/transport/WebClientStreamableHttpTransport.java +++ b/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/client/transport/WebClientStreamableHttpTransport.java @@ -24,9 +24,9 @@ import org.springframework.web.reactive.function.client.WebClient; import org.springframework.web.reactive.function.client.WebClientResponseException; +import io.modelcontextprotocol.json.McpJsonDefaults; import io.modelcontextprotocol.json.McpJsonMapper; import io.modelcontextprotocol.json.TypeRef; -import io.modelcontextprotocol.json.internal.DefaultMcpJson; import io.modelcontextprotocol.spec.ClosedMcpTransportSession; import io.modelcontextprotocol.spec.DefaultMcpTransportSession; import io.modelcontextprotocol.spec.DefaultMcpTransportStream; @@ -596,7 +596,7 @@ public Builder supportedProtocolVersions(List supportedProtocolVersions) */ public WebClientStreamableHttpTransport build() { return new WebClientStreamableHttpTransport( - jsonMapper == null ? DefaultMcpJson.getDefaultMcpJsonMapper() : jsonMapper, webClientBuilder, + jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, webClientBuilder, endpoint, resumableStreams, openConnectionOnStartup, supportedProtocolVersions); } diff --git a/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/client/transport/WebFluxSseClientTransport.java b/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/client/transport/WebFluxSseClientTransport.java index 45ee67449..5549d07d6 100644 --- a/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/client/transport/WebFluxSseClientTransport.java +++ b/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/client/transport/WebFluxSseClientTransport.java @@ -9,9 +9,9 @@ import java.util.function.BiConsumer; import java.util.function.Function; +import io.modelcontextprotocol.json.McpJsonDefaults; import io.modelcontextprotocol.json.McpJsonMapper; import io.modelcontextprotocol.json.TypeRef; -import io.modelcontextprotocol.json.internal.DefaultMcpJson; import io.modelcontextprotocol.spec.HttpHeaders; import io.modelcontextprotocol.spec.McpClientTransport; import io.modelcontextprotocol.spec.McpSchema; @@ -404,7 +404,7 @@ public Builder jsonMapper(McpJsonMapper jsonMapper) { */ public WebFluxSseClientTransport build() { return new WebFluxSseClientTransport(webClientBuilder, - jsonMapper == null ? DefaultMcpJson.getDefaultMcpJsonMapper() : jsonMapper, sseEndpoint); + jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, sseEndpoint); } } diff --git a/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/server/transport/WebFluxSseServerTransportProvider.java b/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/server/transport/WebFluxSseServerTransportProvider.java index 128a47bb9..b7b4f22a6 100644 --- a/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/server/transport/WebFluxSseServerTransportProvider.java +++ b/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/server/transport/WebFluxSseServerTransportProvider.java @@ -10,9 +10,9 @@ import java.util.concurrent.ConcurrentHashMap; import io.modelcontextprotocol.common.McpTransportContext; +import io.modelcontextprotocol.json.McpJsonDefaults; import io.modelcontextprotocol.json.McpJsonMapper; import io.modelcontextprotocol.json.TypeRef; -import io.modelcontextprotocol.json.internal.DefaultMcpJson; import io.modelcontextprotocol.server.McpTransportContextExtractor; import io.modelcontextprotocol.spec.McpError; import io.modelcontextprotocol.spec.McpSchema; @@ -523,7 +523,7 @@ public Builder contextExtractor(McpTransportContextExtractor cont public WebFluxSseServerTransportProvider build() { Assert.notNull(messageEndpoint, "Message endpoint must be set"); return new WebFluxSseServerTransportProvider( - jsonMapper == null ? DefaultMcpJson.getDefaultMcpJsonMapper() : jsonMapper, baseUrl, + jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, baseUrl, messageEndpoint, sseEndpoint, keepAliveInterval, contextExtractor); } diff --git a/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/server/transport/WebFluxStatelessServerTransport.java b/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/server/transport/WebFluxStatelessServerTransport.java index afc3ff17e..78af45642 100644 --- a/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/server/transport/WebFluxStatelessServerTransport.java +++ b/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/server/transport/WebFluxStatelessServerTransport.java @@ -4,8 +4,8 @@ package io.modelcontextprotocol.server.transport; +import io.modelcontextprotocol.json.McpJsonDefaults; import io.modelcontextprotocol.json.McpJsonMapper; -import io.modelcontextprotocol.json.internal.DefaultMcpJson; import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.server.McpStatelessServerHandler; import io.modelcontextprotocol.server.McpTransportContextExtractor; @@ -215,7 +215,7 @@ public Builder contextExtractor(McpTransportContextExtractor cont public WebFluxStatelessServerTransport build() { Assert.notNull(mcpEndpoint, "Message endpoint must be set"); return new WebFluxStatelessServerTransport( - jsonMapper == null ? DefaultMcpJson.getDefaultMcpJsonMapper() : jsonMapper, mcpEndpoint, + jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, mcpEndpoint, contextExtractor); } diff --git a/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/server/transport/WebFluxStreamableServerTransportProvider.java b/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/server/transport/WebFluxStreamableServerTransportProvider.java index 321331541..db171fe50 100644 --- a/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/server/transport/WebFluxStreamableServerTransportProvider.java +++ b/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/server/transport/WebFluxStreamableServerTransportProvider.java @@ -4,9 +4,9 @@ package io.modelcontextprotocol.server.transport; +import io.modelcontextprotocol.json.McpJsonDefaults; import io.modelcontextprotocol.json.McpJsonMapper; import io.modelcontextprotocol.json.TypeRef; -import io.modelcontextprotocol.json.internal.DefaultMcpJson; import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.server.McpTransportContextExtractor; import io.modelcontextprotocol.spec.HttpHeaders; @@ -487,7 +487,7 @@ public Builder keepAliveInterval(Duration keepAliveInterval) { public WebFluxStreamableServerTransportProvider build() { Assert.notNull(mcpEndpoint, "Message endpoint must be set"); return new WebFluxStreamableServerTransportProvider( - jsonMapper == null ? DefaultMcpJson.getDefaultMcpJsonMapper() : jsonMapper, mcpEndpoint, + jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, mcpEndpoint, contextExtractor, disallowDelete, keepAliveInterval); } diff --git a/mcp-spring/mcp-spring-webflux/src/test/java/io/modelcontextprotocol/utils/McpJsonMapperUtils.java b/mcp-spring/mcp-spring-webflux/src/test/java/io/modelcontextprotocol/utils/McpJsonMapperUtils.java index fa27a794d..0177932cc 100644 --- a/mcp-spring/mcp-spring-webflux/src/test/java/io/modelcontextprotocol/utils/McpJsonMapperUtils.java +++ b/mcp-spring/mcp-spring-webflux/src/test/java/io/modelcontextprotocol/utils/McpJsonMapperUtils.java @@ -1,13 +1,13 @@ package io.modelcontextprotocol.utils; +import io.modelcontextprotocol.json.McpJsonDefaults; import io.modelcontextprotocol.json.McpJsonMapper; -import io.modelcontextprotocol.json.internal.DefaultMcpJson; public final class McpJsonMapperUtils { private McpJsonMapperUtils() { } - public static final McpJsonMapper JSON_MAPPER = DefaultMcpJson.getDefaultMcpJsonMapper(); + public static final McpJsonMapper JSON_MAPPER = McpJsonDefaults.getDefaultMcpJsonMapper(); } \ No newline at end of file diff --git a/mcp-spring/mcp-spring-webmvc/src/main/java/io/modelcontextprotocol/server/transport/WebMvcSseServerTransportProvider.java b/mcp-spring/mcp-spring-webmvc/src/main/java/io/modelcontextprotocol/server/transport/WebMvcSseServerTransportProvider.java index f20bdaeb0..c9aea6323 100644 --- a/mcp-spring/mcp-spring-webmvc/src/main/java/io/modelcontextprotocol/server/transport/WebMvcSseServerTransportProvider.java +++ b/mcp-spring/mcp-spring-webmvc/src/main/java/io/modelcontextprotocol/server/transport/WebMvcSseServerTransportProvider.java @@ -12,9 +12,9 @@ import java.util.concurrent.locks.ReentrantLock; import io.modelcontextprotocol.common.McpTransportContext; +import io.modelcontextprotocol.json.McpJsonDefaults; import io.modelcontextprotocol.json.McpJsonMapper; import io.modelcontextprotocol.json.TypeRef; -import io.modelcontextprotocol.json.internal.DefaultMcpJson; import io.modelcontextprotocol.server.McpTransportContextExtractor; import io.modelcontextprotocol.spec.McpError; import io.modelcontextprotocol.spec.McpSchema; @@ -579,7 +579,7 @@ public WebMvcSseServerTransportProvider build() { throw new IllegalStateException("MessageEndpoint must be set"); } return new WebMvcSseServerTransportProvider( - jsonMapper == null ? DefaultMcpJson.getDefaultMcpJsonMapper() : jsonMapper, baseUrl, + jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, baseUrl, messageEndpoint, sseEndpoint, keepAliveInterval, contextExtractor); } diff --git a/mcp-spring/mcp-spring-webmvc/src/main/java/io/modelcontextprotocol/server/transport/WebMvcStatelessServerTransport.java b/mcp-spring/mcp-spring-webmvc/src/main/java/io/modelcontextprotocol/server/transport/WebMvcStatelessServerTransport.java index 2c8c92acd..50156b0bc 100644 --- a/mcp-spring/mcp-spring-webmvc/src/main/java/io/modelcontextprotocol/server/transport/WebMvcStatelessServerTransport.java +++ b/mcp-spring/mcp-spring-webmvc/src/main/java/io/modelcontextprotocol/server/transport/WebMvcStatelessServerTransport.java @@ -5,8 +5,8 @@ package io.modelcontextprotocol.server.transport; import io.modelcontextprotocol.common.McpTransportContext; +import io.modelcontextprotocol.json.McpJsonDefaults; import io.modelcontextprotocol.json.McpJsonMapper; -import io.modelcontextprotocol.json.internal.DefaultMcpJson; import io.modelcontextprotocol.server.McpStatelessServerHandler; import io.modelcontextprotocol.server.McpTransportContextExtractor; import io.modelcontextprotocol.spec.McpError; @@ -233,7 +233,7 @@ public Builder contextExtractor(McpTransportContextExtractor cont public WebMvcStatelessServerTransport build() { Assert.notNull(mcpEndpoint, "Message endpoint must be set"); return new WebMvcStatelessServerTransport( - jsonMapper == null ? DefaultMcpJson.getDefaultMcpJsonMapper() : jsonMapper, mcpEndpoint, + jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, mcpEndpoint, contextExtractor); } diff --git a/mcp-spring/mcp-spring-webmvc/src/main/java/io/modelcontextprotocol/server/transport/WebMvcStreamableServerTransportProvider.java b/mcp-spring/mcp-spring-webmvc/src/main/java/io/modelcontextprotocol/server/transport/WebMvcStreamableServerTransportProvider.java index 5d0be7509..4b4d97e88 100644 --- a/mcp-spring/mcp-spring-webmvc/src/main/java/io/modelcontextprotocol/server/transport/WebMvcStreamableServerTransportProvider.java +++ b/mcp-spring/mcp-spring-webmvc/src/main/java/io/modelcontextprotocol/server/transport/WebMvcStreamableServerTransportProvider.java @@ -10,6 +10,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.locks.ReentrantLock; +import io.modelcontextprotocol.json.McpJsonDefaults; import io.modelcontextprotocol.json.McpJsonMapper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -22,7 +23,6 @@ import org.springframework.web.servlet.function.ServerResponse.SseBuilder; import io.modelcontextprotocol.json.TypeRef; -import io.modelcontextprotocol.json.internal.DefaultMcpJson; import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.server.McpTransportContextExtractor; import io.modelcontextprotocol.spec.HttpHeaders; @@ -681,7 +681,7 @@ public Builder keepAliveInterval(Duration keepAliveInterval) { public WebMvcStreamableServerTransportProvider build() { Assert.notNull(this.mcpEndpoint, "MCP endpoint must be set"); return new WebMvcStreamableServerTransportProvider( - jsonMapper == null ? DefaultMcpJson.getDefaultMcpJsonMapper() : jsonMapper, mcpEndpoint, + jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, mcpEndpoint, disallowDelete, contextExtractor, keepAliveInterval); } diff --git a/mcp-spring/mcp-spring-webmvc/src/test/java/io/modelcontextprotocol/server/transport/WebMvcSseServerTransportProviderTests.java b/mcp-spring/mcp-spring-webmvc/src/test/java/io/modelcontextprotocol/server/transport/WebMvcSseServerTransportProviderTests.java index 93b50b66f..36ea2d354 100644 --- a/mcp-spring/mcp-spring-webmvc/src/test/java/io/modelcontextprotocol/server/transport/WebMvcSseServerTransportProviderTests.java +++ b/mcp-spring/mcp-spring-webmvc/src/test/java/io/modelcontextprotocol/server/transport/WebMvcSseServerTransportProviderTests.java @@ -7,8 +7,8 @@ import io.modelcontextprotocol.client.McpClient; import io.modelcontextprotocol.client.transport.HttpClientSseClientTransport; import io.modelcontextprotocol.common.McpTransportContext; +import io.modelcontextprotocol.json.McpJsonDefaults; import io.modelcontextprotocol.json.McpJsonMapper; -import io.modelcontextprotocol.json.internal.DefaultMcpJson; import io.modelcontextprotocol.server.McpServer; import io.modelcontextprotocol.server.TestUtil; import io.modelcontextprotocol.server.TomcatTestUtil; @@ -105,7 +105,7 @@ public WebMvcSseServerTransportProvider webMvcSseServerTransportProvider() { .baseUrl("http://localhost:" + PORT + "/") .messageEndpoint(MESSAGE_ENDPOINT) .sseEndpoint(WebMvcSseServerTransportProvider.DEFAULT_SSE_ENDPOINT) - .jsonMapper(DefaultMcpJson.getDefaultMcpJsonMapper()) + .jsonMapper(McpJsonDefaults.getDefaultMcpJsonMapper()) .contextExtractor(req -> McpTransportContext.EMPTY) .build(); } diff --git a/mcp-test/src/main/java/io/modelcontextprotocol/MockMcpTransport.java b/mcp-test/src/main/java/io/modelcontextprotocol/MockMcpTransport.java index e5e005932..7168da3f8 100644 --- a/mcp-test/src/main/java/io/modelcontextprotocol/MockMcpTransport.java +++ b/mcp-test/src/main/java/io/modelcontextprotocol/MockMcpTransport.java @@ -9,9 +9,9 @@ import java.util.function.BiConsumer; import java.util.function.Function; +import io.modelcontextprotocol.json.McpJsonDefaults; import io.modelcontextprotocol.json.McpJsonMapper; import io.modelcontextprotocol.json.TypeRef; -import io.modelcontextprotocol.json.internal.DefaultMcpJson; import io.modelcontextprotocol.spec.McpClientTransport; import io.modelcontextprotocol.spec.McpSchema; import io.modelcontextprotocol.spec.McpSchema.JSONRPCNotification; @@ -95,7 +95,7 @@ public Mono closeGracefully() { @Override public T unmarshalFrom(Object data, TypeRef typeRef) { - return DefaultMcpJson.getDefaultMcpJsonMapper().convertValue(data, typeRef); + return McpJsonDefaults.getDefaultMcpJsonMapper().convertValue(data, typeRef); } } diff --git a/mcp-test/src/main/java/io/modelcontextprotocol/util/McpJsonMapperUtils.java b/mcp-test/src/main/java/io/modelcontextprotocol/util/McpJsonMapperUtils.java index 261288dee..45e4a4e3c 100644 --- a/mcp-test/src/main/java/io/modelcontextprotocol/util/McpJsonMapperUtils.java +++ b/mcp-test/src/main/java/io/modelcontextprotocol/util/McpJsonMapperUtils.java @@ -1,13 +1,13 @@ package io.modelcontextprotocol.util; +import io.modelcontextprotocol.json.McpJsonDefaults; import io.modelcontextprotocol.json.McpJsonMapper; -import io.modelcontextprotocol.json.internal.DefaultMcpJson; public final class McpJsonMapperUtils { private McpJsonMapperUtils() { } - public static final McpJsonMapper JSON_MAPPER = DefaultMcpJson.getDefaultMcpJsonMapper(); + public static final McpJsonMapper JSON_MAPPER = McpJsonDefaults.getDefaultMcpJsonMapper(); } \ No newline at end of file From 76fe598fec19ad8a9e3ddf796702011b6acd67a3 Mon Sep 17 00:00:00 2001 From: Scott Lewis Date: Mon, 24 Nov 2025 20:22:44 -0800 Subject: [PATCH 08/11] Fix for McpServiceLoader handling of type erasure. --- .../json/McpJsonDefaults.java | 6 ++- .../util/McpServiceLoader.java | 41 +++---------------- .../MockMcpClientTransport.java | 1 - .../MockMcpServerTransport.java | 1 - .../CompleteCompletionSerializationTest.java | 1 - .../util/McpJsonMapperUtils.java | 1 - 6 files changed, 10 insertions(+), 41 deletions(-) diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/json/McpJsonDefaults.java b/mcp-core/src/main/java/io/modelcontextprotocol/json/McpJsonDefaults.java index 3538ad333..e0a5da370 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/json/McpJsonDefaults.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/json/McpJsonDefaults.java @@ -11,8 +11,10 @@ public class McpJsonDefaults { protected static McpServiceLoader mcpValidatorServiceLoader; public McpJsonDefaults() { - mcpMapperServiceLoader = new McpServiceLoader(); - mcpValidatorServiceLoader = new McpServiceLoader(); + mcpMapperServiceLoader = new McpServiceLoader( + McpJsonMapperSupplier.class); + mcpValidatorServiceLoader = new McpServiceLoader( + JsonSchemaValidatorSupplier.class); } void setMcpJsonMapperSupplier(McpJsonMapperSupplier supplier) { diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/util/McpServiceLoader.java b/mcp-core/src/main/java/io/modelcontextprotocol/util/McpServiceLoader.java index 7eee25861..e67ff46d3 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/util/McpServiceLoader.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/util/McpServiceLoader.java @@ -1,7 +1,5 @@ package io.modelcontextprotocol.util; -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; import java.util.Optional; import java.util.ServiceConfigurationError; import java.util.ServiceLoader; @@ -9,31 +7,12 @@ public class McpServiceLoader, R> { - private Type supplierType; + private Class supplierType; private S supplier; private R supplierResult; - protected abstract class TypeToken { - - private Type type; - - protected TypeToken() { - Type superClass = getClass().getGenericSuperclass(); - this.type = ((ParameterizedType) superClass).getActualTypeArguments()[0]; - } - - public Type getType() { - return type; - } - - } - - protected class SupplierTypeToken extends TypeToken { - - }; - public void setSupplier(S supplier) { this.supplier = supplier; this.supplierResult = null; @@ -44,8 +23,8 @@ public void unsetSupplier(S supplier) { this.supplierResult = null; } - public McpServiceLoader() { - this.supplierType = new SupplierTypeToken().getType(); + public McpServiceLoader(Class supplierType) { + this.supplierType = supplierType; } protected Optional serviceLoad(Class type) { @@ -57,17 +36,9 @@ public synchronized R getDefault() { if (this.supplierResult == null) { if (this.supplier == null) { // Use serviceloader - Optional sl; - try { - sl = serviceLoad((Class) Class.forName(this.supplierType.getTypeName())); - if (sl.isEmpty()) { - throw new ServiceConfigurationError( - "No JsonMapperSupplier available for creating McpJsonMapper"); - } - } - catch (ClassNotFoundException e) { - throw new ServiceConfigurationError( - "ClassNotFoundException for Type=" + this.supplierType.getTypeName()); + Optional sl = serviceLoad(this.supplierType); + if (sl.isEmpty()) { + throw new ServiceConfigurationError("No JsonMapperSupplier available for creating McpJsonMapper"); } this.supplier = (S) sl.get(); } diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/MockMcpClientTransport.java b/mcp-core/src/test/java/io/modelcontextprotocol/MockMcpClientTransport.java index 027c80602..04b058973 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/MockMcpClientTransport.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/MockMcpClientTransport.java @@ -11,7 +11,6 @@ import io.modelcontextprotocol.json.McpJsonDefaults; import io.modelcontextprotocol.json.TypeRef; -import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; import io.modelcontextprotocol.spec.McpClientTransport; import io.modelcontextprotocol.spec.McpSchema; import io.modelcontextprotocol.spec.McpSchema.JSONRPCNotification; diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/MockMcpServerTransport.java b/mcp-core/src/test/java/io/modelcontextprotocol/MockMcpServerTransport.java index e729c24b3..5fefb892d 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/MockMcpServerTransport.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/MockMcpServerTransport.java @@ -10,7 +10,6 @@ import io.modelcontextprotocol.json.McpJsonDefaults; import io.modelcontextprotocol.json.TypeRef; -import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; import io.modelcontextprotocol.spec.McpSchema; import io.modelcontextprotocol.spec.McpSchema.JSONRPCNotification; import io.modelcontextprotocol.spec.McpSchema.JSONRPCRequest; diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/spec/CompleteCompletionSerializationTest.java b/mcp-core/src/test/java/io/modelcontextprotocol/spec/CompleteCompletionSerializationTest.java index e4f2d8aac..3f8c911aa 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/spec/CompleteCompletionSerializationTest.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/spec/CompleteCompletionSerializationTest.java @@ -9,7 +9,6 @@ import io.modelcontextprotocol.json.McpJsonDefaults; import io.modelcontextprotocol.json.McpJsonMapper; -import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; class CompleteCompletionSerializationTest { diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/util/McpJsonMapperUtils.java b/mcp-core/src/test/java/io/modelcontextprotocol/util/McpJsonMapperUtils.java index 459701b11..0af4815c9 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/util/McpJsonMapperUtils.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/util/McpJsonMapperUtils.java @@ -2,7 +2,6 @@ import io.modelcontextprotocol.json.McpJsonDefaults; import io.modelcontextprotocol.json.McpJsonMapper; -import io.modelcontextprotocol.json.internal.DefaultMcpJsonMapperSupplier; public final class McpJsonMapperUtils { From 946facb38a515ccd609217a495ab49f9b0cb61e2 Mon Sep 17 00:00:00 2001 From: Scott Lewis Date: Mon, 24 Nov 2025 20:40:11 -0800 Subject: [PATCH 09/11] Fixes for import reorg --- .../client/LifecycleInitializer.java | 11 +++------ .../client/McpAsyncClient.java | 5 ++-- .../HttpClientStreamableHttpTransport.java | 23 ++++++++----------- .../transport/StdioClientTransport.java | 7 +++--- ...ngMcpAsyncHttpClientRequestCustomizer.java | 1 + .../server/AbstractMcpAsyncServerTests.java | 4 ++++ .../server/AbstractMcpSyncServerTests.java | 4 ++++ .../WebClientStreamableHttpTransport.java | 1 + 8 files changed, 27 insertions(+), 29 deletions(-) diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/client/LifecycleInitializer.java b/mcp-core/src/main/java/io/modelcontextprotocol/client/LifecycleInitializer.java index f8264c591..f56c79a6d 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/client/LifecycleInitializer.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/client/LifecycleInitializer.java @@ -11,14 +11,13 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.function.Function; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import io.modelcontextprotocol.spec.McpClientSession; import io.modelcontextprotocol.spec.McpError; import io.modelcontextprotocol.spec.McpSchema; import io.modelcontextprotocol.spec.McpTransportSessionNotFoundException; import io.modelcontextprotocol.util.Assert; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import reactor.core.publisher.Mono; import reactor.core.publisher.Sinks; import reactor.util.context.ContextView; @@ -288,9 +287,7 @@ public Mono withInitialization(String actionName, Function operation.apply(res) - .contextWrite(c -> c.put(McpAsyncClient.NEGOTIATED_PROTOCOL_VERSION, - res.initializeResult().protocolVersion()))); + .flatMap(operation); }); } @@ -322,8 +319,6 @@ private Mono doInitialize(DefaultInitialization init } return mcpClientSession.sendNotification(McpSchema.METHOD_NOTIFICATION_INITIALIZED, null) - .contextWrite( - c -> c.put(McpAsyncClient.NEGOTIATED_PROTOCOL_VERSION, initializeResult.protocolVersion())) .thenReturn(initializeResult); }).flatMap(initializeResult -> { initialization.cacheResult(initializeResult); diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/client/McpAsyncClient.java b/mcp-core/src/main/java/io/modelcontextprotocol/client/McpAsyncClient.java index 100db6ed9..e6a09cd08 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/client/McpAsyncClient.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/client/McpAsyncClient.java @@ -15,9 +15,6 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.function.Function; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import io.modelcontextprotocol.client.LifecycleInitializer.Initialization; import io.modelcontextprotocol.json.TypeRef; import io.modelcontextprotocol.json.schema.JsonSchemaValidator; @@ -40,6 +37,8 @@ import io.modelcontextprotocol.spec.McpSchema.Root; import io.modelcontextprotocol.util.Assert; import io.modelcontextprotocol.util.Utils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/HttpClientStreamableHttpTransport.java b/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/HttpClientStreamableHttpTransport.java index e4ccf2af0..219da4236 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/HttpClientStreamableHttpTransport.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/HttpClientStreamableHttpTransport.java @@ -20,7 +20,6 @@ import java.util.function.Consumer; import java.util.function.Function; -import io.modelcontextprotocol.client.McpAsyncClient; import io.modelcontextprotocol.client.transport.ResponseSubscribers.ResponseEvent; import io.modelcontextprotocol.client.transport.customizer.McpAsyncHttpClientRequestCustomizer; import io.modelcontextprotocol.client.transport.customizer.McpSyncHttpClientRequestCustomizer; @@ -41,6 +40,9 @@ import io.modelcontextprotocol.spec.ProtocolVersions; import io.modelcontextprotocol.util.Assert; import io.modelcontextprotocol.util.Utils; +import org.reactivestreams.Publisher; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import reactor.core.Disposable; import reactor.core.publisher.Flux; import reactor.core.publisher.FluxSink; @@ -192,9 +194,7 @@ private Publisher createDelete(String sessionId) { .uri(uri) .header("Cache-Control", "no-cache") .header(HttpHeaders.MCP_SESSION_ID, sessionId) - .header(HttpHeaders.PROTOCOL_VERSION, - ctx.getOrDefault(McpAsyncClient.NEGOTIATED_PROTOCOL_VERSION, - this.latestSupportedProtocolVersion)) + .header(HttpHeaders.PROTOCOL_VERSION, this.latestSupportedProtocolVersion) .DELETE(); var transportContext = ctx.getOrDefault(McpTransportContext.KEY, McpTransportContext.EMPTY); return Mono.from(this.httpRequestCustomizer.customize(builder, "DELETE", uri, null, transportContext)); @@ -265,9 +265,7 @@ private Mono reconnect(McpTransportStream stream) { var builder = requestBuilder.uri(uri) .header(HttpHeaders.ACCEPT, TEXT_EVENT_STREAM) .header("Cache-Control", "no-cache") - .header(HttpHeaders.PROTOCOL_VERSION, - connectionCtx.getOrDefault(McpAsyncClient.NEGOTIATED_PROTOCOL_VERSION, - this.latestSupportedProtocolVersion)) + .header(HttpHeaders.PROTOCOL_VERSION, this.latestSupportedProtocolVersion) .GET(); var transportContext = connectionCtx.getOrDefault(McpTransportContext.KEY, McpTransportContext.EMPTY); return Mono.from(this.httpRequestCustomizer.customize(builder, "GET", uri, null, transportContext)); @@ -442,9 +440,7 @@ public Mono sendMessage(McpSchema.JSONRPCMessage sentMessage) { .header(HttpHeaders.ACCEPT, APPLICATION_JSON + ", " + TEXT_EVENT_STREAM) .header(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON) .header(HttpHeaders.CACHE_CONTROL, "no-cache") - .header(HttpHeaders.PROTOCOL_VERSION, - ctx.getOrDefault(McpAsyncClient.NEGOTIATED_PROTOCOL_VERSION, - this.latestSupportedProtocolVersion)) + .header(HttpHeaders.PROTOCOL_VERSION, this.latestSupportedProtocolVersion) .POST(HttpRequest.BodyPublishers.ofString(jsonBody)); var transportContext = ctx.getOrDefault(McpTransportContext.KEY, McpTransportContext.EMPTY); return Mono @@ -818,10 +814,9 @@ public Builder supportedProtocolVersions(List supportedProtocolVersions) */ 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.getDefaultMcpJsonMapper() : jsonMapper, + httpClient, requestBuilder, baseUri, endpoint, resumableStreams, openConnectionOnStartup, + httpRequestCustomizer, supportedProtocolVersions); } } diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/StdioClientTransport.java b/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/StdioClientTransport.java index 340d81e66..1b4eaca97 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/StdioClientTransport.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/StdioClientTransport.java @@ -15,15 +15,14 @@ import java.util.function.Consumer; import java.util.function.Function; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import io.modelcontextprotocol.json.McpJsonMapper; import io.modelcontextprotocol.json.TypeRef; +import io.modelcontextprotocol.json.McpJsonMapper; import io.modelcontextprotocol.spec.McpClientTransport; import io.modelcontextprotocol.spec.McpSchema; import io.modelcontextprotocol.spec.McpSchema.JSONRPCMessage; import io.modelcontextprotocol.util.Assert; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.core.publisher.Sinks; diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/customizer/DelegatingMcpAsyncHttpClientRequestCustomizer.java b/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/customizer/DelegatingMcpAsyncHttpClientRequestCustomizer.java index b89dbe84f..2492efe18 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/customizer/DelegatingMcpAsyncHttpClientRequestCustomizer.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/customizer/DelegatingMcpAsyncHttpClientRequestCustomizer.java @@ -11,6 +11,7 @@ import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.util.Assert; + import reactor.core.publisher.Mono; /** diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/server/AbstractMcpAsyncServerTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/server/AbstractMcpAsyncServerTests.java index 10b1feb30..2a87cfe14 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/server/AbstractMcpAsyncServerTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/server/AbstractMcpAsyncServerTests.java @@ -12,6 +12,10 @@ import java.time.Duration; import java.util.List; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + import io.modelcontextprotocol.spec.McpSchema; import io.modelcontextprotocol.spec.McpSchema.CallToolResult; import io.modelcontextprotocol.spec.McpSchema.GetPromptResult; diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/server/AbstractMcpSyncServerTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/server/AbstractMcpSyncServerTests.java index 02c73875e..425ccb2de 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/server/AbstractMcpSyncServerTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/server/AbstractMcpSyncServerTests.java @@ -11,6 +11,10 @@ import java.util.List; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + import io.modelcontextprotocol.spec.McpSchema; import io.modelcontextprotocol.spec.McpSchema.CallToolResult; import io.modelcontextprotocol.spec.McpSchema.GetPromptResult; diff --git a/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/client/transport/WebClientStreamableHttpTransport.java b/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/client/transport/WebClientStreamableHttpTransport.java index ba754c5cb..45b59ce60 100644 --- a/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/client/transport/WebClientStreamableHttpTransport.java +++ b/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/client/transport/WebClientStreamableHttpTransport.java @@ -24,6 +24,7 @@ import org.springframework.web.reactive.function.client.WebClient; import org.springframework.web.reactive.function.client.WebClientResponseException; +import io.modelcontextprotocol.client.McpAsyncClient; import io.modelcontextprotocol.json.McpJsonDefaults; import io.modelcontextprotocol.json.McpJsonMapper; import io.modelcontextprotocol.json.TypeRef; From b1b8b2a5c4c8ed9de1041d5f4e5629624a60856c Mon Sep 17 00:00:00 2001 From: Scott Lewis Date: Mon, 24 Nov 2025 21:28:48 -0800 Subject: [PATCH 10/11] Merged with current main --- mcp-core/pom.xml | 1 + .../client/LifecycleInitializer.java | 6 ++- .../client/McpClient.java | 2 +- .../HttpClientSseClientTransport.java | 2 - .../HttpClientStreamableHttpTransport.java | 20 ++++++--- .../client/transport/ServerParameters.java | 1 - .../McpAsyncHttpClientRequestCustomizer.java | 4 +- .../McpSyncHttpClientRequestCustomizer.java | 3 +- .../DefaultMcpStatelessServerHandler.java | 9 ++-- .../server/McpAsyncServer.java | 9 ++-- .../server/McpAsyncServerExchange.java | 2 +- .../server/McpServer.java | 4 +- .../server/McpStatelessAsyncServer.java | 33 +++++++------- .../server/McpStatelessSyncServer.java | 7 ++- ...HttpServletSseServerTransportProvider.java | 5 +-- .../HttpServletStatelessServerTransport.java | 3 +- ...vletStreamableServerTransportProvider.java | 7 +-- .../StdioServerTransportProvider.java | 7 ++- .../spec/ClosedMcpTransportSession.java | 1 - ...aultMcpStreamableServerSessionFactory.java | 6 +-- .../spec/DefaultMcpTransportSession.java | 11 +++-- .../spec/DefaultMcpTransportStream.java | 11 +++-- .../spec/McpClientSession.java | 17 ++++--- .../modelcontextprotocol/spec/McpError.java | 6 +-- .../modelcontextprotocol/spec/McpSchema.java | 6 +-- .../spec/McpServerSession.java | 7 ++- .../spec/McpStreamableServerSession.java | 3 +- .../spec/McpTransport.java | 2 +- .../spec/McpTransportStream.java | 5 +-- .../util/KeepAliveScheduler.java | 1 + .../McpUriTemplateManagerTests.java | 5 +-- .../MockMcpClientTransport.java | 1 + .../MockMcpServerTransport.java | 1 + ...AbstractMcpAsyncClientResiliencyTests.java | 33 +++++++------- ...pClientStreamableHttpAsyncClientTests.java | 5 +-- ...tpClientStreamableHttpSyncClientTests.java | 12 ++--- .../client/HttpSseMcpSyncClientTests.java | 14 +++--- ...nitializerPostInitializationHookTests.java | 25 +++++------ .../client/LifecycleInitializerTests.java | 27 ++++++------ .../McpAsyncClientResponseHandlerTests.java | 19 ++++---- .../client/McpAsyncClientTests.java | 11 +++-- .../client/McpClientProtocolVersionTests.java | 7 ++- .../client/StdioMcpAsyncClientTests.java | 10 ++--- .../client/StdioMcpSyncClientTests.java | 13 +++--- .../HttpClientSseClientTransportTests.java | 39 ++++++++-------- ...HttpClientStreamableHttpTransportTest.java | 24 +++++----- ...pAsyncHttpClientRequestCustomizerTest.java | 17 ++++--- ...cpSyncHttpClientRequestCustomizerTest.java | 9 ++-- ...erMcpTransportContextIntegrationTests.java | 17 ++++--- ...ttpVersionNegotiationIntegrationTests.java | 15 +++---- ...erMcpTransportContextIntegrationTests.java | 24 +++++----- .../server/AbstractMcpAsyncServerTests.java | 17 ++++--- ...stractMcpClientServerIntegrationTests.java | 25 +++++------ .../server/AbstractMcpSyncServerTests.java | 17 ++++--- .../AsyncToolSpecificationBuilderTest.java | 2 +- .../HttpServletSseIntegrationTests.java | 19 ++++---- .../HttpServletStatelessIntegrationTests.java | 44 +++++++++---------- ...HttpServletStreamableIntegrationTests.java | 19 ++++---- .../server/McpAsyncServerExchangeTests.java | 29 ++++++------ .../server/McpCompletionTests.java | 10 ++--- .../server/McpServerProtocolVersionTests.java | 7 ++- .../server/McpSyncServerExchangeTests.java | 27 ++++++------ .../server/ResourceTemplateListingTest.java | 7 ++- .../ResourceTemplateManagementTests.java | 13 +++--- .../server/ServletSseMcpAsyncServerTests.java | 3 +- .../server/ServletSseMcpSyncServerTests.java | 3 +- .../server/StdioMcpAsyncServerTests.java | 7 ++- .../server/StdioMcpSyncServerTests.java | 7 ++- ...ervletSseServerCustomContextPathTests.java | 11 +++-- .../StdioServerTransportProviderTests.java | 23 +++++----- .../server/transport/TomcatTestUtil.java | 5 +-- .../CompleteCompletionSerializationTest.java | 11 ++--- .../spec/JSONRPCRequestMcpValidationTest.java | 3 +- .../spec/McpClientSessionTests.java | 9 ++-- .../spec/McpErrorTest.java | 6 +-- .../spec/PromptReferenceEqualsTest.java | 9 ++-- .../spec/json/gson/GsonMcpJsonMapper.java | 7 ++- .../json/gson/GsonMcpJsonMapperTests.java | 15 +++---- .../util/AssertTests.java | 8 ++-- .../util/KeepAliveSchedulerTests.java | 1 + .../modelcontextprotocol/util/ToolsUtils.java | 4 +- .../modelcontextprotocol/util/UtilsTests.java | 10 ++--- 82 files changed, 436 insertions(+), 471 deletions(-) diff --git a/mcp-core/pom.xml b/mcp-core/pom.xml index d47b8011a..00e91772f 100644 --- a/mcp-core/pom.xml +++ b/mcp-core/pom.xml @@ -105,6 +105,7 @@ 0.17.0-SNAPSHOT test + org.springframework spring-webmvc diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/client/LifecycleInitializer.java b/mcp-core/src/main/java/io/modelcontextprotocol/client/LifecycleInitializer.java index f56c79a6d..07d86f40e 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/client/LifecycleInitializer.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/client/LifecycleInitializer.java @@ -287,7 +287,9 @@ public Mono withInitialization(String actionName, Function operation.apply(res) + .contextWrite(c -> c.put(McpAsyncClient.NEGOTIATED_PROTOCOL_VERSION, + res.initializeResult().protocolVersion()))); }); } @@ -319,6 +321,8 @@ private Mono doInitialize(DefaultInitialization init } return mcpClientSession.sendNotification(McpSchema.METHOD_NOTIFICATION_INITIALIZED, null) + .contextWrite( + c -> c.put(McpAsyncClient.NEGOTIATED_PROTOCOL_VERSION, initializeResult.protocolVersion())) .thenReturn(initializeResult); }).flatMap(initializeResult -> { initialization.cacheResult(initializeResult); diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/client/McpClient.java b/mcp-core/src/main/java/io/modelcontextprotocol/client/McpClient.java index ad851c0c4..f7a509b43 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/client/McpClient.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/client/McpClient.java @@ -13,9 +13,9 @@ import java.util.function.Function; import java.util.function.Supplier; -import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.json.McpJsonDefaults; import io.modelcontextprotocol.json.schema.JsonSchemaValidator; +import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.spec.McpClientTransport; import io.modelcontextprotocol.spec.McpSchema; import io.modelcontextprotocol.spec.McpSchema.ClientCapabilities; diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/HttpClientSseClientTransport.java b/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/HttpClientSseClientTransport.java index 4665bed7e..b9ed2711d 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/HttpClientSseClientTransport.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/HttpClientSseClientTransport.java @@ -18,7 +18,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; - import io.modelcontextprotocol.client.transport.ResponseSubscribers.ResponseEvent; import io.modelcontextprotocol.client.transport.customizer.McpAsyncHttpClientRequestCustomizer; import io.modelcontextprotocol.client.transport.customizer.McpSyncHttpClientRequestCustomizer; @@ -28,7 +27,6 @@ import io.modelcontextprotocol.json.TypeRef; import io.modelcontextprotocol.spec.HttpHeaders; import io.modelcontextprotocol.spec.McpClientTransport; -import io.modelcontextprotocol.spec.McpError; import io.modelcontextprotocol.spec.McpSchema; import io.modelcontextprotocol.spec.McpSchema.JSONRPCMessage; import io.modelcontextprotocol.spec.McpTransportException; diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/HttpClientStreamableHttpTransport.java b/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/HttpClientStreamableHttpTransport.java index 219da4236..9c5954729 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/HttpClientStreamableHttpTransport.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/HttpClientStreamableHttpTransport.java @@ -20,6 +20,7 @@ import java.util.function.Consumer; import java.util.function.Function; +import io.modelcontextprotocol.client.McpAsyncClient; import io.modelcontextprotocol.client.transport.ResponseSubscribers.ResponseEvent; import io.modelcontextprotocol.client.transport.customizer.McpAsyncHttpClientRequestCustomizer; import io.modelcontextprotocol.client.transport.customizer.McpSyncHttpClientRequestCustomizer; @@ -194,7 +195,9 @@ private Publisher createDelete(String sessionId) { .uri(uri) .header("Cache-Control", "no-cache") .header(HttpHeaders.MCP_SESSION_ID, sessionId) - .header(HttpHeaders.PROTOCOL_VERSION, this.latestSupportedProtocolVersion) + .header(HttpHeaders.PROTOCOL_VERSION, + ctx.getOrDefault(McpAsyncClient.NEGOTIATED_PROTOCOL_VERSION, + this.latestSupportedProtocolVersion)) .DELETE(); var transportContext = ctx.getOrDefault(McpTransportContext.KEY, McpTransportContext.EMPTY); return Mono.from(this.httpRequestCustomizer.customize(builder, "DELETE", uri, null, transportContext)); @@ -265,7 +268,9 @@ private Mono reconnect(McpTransportStream stream) { var builder = requestBuilder.uri(uri) .header(HttpHeaders.ACCEPT, TEXT_EVENT_STREAM) .header("Cache-Control", "no-cache") - .header(HttpHeaders.PROTOCOL_VERSION, this.latestSupportedProtocolVersion) + .header(HttpHeaders.PROTOCOL_VERSION, + connectionCtx.getOrDefault(McpAsyncClient.NEGOTIATED_PROTOCOL_VERSION, + this.latestSupportedProtocolVersion)) .GET(); var transportContext = connectionCtx.getOrDefault(McpTransportContext.KEY, McpTransportContext.EMPTY); return Mono.from(this.httpRequestCustomizer.customize(builder, "GET", uri, null, transportContext)); @@ -440,7 +445,9 @@ public Mono sendMessage(McpSchema.JSONRPCMessage sentMessage) { .header(HttpHeaders.ACCEPT, APPLICATION_JSON + ", " + TEXT_EVENT_STREAM) .header(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON) .header(HttpHeaders.CACHE_CONTROL, "no-cache") - .header(HttpHeaders.PROTOCOL_VERSION, this.latestSupportedProtocolVersion) + .header(HttpHeaders.PROTOCOL_VERSION, + ctx.getOrDefault(McpAsyncClient.NEGOTIATED_PROTOCOL_VERSION, + this.latestSupportedProtocolVersion)) .POST(HttpRequest.BodyPublishers.ofString(jsonBody)); var transportContext = ctx.getOrDefault(McpTransportContext.KEY, McpTransportContext.EMPTY); return Mono @@ -814,9 +821,10 @@ public Builder supportedProtocolVersions(List supportedProtocolVersions) */ 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.getDefaultMcpJsonMapper() : jsonMapper, httpClient, + requestBuilder, baseUri, endpoint, resumableStreams, openConnectionOnStartup, httpRequestCustomizer, + supportedProtocolVersions); } } diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/ServerParameters.java b/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/ServerParameters.java index 62929755a..25a02279f 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/ServerParameters.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/ServerParameters.java @@ -13,7 +13,6 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; - import io.modelcontextprotocol.util.Assert; /** diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/customizer/McpAsyncHttpClientRequestCustomizer.java b/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/customizer/McpAsyncHttpClientRequestCustomizer.java index bd197be48..756b39c35 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/customizer/McpAsyncHttpClientRequestCustomizer.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/customizer/McpAsyncHttpClientRequestCustomizer.java @@ -8,12 +8,12 @@ import java.net.http.HttpRequest; import org.reactivestreams.Publisher; - -import io.modelcontextprotocol.common.McpTransportContext; import reactor.core.publisher.Mono; import reactor.core.scheduler.Schedulers; import reactor.util.annotation.Nullable; +import io.modelcontextprotocol.common.McpTransportContext; + /** * Customize {@link HttpRequest.Builder} before executing the request, in either SSE or * Streamable HTTP transport. diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/customizer/McpSyncHttpClientRequestCustomizer.java b/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/customizer/McpSyncHttpClientRequestCustomizer.java index 03b9ec181..e22e3aa62 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/customizer/McpSyncHttpClientRequestCustomizer.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/customizer/McpSyncHttpClientRequestCustomizer.java @@ -7,9 +7,10 @@ import java.net.URI; import java.net.http.HttpRequest; +import reactor.util.annotation.Nullable; + import io.modelcontextprotocol.client.McpClient.SyncSpec; import io.modelcontextprotocol.common.McpTransportContext; -import reactor.util.annotation.Nullable; /** * Customize {@link HttpRequest.Builder} before executing the request, either in SSE or diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/server/DefaultMcpStatelessServerHandler.java b/mcp-core/src/main/java/io/modelcontextprotocol/server/DefaultMcpStatelessServerHandler.java index 46b1f600e..d1b55f594 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/server/DefaultMcpStatelessServerHandler.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/server/DefaultMcpStatelessServerHandler.java @@ -4,16 +4,15 @@ package io.modelcontextprotocol.server; -import java.util.Map; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.spec.McpError; import io.modelcontextprotocol.spec.McpSchema; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import reactor.core.publisher.Mono; +import java.util.Map; + class DefaultMcpStatelessServerHandler implements McpStatelessServerHandler { private static final Logger logger = LoggerFactory.getLogger(DefaultMcpStatelessServerHandler.class); diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/server/McpAsyncServer.java b/mcp-core/src/main/java/io/modelcontextprotocol/server/McpAsyncServer.java index 83b10558c..23285d514 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/server/McpAsyncServer.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/server/McpAsyncServer.java @@ -4,8 +4,6 @@ package io.modelcontextprotocol.server; -import static io.modelcontextprotocol.spec.McpError.RESOURCE_NOT_FOUND; - import java.time.Duration; import java.util.HashMap; import java.util.List; @@ -16,9 +14,6 @@ import java.util.concurrent.CopyOnWriteArrayList; import java.util.function.BiFunction; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import io.modelcontextprotocol.json.McpJsonMapper; import io.modelcontextprotocol.json.TypeRef; import io.modelcontextprotocol.json.schema.JsonSchemaValidator; @@ -43,9 +38,13 @@ import io.modelcontextprotocol.util.DefaultMcpUriTemplateManagerFactory; import io.modelcontextprotocol.util.McpUriTemplateManagerFactory; import io.modelcontextprotocol.util.Utils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; +import static io.modelcontextprotocol.spec.McpError.RESOURCE_NOT_FOUND; + /** * The Model Context Protocol (MCP) server implementation that provides asynchronous * communication using Project Reactor's Mono and Flux types. diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/server/McpAsyncServerExchange.java b/mcp-core/src/main/java/io/modelcontextprotocol/server/McpAsyncServerExchange.java index 95e0c35bc..a15c58cd5 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/server/McpAsyncServerExchange.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/server/McpAsyncServerExchange.java @@ -4,10 +4,10 @@ package io.modelcontextprotocol.server; +import io.modelcontextprotocol.common.McpTransportContext; import java.util.ArrayList; import java.util.Collections; -import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.json.TypeRef; import io.modelcontextprotocol.spec.McpError; import io.modelcontextprotocol.spec.McpLoggableSession; diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/server/McpServer.java b/mcp-core/src/main/java/io/modelcontextprotocol/server/McpServer.java index c3312640a..2e4026325 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/server/McpServer.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/server/McpServer.java @@ -4,6 +4,7 @@ package io.modelcontextprotocol.server; +import io.modelcontextprotocol.common.McpTransportContext; import java.time.Duration; import java.util.ArrayList; import java.util.Arrays; @@ -13,12 +14,13 @@ import java.util.function.BiConsumer; import java.util.function.BiFunction; -import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.json.McpJsonDefaults; import io.modelcontextprotocol.json.McpJsonMapper; + import io.modelcontextprotocol.json.schema.JsonSchemaValidator; import io.modelcontextprotocol.spec.McpSchema; import io.modelcontextprotocol.spec.McpSchema.CallToolResult; +import io.modelcontextprotocol.spec.McpSchema.ResourceTemplate; import io.modelcontextprotocol.spec.McpServerTransportProvider; import io.modelcontextprotocol.spec.McpStatelessServerTransport; import io.modelcontextprotocol.spec.McpStreamableServerTransportProvider; diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/server/McpStatelessAsyncServer.java b/mcp-core/src/main/java/io/modelcontextprotocol/server/McpStatelessAsyncServer.java index 322ada193..c7a1fd0d7 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/server/McpStatelessAsyncServer.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/server/McpStatelessAsyncServer.java @@ -4,24 +4,9 @@ package io.modelcontextprotocol.server; -import static io.modelcontextprotocol.spec.McpError.RESOURCE_NOT_FOUND; - -import java.time.Duration; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.CopyOnWriteArrayList; -import java.util.function.BiFunction; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import io.modelcontextprotocol.common.McpTransportContext; -import io.modelcontextprotocol.json.McpJsonMapper; import io.modelcontextprotocol.json.TypeRef; +import io.modelcontextprotocol.json.McpJsonMapper; +import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.json.schema.JsonSchemaValidator; import io.modelcontextprotocol.server.McpStatelessServerFeatures.AsyncResourceTemplateSpecification; import io.modelcontextprotocol.spec.McpError; @@ -37,9 +22,23 @@ import io.modelcontextprotocol.util.DefaultMcpUriTemplateManagerFactory; import io.modelcontextprotocol.util.McpUriTemplateManagerFactory; import io.modelcontextprotocol.util.Utils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; +import java.time.Duration; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.function.BiFunction; + +import static io.modelcontextprotocol.spec.McpError.RESOURCE_NOT_FOUND; + /** * A stateless MCP server implementation for use with Streamable HTTP transport types. It * allows simple horizontal scalability since it does not maintain a session and does not diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/server/McpStatelessSyncServer.java b/mcp-core/src/main/java/io/modelcontextprotocol/server/McpStatelessSyncServer.java index 17d66a3d5..6849eb8ed 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/server/McpStatelessSyncServer.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/server/McpStatelessSyncServer.java @@ -4,14 +4,13 @@ package io.modelcontextprotocol.server; -import java.util.List; - +import io.modelcontextprotocol.spec.McpSchema; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - -import io.modelcontextprotocol.spec.McpSchema; import reactor.core.publisher.Mono; +import java.util.List; + /** * A stateless MCP server implementation for use with Streamable HTTP transport types. It * allows simple horizontal scalability since it does not maintain a session and does not diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletSseServerTransportProvider.java b/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletSseServerTransportProvider.java index bf1d2863a..476aafafe 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletSseServerTransportProvider.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletSseServerTransportProvider.java @@ -14,9 +14,6 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicBoolean; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.json.McpJsonDefaults; import io.modelcontextprotocol.json.McpJsonMapper; @@ -36,6 +33,8 @@ import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletStatelessServerTransport.java b/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletStatelessServerTransport.java index eba7ba976..ae74cf839 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletStatelessServerTransport.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletStatelessServerTransport.java @@ -11,9 +11,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.json.McpJsonDefaults; import io.modelcontextprotocol.json.McpJsonMapper; + +import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.server.McpStatelessServerHandler; import io.modelcontextprotocol.server.McpTransportContextExtractor; import io.modelcontextprotocol.spec.McpError; diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletStreamableServerTransportProvider.java b/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletStreamableServerTransportProvider.java index 5581e6bcd..5ed308b0b 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletStreamableServerTransportProvider.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/HttpServletStreamableServerTransportProvider.java @@ -16,10 +16,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import io.modelcontextprotocol.common.McpTransportContext; -import io.modelcontextprotocol.json.McpJsonDefaults; -import io.modelcontextprotocol.json.McpJsonMapper; import io.modelcontextprotocol.json.TypeRef; + +import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.server.McpTransportContextExtractor; import io.modelcontextprotocol.spec.HttpHeaders; import io.modelcontextprotocol.spec.McpError; @@ -29,6 +28,8 @@ import io.modelcontextprotocol.spec.McpStreamableServerTransportProvider; import io.modelcontextprotocol.spec.ProtocolVersions; import io.modelcontextprotocol.util.Assert; +import io.modelcontextprotocol.json.McpJsonDefaults; +import io.modelcontextprotocol.json.McpJsonMapper; import io.modelcontextprotocol.util.KeepAliveScheduler; import jakarta.servlet.AsyncContext; import jakarta.servlet.ServletException; diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/StdioServerTransportProvider.java b/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/StdioServerTransportProvider.java index eb2a143d3..68be62931 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/StdioServerTransportProvider.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/server/transport/StdioServerTransportProvider.java @@ -15,10 +15,6 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Function; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import io.modelcontextprotocol.json.McpJsonMapper; import io.modelcontextprotocol.json.TypeRef; import io.modelcontextprotocol.spec.McpError; import io.modelcontextprotocol.spec.McpSchema; @@ -28,6 +24,9 @@ import io.modelcontextprotocol.spec.McpServerTransportProvider; import io.modelcontextprotocol.spec.ProtocolVersions; import io.modelcontextprotocol.util.Assert; +import io.modelcontextprotocol.json.McpJsonMapper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.core.publisher.Sinks; diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/spec/ClosedMcpTransportSession.java b/mcp-core/src/main/java/io/modelcontextprotocol/spec/ClosedMcpTransportSession.java index 212ba82f9..b18364abb 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/spec/ClosedMcpTransportSession.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/spec/ClosedMcpTransportSession.java @@ -6,7 +6,6 @@ import java.util.Optional; import org.reactivestreams.Publisher; - import reactor.core.publisher.Mono; import reactor.util.annotation.Nullable; diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/spec/DefaultMcpStreamableServerSessionFactory.java b/mcp-core/src/main/java/io/modelcontextprotocol/spec/DefaultMcpStreamableServerSessionFactory.java index 1892c48f7..f497afd43 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/spec/DefaultMcpStreamableServerSessionFactory.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/spec/DefaultMcpStreamableServerSessionFactory.java @@ -4,13 +4,13 @@ package io.modelcontextprotocol.spec; +import io.modelcontextprotocol.server.McpNotificationHandler; +import io.modelcontextprotocol.server.McpRequestHandler; + import java.time.Duration; import java.util.Map; import java.util.UUID; -import io.modelcontextprotocol.server.McpNotificationHandler; -import io.modelcontextprotocol.server.McpRequestHandler; - /** * A default implementation of {@link McpStreamableServerSession.Factory}. * diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/spec/DefaultMcpTransportSession.java b/mcp-core/src/main/java/io/modelcontextprotocol/spec/DefaultMcpTransportSession.java index d3f6b9a2f..fdb7bfd89 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/spec/DefaultMcpTransportSession.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/spec/DefaultMcpTransportSession.java @@ -4,19 +4,18 @@ package io.modelcontextprotocol.spec; -import java.util.Optional; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicReference; -import java.util.function.Function; - import org.reactivestreams.Publisher; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - import reactor.core.Disposable; import reactor.core.Disposables; import reactor.core.publisher.Mono; +import java.util.Optional; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Function; + /** * Default implementation of {@link McpTransportSession} which manages the open * connections using tye {@link Disposable} type and allows to perform clean up using the diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/spec/DefaultMcpTransportStream.java b/mcp-core/src/main/java/io/modelcontextprotocol/spec/DefaultMcpTransportStream.java index 6db8eabfe..8d63fb50d 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/spec/DefaultMcpTransportStream.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/spec/DefaultMcpTransportStream.java @@ -4,19 +4,18 @@ package io.modelcontextprotocol.spec; -import java.util.Optional; -import java.util.concurrent.atomic.AtomicLong; -import java.util.concurrent.atomic.AtomicReference; -import java.util.function.Function; - import org.reactivestreams.Publisher; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.util.function.Tuple2; +import java.util.Optional; +import java.util.concurrent.atomic.AtomicLong; +import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Function; + /** * An implementation of {@link McpTransportStream} using Project Reactor types. * diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpClientSession.java b/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpClientSession.java index 70bd46df3..0ba7ab3b8 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpClientSession.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpClientSession.java @@ -4,6 +4,14 @@ package io.modelcontextprotocol.spec; +import io.modelcontextprotocol.json.TypeRef; +import io.modelcontextprotocol.util.Assert; +import org.reactivestreams.Publisher; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import reactor.core.publisher.Mono; +import reactor.core.publisher.MonoSink; + import java.time.Duration; import java.util.Map; import java.util.UUID; @@ -11,15 +19,6 @@ import java.util.concurrent.atomic.AtomicLong; import java.util.function.Function; -import org.reactivestreams.Publisher; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import io.modelcontextprotocol.json.TypeRef; -import io.modelcontextprotocol.util.Assert; -import reactor.core.publisher.Mono; -import reactor.core.publisher.MonoSink; - /** * Default implementation of the MCP (Model Context Protocol) session that manages * bidirectional JSON-RPC communication between clients and servers. This implementation diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpError.java b/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpError.java index 2492e8992..d6e549fdc 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpError.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpError.java @@ -4,12 +4,12 @@ package io.modelcontextprotocol.spec; -import java.util.Map; -import java.util.function.Function; - import io.modelcontextprotocol.spec.McpSchema.JSONRPCResponse.JSONRPCError; import io.modelcontextprotocol.util.Assert; +import java.util.Map; +import java.util.function.Function; + public class McpError extends RuntimeException { /** diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpSchema.java b/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpSchema.java index 1c1661fca..734cff237 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpSchema.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpSchema.java @@ -11,19 +11,17 @@ import java.util.List; import java.util.Map; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; - import io.modelcontextprotocol.json.McpJsonMapper; import io.modelcontextprotocol.json.TypeRef; import io.modelcontextprotocol.util.Assert; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Based on the JSON-RPC 2.0 diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpServerSession.java b/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpServerSession.java index 584086143..241f7d8b5 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpServerSession.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpServerSession.java @@ -11,16 +11,15 @@ import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicReference; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import io.modelcontextprotocol.common.McpTransportContext; -import io.modelcontextprotocol.json.TypeRef; import io.modelcontextprotocol.server.McpAsyncServerExchange; import io.modelcontextprotocol.server.McpInitRequestHandler; import io.modelcontextprotocol.server.McpNotificationHandler; import io.modelcontextprotocol.server.McpRequestHandler; +import io.modelcontextprotocol.json.TypeRef; import io.modelcontextprotocol.util.Assert; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import reactor.core.publisher.Mono; import reactor.core.publisher.MonoSink; import reactor.core.publisher.Sinks; diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpStreamableServerSession.java b/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpStreamableServerSession.java index cdc251208..95f8959f5 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpStreamableServerSession.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpStreamableServerSession.java @@ -15,8 +15,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.json.TypeRef; + +import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.server.McpAsyncServerExchange; import io.modelcontextprotocol.server.McpNotificationHandler; import io.modelcontextprotocol.server.McpRequestHandler; diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpTransport.java b/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpTransport.java index 140039685..0a732bab6 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpTransport.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpTransport.java @@ -6,8 +6,8 @@ import java.util.List; -import io.modelcontextprotocol.json.TypeRef; import io.modelcontextprotocol.spec.McpSchema.JSONRPCMessage; +import io.modelcontextprotocol.json.TypeRef; import reactor.core.publisher.Mono; /** diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpTransportStream.java b/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpTransportStream.java index 7b1d834d0..322afda63 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpTransportStream.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpTransportStream.java @@ -4,12 +4,11 @@ package io.modelcontextprotocol.spec; -import java.util.Optional; - import org.reactivestreams.Publisher; - import reactor.util.function.Tuple2; +import java.util.Optional; + /** * A representation of a stream at the transport layer of the MCP protocol. In particular, * it is currently used in the Streamable HTTP implementation to potentially be able to diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/util/KeepAliveScheduler.java b/mcp-core/src/main/java/io/modelcontextprotocol/util/KeepAliveScheduler.java index 658eb2fc3..6d53ed516 100644 --- a/mcp-core/src/main/java/io/modelcontextprotocol/util/KeepAliveScheduler.java +++ b/mcp-core/src/main/java/io/modelcontextprotocol/util/KeepAliveScheduler.java @@ -12,6 +12,7 @@ import org.slf4j.LoggerFactory; import io.modelcontextprotocol.json.TypeRef; + import io.modelcontextprotocol.spec.McpSchema; import io.modelcontextprotocol.spec.McpSession; import reactor.core.Disposable; diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/McpUriTemplateManagerTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/McpUriTemplateManagerTests.java index fb467601c..8f68f0d6e 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/McpUriTemplateManagerTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/McpUriTemplateManagerTests.java @@ -12,12 +12,11 @@ import java.util.List; import java.util.Map; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - import io.modelcontextprotocol.util.DefaultMcpUriTemplateManagerFactory; import io.modelcontextprotocol.util.McpUriTemplateManager; import io.modelcontextprotocol.util.McpUriTemplateManagerFactory; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Tests for {@link McpUriTemplateManager} and its implementations. diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/MockMcpClientTransport.java b/mcp-core/src/test/java/io/modelcontextprotocol/MockMcpClientTransport.java index 04b058973..326fa5339 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/MockMcpClientTransport.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/MockMcpClientTransport.java @@ -10,6 +10,7 @@ import java.util.function.Function; import io.modelcontextprotocol.json.McpJsonDefaults; +import io.modelcontextprotocol.json.McpJsonMapper; import io.modelcontextprotocol.json.TypeRef; import io.modelcontextprotocol.spec.McpClientTransport; import io.modelcontextprotocol.spec.McpSchema; diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/MockMcpServerTransport.java b/mcp-core/src/test/java/io/modelcontextprotocol/MockMcpServerTransport.java index 5fefb892d..dfb01b034 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/MockMcpServerTransport.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/MockMcpServerTransport.java @@ -9,6 +9,7 @@ import java.util.function.BiConsumer; import io.modelcontextprotocol.json.McpJsonDefaults; +import io.modelcontextprotocol.json.McpJsonMapper; import io.modelcontextprotocol.json.TypeRef; import io.modelcontextprotocol.spec.McpSchema; import io.modelcontextprotocol.spec.McpSchema.JSONRPCNotification; diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/client/AbstractMcpAsyncClientResiliencyTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/client/AbstractMcpAsyncClientResiliencyTests.java index cb74d6f50..183b8a365 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/client/AbstractMcpAsyncClientResiliencyTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/client/AbstractMcpAsyncClientResiliencyTests.java @@ -4,7 +4,21 @@ package io.modelcontextprotocol.client; -import static org.assertj.core.api.Assertions.assertThatCode; +import eu.rekawek.toxiproxy.Proxy; +import eu.rekawek.toxiproxy.ToxiproxyClient; +import eu.rekawek.toxiproxy.model.ToxicDirection; +import io.modelcontextprotocol.spec.McpClientTransport; +import io.modelcontextprotocol.spec.McpSchema; +import io.modelcontextprotocol.spec.McpTransport; +import io.modelcontextprotocol.spec.McpTransportSessionClosedException; +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.Network; +import org.testcontainers.containers.ToxiproxyContainer; +import org.testcontainers.containers.wait.strategy.Wait; +import reactor.test.StepVerifier; import java.io.IOException; import java.time.Duration; @@ -14,22 +28,7 @@ import java.util.function.Consumer; import java.util.function.Function; -import org.junit.jupiter.api.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testcontainers.containers.GenericContainer; -import org.testcontainers.containers.Network; -import org.testcontainers.containers.ToxiproxyContainer; -import org.testcontainers.containers.wait.strategy.Wait; - -import eu.rekawek.toxiproxy.Proxy; -import eu.rekawek.toxiproxy.ToxiproxyClient; -import eu.rekawek.toxiproxy.model.ToxicDirection; -import io.modelcontextprotocol.spec.McpClientTransport; -import io.modelcontextprotocol.spec.McpSchema; -import io.modelcontextprotocol.spec.McpTransport; -import io.modelcontextprotocol.spec.McpTransportSessionClosedException; -import reactor.test.StepVerifier; +import static org.assertj.core.api.Assertions.assertThatCode; /** * Resiliency test suite for the {@link McpAsyncClient} that can be used with different diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/client/HttpClientStreamableHttpAsyncClientTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/client/HttpClientStreamableHttpAsyncClientTests.java index 1e015ca5e..c4157bc37 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/client/HttpClientStreamableHttpAsyncClientTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/client/HttpClientStreamableHttpAsyncClientTests.java @@ -4,15 +4,14 @@ package io.modelcontextprotocol.client; +import io.modelcontextprotocol.client.transport.HttpClientStreamableHttpTransport; +import io.modelcontextprotocol.spec.McpClientTransport; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Timeout; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.wait.strategy.Wait; -import io.modelcontextprotocol.client.transport.HttpClientStreamableHttpTransport; -import io.modelcontextprotocol.spec.McpClientTransport; - @Timeout(15) public class HttpClientStreamableHttpAsyncClientTests extends AbstractMcpAsyncClientTests { diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/client/HttpClientStreamableHttpSyncClientTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/client/HttpClientStreamableHttpSyncClientTests.java index d7b8c0121..d59ae35b4 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/client/HttpClientStreamableHttpSyncClientTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/client/HttpClientStreamableHttpSyncClientTests.java @@ -4,12 +4,6 @@ package io.modelcontextprotocol.client; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.atLeastOnce; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; - import java.net.URI; import java.util.Map; @@ -25,6 +19,12 @@ import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.spec.McpClientTransport; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.atLeastOnce; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + @Timeout(15) public class HttpClientStreamableHttpSyncClientTests extends AbstractMcpSyncClientTests { diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/client/HttpSseMcpSyncClientTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/client/HttpSseMcpSyncClientTests.java index 672c4f64c..483d38669 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/client/HttpSseMcpSyncClientTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/client/HttpSseMcpSyncClientTests.java @@ -4,13 +4,6 @@ package io.modelcontextprotocol.client; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.ArgumentMatchers.isNull; -import static org.mockito.Mockito.atLeastOnce; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; - import java.net.URI; import java.util.Map; @@ -26,6 +19,13 @@ import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.spec.McpClientTransport; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isNull; +import static org.mockito.Mockito.atLeastOnce; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + /** * Tests for the {@link McpSyncClient} with {@link HttpClientSseClientTransport}. * diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/client/LifecycleInitializerPostInitializationHookTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/client/LifecycleInitializerPostInitializationHookTests.java index 6bb4915b4..6f7390f19 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/client/LifecycleInitializerPostInitializationHookTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/client/LifecycleInitializerPostInitializationHookTests.java @@ -4,34 +4,33 @@ package io.modelcontextprotocol.client; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - import java.time.Duration; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Function; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - import io.modelcontextprotocol.client.LifecycleInitializer.Initialization; import io.modelcontextprotocol.spec.McpClientSession; import io.modelcontextprotocol.spec.McpSchema; import io.modelcontextprotocol.spec.McpTransportSessionNotFoundException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; import reactor.core.publisher.Mono; import reactor.core.scheduler.Schedulers; import reactor.test.StepVerifier; import reactor.util.context.ContextView; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + /** * Tests for {@link LifecycleInitializer} postInitializationHook functionality. * diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/client/LifecycleInitializerTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/client/LifecycleInitializerTests.java index fd9837207..787ee9480 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/client/LifecycleInitializerTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/client/LifecycleInitializerTests.java @@ -4,30 +4,20 @@ package io.modelcontextprotocol.client; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - import java.time.Duration; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Function; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - import io.modelcontextprotocol.client.LifecycleInitializer.Initialization; import io.modelcontextprotocol.spec.McpClientSession; import io.modelcontextprotocol.spec.McpSchema; import io.modelcontextprotocol.spec.McpTransportSessionNotFoundException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; import reactor.core.publisher.Mono; import reactor.core.scheduler.Schedulers; import reactor.test.StepVerifier; @@ -35,6 +25,15 @@ import reactor.util.context.Context; import reactor.util.context.ContextView; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + /** * Tests for {@link LifecycleInitializer}. */ diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/client/McpAsyncClientResponseHandlerTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/client/McpAsyncClientResponseHandlerTests.java index 1bd1c4b6b..612a65898 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/client/McpAsyncClientResponseHandlerTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/client/McpAsyncClientResponseHandlerTests.java @@ -4,30 +4,29 @@ package io.modelcontextprotocol.client; -import static io.modelcontextprotocol.spec.McpSchema.METHOD_INITIALIZE; -import static io.modelcontextprotocol.util.McpJsonMapperUtils.JSON_MAPPER; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.function.Function; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.EnumSource; - -import io.modelcontextprotocol.MockMcpClientTransport; import io.modelcontextprotocol.json.TypeRef; +import io.modelcontextprotocol.MockMcpClientTransport; import io.modelcontextprotocol.spec.McpSchema; import io.modelcontextprotocol.spec.McpSchema.ClientCapabilities; import io.modelcontextprotocol.spec.McpSchema.InitializeResult; import io.modelcontextprotocol.spec.McpSchema.PaginatedRequest; import io.modelcontextprotocol.spec.McpSchema.Root; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; import reactor.core.publisher.Mono; +import static io.modelcontextprotocol.spec.McpSchema.METHOD_INITIALIZE; +import static io.modelcontextprotocol.util.McpJsonMapperUtils.JSON_MAPPER; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + class McpAsyncClientResponseHandlerTests { private static final McpSchema.Implementation SERVER_INFO = new McpSchema.Implementation("test-server", "1.0.0"); diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/client/McpAsyncClientTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/client/McpAsyncClientTests.java index 6a306ead2..48bf1da5b 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/client/McpAsyncClientTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/client/McpAsyncClientTests.java @@ -4,10 +4,6 @@ package io.modelcontextprotocol.client; -import static io.modelcontextprotocol.util.McpJsonMapperUtils.JSON_MAPPER; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatCode; - import java.util.List; import java.util.Map; import java.util.Objects; @@ -16,15 +12,18 @@ import java.util.function.Function; import java.util.stream.Collectors; -import org.junit.jupiter.api.Test; - import io.modelcontextprotocol.json.TypeRef; import io.modelcontextprotocol.spec.McpClientTransport; import io.modelcontextprotocol.spec.McpSchema; import io.modelcontextprotocol.spec.ProtocolVersions; +import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; +import static io.modelcontextprotocol.util.McpJsonMapperUtils.JSON_MAPPER; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatCode; + class McpAsyncClientTests { public static final McpSchema.Implementation MOCK_SERVER_INFO = new McpSchema.Implementation("test-server", diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/client/McpClientProtocolVersionTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/client/McpClientProtocolVersionTests.java index 42c98418a..a94b9b6a7 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/client/McpClientProtocolVersionTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/client/McpClientProtocolVersionTests.java @@ -4,20 +4,19 @@ package io.modelcontextprotocol.client; -import static org.assertj.core.api.Assertions.assertThat; - import java.time.Duration; import java.util.List; -import org.junit.jupiter.api.Test; - import io.modelcontextprotocol.MockMcpClientTransport; import io.modelcontextprotocol.spec.McpSchema; import io.modelcontextprotocol.spec.McpSchema.InitializeResult; import io.modelcontextprotocol.spec.McpSchema.ServerCapabilities; +import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; +import static org.assertj.core.api.Assertions.assertThat; + /** * Tests for MCP protocol version negotiation and compatibility. */ diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/client/StdioMcpAsyncClientTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/client/StdioMcpAsyncClientTests.java index 751e2a57c..aa8aaa397 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/client/StdioMcpAsyncClientTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/client/StdioMcpAsyncClientTests.java @@ -4,15 +4,15 @@ package io.modelcontextprotocol.client; -import static io.modelcontextprotocol.client.ServerParameterUtils.createServerParameters; -import static io.modelcontextprotocol.util.McpJsonMapperUtils.JSON_MAPPER; - import java.time.Duration; -import org.junit.jupiter.api.Timeout; - +import io.modelcontextprotocol.client.transport.ServerParameters; import io.modelcontextprotocol.client.transport.StdioClientTransport; import io.modelcontextprotocol.spec.McpClientTransport; +import org.junit.jupiter.api.Timeout; + +import static io.modelcontextprotocol.client.ServerParameterUtils.createServerParameters; +import static io.modelcontextprotocol.util.McpJsonMapperUtils.JSON_MAPPER; /** * Tests for the {@link McpAsyncClient} with {@link StdioClientTransport}. diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/client/StdioMcpSyncClientTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/client/StdioMcpSyncClientTests.java index 7087b2d3c..b1e567989 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/client/StdioMcpSyncClientTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/client/StdioMcpSyncClientTests.java @@ -4,24 +4,23 @@ package io.modelcontextprotocol.client; -import static io.modelcontextprotocol.client.ServerParameterUtils.createServerParameters; -import static io.modelcontextprotocol.util.McpJsonMapperUtils.JSON_MAPPER; -import static org.assertj.core.api.Assertions.assertThat; - import java.time.Duration; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.Timeout; - import io.modelcontextprotocol.client.transport.ServerParameters; import io.modelcontextprotocol.client.transport.StdioClientTransport; import io.modelcontextprotocol.spec.McpClientTransport; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import reactor.core.publisher.Sinks; import reactor.test.StepVerifier; +import static io.modelcontextprotocol.client.ServerParameterUtils.createServerParameters; +import static io.modelcontextprotocol.util.McpJsonMapperUtils.JSON_MAPPER; +import static org.assertj.core.api.Assertions.assertThat; + /** * Tests for the {@link McpSyncClient} with {@link StdioClientTransport}. * diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/client/transport/HttpClientSseClientTransportTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/client/transport/HttpClientSseClientTransportTests.java index 71ade20ef..c5c365798 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/client/transport/HttpClientSseClientTransportTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/client/transport/HttpClientSseClientTransportTests.java @@ -4,17 +4,6 @@ package io.modelcontextprotocol.client.transport; -import static io.modelcontextprotocol.util.McpJsonMapperUtils.JSON_MAPPER; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatCode; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.ArgumentMatchers.isNull; -import static org.mockito.Mockito.clearInvocations; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; @@ -25,6 +14,12 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.function.Function; +import io.modelcontextprotocol.client.transport.customizer.McpAsyncHttpClientRequestCustomizer; +import io.modelcontextprotocol.client.transport.customizer.McpSyncHttpClientRequestCustomizer; +import io.modelcontextprotocol.common.McpTransportContext; +import io.modelcontextprotocol.spec.McpSchema; +import io.modelcontextprotocol.spec.McpSchema.JSONRPCRequest; + import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; @@ -32,20 +27,26 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; import org.mockito.ArgumentCaptor; -import org.springframework.http.codec.ServerSentEvent; -import org.springframework.web.util.UriComponentsBuilder; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.wait.strategy.Wait; - -import io.modelcontextprotocol.client.transport.customizer.McpAsyncHttpClientRequestCustomizer; -import io.modelcontextprotocol.client.transport.customizer.McpSyncHttpClientRequestCustomizer; -import io.modelcontextprotocol.common.McpTransportContext; -import io.modelcontextprotocol.spec.McpSchema; -import io.modelcontextprotocol.spec.McpSchema.JSONRPCRequest; import reactor.core.publisher.Mono; import reactor.core.publisher.Sinks; import reactor.test.StepVerifier; +import org.springframework.http.codec.ServerSentEvent; +import org.springframework.web.util.UriComponentsBuilder; + +import static io.modelcontextprotocol.util.McpJsonMapperUtils.JSON_MAPPER; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatCode; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isNull; +import static org.mockito.Mockito.clearInvocations; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + /** * Tests for the {@link HttpClientSseClientTransport} class. * diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/client/transport/HttpClientStreamableHttpTransportTest.java b/mcp-core/src/test/java/io/modelcontextprotocol/client/transport/HttpClientStreamableHttpTransportTest.java index ef0d7ecc8..f9536b690 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/client/transport/HttpClientStreamableHttpTransportTest.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/client/transport/HttpClientStreamableHttpTransportTest.java @@ -4,31 +4,29 @@ package io.modelcontextprotocol.client.transport; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.atLeastOnce; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - +import io.modelcontextprotocol.client.transport.customizer.McpAsyncHttpClientRequestCustomizer; +import io.modelcontextprotocol.client.transport.customizer.McpSyncHttpClientRequestCustomizer; +import io.modelcontextprotocol.common.McpTransportContext; +import io.modelcontextprotocol.spec.McpSchema; import java.net.URI; import java.net.URISyntaxException; import java.util.Map; import java.util.function.Consumer; - import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.wait.strategy.Wait; - -import io.modelcontextprotocol.client.transport.customizer.McpAsyncHttpClientRequestCustomizer; -import io.modelcontextprotocol.client.transport.customizer.McpSyncHttpClientRequestCustomizer; -import io.modelcontextprotocol.common.McpTransportContext; -import io.modelcontextprotocol.spec.McpSchema; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.atLeastOnce; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + /** * Tests for the {@link HttpClientStreamableHttpTransport} class. * diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/client/transport/customizer/DelegatingMcpAsyncHttpClientRequestCustomizerTest.java b/mcp-core/src/test/java/io/modelcontextprotocol/client/transport/customizer/DelegatingMcpAsyncHttpClientRequestCustomizerTest.java index f47d02a66..a04787aa3 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/client/transport/customizer/DelegatingMcpAsyncHttpClientRequestCustomizerTest.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/client/transport/customizer/DelegatingMcpAsyncHttpClientRequestCustomizerTest.java @@ -4,22 +4,21 @@ package io.modelcontextprotocol.client.transport.customizer; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - import java.net.URI; import java.net.http.HttpRequest; import java.util.List; - import org.junit.jupiter.api.Test; - -import io.modelcontextprotocol.common.McpTransportContext; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; +import io.modelcontextprotocol.common.McpTransportContext; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + /** * Tests for {@link DelegatingMcpAsyncHttpClientRequestCustomizer}. * diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/client/transport/customizer/DelegatingMcpSyncHttpClientRequestCustomizerTest.java b/mcp-core/src/test/java/io/modelcontextprotocol/client/transport/customizer/DelegatingMcpSyncHttpClientRequestCustomizerTest.java index f48167550..6c51a3d12 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/client/transport/customizer/DelegatingMcpSyncHttpClientRequestCustomizerTest.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/client/transport/customizer/DelegatingMcpSyncHttpClientRequestCustomizerTest.java @@ -4,19 +4,18 @@ package io.modelcontextprotocol.client.transport.customizer; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.Mockito.verify; - import java.net.URI; import java.net.http.HttpRequest; import java.util.List; - import org.junit.jupiter.api.Test; import org.mockito.Mockito; import io.modelcontextprotocol.common.McpTransportContext; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.Mockito.verify; + /** * Tests for {@link DelegatingMcpSyncHttpClientRequestCustomizer}. * diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/common/AsyncServerMcpTransportContextIntegrationTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/common/AsyncServerMcpTransportContextIntegrationTests.java index 600f93491..8b2dea462 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/common/AsyncServerMcpTransportContextIntegrationTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/common/AsyncServerMcpTransportContextIntegrationTests.java @@ -4,18 +4,9 @@ package io.modelcontextprotocol.common; -import static org.assertj.core.api.Assertions.assertThat; - import java.util.Map; import java.util.function.BiFunction; -import org.apache.catalina.LifecycleException; -import org.apache.catalina.LifecycleState; -import org.apache.catalina.startup.Tomcat; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.Timeout; - import io.modelcontextprotocol.client.McpAsyncClient; import io.modelcontextprotocol.client.McpClient; import io.modelcontextprotocol.client.transport.HttpClientSseClientTransport; @@ -34,9 +25,17 @@ import io.modelcontextprotocol.spec.McpSchema; import jakarta.servlet.Servlet; import jakarta.servlet.http.HttpServletRequest; +import org.apache.catalina.LifecycleException; +import org.apache.catalina.LifecycleState; +import org.apache.catalina.startup.Tomcat; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; +import static org.assertj.core.api.Assertions.assertThat; + /** * Integration tests for {@link McpTransportContext} propagation between MCP clients and * async servers. diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/common/HttpClientStreamableHttpVersionNegotiationIntegrationTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/common/HttpClientStreamableHttpVersionNegotiationIntegrationTests.java index 0b58eaad4..8efb6a960 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/common/HttpClientStreamableHttpVersionNegotiationIntegrationTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/common/HttpClientStreamableHttpVersionNegotiationIntegrationTests.java @@ -4,18 +4,10 @@ package io.modelcontextprotocol.common; -import static org.assertj.core.api.Assertions.assertThat; - import java.util.List; import java.util.Map; import java.util.function.BiFunction; -import org.apache.catalina.LifecycleException; -import org.apache.catalina.LifecycleState; -import org.apache.catalina.startup.Tomcat; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Test; - import io.modelcontextprotocol.client.McpClient; import io.modelcontextprotocol.client.transport.HttpClientStreamableHttpTransport; import io.modelcontextprotocol.server.McpServer; @@ -27,6 +19,13 @@ import io.modelcontextprotocol.server.transport.TomcatTestUtil; import io.modelcontextprotocol.spec.McpSchema; import io.modelcontextprotocol.spec.ProtocolVersions; +import org.apache.catalina.LifecycleException; +import org.apache.catalina.LifecycleState; +import org.apache.catalina.startup.Tomcat; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; class HttpClientStreamableHttpVersionNegotiationIntegrationTests { diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/common/SyncServerMcpTransportContextIntegrationTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/common/SyncServerMcpTransportContextIntegrationTests.java index eaede29ad..cc8f4c4be 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/common/SyncServerMcpTransportContextIntegrationTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/common/SyncServerMcpTransportContextIntegrationTests.java @@ -4,19 +4,6 @@ package io.modelcontextprotocol.common; -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.Map; -import java.util.function.BiFunction; -import java.util.function.Supplier; - -import org.apache.catalina.LifecycleException; -import org.apache.catalina.LifecycleState; -import org.apache.catalina.startup.Tomcat; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.Timeout; - import io.modelcontextprotocol.client.McpClient; import io.modelcontextprotocol.client.McpClient.SyncSpec; import io.modelcontextprotocol.client.McpSyncClient; @@ -35,6 +22,17 @@ import io.modelcontextprotocol.spec.McpSchema; import jakarta.servlet.Servlet; import jakarta.servlet.http.HttpServletRequest; +import java.util.Map; +import java.util.function.BiFunction; +import java.util.function.Supplier; +import org.apache.catalina.LifecycleException; +import org.apache.catalina.LifecycleState; +import org.apache.catalina.startup.Tomcat; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; + +import static org.assertj.core.api.Assertions.assertThat; /** * Test both Client and Server {@link McpTransportContext} integration, in two steps. diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/server/AbstractMcpAsyncServerTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/server/AbstractMcpAsyncServerTests.java index 2a87cfe14..090710248 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/server/AbstractMcpAsyncServerTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/server/AbstractMcpAsyncServerTests.java @@ -4,18 +4,9 @@ package io.modelcontextprotocol.server; -import static io.modelcontextprotocol.util.ToolsUtils.EMPTY_JSON_SCHEMA; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatCode; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - import java.time.Duration; import java.util.List; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - import io.modelcontextprotocol.spec.McpSchema; import io.modelcontextprotocol.spec.McpSchema.CallToolResult; import io.modelcontextprotocol.spec.McpSchema.GetPromptResult; @@ -26,9 +17,17 @@ import io.modelcontextprotocol.spec.McpSchema.ServerCapabilities; import io.modelcontextprotocol.spec.McpSchema.Tool; import io.modelcontextprotocol.spec.McpServerTransportProvider; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; +import static io.modelcontextprotocol.util.ToolsUtils.EMPTY_JSON_SCHEMA; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatCode; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + /** * Test suite for the {@link McpAsyncServer} that can be used with different * {@link io.modelcontextprotocol.spec.McpServerTransportProvider} implementations. diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/server/AbstractMcpClientServerIntegrationTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/server/AbstractMcpClientServerIntegrationTests.java index 3c776e00c..1f5387f37 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/server/AbstractMcpClientServerIntegrationTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/server/AbstractMcpClientServerIntegrationTests.java @@ -4,15 +4,6 @@ package io.modelcontextprotocol.server; -import static io.modelcontextprotocol.util.ToolsUtils.EMPTY_JSON_SCHEMA; -import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson; -import static net.javacrumbs.jsonunit.assertj.JsonAssertions.json; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.assertj.core.api.Assertions.assertWith; -import static org.awaitility.Awaitility.await; -import static org.mockito.Mockito.mock; - import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; @@ -30,10 +21,6 @@ import java.util.function.Function; import java.util.stream.Collectors; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; - import io.modelcontextprotocol.client.McpClient; import io.modelcontextprotocol.common.McpTransportContext; import io.modelcontextprotocol.spec.McpError; @@ -58,9 +45,21 @@ import io.modelcontextprotocol.spec.McpSchema.Tool; import io.modelcontextprotocol.util.Utils; import net.javacrumbs.jsonunit.core.Option; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.ValueSource; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; +import static io.modelcontextprotocol.util.ToolsUtils.EMPTY_JSON_SCHEMA; +import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson; +import static net.javacrumbs.jsonunit.assertj.JsonAssertions.json; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.assertj.core.api.Assertions.assertWith; +import static org.awaitility.Awaitility.await; +import static org.mockito.Mockito.mock; + public abstract class AbstractMcpClientServerIntegrationTests { protected ConcurrentHashMap clientBuilders = new ConcurrentHashMap<>(); diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/server/AbstractMcpSyncServerTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/server/AbstractMcpSyncServerTests.java index 425ccb2de..915c658e3 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/server/AbstractMcpSyncServerTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/server/AbstractMcpSyncServerTests.java @@ -4,17 +4,8 @@ package io.modelcontextprotocol.server; -import static io.modelcontextprotocol.util.ToolsUtils.EMPTY_JSON_SCHEMA; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatCode; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - import java.util.List; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - import io.modelcontextprotocol.spec.McpSchema; import io.modelcontextprotocol.spec.McpSchema.CallToolResult; import io.modelcontextprotocol.spec.McpSchema.GetPromptResult; @@ -25,6 +16,14 @@ import io.modelcontextprotocol.spec.McpSchema.ServerCapabilities; import io.modelcontextprotocol.spec.McpSchema.Tool; import io.modelcontextprotocol.spec.McpServerTransportProvider; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static io.modelcontextprotocol.util.ToolsUtils.EMPTY_JSON_SCHEMA; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatCode; +import static org.assertj.core.api.Assertions.assertThatThrownBy; /** * Test suite for the {@link McpSyncServer} that can be used with different diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/server/AsyncToolSpecificationBuilderTest.java b/mcp-core/src/test/java/io/modelcontextprotocol/server/AsyncToolSpecificationBuilderTest.java index 9795bb870..62332fcdb 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/server/AsyncToolSpecificationBuilderTest.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/server/AsyncToolSpecificationBuilderTest.java @@ -11,9 +11,9 @@ import java.util.List; import java.util.Map; +import io.modelcontextprotocol.spec.McpSchema; import org.junit.jupiter.api.Test; -import io.modelcontextprotocol.spec.McpSchema; import io.modelcontextprotocol.spec.McpSchema.CallToolRequest; import io.modelcontextprotocol.spec.McpSchema.CallToolResult; import io.modelcontextprotocol.spec.McpSchema.TextContent; diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/server/HttpServletSseIntegrationTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/server/HttpServletSseIntegrationTests.java index f3a1a8c8a..d2b9d14d0 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/server/HttpServletSseIntegrationTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/server/HttpServletSseIntegrationTests.java @@ -4,20 +4,10 @@ package io.modelcontextprotocol.server; -import static org.assertj.core.api.Assertions.assertThat; - import java.time.Duration; import java.util.Map; import java.util.stream.Stream; -import org.apache.catalina.LifecycleException; -import org.apache.catalina.LifecycleState; -import org.apache.catalina.startup.Tomcat; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Timeout; -import org.junit.jupiter.params.provider.Arguments; - import io.modelcontextprotocol.client.McpClient; import io.modelcontextprotocol.client.transport.HttpClientSseClientTransport; import io.modelcontextprotocol.common.McpTransportContext; @@ -26,6 +16,15 @@ import io.modelcontextprotocol.server.transport.HttpServletSseServerTransportProvider; import io.modelcontextprotocol.server.transport.TomcatTestUtil; import jakarta.servlet.http.HttpServletRequest; +import org.apache.catalina.LifecycleException; +import org.apache.catalina.LifecycleState; +import org.apache.catalina.startup.Tomcat; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Timeout; +import org.junit.jupiter.params.provider.Arguments; + +import static org.assertj.core.api.Assertions.assertThat; @Timeout(15) class HttpServletSseIntegrationTests extends AbstractMcpClientServerIntegrationTests { diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/server/HttpServletStatelessIntegrationTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/server/HttpServletStatelessIntegrationTests.java index 954c29827..491c2d4ed 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/server/HttpServletStatelessIntegrationTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/server/HttpServletStatelessIntegrationTests.java @@ -4,15 +4,6 @@ package io.modelcontextprotocol.server; -import static io.modelcontextprotocol.server.transport.HttpServletStatelessServerTransport.APPLICATION_JSON; -import static io.modelcontextprotocol.server.transport.HttpServletStatelessServerTransport.TEXT_EVENT_STREAM; -import static io.modelcontextprotocol.util.McpJsonMapperUtils.JSON_MAPPER; -import static io.modelcontextprotocol.util.ToolsUtils.EMPTY_JSON_SCHEMA; -import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson; -import static net.javacrumbs.jsonunit.assertj.JsonAssertions.json; -import static org.assertj.core.api.Assertions.assertThat; -import static org.awaitility.Awaitility.await; - import java.time.Duration; import java.util.List; import java.util.Map; @@ -20,19 +11,6 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.function.BiFunction; -import org.apache.catalina.LifecycleException; -import org.apache.catalina.LifecycleState; -import org.apache.catalina.startup.Tomcat; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.Timeout; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; -import org.springframework.mock.web.MockHttpServletRequest; -import org.springframework.mock.web.MockHttpServletResponse; -import org.springframework.web.client.RestClient; - import io.modelcontextprotocol.client.McpClient; import io.modelcontextprotocol.client.transport.HttpClientStreamableHttpTransport; import io.modelcontextprotocol.common.McpTransportContext; @@ -53,6 +31,28 @@ import io.modelcontextprotocol.spec.McpSchema.Tool; import io.modelcontextprotocol.spec.ProtocolVersions; import net.javacrumbs.jsonunit.core.Option; +import org.apache.catalina.LifecycleException; +import org.apache.catalina.LifecycleState; +import org.apache.catalina.startup.Tomcat; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +import org.springframework.mock.web.MockHttpServletRequest; +import org.springframework.mock.web.MockHttpServletResponse; +import org.springframework.web.client.RestClient; + +import static io.modelcontextprotocol.server.transport.HttpServletStatelessServerTransport.APPLICATION_JSON; +import static io.modelcontextprotocol.server.transport.HttpServletStatelessServerTransport.TEXT_EVENT_STREAM; +import static io.modelcontextprotocol.util.McpJsonMapperUtils.JSON_MAPPER; +import static io.modelcontextprotocol.util.ToolsUtils.EMPTY_JSON_SCHEMA; +import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson; +import static net.javacrumbs.jsonunit.assertj.JsonAssertions.json; +import static org.assertj.core.api.Assertions.assertThat; +import static org.awaitility.Awaitility.await; @Timeout(15) class HttpServletStatelessIntegrationTests { diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/server/HttpServletStreamableIntegrationTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/server/HttpServletStreamableIntegrationTests.java index 76073fa3b..81423e0c5 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/server/HttpServletStreamableIntegrationTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/server/HttpServletStreamableIntegrationTests.java @@ -4,20 +4,10 @@ package io.modelcontextprotocol.server; -import static org.assertj.core.api.Assertions.assertThat; - import java.time.Duration; import java.util.Map; import java.util.stream.Stream; -import org.apache.catalina.LifecycleException; -import org.apache.catalina.LifecycleState; -import org.apache.catalina.startup.Tomcat; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Timeout; -import org.junit.jupiter.params.provider.Arguments; - import io.modelcontextprotocol.client.McpClient; import io.modelcontextprotocol.client.transport.HttpClientStreamableHttpTransport; import io.modelcontextprotocol.common.McpTransportContext; @@ -26,6 +16,15 @@ import io.modelcontextprotocol.server.transport.HttpServletStreamableServerTransportProvider; import io.modelcontextprotocol.server.transport.TomcatTestUtil; import jakarta.servlet.http.HttpServletRequest; +import org.apache.catalina.LifecycleException; +import org.apache.catalina.LifecycleState; +import org.apache.catalina.startup.Tomcat; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Timeout; +import org.junit.jupiter.params.provider.Arguments; + +import static org.assertj.core.api.Assertions.assertThat; @Timeout(15) class HttpServletStreamableIntegrationTests extends AbstractMcpClientServerIntegrationTests { diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/server/McpAsyncServerExchangeTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/server/McpAsyncServerExchangeTests.java index c8f2aed77..640d34c9c 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/server/McpAsyncServerExchangeTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/server/McpAsyncServerExchangeTests.java @@ -4,33 +4,32 @@ package io.modelcontextprotocol.server; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - +import io.modelcontextprotocol.common.McpTransportContext; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; +import io.modelcontextprotocol.spec.McpError; +import io.modelcontextprotocol.spec.McpSchema; +import io.modelcontextprotocol.spec.McpServerSession; +import io.modelcontextprotocol.json.TypeRef; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; - -import io.modelcontextprotocol.common.McpTransportContext; -import io.modelcontextprotocol.json.TypeRef; -import io.modelcontextprotocol.spec.McpError; -import io.modelcontextprotocol.spec.McpSchema; -import io.modelcontextprotocol.spec.McpServerSession; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + /** * Tests for {@link McpAsyncServerExchange}. * diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/server/McpCompletionTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/server/McpCompletionTests.java index fa4e7e7ee..54fb80a78 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/server/McpCompletionTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/server/McpCompletionTests.java @@ -4,9 +4,6 @@ package io.modelcontextprotocol.server; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; - import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicReference; @@ -15,15 +12,17 @@ import org.apache.catalina.LifecycleException; import org.apache.catalina.LifecycleState; import org.apache.catalina.startup.Tomcat; + +import static org.assertj.core.api.Assertions.assertThat; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import io.modelcontextprotocol.client.McpClient; import io.modelcontextprotocol.client.transport.HttpClientSseClientTransport; import io.modelcontextprotocol.server.transport.HttpServletSseServerTransportProvider; import io.modelcontextprotocol.server.transport.TomcatTestUtil; -import io.modelcontextprotocol.spec.McpError; import io.modelcontextprotocol.spec.McpSchema; import io.modelcontextprotocol.spec.McpSchema.CompleteRequest; import io.modelcontextprotocol.spec.McpSchema.CompleteResult; @@ -31,11 +30,12 @@ import io.modelcontextprotocol.spec.McpSchema.InitializeResult; import io.modelcontextprotocol.spec.McpSchema.Prompt; import io.modelcontextprotocol.spec.McpSchema.PromptArgument; -import io.modelcontextprotocol.spec.McpSchema.PromptReference; import io.modelcontextprotocol.spec.McpSchema.ReadResourceResult; import io.modelcontextprotocol.spec.McpSchema.Resource; import io.modelcontextprotocol.spec.McpSchema.ResourceReference; +import io.modelcontextprotocol.spec.McpSchema.PromptReference; import io.modelcontextprotocol.spec.McpSchema.ServerCapabilities; +import io.modelcontextprotocol.spec.McpError; /** * Tests for completion functionality with context support. diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/server/McpServerProtocolVersionTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/server/McpServerProtocolVersionTests.java index 84dc24650..cdd2bacb7 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/server/McpServerProtocolVersionTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/server/McpServerProtocolVersionTests.java @@ -4,16 +4,15 @@ package io.modelcontextprotocol.server; -import static org.assertj.core.api.Assertions.assertThat; - import java.util.List; import java.util.UUID; -import org.junit.jupiter.api.Test; - import io.modelcontextprotocol.MockMcpServerTransport; import io.modelcontextprotocol.MockMcpServerTransportProvider; import io.modelcontextprotocol.spec.McpSchema; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for MCP server protocol version negotiation and compatibility. diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/server/McpSyncServerExchangeTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/server/McpSyncServerExchangeTests.java index 79b84600a..069d0f896 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/server/McpSyncServerExchangeTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/server/McpSyncServerExchangeTests.java @@ -4,31 +4,30 @@ package io.modelcontextprotocol.server; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; +import io.modelcontextprotocol.spec.McpError; +import io.modelcontextprotocol.spec.McpSchema; +import io.modelcontextprotocol.spec.McpServerSession; +import io.modelcontextprotocol.json.TypeRef; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; - -import io.modelcontextprotocol.json.TypeRef; -import io.modelcontextprotocol.spec.McpError; -import io.modelcontextprotocol.spec.McpSchema; -import io.modelcontextprotocol.spec.McpServerSession; import reactor.core.publisher.Mono; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + /** * Tests for {@link McpSyncServerExchange}. * diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/server/ResourceTemplateListingTest.java b/mcp-core/src/test/java/io/modelcontextprotocol/server/ResourceTemplateListingTest.java index 1f1fb09d9..61703c306 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/server/ResourceTemplateListingTest.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/server/ResourceTemplateListingTest.java @@ -4,14 +4,13 @@ package io.modelcontextprotocol.server; -import static org.assertj.core.api.Assertions.assertThat; +import io.modelcontextprotocol.spec.McpSchema; +import org.junit.jupiter.api.Test; import java.util.List; import java.util.stream.Collectors; -import org.junit.jupiter.api.Test; - -import io.modelcontextprotocol.spec.McpSchema; +import static org.assertj.core.api.Assertions.assertThat; /** * Test to verify the separation of regular resources and resource templates. Regular diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/server/ResourceTemplateManagementTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/server/ResourceTemplateManagementTests.java index 5e1403ace..b7d46a967 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/server/ResourceTemplateManagementTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/server/ResourceTemplateManagementTests.java @@ -4,24 +4,23 @@ package io.modelcontextprotocol.server; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatCode; - import java.time.Duration; import java.util.List; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - import io.modelcontextprotocol.MockMcpServerTransport; import io.modelcontextprotocol.MockMcpServerTransportProvider; import io.modelcontextprotocol.spec.McpSchema.ReadResourceResult; import io.modelcontextprotocol.spec.McpSchema.ResourceTemplate; import io.modelcontextprotocol.spec.McpSchema.ServerCapabilities; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatCode; + /** * Test suite for Resource Template Management functionality. Tests the new * addResourceTemplate() and removeResourceTemplate() methods, as well as the Map-based diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/server/ServletSseMcpAsyncServerTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/server/ServletSseMcpAsyncServerTests.java index cd69bee07..8906adfe0 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/server/ServletSseMcpAsyncServerTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/server/ServletSseMcpAsyncServerTests.java @@ -4,10 +4,9 @@ package io.modelcontextprotocol.server; -import org.junit.jupiter.api.Timeout; - import io.modelcontextprotocol.server.transport.HttpServletSseServerTransportProvider; import io.modelcontextprotocol.spec.McpServerTransportProvider; +import org.junit.jupiter.api.Timeout; /** * Tests for {@link McpAsyncServer} using {@link HttpServletSseServerTransportProvider}. diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/server/ServletSseMcpSyncServerTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/server/ServletSseMcpSyncServerTests.java index cc96cefb7..7b77f9241 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/server/ServletSseMcpSyncServerTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/server/ServletSseMcpSyncServerTests.java @@ -4,10 +4,9 @@ package io.modelcontextprotocol.server; -import org.junit.jupiter.api.Timeout; - import io.modelcontextprotocol.server.transport.HttpServletSseServerTransportProvider; import io.modelcontextprotocol.spec.McpServerTransportProvider; +import org.junit.jupiter.api.Timeout; /** * Tests for {@link McpSyncServer} using {@link HttpServletSseServerTransportProvider}. diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/server/StdioMcpAsyncServerTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/server/StdioMcpAsyncServerTests.java index f20f7cf9f..b2dfbea25 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/server/StdioMcpAsyncServerTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/server/StdioMcpAsyncServerTests.java @@ -4,12 +4,11 @@ package io.modelcontextprotocol.server; -import static io.modelcontextprotocol.util.McpJsonMapperUtils.JSON_MAPPER; - -import org.junit.jupiter.api.Timeout; - import io.modelcontextprotocol.server.transport.StdioServerTransportProvider; import io.modelcontextprotocol.spec.McpServerTransportProvider; +import org.junit.jupiter.api.Timeout; + +import static io.modelcontextprotocol.util.McpJsonMapperUtils.JSON_MAPPER; /** * Tests for {@link McpAsyncServer} using {@link StdioServerTransport}. diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/server/StdioMcpSyncServerTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/server/StdioMcpSyncServerTests.java index 68acead68..c97c75d38 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/server/StdioMcpSyncServerTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/server/StdioMcpSyncServerTests.java @@ -4,12 +4,11 @@ package io.modelcontextprotocol.server; -import static io.modelcontextprotocol.util.McpJsonMapperUtils.JSON_MAPPER; - -import org.junit.jupiter.api.Timeout; - import io.modelcontextprotocol.server.transport.StdioServerTransportProvider; import io.modelcontextprotocol.spec.McpServerTransportProvider; +import org.junit.jupiter.api.Timeout; + +import static io.modelcontextprotocol.util.McpJsonMapperUtils.JSON_MAPPER; /** * Tests for {@link McpSyncServer} using {@link StdioServerTransportProvider}. diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/server/transport/HttpServletSseServerCustomContextPathTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/server/transport/HttpServletSseServerCustomContextPathTests.java index 916fdc627..be88097b3 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/server/transport/HttpServletSseServerCustomContextPathTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/server/transport/HttpServletSseServerCustomContextPathTests.java @@ -4,8 +4,10 @@ package io.modelcontextprotocol.server.transport; -import static org.assertj.core.api.Assertions.assertThat; - +import io.modelcontextprotocol.client.McpClient; +import io.modelcontextprotocol.client.transport.HttpClientSseClientTransport; +import io.modelcontextprotocol.server.McpServer; +import io.modelcontextprotocol.spec.McpSchema; import org.apache.catalina.LifecycleException; import org.apache.catalina.LifecycleState; import org.apache.catalina.startup.Tomcat; @@ -13,10 +15,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import io.modelcontextprotocol.client.McpClient; -import io.modelcontextprotocol.client.transport.HttpClientSseClientTransport; -import io.modelcontextprotocol.server.McpServer; -import io.modelcontextprotocol.spec.McpSchema; +import static org.assertj.core.api.Assertions.assertThat; class HttpServletSseServerCustomContextPathTests { diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/server/transport/StdioServerTransportProviderTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/server/transport/StdioServerTransportProviderTests.java index 381e9a7f1..6a70af33d 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/server/transport/StdioServerTransportProviderTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/server/transport/StdioServerTransportProviderTests.java @@ -4,13 +4,6 @@ package io.modelcontextprotocol.server.transport; -import static io.modelcontextprotocol.util.McpJsonMapperUtils.JSON_MAPPER; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.InputStream; @@ -21,18 +14,24 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; - import io.modelcontextprotocol.spec.McpError; import io.modelcontextprotocol.spec.McpSchema; import io.modelcontextprotocol.spec.McpServerSession; import io.modelcontextprotocol.spec.McpServerTransport; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; +import static io.modelcontextprotocol.util.McpJsonMapperUtils.JSON_MAPPER; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + /** * Tests for {@link StdioServerTransportProvider}. * diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/server/transport/TomcatTestUtil.java b/mcp-core/src/test/java/io/modelcontextprotocol/server/transport/TomcatTestUtil.java index d7e4fb865..490e29838 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/server/transport/TomcatTestUtil.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/server/transport/TomcatTestUtil.java @@ -8,14 +8,13 @@ import java.net.InetSocketAddress; import java.net.ServerSocket; +import jakarta.servlet.Filter; +import jakarta.servlet.Servlet; import org.apache.catalina.Context; import org.apache.catalina.startup.Tomcat; import org.apache.tomcat.util.descriptor.web.FilterDef; import org.apache.tomcat.util.descriptor.web.FilterMap; -import jakarta.servlet.Filter; -import jakarta.servlet.Servlet; - /** * @author Christian Tzolov * @author Daniel Garnier-Moiroux diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/spec/CompleteCompletionSerializationTest.java b/mcp-core/src/test/java/io/modelcontextprotocol/spec/CompleteCompletionSerializationTest.java index 3f8c911aa..da5422e4e 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/spec/CompleteCompletionSerializationTest.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/spec/CompleteCompletionSerializationTest.java @@ -1,14 +1,11 @@ package io.modelcontextprotocol.spec; -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.io.IOException; -import java.util.Collections; - -import org.junit.jupiter.api.Test; - import io.modelcontextprotocol.json.McpJsonDefaults; import io.modelcontextprotocol.json.McpJsonMapper; +import org.junit.jupiter.api.Test; +import java.io.IOException; +import java.util.Collections; +import static org.junit.jupiter.api.Assertions.assertEquals; class CompleteCompletionSerializationTest { diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/spec/JSONRPCRequestMcpValidationTest.java b/mcp-core/src/test/java/io/modelcontextprotocol/spec/JSONRPCRequestMcpValidationTest.java index 4d62ef567..fbe17d464 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/spec/JSONRPCRequestMcpValidationTest.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/spec/JSONRPCRequestMcpValidationTest.java @@ -4,13 +4,12 @@ package io.modelcontextprotocol.spec; +import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import org.junit.jupiter.api.Test; - /** * Tests for MCP-specific validation of JSONRPCRequest ID requirements. * diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/spec/McpClientSessionTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/spec/McpClientSessionTests.java index 2cb79b425..3de06f503 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/spec/McpClientSessionTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/spec/McpClientSessionTests.java @@ -4,22 +4,21 @@ package io.modelcontextprotocol.spec; -import static org.assertj.core.api.Assertions.assertThat; - import java.time.Duration; import java.util.Map; import java.util.function.Function; +import io.modelcontextprotocol.MockMcpClientTransport; +import io.modelcontextprotocol.json.TypeRef; import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - -import io.modelcontextprotocol.MockMcpClientTransport; -import io.modelcontextprotocol.json.TypeRef; import reactor.core.publisher.Mono; import reactor.core.publisher.Sinks; import reactor.test.StepVerifier; +import static org.assertj.core.api.Assertions.assertThat; + /** * Test suite for {@link McpClientSession} that verifies its JSON-RPC message handling, * request-response correlation, and notification processing. diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/spec/McpErrorTest.java b/mcp-core/src/test/java/io/modelcontextprotocol/spec/McpErrorTest.java index f4d13a630..0978ffe0b 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/spec/McpErrorTest.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/spec/McpErrorTest.java @@ -1,11 +1,11 @@ package io.modelcontextprotocol.spec; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; +import org.junit.jupiter.api.Test; import java.util.Map; -import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; class McpErrorTest { diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/spec/PromptReferenceEqualsTest.java b/mcp-core/src/test/java/io/modelcontextprotocol/spec/PromptReferenceEqualsTest.java index 03da264d0..1d7be0b51 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/spec/PromptReferenceEqualsTest.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/spec/PromptReferenceEqualsTest.java @@ -4,13 +4,12 @@ package io.modelcontextprotocol.spec; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; - +import io.modelcontextprotocol.spec.McpSchema.PromptReference; import org.junit.jupiter.api.Test; -import io.modelcontextprotocol.spec.McpSchema.PromptReference; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Test class to verify the equals method implementation for PromptReference. diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/spec/json/gson/GsonMcpJsonMapper.java b/mcp-core/src/test/java/io/modelcontextprotocol/spec/json/gson/GsonMcpJsonMapper.java index e1ab905a1..ef7cd2737 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/spec/json/gson/GsonMcpJsonMapper.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/spec/json/gson/GsonMcpJsonMapper.java @@ -1,15 +1,14 @@ package io.modelcontextprotocol.spec.json.gson; -import java.io.IOException; -import java.nio.charset.StandardCharsets; - import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.ToNumberPolicy; - import io.modelcontextprotocol.json.McpJsonMapper; import io.modelcontextprotocol.json.TypeRef; +import java.io.IOException; +import java.nio.charset.StandardCharsets; + /** * Test-only Gson-based implementation of McpJsonMapper. This lives under src/test/java so * it doesn't affect production code or dependencies. diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/spec/json/gson/GsonMcpJsonMapperTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/spec/json/gson/GsonMcpJsonMapperTests.java index e2e7e8b1a..498194d17 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/spec/json/gson/GsonMcpJsonMapperTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/spec/json/gson/GsonMcpJsonMapperTests.java @@ -1,18 +1,17 @@ package io.modelcontextprotocol.spec.json.gson; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertInstanceOf; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import io.modelcontextprotocol.spec.McpSchema; +import io.modelcontextprotocol.json.TypeRef; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.util.List; import java.util.Map; -import org.junit.jupiter.api.Test; - -import io.modelcontextprotocol.json.TypeRef; -import io.modelcontextprotocol.spec.McpSchema; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; class GsonMcpJsonMapperTests { diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/util/AssertTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/util/AssertTests.java index 6c2254853..0038d4e1b 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/util/AssertTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/util/AssertTests.java @@ -4,13 +4,13 @@ package io.modelcontextprotocol.util; -import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; +import org.junit.jupiter.api.Test; import java.util.List; -import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; class AssertTests { diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/util/KeepAliveSchedulerTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/util/KeepAliveSchedulerTests.java index 752f30b38..d5ef8a91c 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/util/KeepAliveSchedulerTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/util/KeepAliveSchedulerTests.java @@ -17,6 +17,7 @@ import org.junit.jupiter.api.Test; import io.modelcontextprotocol.json.TypeRef; + import io.modelcontextprotocol.spec.McpSchema; import io.modelcontextprotocol.spec.McpSession; import reactor.core.Disposable; diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/util/ToolsUtils.java b/mcp-core/src/test/java/io/modelcontextprotocol/util/ToolsUtils.java index 5df692941..ce8755223 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/util/ToolsUtils.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/util/ToolsUtils.java @@ -1,9 +1,9 @@ package io.modelcontextprotocol.util; -import java.util.Collections; - import io.modelcontextprotocol.spec.McpSchema; +import java.util.Collections; + public final class ToolsUtils { private ToolsUtils() { diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/util/UtilsTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/util/UtilsTests.java index 904ea7f49..0f2e689b5 100644 --- a/mcp-core/src/test/java/io/modelcontextprotocol/util/UtilsTests.java +++ b/mcp-core/src/test/java/io/modelcontextprotocol/util/UtilsTests.java @@ -4,17 +4,17 @@ package io.modelcontextprotocol.util; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; import java.net.URI; import java.util.Collection; import java.util.List; import java.util.Map; -import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; From 793f43b2b7bf7065c441e63476ec0db803fdf87a Mon Sep 17 00:00:00 2001 From: Scott Lewis Date: Mon, 24 Nov 2025 23:10:15 -0800 Subject: [PATCH 11/11] Removed obsolete file --- ...io.modelcontextprotocol.json.internal.DefaultMcpJson.xml | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 mcp-core/src/main/resources/OSGI-INF/io.modelcontextprotocol.json.internal.DefaultMcpJson.xml diff --git a/mcp-core/src/main/resources/OSGI-INF/io.modelcontextprotocol.json.internal.DefaultMcpJson.xml b/mcp-core/src/main/resources/OSGI-INF/io.modelcontextprotocol.json.internal.DefaultMcpJson.xml deleted file mode 100644 index ab9934d79..000000000 --- a/mcp-core/src/main/resources/OSGI-INF/io.modelcontextprotocol.json.internal.DefaultMcpJson.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - -