Remove deprecated APIs and modules for 1.0.0 release (#807)

- Remove mcp-json-jackson module (JacksonMcpJsonMapper, DefaultJsonSchemaValidator)
- Remove deprecated session interfaces (McpServerSession, McpClientSession methods)
- Remove deprecated server methods (loggingNotification, McpAsyncServerExchange constructor)
- Remove deprecated schema definitions and constructors (McpSchema, McpError, tool/content classes)
- Replace generic McpError with appropriate exception types (IllegalStateException, IllegalArgumentException)
- Update all tests to use current APIs

---------

Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
This commit is contained in:
Dariusz Jędrzejczyk 2026-02-20 17:32:40 +01:00 • committed by GitHub
commit 4c1c3d8d5c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 261 additions and 1940 deletions

View file

@ -13,6 +13,7 @@ import io.modelcontextprotocol.json.McpJsonDefaults;
import io.modelcontextprotocol.json.TypeRef;
import io.modelcontextprotocol.spec.McpClientTransport;
import io.modelcontextprotocol.spec.McpSchema;
import io.modelcontextprotocol.spec.ProtocolVersions;
import io.modelcontextprotocol.spec.McpSchema.JSONRPCNotification;
import io.modelcontextprotocol.spec.McpSchema.JSONRPCRequest;
import reactor.core.publisher.Mono;
@ -29,7 +30,7 @@ public class MockMcpClientTransport implements McpClientTransport {
private final BiConsumer<MockMcpClientTransport, McpSchema.JSONRPCMessage> interceptor;
private String protocolVersion = McpSchema.LATEST_PROTOCOL_VERSION;
private String protocolVersion = ProtocolVersions.MCP_2025_11_25;
public MockMcpClientTransport() {
this((t, msg) -> {

View file

@ -13,6 +13,7 @@ import java.util.function.Function;
import io.modelcontextprotocol.json.TypeRef;
import io.modelcontextprotocol.MockMcpClientTransport;
import io.modelcontextprotocol.spec.McpSchema;
import io.modelcontextprotocol.spec.ProtocolVersions;
import io.modelcontextprotocol.spec.McpSchema.ClientCapabilities;
import io.modelcontextprotocol.spec.McpSchema.InitializeResult;
import io.modelcontextprotocol.spec.McpSchema.PaginatedRequest;
@ -42,7 +43,7 @@ class McpAsyncClientResponseHandlerTests {
private static MockMcpClientTransport initializationEnabledTransport(
McpSchema.ServerCapabilities mockServerCapabilities, McpSchema.Implementation mockServerInfo) {
McpSchema.InitializeResult mockInitResult = new McpSchema.InitializeResult(McpSchema.LATEST_PROTOCOL_VERSION,
McpSchema.InitializeResult mockInitResult = new McpSchema.InitializeResult(ProtocolVersions.MCP_2025_11_25,
mockServerCapabilities, mockServerInfo, "Test instructions");
return new MockMcpClientTransport((t, message) -> {
@ -51,7 +52,7 @@ class McpAsyncClientResponseHandlerTests {
r.id(), mockInitResult, null);
t.simulateIncomingMessage(initResponse);
}
}).withProtocolVersion(McpSchema.LATEST_PROTOCOL_VERSION);
}).withProtocolVersion(ProtocolVersions.MCP_2025_11_25);
}
@Test
@ -212,8 +213,12 @@ class McpAsyncClientResponseHandlerTests {
assertThat(asyncMcpClient.initialize().block()).isNotNull();
// Create a mock resources list that the server will return
McpSchema.Resource mockResource = new McpSchema.Resource("test://resource", "Test Resource", "A test resource",
"text/plain", null);
McpSchema.Resource mockResource = McpSchema.Resource.builder()
.uri("test://resource")
.name("Test Resource")
.description("A test resource")
.mimeType("text/plain")
.build();
McpSchema.ListResourcesResult mockResourcesResult = new McpSchema.ListResourcesResult(List.of(mockResource),
null);

View file

@ -11,6 +11,7 @@ import io.modelcontextprotocol.MockMcpClientTransport;
import io.modelcontextprotocol.spec.McpSchema;
import io.modelcontextprotocol.spec.McpSchema.InitializeResult;
import io.modelcontextprotocol.spec.McpSchema.ServerCapabilities;
import io.modelcontextprotocol.spec.ProtocolVersions;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
@ -68,7 +69,7 @@ class McpClientProtocolVersionTests {
.requestTimeout(REQUEST_TIMEOUT)
.build();
client.setProtocolVersions(List.of(oldVersion, McpSchema.LATEST_PROTOCOL_VERSION));
client.setProtocolVersions(List.of(oldVersion, ProtocolVersions.MCP_2025_11_25));
try {
Mono<InitializeResult> initializeResultMono = client.initialize();
@ -77,7 +78,7 @@ class McpClientProtocolVersionTests {
McpSchema.JSONRPCRequest request = transport.getLastSentMessageAsRequest();
assertThat(request.params()).isInstanceOf(McpSchema.InitializeRequest.class);
McpSchema.InitializeRequest initRequest = (McpSchema.InitializeRequest) request.params();
assertThat(initRequest.protocolVersion()).isIn(List.of(oldVersion, McpSchema.LATEST_PROTOCOL_VERSION));
assertThat(initRequest.protocolVersion()).isIn(List.of(oldVersion, ProtocolVersions.MCP_2025_11_25));
transport.simulateIncomingMessage(new McpSchema.JSONRPCResponse(McpSchema.JSONRPC_VERSION, request.id(),
new McpSchema.InitializeResult(oldVersion, ServerCapabilities.builder().build(),
@ -123,7 +124,7 @@ class McpClientProtocolVersionTests {
void shouldUseHighestVersionWhenMultipleSupported() {
String oldVersion = "0.1.0";
String middleVersion = "0.2.0";
String latestVersion = McpSchema.LATEST_PROTOCOL_VERSION;
String latestVersion = ProtocolVersions.MCP_2025_11_25;
MockMcpClientTransport transport = new MockMcpClientTransport();
McpAsyncClient client = McpClient.async(transport)

View file

@ -8,6 +8,7 @@ import io.modelcontextprotocol.client.transport.customizer.McpAsyncHttpClientReq
import io.modelcontextprotocol.client.transport.customizer.McpSyncHttpClientRequestCustomizer;
import io.modelcontextprotocol.common.McpTransportContext;
import io.modelcontextprotocol.spec.McpSchema;
import io.modelcontextprotocol.spec.ProtocolVersions;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Map;
@ -78,7 +79,7 @@ class HttpClientStreamableHttpTransportTest {
withTransport(transport, (t) -> {
// Send test message
var initializeRequest = new McpSchema.InitializeRequest(McpSchema.LATEST_PROTOCOL_VERSION,
var initializeRequest = new McpSchema.InitializeRequest(ProtocolVersions.MCP_2025_11_25,
McpSchema.ClientCapabilities.builder().roots(true).build(),
new McpSchema.Implementation("MCP Client", "0.3.1"));
var testMessage = new McpSchema.JSONRPCRequest(McpSchema.JSONRPC_VERSION, McpSchema.METHOD_INITIALIZE,
@ -108,7 +109,7 @@ class HttpClientStreamableHttpTransportTest {
withTransport(transport, (t) -> {
// Send test message
var initializeRequest = new McpSchema.InitializeRequest(McpSchema.LATEST_PROTOCOL_VERSION,
var initializeRequest = new McpSchema.InitializeRequest(ProtocolVersions.MCP_2025_11_25,
McpSchema.ClientCapabilities.builder().roots(true).build(),
new McpSchema.Implementation("MCP Client", "0.3.1"));
var testMessage = new McpSchema.JSONRPCRequest(McpSchema.JSONRPC_VERSION, McpSchema.METHOD_INITIALIZE,
@ -131,7 +132,7 @@ class HttpClientStreamableHttpTransportTest {
StepVerifier.create(transport.closeGracefully()).verifyComplete();
var initializeRequest = new McpSchema.InitializeRequest(McpSchema.LATEST_PROTOCOL_VERSION,
var initializeRequest = new McpSchema.InitializeRequest(ProtocolVersions.MCP_2025_11_25,
McpSchema.ClientCapabilities.builder().roots(true).build(),
new McpSchema.Implementation("MCP Client", "0.3.1"));
var testMessage = new McpSchema.JSONRPCRequest(McpSchema.JSONRPC_VERSION, McpSchema.METHOD_INITIALIZE,
@ -146,7 +147,7 @@ class HttpClientStreamableHttpTransportTest {
void testCloseInitialized() {
var transport = HttpClientStreamableHttpTransport.builder(host).build();
var initializeRequest = new McpSchema.InitializeRequest(McpSchema.LATEST_PROTOCOL_VERSION,
var initializeRequest = new McpSchema.InitializeRequest(ProtocolVersions.MCP_2025_11_25,
McpSchema.ClientCapabilities.builder().roots(true).build(),
new McpSchema.Implementation("MCP Client", "0.3.1"));
var testMessage = new McpSchema.JSONRPCRequest(McpSchema.JSONRPC_VERSION, McpSchema.METHOD_INITIALIZE,

View file

@ -132,8 +132,10 @@ public class AsyncServerMcpTransportContextIntegrationTests {
private final BiFunction<McpTransportContext, McpSchema.CallToolRequest, Mono<McpSchema.CallToolResult>> asyncStatelessHandler = (
transportContext, request) -> {
return Mono
.just(new McpSchema.CallToolResult(transportContext.get("server-side-header-value").toString(), null));
return Mono.just(McpSchema.CallToolResult.builder()
.addTextContent(transportContext.get("server-side-header-value").toString())
.isError(false)
.build());
};
private final BiFunction<McpAsyncServerExchange, McpSchema.CallToolRequest, Mono<McpSchema.CallToolResult>> asyncStatefulHandler = (
@ -198,7 +200,10 @@ public class AsyncServerMcpTransportContextIntegrationTests {
var mcpServer = McpServer.async(streamableServerTransport)
.capabilities(McpSchema.ServerCapabilities.builder().tools(true).build())
.tools(new McpServerFeatures.AsyncToolSpecification(tool, null, asyncStatefulHandler))
.tools(McpServerFeatures.AsyncToolSpecification.builder()
.tool(tool)
.callHandler(asyncStatefulHandler)
.build())
.build();
StepVerifier.create(asyncStreamableClient.initialize()).assertNext(initResult -> {
@ -229,7 +234,10 @@ public class AsyncServerMcpTransportContextIntegrationTests {
var mcpServer = McpServer.async(sseServerTransport)
.capabilities(McpSchema.ServerCapabilities.builder().tools(true).build())
.tools(new McpServerFeatures.AsyncToolSpecification(tool, null, asyncStatefulHandler))
.tools(McpServerFeatures.AsyncToolSpecification.builder()
.tool(tool)
.callHandler(asyncStatefulHandler)
.build())
.build();
StepVerifier.create(asyncSseClient.initialize()).assertNext(initResult -> {

View file

@ -47,12 +47,14 @@ class HttpClientStreamableHttpVersionNegotiationIntegrationTests {
.build();
private final BiFunction<McpSyncServerExchange, McpSchema.CallToolRequest, McpSchema.CallToolResult> toolHandler = (
exchange, request) -> new McpSchema.CallToolResult(
exchange.transportContext().get("protocol-version").toString(), null);
exchange, request) -> McpSchema.CallToolResult.builder()
.addTextContent(exchange.transportContext().get("protocol-version").toString())
.isError(false)
.build();
McpSyncServer mcpServer = McpServer.sync(transport)
.capabilities(McpSchema.ServerCapabilities.builder().tools(false).build())
.tools(new McpServerFeatures.SyncToolSpecification(toolSpec, null, toolHandler))
.tools(McpServerFeatures.SyncToolSpecification.builder().tool(toolSpec).callHandler(toolHandler).build())
.build();
@AfterEach

View file

@ -78,8 +78,10 @@ public class SyncServerMcpTransportContextIntegrationTests {
};
private final BiFunction<McpTransportContext, McpSchema.CallToolRequest, McpSchema.CallToolResult> statelessHandler = (
transportContext,
request) -> new McpSchema.CallToolResult(transportContext.get("server-side-header-value").toString(), null);
transportContext, request) -> McpSchema.CallToolResult.builder()
.addTextContent(transportContext.get("server-side-header-value").toString())
.isError(false)
.build();
private final BiFunction<McpSyncServerExchange, McpSchema.CallToolRequest, McpSchema.CallToolResult> statefulHandler = (
exchange, request) -> statelessHandler.apply(exchange.transportContext(), request);
@ -172,7 +174,7 @@ public class SyncServerMcpTransportContextIntegrationTests {
var mcpServer = McpServer.sync(streamableServerTransport)
.capabilities(McpSchema.ServerCapabilities.builder().tools(true).build())
.tools(new McpServerFeatures.SyncToolSpecification(tool, null, statefulHandler))
.tools(McpServerFeatures.SyncToolSpecification.builder().tool(tool).callHandler(statefulHandler).build())
.build();
McpSchema.InitializeResult initResult = streamableClient.initialize();
@ -198,7 +200,7 @@ public class SyncServerMcpTransportContextIntegrationTests {
var mcpServer = McpServer.sync(sseServerTransport)
.capabilities(McpSchema.ServerCapabilities.builder().tools(true).build())
.tools(new McpServerFeatures.SyncToolSpecification(tool, null, statefulHandler))
.tools(McpServerFeatures.SyncToolSpecification.builder().tool(tool).callHandler(statefulHandler).build())
.build();
McpSchema.InitializeResult initResult = sseClient.initialize();

View file

@ -10,6 +10,7 @@ import java.util.UUID;
import io.modelcontextprotocol.MockMcpServerTransport;
import io.modelcontextprotocol.MockMcpServerTransportProvider;
import io.modelcontextprotocol.spec.McpSchema;
import io.modelcontextprotocol.spec.ProtocolVersions;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
@ -36,8 +37,7 @@ class McpServerProtocolVersionTests {
String requestId = UUID.randomUUID().toString();
transportProvider
.simulateIncomingMessage(jsonRpcInitializeRequest(requestId, McpSchema.LATEST_PROTOCOL_VERSION));
transportProvider.simulateIncomingMessage(jsonRpcInitializeRequest(requestId, ProtocolVersions.MCP_2025_11_25));
McpSchema.JSONRPCMessage response = serverTransport.getLastSentMessage();
assertThat(response).isInstanceOf(McpSchema.JSONRPCResponse.class);
@ -60,7 +60,7 @@ class McpServerProtocolVersionTests {
McpAsyncServer server = McpServer.async(transportProvider).serverInfo(SERVER_INFO).build();
server.setProtocolVersions(List.of(oldVersion, McpSchema.LATEST_PROTOCOL_VERSION));
server.setProtocolVersions(List.of(oldVersion, ProtocolVersions.MCP_2025_11_25));
String requestId = UUID.randomUUID().toString();
@ -105,7 +105,7 @@ class McpServerProtocolVersionTests {
void shouldUseHighestVersionWhenMultipleSupported() {
String oldVersion = "0.1.0";
String middleVersion = "0.2.0";
String latestVersion = McpSchema.LATEST_PROTOCOL_VERSION;
String latestVersion = ProtocolVersions.MCP_2025_11_25;
MockMcpServerTransport serverTransport = new MockMcpServerTransport();
var transportProvider = new MockMcpServerTransportProvider(serverTransport);

View file

@ -185,7 +185,7 @@ class StdioServerTransportProviderTests {
// Send notification before setting session factory
StepVerifier.create(transportProvider.notifyClients("testNotification", Map.of("key", "value")))
.verifyErrorSatisfies(error -> {
assertThat(error).isInstanceOf(McpError.class);
assertThat(error).isInstanceOf(IllegalStateException.class);
});
}

View file

@ -17,10 +17,10 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import io.modelcontextprotocol.spec.McpSchema.TextResourceContents;
import org.assertj.core.api.InstanceOfAssertFactories;
import org.junit.jupiter.api.Test;
import io.modelcontextprotocol.spec.McpSchema.TextResourceContents;
import net.javacrumbs.jsonunit.core.Option;
/**
@ -72,7 +72,7 @@ public class McpSchemaTests {
@Test
void testImageContent() throws Exception {
McpSchema.ImageContent test = new McpSchema.ImageContent(null, null, "base64encodeddata", "image/png");
McpSchema.ImageContent test = new McpSchema.ImageContent(null, "base64encodeddata", "image/png");
String value = JSON_MAPPER.writeValueAsString(test);
assertThatJson(value).when(Option.IGNORING_ARRAY_ORDER)
@ -160,7 +160,7 @@ public class McpSchemaTests {
McpSchema.TextResourceContents resourceContents = new McpSchema.TextResourceContents("resource://test",
"text/plain", "Sample resource content");
McpSchema.EmbeddedResource test = new McpSchema.EmbeddedResource(null, null, resourceContents);
McpSchema.EmbeddedResource test = new McpSchema.EmbeddedResource(null, resourceContents);
String value = JSON_MAPPER.writeValueAsString(test);
assertThatJson(value).when(Option.IGNORING_ARRAY_ORDER)
@ -191,7 +191,7 @@ public class McpSchemaTests {
McpSchema.BlobResourceContents resourceContents = new McpSchema.BlobResourceContents("resource://test",
"application/octet-stream", "base64encodedblob");
McpSchema.EmbeddedResource test = new McpSchema.EmbeddedResource(null, null, resourceContents);
McpSchema.EmbeddedResource test = new McpSchema.EmbeddedResource(null, resourceContents);
String value = JSON_MAPPER.writeValueAsString(test);
assertThatJson(value).when(Option.IGNORING_ARRAY_ORDER)
@ -366,8 +366,13 @@ public class McpSchemaTests {
McpSchema.Annotations annotations = new McpSchema.Annotations(
Arrays.asList(McpSchema.Role.USER, McpSchema.Role.ASSISTANT), 0.8);
McpSchema.Resource resource = new McpSchema.Resource("resource://test", "Test Resource", "A test resource",
"text/plain", annotations);
McpSchema.Resource resource = McpSchema.Resource.builder()
.uri("resource://test")
.name("Test Resource")
.description("A test resource")
.mimeType("text/plain")
.annotations(annotations)
.build();
String value = JSON_MAPPER.writeValueAsString(resource);
assertThatJson(value).when(Option.IGNORING_ARRAY_ORDER)
@ -451,11 +456,19 @@ public class McpSchemaTests {
@Test
void testListResourcesResult() throws Exception {
McpSchema.Resource resource1 = new McpSchema.Resource("resource://test1", "Test Resource 1",
"First test resource", "text/plain", null);
McpSchema.Resource resource1 = McpSchema.Resource.builder()
.uri("resource://test1")
.name("Test Resource 1")
.description("First test resource")
.mimeType("text/plain")
.build();
McpSchema.Resource resource2 = new McpSchema.Resource("resource://test2", "Test Resource 2",
"Second test resource", "application/json", null);
McpSchema.Resource resource2 = McpSchema.Resource.builder()
.uri("resource://test2")
.name("Test Resource 2")
.description("Second test resource")
.mimeType("application/json")
.build();
Map<String, Object> meta = Map.of("metaKey", "metaValue");
@ -1274,7 +1287,7 @@ public class McpSchemaTests {
@Test
void testCallToolResultBuilderWithMultipleContents() throws Exception {
McpSchema.TextContent textContent = new McpSchema.TextContent("Text result");
McpSchema.ImageContent imageContent = new McpSchema.ImageContent(null, null, "base64data", "image/png");
McpSchema.ImageContent imageContent = new McpSchema.ImageContent(null, "base64data", "image/png");
McpSchema.CallToolResult result = McpSchema.CallToolResult.builder()
.addContent(textContent)
@ -1295,7 +1308,7 @@ public class McpSchemaTests {
@Test
void testCallToolResultBuilderWithContentList() throws Exception {
McpSchema.TextContent textContent = new McpSchema.TextContent("Text result");
McpSchema.ImageContent imageContent = new McpSchema.ImageContent(null, null, "base64data", "image/png");
McpSchema.ImageContent imageContent = new McpSchema.ImageContent(null, "base64data", "image/png");
List<McpSchema.Content> contents = Arrays.asList(textContent, imageContent);
McpSchema.CallToolResult result = McpSchema.CallToolResult.builder().content(contents).isError(true).build();
@ -1326,27 +1339,6 @@ public class McpSchemaTests {
{"content":[{"type":"text","text":"Error: Operation failed"}],"isError":true}"""));
}
@Test
void testCallToolResultStringConstructor() throws Exception {
// Test the existing string constructor alongside the builder
McpSchema.CallToolResult result1 = new McpSchema.CallToolResult("Simple result", false);
McpSchema.CallToolResult result2 = McpSchema.CallToolResult.builder()
.addTextContent("Simple result")
.isError(false)
.build();
String value1 = JSON_MAPPER.writeValueAsString(result1);
String value2 = JSON_MAPPER.writeValueAsString(result2);
// Both should produce the same JSON
assertThat(value1).isEqualTo(value2);
assertThatJson(value1).when(Option.IGNORING_ARRAY_ORDER)
.when(Option.IGNORING_EXTRA_ARRAY_ITEMS)
.isObject()
.isEqualTo(json("""
{"content":[{"type":"text","text":"Simple result"}],"isError":false}"""));
}
// Sampling Tests
@Test