diff --git a/README.md b/README.md
index 39ba13926..7bda15006 100644
--- a/README.md
+++ b/README.md
@@ -47,6 +47,7 @@ Please follow the [Contributing Guidelines](CONTRIBUTING.md).
- Christian Tzolov
- Dariusz Jędrzejczyk
+- Daniel Garnier-Moiroux
## Links
@@ -54,6 +55,133 @@ Please follow the [Contributing Guidelines](CONTRIBUTING.md).
- [Issue Tracker](https://github.com/modelcontextprotocol/java-sdk/issues)
- [CI/CD](https://github.com/modelcontextprotocol/java-sdk/actions)
+## Architecture and Design Decisions
+
+### Introduction
+
+Building a general-purpose MCP Java SDK requires making technology decisions in areas where the JDK provides limited or no support. The Java ecosystem is powerful but fragmented: multiple valid approaches exist, each with strong communities.
+Our goal is not to prescribe "the one true way," but to provide a reference implementation of the MCP specification that is:
+
+* **Pragmatic** – makes developers productive quickly
+* **Interoperable** – aligns with widely used libraries and practices
+* **Pluggable** – allows alternatives where projects prefer different stacks
+* **Grounded in team familiarity** – we chose technologies the team can be productive with today, while remaining open to community contributions that broaden the SDK
+
+### Key Choices and Considerations
+
+The SDK had to make decisions in the following areas:
+
+1. **JSON serialization** – mapping between JSON and Java types
+
+2. **Programming model** – supporting asynchronous processing, cancellation, and streaming while staying simple for blocking use cases
+
+3. **Observability** – logging and enabling integration with metrics/tracing
+
+4. **Remote clients and servers** – supporting both consuming MCP servers (client transport) and exposing MCP endpoints (server transport with authorization)
+
+The following sections explain what we chose, why it made sense, and how the choices align with the SDK's goals.
+
+### 1. JSON Serialization
+
+* **SDK Choice**: Jackson for JSON serialization and deserialization, behind an SDK abstraction (`mcp-json`)
+
+* **Why**: Jackson is widely adopted across the Java ecosystem, provides strong performance and a mature annotation model, and is familiar to the SDK team and many potential contributors.
+
+* **How we expose it**: Public APIs use a zero-dependency abstraction (`mcp-json`). Jackson is shipped as the default implementation (`mcp-jackson2`), but alternatives can be plugged in.
+
+* **How it fits the SDK**: This offers a pragmatic default while keeping flexibility for projects that prefer different JSON libraries.
+
+### 2. Programming Model
+
+* **SDK Choice**: Reactive Streams for public APIs, with Project Reactor as the internal implementation and a synchronous facade for blocking use cases
+
+* **Why**: MCP builds on JSON-RPC's asynchronous nature and defines a bidirectional protocol on top of it, enabling asynchronous and streaming interactions. MCP explicitly supports:
+
+ * Multiple in-flight requests and responses
+ * Notifications that do not expect a reply
+ * STDIO transports for inter-process communication using pipes
+ * Streaming transports such as Server-Sent Events and Streamable HTTP
+
+ These requirements call for a programming model more powerful than single-result futures like `CompletableFuture`.
+
+ * **Reactive Streams: the Community Standard**
+
+ Reactive Streams is a small Java specification that standardizes asynchronous stream processing with backpressure. It defines four minimal interfaces (Publisher, Subscriber, Subscription, and Processor). These interfaces are widely recognized as the standard contract for async, non-blocking pipelines in Java.
+
+ * **Reactive Streams Implementation**
+
+ The SDK uses Project Reactor as its implementation of the Reactive Streams specification. Reactor is mature, widely adopted, provides rich operators, and integrates well with observability through context propagation. Team familiarity also allowed us to deliver a solid foundation quickly.
+ We plan to convert the public API to only expose Reactive Streams interfaces. By defining the public API in terms of Reactive Streams interfaces and using Reactor internally, the SDK stays standards-based while benefiting from a practical, production-ready implementation.
+
+ * **Synchronous Facade in the SDK**
+
+ Not all MCP use cases require streaming pipelines. Many scenarios are as simple as "send a request and block until I get the result."
+ To support this, the SDK provides a synchronous facade layered on top of the reactive core. Developers can stay in a blocking model when it's enough, while still having access to asynchronous streaming when needed.
+
+* **How it fits the SDK**: This design balances scalability, approachability, and future evolution such as Virtual Threads and Structured Concurrency in upcoming JDKs.
+
+### 3. Observability
+
+* **SDK Choice**: SLF4J for logging; Reactor Context for observability propagation
+
+* **Why**: SLF4J is the de facto logging facade in Java, with broad compatibility. Reactor Context enables propagation of observability data such as correlation IDs and tracing state across async boundaries. This ensures interoperability with modern observability frameworks.
+
+* **How we expose it**: Public APIs log through SLF4J only, with no backend included. Observability metadata flows through Reactor pipelines. The SDK itself does not ship metrics or tracing implementations.
+
+* **How it fits the SDK**: This provides reliable logging by default and seamless integration with Micrometer, OpenTelemetry, or similar systems for metrics and tracing.
+
+### 4. Remote MCP Clients and Servers
+
+MCP supports both clients (applications consuming MCP servers) and servers (applications exposing MCP endpoints). The SDK provides support for both sides.
+
+#### Client Transport in the SDK
+
+* **SDK Choice**: JDK HttpClient (Java 11+) as the default client, with optional Spring WebClient support
+
+* **Why**: The JDK HttpClient is built-in, portable, and supports streaming responses. This keeps the default lightweight with no extra dependencies. Spring WebClient support is available for Spring-based projects.
+
+* **How we expose it**: MCP Client APIs are transport-agnostic. The core module ships with JDK HttpClient transport. A Spring module provides WebClient integration.
+
+* **How it fits the SDK**: This ensures all applications can talk to MCP servers out of the box, while allowing richer integration in Spring and other environments.
+
+#### Server Transport in the SDK
+
+* **SDK Choice**: Jakarta Servlet implementation in core, with optional Spring WebFlux and Spring WebMVC providers
+
+* **Why**: Servlet is the most widely deployed Java server API. WebFlux and WebMVC cover a significant part of the Spring community. Together these provide reach across blocking and non-blocking models.
+
+* **How we expose it**: Server APIs are transport-agnostic. Core includes Servlet support. Spring modules extend support for WebFlux and WebMVC.
+
+* **How it fits the SDK**: This allows developers to expose MCP servers in the most common Java environments today, while enabling other transport implementations such as Netty, Vert.x, or Helidon.
+
+#### Authorization in the SDK
+
+* **SDK Choice**: Pluggable authorization hooks for MCP servers; no built-in implementation
+
+* **Why**: MCP servers must restrict access to authenticated and authorized clients. Authorization needs differ across environments such as Spring Security, MicroProfile JWT, or custom solutions. Providing hooks avoids lock-in and leverages proven libraries.
+
+* **How we expose it**: Authorization is integrated into the server transport layer. The SDK does not include its own authorization system.
+
+* **How it fits the SDK**: This keeps server-side security ecosystem-neutral, while ensuring applications can plug in their preferred authorization strategy.
+
+### Project Structure of the SDK
+
+The SDK is organized into modules to separate concerns and allow adopters to bring in only what they need:
+* `mcp-bom` – Dependency versions
+* `mcp-core` – Reference implementation (STDIO, JDK HttpClient, Servlet)
+* `mcp-json` – JSON abstraction
+* `mcp-jackson2` – Jackson implementation of JSON binding
+* `mcp` – Convenience bundle (core + Jackson)
+* `mcp-test` – Shared testing utilities
+* `mcp-spring` – Spring integrations (WebClient, WebFlux, WebMVC)
+
+For example, a minimal adopter may depend only on `mcp` (core + Jackson), while a Spring-based application can use `mcp-spring` for deeper framework integration.
+
+### Future Directions
+
+The SDK is designed to evolve with the Java ecosystem. Areas we are actively watching include:
+Concurrency in the JDK – Virtual Threads and Structured Concurrency may simplify the synchronous API story
+
## License
This project is licensed under the [MIT License](LICENSE).
diff --git a/mcp-bom/pom.xml b/mcp-bom/pom.xml
index 6b1027a21..e23b5adf1 100644
--- a/mcp-bom/pom.xml
+++ b/mcp-bom/pom.xml
@@ -7,7 +7,7 @@
io.modelcontextprotocol.sdk
mcp-parent
- 0.14.0-SNAPSHOT
+ 0.14.2-SNAPSHOT
mcp-bom
diff --git a/mcp-core/pom.xml b/mcp-core/pom.xml
index 8637303fe..31153bb93 100644
--- a/mcp-core/pom.xml
+++ b/mcp-core/pom.xml
@@ -6,7 +6,7 @@
io.modelcontextprotocol.sdk
mcp-parent
- 0.14.0-SNAPSHOT
+ 0.14.2-SNAPSHOT
mcp-core
jar
@@ -68,7 +68,7 @@
io.modelcontextprotocol.sdk
mcp-json
- 0.14.0-SNAPSHOT
+ 0.14.2-SNAPSHOT
@@ -101,7 +101,7 @@
io.modelcontextprotocol.sdk
mcp-json-jackson2
- 0.14.0-SNAPSHOT
+ 0.14.2-SNAPSHOT
test
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 dcba3af1f..ac4b36990 100644
--- a/mcp-core/src/main/java/io/modelcontextprotocol/server/McpAsyncServer.java
+++ b/mcp-core/src/main/java/io/modelcontextprotocol/server/McpAsyncServer.java
@@ -36,7 +36,7 @@
import io.modelcontextprotocol.spec.McpServerTransportProviderBase;
import io.modelcontextprotocol.spec.McpStreamableServerTransportProvider;
import io.modelcontextprotocol.util.Assert;
-import io.modelcontextprotocol.util.DeafaultMcpUriTemplateManagerFactory;
+import io.modelcontextprotocol.util.DefaultMcpUriTemplateManagerFactory;
import io.modelcontextprotocol.util.McpUriTemplateManagerFactory;
import io.modelcontextprotocol.util.Utils;
import org.slf4j.Logger;
@@ -120,7 +120,7 @@ public class McpAsyncServer {
private List protocolVersions;
- private McpUriTemplateManagerFactory uriTemplateManagerFactory = new DeafaultMcpUriTemplateManagerFactory();
+ private McpUriTemplateManagerFactory uriTemplateManagerFactory = new DefaultMcpUriTemplateManagerFactory();
/**
* Create a new McpAsyncServer with the given transport provider and capabilities.
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 8e3ebf9e8..ecfb74b6a 100644
--- a/mcp-core/src/main/java/io/modelcontextprotocol/server/McpServer.java
+++ b/mcp-core/src/main/java/io/modelcontextprotocol/server/McpServer.java
@@ -25,7 +25,7 @@
import io.modelcontextprotocol.spec.McpStatelessServerTransport;
import io.modelcontextprotocol.spec.McpStreamableServerTransportProvider;
import io.modelcontextprotocol.util.Assert;
-import io.modelcontextprotocol.util.DeafaultMcpUriTemplateManagerFactory;
+import io.modelcontextprotocol.util.DefaultMcpUriTemplateManagerFactory;
import io.modelcontextprotocol.util.McpUriTemplateManagerFactory;
import reactor.core.publisher.Mono;
@@ -268,7 +268,7 @@ public McpAsyncServer build() {
*/
abstract class AsyncSpecification> {
- McpUriTemplateManagerFactory uriTemplateManagerFactory = new DeafaultMcpUriTemplateManagerFactory();
+ McpUriTemplateManagerFactory uriTemplateManagerFactory = new DefaultMcpUriTemplateManagerFactory();
McpJsonMapper jsonMapper;
@@ -865,7 +865,7 @@ public McpSyncServer build() {
*/
abstract class SyncSpecification> {
- McpUriTemplateManagerFactory uriTemplateManagerFactory = new DeafaultMcpUriTemplateManagerFactory();
+ McpUriTemplateManagerFactory uriTemplateManagerFactory = new DefaultMcpUriTemplateManagerFactory();
McpJsonMapper jsonMapper;
@@ -1407,7 +1407,7 @@ class StatelessAsyncSpecification {
private final McpStatelessServerTransport transport;
- McpUriTemplateManagerFactory uriTemplateManagerFactory = new DeafaultMcpUriTemplateManagerFactory();
+ McpUriTemplateManagerFactory uriTemplateManagerFactory = new DefaultMcpUriTemplateManagerFactory();
McpJsonMapper jsonMapper;
@@ -1870,7 +1870,7 @@ class StatelessSyncSpecification {
boolean immediateExecution = false;
- McpUriTemplateManagerFactory uriTemplateManagerFactory = new DeafaultMcpUriTemplateManagerFactory();
+ McpUriTemplateManagerFactory uriTemplateManagerFactory = new DefaultMcpUriTemplateManagerFactory();
McpJsonMapper jsonMapper;
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 823aca41d..997df7225 100644
--- a/mcp-core/src/main/java/io/modelcontextprotocol/server/McpStatelessAsyncServer.java
+++ b/mcp-core/src/main/java/io/modelcontextprotocol/server/McpStatelessAsyncServer.java
@@ -20,7 +20,7 @@
import io.modelcontextprotocol.spec.McpSchema.Tool;
import io.modelcontextprotocol.spec.McpStatelessServerTransport;
import io.modelcontextprotocol.util.Assert;
-import io.modelcontextprotocol.util.DeafaultMcpUriTemplateManagerFactory;
+import io.modelcontextprotocol.util.DefaultMcpUriTemplateManagerFactory;
import io.modelcontextprotocol.util.McpUriTemplateManagerFactory;
import io.modelcontextprotocol.util.Utils;
import org.slf4j.Logger;
@@ -74,7 +74,7 @@ public class McpStatelessAsyncServer {
private List protocolVersions;
- private McpUriTemplateManagerFactory uriTemplateManagerFactory = new DeafaultMcpUriTemplateManagerFactory();
+ private McpUriTemplateManagerFactory uriTemplateManagerFactory = new DefaultMcpUriTemplateManagerFactory();
private final JsonSchemaValidator jsonSchemaValidator;
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 12835a57a..e43469903 100644
--- a/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpSchema.java
+++ b/mcp-core/src/main/java/io/modelcontextprotocol/spec/McpSchema.java
@@ -306,7 +306,7 @@ public record JSONRPCResponse( // @formatter:off
@JsonInclude(JsonInclude.Include.NON_ABSENT)
@JsonIgnoreProperties(ignoreUnknown = true)
public record JSONRPCError( // @formatter:off
- @JsonProperty("code") int code,
+ @JsonProperty("code") Integer code,
@JsonProperty("message") String message,
@JsonProperty("data") Object data) { // @formatter:on
}
@@ -1064,8 +1064,8 @@ public UnsubscribeRequest(String uri) {
* The contents of a specific resource or sub-resource.
*/
@JsonTypeInfo(use = JsonTypeInfo.Id.DEDUCTION)
- @JsonSubTypes({ @JsonSubTypes.Type(value = TextResourceContents.class, name = "text"),
- @JsonSubTypes.Type(value = BlobResourceContents.class, name = "blob") })
+ @JsonSubTypes({ @JsonSubTypes.Type(value = TextResourceContents.class),
+ @JsonSubTypes.Type(value = BlobResourceContents.class) })
public sealed interface ResourceContents extends Meta permits TextResourceContents, BlobResourceContents {
/**
@@ -1822,14 +1822,14 @@ public record CreateMessageRequest( // @formatter:off
@JsonProperty("systemPrompt") String systemPrompt,
@JsonProperty("includeContext") ContextInclusionStrategy includeContext,
@JsonProperty("temperature") Double temperature,
- @JsonProperty("maxTokens") int maxTokens,
+ @JsonProperty("maxTokens") Integer maxTokens,
@JsonProperty("stopSequences") List stopSequences,
@JsonProperty("metadata") Map metadata,
@JsonProperty("_meta") Map meta) implements Request { // @formatter:on
// backwards compatibility constructor
public CreateMessageRequest(List messages, ModelPreferences modelPreferences,
- String systemPrompt, ContextInclusionStrategy includeContext, Double temperature, int maxTokens,
+ String systemPrompt, ContextInclusionStrategy includeContext, Double temperature, Integer maxTokens,
List stopSequences, Map metadata) {
this(messages, modelPreferences, systemPrompt, includeContext, temperature, maxTokens, stopSequences,
metadata, null);
@@ -1859,7 +1859,7 @@ public static class Builder {
private Double temperature;
- private int maxTokens;
+ private Integer maxTokens;
private List stopSequences;
@@ -2501,6 +2501,7 @@ public CompleteResult(CompleteCompletion completion) {
* @param hasMore Indicates whether there are additional completion options beyond
* those provided in the current response, even if the exact total is unknown
*/
+ @JsonInclude(JsonInclude.Include.ALWAYS)
public record CompleteCompletion( // @formatter:off
@JsonProperty("values") List values,
@JsonProperty("total") Integer total,
diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/util/DefaultMcpUriTemplateManager.java b/mcp-core/src/main/java/io/modelcontextprotocol/util/DefaultMcpUriTemplateManager.java
index ef51183a1..c3b922edf 100644
--- a/mcp-core/src/main/java/io/modelcontextprotocol/util/DefaultMcpUriTemplateManager.java
+++ b/mcp-core/src/main/java/io/modelcontextprotocol/util/DefaultMcpUriTemplateManager.java
@@ -141,12 +141,30 @@ public boolean matches(String uri) {
return uri.equals(this.uriTemplate);
}
- // Convert the pattern to a regex
- String regex = this.uriTemplate.replaceAll("\\{[^/]+?\\}", "([^/]+?)");
- regex = regex.replace("/", "\\/");
+ // Convert the URI template into a robust regex pattern that escapes special
+ // characters like '?'.
+ StringBuilder patternBuilder = new StringBuilder("^");
+ Matcher variableMatcher = URI_VARIABLE_PATTERN.matcher(this.uriTemplate);
+ int lastEnd = 0;
+
+ while (variableMatcher.find()) {
+ // Append the literal part of the template, safely quoted
+ String textBefore = this.uriTemplate.substring(lastEnd, variableMatcher.start());
+ patternBuilder.append(Pattern.quote(textBefore));
+ // Append a capturing group for the variable itself
+ patternBuilder.append("([^/]+?)");
+ lastEnd = variableMatcher.end();
+ }
+
+ // Append any remaining literal text after the last variable
+ if (lastEnd < this.uriTemplate.length()) {
+ patternBuilder.append(Pattern.quote(this.uriTemplate.substring(lastEnd)));
+ }
+
+ patternBuilder.append("$");
// Check if the URI matches the regex
- return Pattern.compile(regex).matcher(uri).matches();
+ return Pattern.compile(patternBuilder.toString()).matcher(uri).matches();
}
@Override
diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/util/DeafaultMcpUriTemplateManagerFactory.java b/mcp-core/src/main/java/io/modelcontextprotocol/util/DefaultMcpUriTemplateManagerFactory.java
similarity index 86%
rename from mcp-core/src/main/java/io/modelcontextprotocol/util/DeafaultMcpUriTemplateManagerFactory.java
rename to mcp-core/src/main/java/io/modelcontextprotocol/util/DefaultMcpUriTemplateManagerFactory.java
index 44ea31690..fd1a3bd71 100644
--- a/mcp-core/src/main/java/io/modelcontextprotocol/util/DeafaultMcpUriTemplateManagerFactory.java
+++ b/mcp-core/src/main/java/io/modelcontextprotocol/util/DefaultMcpUriTemplateManagerFactory.java
@@ -7,7 +7,7 @@
/**
* @author Christian Tzolov
*/
-public class DeafaultMcpUriTemplateManagerFactory implements McpUriTemplateManagerFactory {
+public class DefaultMcpUriTemplateManagerFactory implements McpUriTemplateManagerFactory {
/**
* Creates a new instance of {@link McpUriTemplateManager} with the specified URI
diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/McpUriTemplateManagerTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/McpUriTemplateManagerTests.java
index 6f041daa6..8f68f0d6e 100644
--- a/mcp-core/src/test/java/io/modelcontextprotocol/McpUriTemplateManagerTests.java
+++ b/mcp-core/src/test/java/io/modelcontextprotocol/McpUriTemplateManagerTests.java
@@ -12,7 +12,7 @@
import java.util.List;
import java.util.Map;
-import io.modelcontextprotocol.util.DeafaultMcpUriTemplateManagerFactory;
+import io.modelcontextprotocol.util.DefaultMcpUriTemplateManagerFactory;
import io.modelcontextprotocol.util.McpUriTemplateManager;
import io.modelcontextprotocol.util.McpUriTemplateManagerFactory;
import org.junit.jupiter.api.BeforeEach;
@@ -29,7 +29,7 @@ public class McpUriTemplateManagerTests {
@BeforeEach
void setUp() {
- this.uriTemplateFactory = new DeafaultMcpUriTemplateManagerFactory();
+ this.uriTemplateFactory = new DefaultMcpUriTemplateManagerFactory();
}
@Test
@@ -94,4 +94,13 @@ void shouldMatchUriAgainstTemplatePattern() {
assertFalse(uriTemplateManager.matches("/api/users/123/comments/456"));
}
+ @Test
+ void shouldMatchUriWithQueryParameters() {
+ String templateWithQuery = "file://name/search?={search}";
+ var uriTemplateManager = this.uriTemplateFactory.create(templateWithQuery);
+
+ assertTrue(uriTemplateManager.matches("file://name/search?=abcd"),
+ "Should correctly match a URI containing query parameters.");
+ }
+
}
diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/spec/CompleteCompletionSerializationTest.java b/mcp-core/src/test/java/io/modelcontextprotocol/spec/CompleteCompletionSerializationTest.java
new file mode 100644
index 000000000..55f71fea4
--- /dev/null
+++ b/mcp-core/src/test/java/io/modelcontextprotocol/spec/CompleteCompletionSerializationTest.java
@@ -0,0 +1,28 @@
+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;
+
+class CompleteCompletionSerializationTest {
+
+ @Test
+ void codeCompletionSerialization() throws IOException {
+ McpJsonMapper jsonMapper = McpJsonMapper.getDefault();
+ McpSchema.CompleteResult.CompleteCompletion codeComplete = new McpSchema.CompleteResult.CompleteCompletion(
+ Collections.emptyList(), 0, false);
+ String json = jsonMapper.writeValueAsString(codeComplete);
+ String expected = """
+ {"values":[],"total":0,"hasMore":false}""";
+ assertEquals(expected, json, json);
+
+ McpSchema.CompleteResult completeResult = new McpSchema.CompleteResult(codeComplete);
+ json = jsonMapper.writeValueAsString(completeResult);
+ expected = """
+ {"completion":{"values":[],"total":0,"hasMore":false}}""";
+ assertEquals(expected, json, json);
+ }
+
+}
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 d03a6926d..fbe17d464 100644
--- a/mcp-core/src/test/java/io/modelcontextprotocol/spec/JSONRPCRequestMcpValidationTest.java
+++ b/mcp-core/src/test/java/io/modelcontextprotocol/spec/JSONRPCRequestMcpValidationTest.java
@@ -5,7 +5,10 @@
package io.modelcontextprotocol.spec;
import org.junit.jupiter.api.Test;
-import static org.junit.jupiter.api.Assertions.*;
+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;
/**
* Tests for MCP-specific validation of JSONRPCRequest ID requirements.
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 84d650ab3..0978ffe0b 100644
--- a/mcp-core/src/test/java/io/modelcontextprotocol/spec/McpErrorTest.java
+++ b/mcp-core/src/test/java/io/modelcontextprotocol/spec/McpErrorTest.java
@@ -4,7 +4,8 @@
import java.util.Map;
-import static org.junit.jupiter.api.Assertions.*;
+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 382cda1ce..1d7be0b51 100644
--- a/mcp-core/src/test/java/io/modelcontextprotocol/spec/PromptReferenceEqualsTest.java
+++ b/mcp-core/src/test/java/io/modelcontextprotocol/spec/PromptReferenceEqualsTest.java
@@ -7,7 +7,9 @@
import io.modelcontextprotocol.spec.McpSchema.PromptReference;
import org.junit.jupiter.api.Test;
-import static org.junit.jupiter.api.Assertions.*;
+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/GsonMcpJsonMapperTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/spec/json/gson/GsonMcpJsonMapperTests.java
index 4f1dffe1d..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
@@ -8,7 +8,10 @@
import java.util.List;
import java.util.Map;
-import static org.junit.jupiter.api.Assertions.*;
+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 08555fef5..0038d4e1b 100644
--- a/mcp-core/src/test/java/io/modelcontextprotocol/util/AssertTests.java
+++ b/mcp-core/src/test/java/io/modelcontextprotocol/util/AssertTests.java
@@ -8,7 +8,9 @@
import java.util.List;
-import static org.junit.jupiter.api.Assertions.*;
+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-json-jackson2/pom.xml b/mcp-json-jackson2/pom.xml
index b3d0a16de..1b7785df6 100644
--- a/mcp-json-jackson2/pom.xml
+++ b/mcp-json-jackson2/pom.xml
@@ -6,7 +6,7 @@
io.modelcontextprotocol.sdk
mcp-parent
- 0.14.0-SNAPSHOT
+ 0.14.2-SNAPSHOT
mcp-json-jackson2
jar
@@ -37,7 +37,7 @@
io.modelcontextprotocol.sdk
mcp-json
- 0.14.0-SNAPSHOT
+ 0.14.2-SNAPSHOT
com.fasterxml.jackson.core
@@ -49,5 +49,31 @@
json-schema-validator
${json-schema-validator.version}
+
+
+ org.assertj
+ assertj-core
+ ${assert4j.version}
+ test
+
+
+ org.junit.jupiter
+ junit-jupiter-api
+ ${junit.version}
+ test
+
+
+ org.junit.jupiter
+ junit-jupiter-params
+ ${junit.version}
+ test
+
+
+ org.mockito
+ mockito-core
+ ${mockito.version}
+ test
+
+
diff --git a/mcp-json-jackson2/src/main/java/io/modelcontextprotocol/json/schema/jackson/DefaultJsonSchemaValidator.java b/mcp-json-jackson2/src/main/java/io/modelcontextprotocol/json/schema/jackson/DefaultJsonSchemaValidator.java
index 7ec0419c8..15511c9c2 100644
--- a/mcp-json-jackson2/src/main/java/io/modelcontextprotocol/json/schema/jackson/DefaultJsonSchemaValidator.java
+++ b/mcp-json-jackson2/src/main/java/io/modelcontextprotocol/json/schema/jackson/DefaultJsonSchemaValidator.java
@@ -7,18 +7,16 @@
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
-import io.modelcontextprotocol.json.schema.JsonSchemaValidator;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.node.ObjectNode;
import com.networknt.schema.JsonSchema;
import com.networknt.schema.JsonSchemaFactory;
import com.networknt.schema.SpecVersion;
import com.networknt.schema.ValidationMessage;
+import io.modelcontextprotocol.json.schema.JsonSchemaValidator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Default implementation of the {@link JsonSchemaValidator} interface. This class
@@ -60,7 +58,9 @@ public ValidationResponse validate(Map schema, Object structured
try {
- JsonNode jsonStructuredOutput = this.objectMapper.valueToTree(structuredContent);
+ JsonNode jsonStructuredOutput = (structuredContent instanceof String)
+ ? this.objectMapper.readTree((String) structuredContent)
+ : this.objectMapper.valueToTree(structuredContent);
Set validationResult = this.getOrCreateJsonSchema(schema).validate(jsonStructuredOutput);
@@ -125,17 +125,6 @@ private JsonSchema createJsonSchema(Map schema) throws JsonProce
};
}
- // Handle additionalProperties setting
- if (schemaNode.isObject()) {
- ObjectNode objectSchemaNode = (ObjectNode) schemaNode;
- if (!objectSchemaNode.has("additionalProperties")) {
- // Clone the node before modification to avoid mutating the original
- objectSchemaNode = objectSchemaNode.deepCopy();
- objectSchemaNode.put("additionalProperties", false);
- schemaNode = objectSchemaNode;
- }
- }
-
return this.schemaFactory.getSchema(schemaNode);
}
diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/spec/DefaultJsonSchemaValidatorTests.java b/mcp-json-jackson2/src/test/java/io/modelcontextprotocol/json/DefaultJsonSchemaValidatorTests.java
similarity index 84%
rename from mcp-core/src/test/java/io/modelcontextprotocol/spec/DefaultJsonSchemaValidatorTests.java
rename to mcp-json-jackson2/src/test/java/io/modelcontextprotocol/json/DefaultJsonSchemaValidatorTests.java
index 76ca29684..7642f0480 100644
--- a/mcp-core/src/test/java/io/modelcontextprotocol/spec/DefaultJsonSchemaValidatorTests.java
+++ b/mcp-json-jackson2/src/test/java/io/modelcontextprotocol/json/DefaultJsonSchemaValidatorTests.java
@@ -2,7 +2,7 @@
* Copyright 2024-2024 the original author or authors.
*/
-package io.modelcontextprotocol.spec;
+package io.modelcontextprotocol.json;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -13,6 +13,7 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
+import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
@@ -64,6 +65,16 @@ private Map toMap(String json) {
}
}
+ private List