Clean up AbstractMcpClientServerIntegrationTests
Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
This commit is contained in:
parent
d1ef187c9c
commit
439dc90d25
3 changed files with 142 additions and 300 deletions
|
|
@ -12,7 +12,6 @@ import java.time.Duration;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
@ -52,9 +51,7 @@ import io.modelcontextprotocol.spec.McpSchema.TextContent;
|
||||||
import io.modelcontextprotocol.spec.McpSchema.Tool;
|
import io.modelcontextprotocol.spec.McpSchema.Tool;
|
||||||
import io.modelcontextprotocol.util.Utils;
|
import io.modelcontextprotocol.util.Utils;
|
||||||
import net.javacrumbs.jsonunit.core.Option;
|
import net.javacrumbs.jsonunit.core.Option;
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.params.provider.MethodSource;
|
|
||||||
import org.junit.jupiter.params.provider.ValueSource;
|
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
import static io.modelcontextprotocol.util.ToolsUtils.EMPTY_JSON_SCHEMA;
|
import static io.modelcontextprotocol.util.ToolsUtils.EMPTY_JSON_SCHEMA;
|
||||||
|
|
@ -72,26 +69,20 @@ import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
public abstract class AbstractMcpClientServerIntegrationTests {
|
public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
|
|
||||||
protected ConcurrentHashMap<String, McpClient.SyncSpec> clientBuilders = new ConcurrentHashMap<>();
|
|
||||||
|
|
||||||
abstract protected void prepareClients(int port, String mcpEndpoint);
|
|
||||||
|
|
||||||
abstract protected McpServer.AsyncSpecification<?> prepareAsyncServerBuilder();
|
abstract protected McpServer.AsyncSpecification<?> prepareAsyncServerBuilder();
|
||||||
|
|
||||||
abstract protected McpServer.SyncSpecification<?> prepareSyncServerBuilder();
|
abstract protected McpServer.SyncSpecification<?> prepareSyncServerBuilder();
|
||||||
|
|
||||||
@ParameterizedTest(name = "{0} : {displayName} ")
|
abstract protected McpClient.SyncSpec getMcpClientBuilder();
|
||||||
@MethodSource("clientsForTesting")
|
|
||||||
void simple(String clientType) {
|
|
||||||
|
|
||||||
var clientBuilder = clientBuilders.get(clientType);
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void simple() {
|
||||||
var server = prepareAsyncServerBuilder().serverInfo("test-server", "1.0.0")
|
var server = prepareAsyncServerBuilder().serverInfo("test-server", "1.0.0")
|
||||||
.requestTimeout(Duration.ofSeconds(1000))
|
.requestTimeout(Duration.ofSeconds(1000))
|
||||||
.build();
|
.build();
|
||||||
try (
|
try (
|
||||||
// Create client without sampling capabilities
|
// Create client without sampling capabilities
|
||||||
var client = clientBuilder
|
var client = getMcpClientBuilder()
|
||||||
.clientInfo(McpSchema.Implementation.builder("Sample " + "client", "0.0.0").build())
|
.clientInfo(McpSchema.Implementation.builder("Sample " + "client", "0.0.0").build())
|
||||||
.requestTimeout(Duration.ofSeconds(1000))
|
.requestTimeout(Duration.ofSeconds(1000))
|
||||||
.build()) {
|
.build()) {
|
||||||
|
|
@ -107,12 +98,8 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
// ---------------------------------------
|
// ---------------------------------------
|
||||||
// Sampling Tests
|
// Sampling Tests
|
||||||
// ---------------------------------------
|
// ---------------------------------------
|
||||||
@ParameterizedTest(name = "{0} : {displayName} ")
|
@Test
|
||||||
@MethodSource("clientsForTesting")
|
void testCreateMessageWithoutSamplingCapabilities() {
|
||||||
void testCreateMessageWithoutSamplingCapabilities(String clientType) {
|
|
||||||
|
|
||||||
var clientBuilder = clientBuilders.get(clientType);
|
|
||||||
|
|
||||||
McpServerFeatures.AsyncToolSpecification tool = McpServerFeatures.AsyncToolSpecification.builder()
|
McpServerFeatures.AsyncToolSpecification tool = McpServerFeatures.AsyncToolSpecification.builder()
|
||||||
.tool(Tool.builder("tool1", EMPTY_JSON_SCHEMA).description("tool1 description").build())
|
.tool(Tool.builder("tool1", EMPTY_JSON_SCHEMA).description("tool1 description").build())
|
||||||
.callHandler((exchange, request) -> {
|
.callHandler((exchange, request) -> {
|
||||||
|
|
@ -125,7 +112,7 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
|
|
||||||
try (
|
try (
|
||||||
// Create client without sampling capabilities
|
// Create client without sampling capabilities
|
||||||
var client = clientBuilder
|
var client = getMcpClientBuilder()
|
||||||
.clientInfo(McpSchema.Implementation.builder("Sample " + "client", "0.0.0").build())
|
.clientInfo(McpSchema.Implementation.builder("Sample " + "client", "0.0.0").build())
|
||||||
.build()) {
|
.build()) {
|
||||||
|
|
||||||
|
|
@ -144,12 +131,8 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest(name = "{0} : {displayName} ")
|
@Test
|
||||||
@MethodSource("clientsForTesting")
|
void testCreateMessageSuccess() {
|
||||||
void testCreateMessageSuccess(String clientType) {
|
|
||||||
|
|
||||||
var clientBuilder = clientBuilders.get(clientType);
|
|
||||||
|
|
||||||
Function<CreateMessageRequest, CreateMessageResult> samplingHandler = request -> {
|
Function<CreateMessageRequest, CreateMessageResult> samplingHandler = request -> {
|
||||||
assertThat(request.messages()).hasSize(1);
|
assertThat(request.messages()).hasSize(1);
|
||||||
assertThat(request.messages().get(0).content()).isInstanceOf(McpSchema.TextContent.class);
|
assertThat(request.messages().get(0).content()).isInstanceOf(McpSchema.TextContent.class);
|
||||||
|
|
@ -190,7 +173,7 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
|
|
||||||
var mcpServer = prepareAsyncServerBuilder().serverInfo("test-server", "1.0.0").tools(tool).build();
|
var mcpServer = prepareAsyncServerBuilder().serverInfo("test-server", "1.0.0").tools(tool).build();
|
||||||
|
|
||||||
try (var mcpClient = clientBuilder
|
try (var mcpClient = getMcpClientBuilder()
|
||||||
.clientInfo(McpSchema.Implementation.builder("Sample client", "0.0.0").build())
|
.clientInfo(McpSchema.Implementation.builder("Sample client", "0.0.0").build())
|
||||||
.capabilities(ClientCapabilities.builder().sampling().build())
|
.capabilities(ClientCapabilities.builder().sampling().build())
|
||||||
.sampling(samplingHandler)
|
.sampling(samplingHandler)
|
||||||
|
|
@ -219,14 +202,8 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest(name = "{0} : {displayName} ")
|
@Test
|
||||||
@MethodSource("clientsForTesting")
|
void testCreateMessageWithRequestTimeoutSuccess() {
|
||||||
void testCreateMessageWithRequestTimeoutSuccess(String clientType) throws InterruptedException {
|
|
||||||
|
|
||||||
// Client
|
|
||||||
|
|
||||||
var clientBuilder = clientBuilders.get(clientType);
|
|
||||||
|
|
||||||
Function<CreateMessageRequest, CreateMessageResult> samplingHandler = request -> {
|
Function<CreateMessageRequest, CreateMessageResult> samplingHandler = request -> {
|
||||||
assertThat(request.messages()).hasSize(1);
|
assertThat(request.messages()).hasSize(1);
|
||||||
assertThat(request.messages().get(0).content()).isInstanceOf(McpSchema.TextContent.class);
|
assertThat(request.messages().get(0).content()).isInstanceOf(McpSchema.TextContent.class);
|
||||||
|
|
@ -276,7 +253,7 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
.requestTimeout(Duration.ofSeconds(4))
|
.requestTimeout(Duration.ofSeconds(4))
|
||||||
.tools(tool)
|
.tools(tool)
|
||||||
.build();
|
.build();
|
||||||
try (var mcpClient = clientBuilder
|
try (var mcpClient = getMcpClientBuilder()
|
||||||
.clientInfo(McpSchema.Implementation.builder("Sample client", "0.0.0").build())
|
.clientInfo(McpSchema.Implementation.builder("Sample client", "0.0.0").build())
|
||||||
.capabilities(ClientCapabilities.builder().sampling().build())
|
.capabilities(ClientCapabilities.builder().sampling().build())
|
||||||
.sampling(samplingHandler)
|
.sampling(samplingHandler)
|
||||||
|
|
@ -305,12 +282,8 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest(name = "{0} : {displayName} ")
|
@Test
|
||||||
@MethodSource("clientsForTesting")
|
void testCreateMessageWithRequestTimeoutFail() {
|
||||||
void testCreateMessageWithRequestTimeoutFail(String clientType) throws InterruptedException {
|
|
||||||
|
|
||||||
var clientBuilder = clientBuilders.get(clientType);
|
|
||||||
|
|
||||||
Function<CreateMessageRequest, CreateMessageResult> samplingHandler = request -> {
|
Function<CreateMessageRequest, CreateMessageResult> samplingHandler = request -> {
|
||||||
assertThat(request.messages()).hasSize(1);
|
assertThat(request.messages()).hasSize(1);
|
||||||
assertThat(request.messages().get(0).content()).isInstanceOf(McpSchema.TextContent.class);
|
assertThat(request.messages().get(0).content()).isInstanceOf(McpSchema.TextContent.class);
|
||||||
|
|
@ -355,7 +328,7 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
.tools(tool)
|
.tools(tool)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try (var mcpClient = clientBuilder
|
try (var mcpClient = getMcpClientBuilder()
|
||||||
.clientInfo(McpSchema.Implementation.builder("Sample client", "0.0.0").build())
|
.clientInfo(McpSchema.Implementation.builder("Sample client", "0.0.0").build())
|
||||||
.capabilities(ClientCapabilities.builder().sampling().build())
|
.capabilities(ClientCapabilities.builder().sampling().build())
|
||||||
.sampling(samplingHandler)
|
.sampling(samplingHandler)
|
||||||
|
|
@ -376,12 +349,8 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
// ---------------------------------------
|
// ---------------------------------------
|
||||||
// Elicitation Tests
|
// Elicitation Tests
|
||||||
// ---------------------------------------
|
// ---------------------------------------
|
||||||
@ParameterizedTest(name = "{0} : {displayName} ")
|
@Test
|
||||||
@MethodSource("clientsForTesting")
|
void testCreateElicitationWithoutElicitationCapabilities() {
|
||||||
void testCreateElicitationWithoutElicitationCapabilities(String clientType) {
|
|
||||||
|
|
||||||
var clientBuilder = clientBuilders.get(clientType);
|
|
||||||
|
|
||||||
McpServerFeatures.AsyncToolSpecification tool = McpServerFeatures.AsyncToolSpecification.builder()
|
McpServerFeatures.AsyncToolSpecification tool = McpServerFeatures.AsyncToolSpecification.builder()
|
||||||
.tool(Tool.builder("tool1", EMPTY_JSON_SCHEMA).description("tool1 description").build())
|
.tool(Tool.builder("tool1", EMPTY_JSON_SCHEMA).description("tool1 description").build())
|
||||||
.callHandler((exchange, request) -> exchange.createElicitation(mock(McpSchema.ElicitFormRequest.class))
|
.callHandler((exchange, request) -> exchange.createElicitation(mock(McpSchema.ElicitFormRequest.class))
|
||||||
|
|
@ -391,7 +360,8 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
var server = prepareAsyncServerBuilder().serverInfo("test-server", "1.0.0").tools(tool).build();
|
var server = prepareAsyncServerBuilder().serverInfo("test-server", "1.0.0").tools(tool).build();
|
||||||
|
|
||||||
// Create client without elicitation capabilities
|
// Create client without elicitation capabilities
|
||||||
try (var client = clientBuilder.clientInfo(McpSchema.Implementation.builder("Sample client", "0.0.0").build())
|
try (var client = getMcpClientBuilder()
|
||||||
|
.clientInfo(McpSchema.Implementation.builder("Sample client", "0.0.0").build())
|
||||||
.build()) {
|
.build()) {
|
||||||
|
|
||||||
assertThat(client.initialize()).isNotNull();
|
assertThat(client.initialize()).isNotNull();
|
||||||
|
|
@ -409,12 +379,8 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest(name = "{0} : {displayName} ")
|
@Test
|
||||||
@MethodSource("clientsForTesting")
|
void testCreateElicitationSuccess() {
|
||||||
void testCreateElicitationSuccess(String clientType) {
|
|
||||||
|
|
||||||
var clientBuilder = clientBuilders.get(clientType);
|
|
||||||
|
|
||||||
Function<McpSchema.ElicitFormRequest, McpSchema.ElicitResult> formElicitationHandler = request -> {
|
Function<McpSchema.ElicitFormRequest, McpSchema.ElicitResult> formElicitationHandler = request -> {
|
||||||
assertThat(request.message()).isNotEmpty();
|
assertThat(request.message()).isNotEmpty();
|
||||||
assertThat(request.requestedSchema()).isNotNull();
|
assertThat(request.requestedSchema()).isNotNull();
|
||||||
|
|
@ -447,7 +413,7 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
|
|
||||||
var mcpServer = prepareAsyncServerBuilder().serverInfo("test-server", "1.0.0").tools(tool).build();
|
var mcpServer = prepareAsyncServerBuilder().serverInfo("test-server", "1.0.0").tools(tool).build();
|
||||||
|
|
||||||
try (var mcpClient = clientBuilder
|
try (var mcpClient = getMcpClientBuilder()
|
||||||
.clientInfo(McpSchema.Implementation.builder("Sample client", "0.0.0").build())
|
.clientInfo(McpSchema.Implementation.builder("Sample client", "0.0.0").build())
|
||||||
.capabilities(ClientCapabilities.builder().elicitation().build())
|
.capabilities(ClientCapabilities.builder().elicitation().build())
|
||||||
.elicitation(formElicitationHandler)
|
.elicitation(formElicitationHandler)
|
||||||
|
|
@ -472,12 +438,8 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest(name = "{0} : {displayName} ")
|
@Test
|
||||||
@MethodSource("clientsForTesting")
|
void testCreateElicitationWithApplyDefaults() {
|
||||||
void testCreateElicitationWithApplyDefaults(String clientType) {
|
|
||||||
|
|
||||||
var clientBuilder = clientBuilders.get(clientType);
|
|
||||||
|
|
||||||
// Client handler returns empty content — SDK should apply defaults
|
// Client handler returns empty content — SDK should apply defaults
|
||||||
Function<McpSchema.ElicitFormRequest, McpSchema.ElicitResult> elicitationHandler = request -> {
|
Function<McpSchema.ElicitFormRequest, McpSchema.ElicitResult> elicitationHandler = request -> {
|
||||||
assertThat(request.message()).isNotEmpty();
|
assertThat(request.message()).isNotEmpty();
|
||||||
|
|
@ -511,7 +473,7 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
|
|
||||||
var mcpServer = prepareAsyncServerBuilder().serverInfo("test-server", "1.0.0").tools(tool).build();
|
var mcpServer = prepareAsyncServerBuilder().serverInfo("test-server", "1.0.0").tools(tool).build();
|
||||||
|
|
||||||
try (var mcpClient = clientBuilder.clientInfo(new McpSchema.Implementation("Sample client", "0.0.0"))
|
try (var mcpClient = getMcpClientBuilder().clientInfo(new McpSchema.Implementation("Sample client", "0.0.0"))
|
||||||
.capabilities(ClientCapabilities.builder().elicitation(true, false).build())
|
.capabilities(ClientCapabilities.builder().elicitation(true, false).build())
|
||||||
.elicitation(elicitationHandler)
|
.elicitation(elicitationHandler)
|
||||||
.applyElicitationDefaults(true)
|
.applyElicitationDefaults(true)
|
||||||
|
|
@ -537,12 +499,8 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest(name = "{0} : {displayName} ")
|
@Test
|
||||||
@MethodSource("clientsForTesting")
|
void testCreateElicitationWithApplyDefaultsAndUnmodifiableMap() {
|
||||||
void testCreateElicitationWithApplyDefaultsAndUnmodifiableMap(String clientType) {
|
|
||||||
|
|
||||||
var clientBuilder = clientBuilders.get(clientType);
|
|
||||||
|
|
||||||
// Client handler returns an unmodifiable map (Map.of()) — SDK must copy into a
|
// Client handler returns an unmodifiable map (Map.of()) — SDK must copy into a
|
||||||
// mutable map before applying defaults.
|
// mutable map before applying defaults.
|
||||||
Function<McpSchema.ElicitFormRequest, McpSchema.ElicitResult> elicitationHandler = request -> new McpSchema.ElicitResult(
|
Function<McpSchema.ElicitFormRequest, McpSchema.ElicitResult> elicitationHandler = request -> new McpSchema.ElicitResult(
|
||||||
|
|
@ -573,7 +531,7 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
|
|
||||||
var mcpServer = prepareAsyncServerBuilder().serverInfo("test-server", "1.0.0").tools(tool).build();
|
var mcpServer = prepareAsyncServerBuilder().serverInfo("test-server", "1.0.0").tools(tool).build();
|
||||||
|
|
||||||
try (var mcpClient = clientBuilder.clientInfo(new McpSchema.Implementation("Sample client", "0.0.0"))
|
try (var mcpClient = getMcpClientBuilder().clientInfo(new McpSchema.Implementation("Sample client", "0.0.0"))
|
||||||
.capabilities(ClientCapabilities.builder().elicitation(true, false).build())
|
.capabilities(ClientCapabilities.builder().elicitation(true, false).build())
|
||||||
.elicitation(elicitationHandler)
|
.elicitation(elicitationHandler)
|
||||||
.applyElicitationDefaults(true)
|
.applyElicitationDefaults(true)
|
||||||
|
|
@ -597,12 +555,8 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest(name = "{0} : {displayName} ")
|
@Test
|
||||||
@MethodSource("clientsForTesting")
|
void testCreateElicitationApplyDefaultsDisabledLeavesContentUntouched() {
|
||||||
void testCreateElicitationApplyDefaultsDisabledLeavesContentUntouched(String clientType) {
|
|
||||||
|
|
||||||
var clientBuilder = clientBuilders.get(clientType);
|
|
||||||
|
|
||||||
Function<McpSchema.ElicitFormRequest, McpSchema.ElicitResult> elicitationHandler = request -> new McpSchema.ElicitResult(
|
Function<McpSchema.ElicitFormRequest, McpSchema.ElicitResult> elicitationHandler = request -> new McpSchema.ElicitResult(
|
||||||
McpSchema.ElicitResult.Action.ACCEPT, new HashMap<>());
|
McpSchema.ElicitResult.Action.ACCEPT, new HashMap<>());
|
||||||
|
|
||||||
|
|
@ -629,7 +583,7 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
var mcpServer = prepareAsyncServerBuilder().serverInfo("test-server", "1.0.0").tools(tool).build();
|
var mcpServer = prepareAsyncServerBuilder().serverInfo("test-server", "1.0.0").tools(tool).build();
|
||||||
|
|
||||||
// applyElicitationDefaults intentionally NOT called — default false.
|
// applyElicitationDefaults intentionally NOT called — default false.
|
||||||
try (var mcpClient = clientBuilder.clientInfo(new McpSchema.Implementation("Sample client", "0.0.0"))
|
try (var mcpClient = getMcpClientBuilder().clientInfo(new McpSchema.Implementation("Sample client", "0.0.0"))
|
||||||
.capabilities(ClientCapabilities.builder().elicitation(true, false).build())
|
.capabilities(ClientCapabilities.builder().elicitation(true, false).build())
|
||||||
.elicitation(elicitationHandler)
|
.elicitation(elicitationHandler)
|
||||||
.build()) {
|
.build()) {
|
||||||
|
|
@ -651,12 +605,8 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest(name = "{0} : {displayName} ")
|
@Test
|
||||||
@MethodSource("clientsForTesting")
|
void testCreateElicitationApplyDefaultsSkippedOnDecline() {
|
||||||
void testCreateElicitationApplyDefaultsSkippedOnDecline(String clientType) {
|
|
||||||
|
|
||||||
var clientBuilder = clientBuilders.get(clientType);
|
|
||||||
|
|
||||||
Function<McpSchema.ElicitFormRequest, McpSchema.ElicitResult> elicitationHandler = request -> new McpSchema.ElicitResult(
|
Function<McpSchema.ElicitFormRequest, McpSchema.ElicitResult> elicitationHandler = request -> new McpSchema.ElicitResult(
|
||||||
McpSchema.ElicitResult.Action.DECLINE, new HashMap<>());
|
McpSchema.ElicitResult.Action.DECLINE, new HashMap<>());
|
||||||
|
|
||||||
|
|
@ -682,7 +632,7 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
|
|
||||||
var mcpServer = prepareAsyncServerBuilder().serverInfo("test-server", "1.0.0").tools(tool).build();
|
var mcpServer = prepareAsyncServerBuilder().serverInfo("test-server", "1.0.0").tools(tool).build();
|
||||||
|
|
||||||
try (var mcpClient = clientBuilder.clientInfo(new McpSchema.Implementation("Sample client", "0.0.0"))
|
try (var mcpClient = getMcpClientBuilder().clientInfo(new McpSchema.Implementation("Sample client", "0.0.0"))
|
||||||
.capabilities(ClientCapabilities.builder().elicitation(true, false).build())
|
.capabilities(ClientCapabilities.builder().elicitation(true, false).build())
|
||||||
.elicitation(elicitationHandler)
|
.elicitation(elicitationHandler)
|
||||||
.applyElicitationDefaults(true)
|
.applyElicitationDefaults(true)
|
||||||
|
|
@ -705,12 +655,8 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest(name = "{0} : {displayName} ")
|
@Test
|
||||||
@MethodSource("clientsForTesting")
|
void testCreateElicitationApplyDefaultsPreservesMeta() {
|
||||||
void testCreateElicitationApplyDefaultsPreservesMeta(String clientType) {
|
|
||||||
|
|
||||||
var clientBuilder = clientBuilders.get(clientType);
|
|
||||||
|
|
||||||
Map<String, Object> meta = Map.of("trace-id", "abc-123");
|
Map<String, Object> meta = Map.of("trace-id", "abc-123");
|
||||||
Function<McpSchema.ElicitFormRequest, McpSchema.ElicitResult> elicitationHandler = request -> new McpSchema.ElicitResult(
|
Function<McpSchema.ElicitFormRequest, McpSchema.ElicitResult> elicitationHandler = request -> new McpSchema.ElicitResult(
|
||||||
McpSchema.ElicitResult.Action.ACCEPT, new HashMap<>(), meta);
|
McpSchema.ElicitResult.Action.ACCEPT, new HashMap<>(), meta);
|
||||||
|
|
@ -737,7 +683,7 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
|
|
||||||
var mcpServer = prepareAsyncServerBuilder().serverInfo("test-server", "1.0.0").tools(tool).build();
|
var mcpServer = prepareAsyncServerBuilder().serverInfo("test-server", "1.0.0").tools(tool).build();
|
||||||
|
|
||||||
try (var mcpClient = clientBuilder.clientInfo(new McpSchema.Implementation("Sample client", "0.0.0"))
|
try (var mcpClient = getMcpClientBuilder().clientInfo(new McpSchema.Implementation("Sample client", "0.0.0"))
|
||||||
.capabilities(ClientCapabilities.builder().elicitation(true, false).build())
|
.capabilities(ClientCapabilities.builder().elicitation(true, false).build())
|
||||||
.elicitation(elicitationHandler)
|
.elicitation(elicitationHandler)
|
||||||
.applyElicitationDefaults(true)
|
.applyElicitationDefaults(true)
|
||||||
|
|
@ -761,12 +707,8 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest(name = "{0} : {displayName} ")
|
@Test
|
||||||
@MethodSource("clientsForTesting")
|
void testCreateElicitationWithRequestTimeoutSuccess() {
|
||||||
void testCreateElicitationWithRequestTimeoutSuccess(String clientType) {
|
|
||||||
|
|
||||||
var clientBuilder = clientBuilders.get(clientType);
|
|
||||||
|
|
||||||
Function<ElicitFormRequest, ElicitResult> elicitationHandler = request -> {
|
Function<ElicitFormRequest, ElicitResult> elicitationHandler = request -> {
|
||||||
assertThat(request.message()).isNotEmpty();
|
assertThat(request.message()).isNotEmpty();
|
||||||
assertThat(((McpSchema.ElicitFormRequest) request).requestedSchema()).isNotNull();
|
assertThat(((McpSchema.ElicitFormRequest) request).requestedSchema()).isNotNull();
|
||||||
|
|
@ -801,7 +743,7 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
.tools(tool)
|
.tools(tool)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try (var mcpClient = clientBuilder
|
try (var mcpClient = getMcpClientBuilder()
|
||||||
.clientInfo(McpSchema.Implementation.builder("Sample client", "0.0.0").build())
|
.clientInfo(McpSchema.Implementation.builder("Sample client", "0.0.0").build())
|
||||||
.capabilities(ClientCapabilities.builder().elicitation().build())
|
.capabilities(ClientCapabilities.builder().elicitation().build())
|
||||||
.elicitation(elicitationHandler)
|
.elicitation(elicitationHandler)
|
||||||
|
|
@ -826,14 +768,10 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest(name = "{0} : {displayName} ")
|
@Test
|
||||||
@MethodSource("clientsForTesting")
|
void testCreateElicitationWithRequestTimeoutFail() {
|
||||||
void testCreateElicitationWithRequestTimeoutFail(String clientType) {
|
|
||||||
|
|
||||||
var latch = new CountDownLatch(1);
|
var latch = new CountDownLatch(1);
|
||||||
|
|
||||||
var clientBuilder = clientBuilders.get(clientType);
|
|
||||||
|
|
||||||
Function<ElicitFormRequest, ElicitResult> elicitationHandler = request -> {
|
Function<ElicitFormRequest, ElicitResult> elicitationHandler = request -> {
|
||||||
assertThat(request.message()).isNotEmpty();
|
assertThat(request.message()).isNotEmpty();
|
||||||
assertThat(request.requestedSchema()).isNotNull();
|
assertThat(request.requestedSchema()).isNotNull();
|
||||||
|
|
@ -877,7 +815,7 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
.tools(tool)
|
.tools(tool)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try (var mcpClient = clientBuilder
|
try (var mcpClient = getMcpClientBuilder()
|
||||||
.clientInfo(McpSchema.Implementation.builder("Sample client", "0.0.0").build())
|
.clientInfo(McpSchema.Implementation.builder("Sample client", "0.0.0").build())
|
||||||
.capabilities(ClientCapabilities.builder().elicitation().build())
|
.capabilities(ClientCapabilities.builder().elicitation().build())
|
||||||
.elicitation(elicitationHandler)
|
.elicitation(elicitationHandler)
|
||||||
|
|
@ -898,15 +836,12 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest(name = "{0} : {displayName} ")
|
@Test
|
||||||
@MethodSource("clientsForTesting")
|
void testCreateUrlElicitationSuccess() {
|
||||||
void testCreateUrlElicitationSuccess(String clientType) {
|
|
||||||
var elicitationRequest = McpSchema.ElicitUrlRequest
|
var elicitationRequest = McpSchema.ElicitUrlRequest
|
||||||
.builder("Test message", "https://example.com/auth", "elicitation-123")
|
.builder("Test message", "https://example.com/auth", "elicitation-123")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
var clientBuilder = clientBuilders.get(clientType);
|
|
||||||
|
|
||||||
Function<McpSchema.ElicitUrlRequest, McpSchema.ElicitResult> urlElicitationHandler = request -> {
|
Function<McpSchema.ElicitUrlRequest, McpSchema.ElicitResult> urlElicitationHandler = request -> {
|
||||||
assertThat(request.message()).isEqualTo("Test message");
|
assertThat(request.message()).isEqualTo("Test message");
|
||||||
assertThat(request.url()).isEqualTo("https://example.com/auth");
|
assertThat(request.url()).isEqualTo("https://example.com/auth");
|
||||||
|
|
@ -930,7 +865,7 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
|
|
||||||
var mcpServer = prepareAsyncServerBuilder().serverInfo("test-server", "1.0.0").tools(tool).build();
|
var mcpServer = prepareAsyncServerBuilder().serverInfo("test-server", "1.0.0").tools(tool).build();
|
||||||
|
|
||||||
try (var mcpClient = clientBuilder
|
try (var mcpClient = getMcpClientBuilder()
|
||||||
.clientInfo(McpSchema.Implementation.builder("Sample client", "0.0.0").build())
|
.clientInfo(McpSchema.Implementation.builder("Sample client", "0.0.0").build())
|
||||||
.capabilities(ClientCapabilities.builder().elicitation(false, true).build())
|
.capabilities(ClientCapabilities.builder().elicitation(false, true).build())
|
||||||
.urlElicitation(urlElicitationHandler)
|
.urlElicitation(urlElicitationHandler)
|
||||||
|
|
@ -950,12 +885,8 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest(name = "{0} : {displayName} ")
|
@Test
|
||||||
@MethodSource("clientsForTesting")
|
void testElicitationCompleteNotification() throws InterruptedException {
|
||||||
void testElicitationCompleteNotification(String clientType) throws InterruptedException {
|
|
||||||
|
|
||||||
var clientBuilder = clientBuilders.get(clientType);
|
|
||||||
|
|
||||||
CountDownLatch notificationLatch = new CountDownLatch(1);
|
CountDownLatch notificationLatch = new CountDownLatch(1);
|
||||||
AtomicReference<McpSchema.ElicitationCompleteNotification> notificationRef = new AtomicReference<>();
|
AtomicReference<McpSchema.ElicitationCompleteNotification> notificationRef = new AtomicReference<>();
|
||||||
AtomicReference<String> sessionId = new AtomicReference<>();
|
AtomicReference<String> sessionId = new AtomicReference<>();
|
||||||
|
|
@ -980,7 +911,7 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
|
|
||||||
var mcpServer = prepareAsyncServerBuilder().serverInfo("test-server", "1.0.0").tools(tool).build();
|
var mcpServer = prepareAsyncServerBuilder().serverInfo("test-server", "1.0.0").tools(tool).build();
|
||||||
|
|
||||||
try (var mcpClient = clientBuilder
|
try (var mcpClient = getMcpClientBuilder()
|
||||||
.clientInfo(McpSchema.Implementation.builder("Sample client", "0.0.0").build())
|
.clientInfo(McpSchema.Implementation.builder("Sample client", "0.0.0").build())
|
||||||
.elicitationCompleteConsumer(elicitationCompleteConsumer)
|
.elicitationCompleteConsumer(elicitationCompleteConsumer)
|
||||||
// enable elicitation so that we can register an elicitation complete consumer
|
// enable elicitation so that we can register an elicitation complete consumer
|
||||||
|
|
@ -1006,12 +937,8 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest(name = "{0} : {displayName} ")
|
@Test
|
||||||
@MethodSource("clientsForTesting")
|
void testElicitationRequiredError() {
|
||||||
void testElicitationRequiredError(String clientType) throws InterruptedException {
|
|
||||||
|
|
||||||
var clientBuilder = clientBuilders.get(clientType);
|
|
||||||
|
|
||||||
// Capture the session ID so we can trigger an "elicitation complete" notification
|
// Capture the session ID so we can trigger an "elicitation complete" notification
|
||||||
McpServerFeatures.AsyncToolSpecification tool = McpServerFeatures.AsyncToolSpecification.builder()
|
McpServerFeatures.AsyncToolSpecification tool = McpServerFeatures.AsyncToolSpecification.builder()
|
||||||
.tool(Tool.builder("tool1", EMPTY_JSON_SCHEMA).description("tool1 description").build())
|
.tool(Tool.builder("tool1", EMPTY_JSON_SCHEMA).description("tool1 description").build())
|
||||||
|
|
@ -1027,7 +954,7 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
Function<McpSchema.ElicitUrlRequest, ElicitResult> elicitationHandler = request -> ElicitResult
|
Function<McpSchema.ElicitUrlRequest, ElicitResult> elicitationHandler = request -> ElicitResult
|
||||||
.builder(ElicitResult.Action.ACCEPT)
|
.builder(ElicitResult.Action.ACCEPT)
|
||||||
.build();
|
.build();
|
||||||
try (var mcpClient = clientBuilder
|
try (var mcpClient = getMcpClientBuilder()
|
||||||
.clientInfo(McpSchema.Implementation.builder("Sample client", "0.0.0").build())
|
.clientInfo(McpSchema.Implementation.builder("Sample client", "0.0.0").build())
|
||||||
.urlElicitation(elicitationHandler)
|
.urlElicitation(elicitationHandler)
|
||||||
.build()) {
|
.build()) {
|
||||||
|
|
@ -1060,11 +987,8 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
// ---------------------------------------
|
// ---------------------------------------
|
||||||
// Roots Tests
|
// Roots Tests
|
||||||
// ---------------------------------------
|
// ---------------------------------------
|
||||||
@ParameterizedTest(name = "{0} : {displayName} ")
|
@Test
|
||||||
@MethodSource("clientsForTesting")
|
void testRootsSuccess() {
|
||||||
void testRootsSuccess(String clientType) {
|
|
||||||
var clientBuilder = clientBuilders.get(clientType);
|
|
||||||
|
|
||||||
List<Root> roots = List.of(Root.builder("uri1://").name("root1").build(),
|
List<Root> roots = List.of(Root.builder("uri1://").name("root1").build(),
|
||||||
Root.builder("uri2://").name("root2").build());
|
Root.builder("uri2://").name("root2").build());
|
||||||
|
|
||||||
|
|
@ -1074,7 +998,7 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
.rootsChangeHandler((exchange, rootsUpdate) -> rootsRef.set(rootsUpdate))
|
.rootsChangeHandler((exchange, rootsUpdate) -> rootsRef.set(rootsUpdate))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try (var mcpClient = clientBuilder.capabilities(ClientCapabilities.builder().roots(true).build())
|
try (var mcpClient = getMcpClientBuilder().capabilities(ClientCapabilities.builder().roots(true).build())
|
||||||
.roots(roots)
|
.roots(roots)
|
||||||
.build()) {
|
.build()) {
|
||||||
|
|
||||||
|
|
@ -1109,12 +1033,8 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest(name = "{0} : {displayName} ")
|
@Test
|
||||||
@MethodSource("clientsForTesting")
|
void testRootsWithoutCapability() {
|
||||||
void testRootsWithoutCapability(String clientType) {
|
|
||||||
|
|
||||||
var clientBuilder = clientBuilders.get(clientType);
|
|
||||||
|
|
||||||
McpServerFeatures.SyncToolSpecification tool = McpServerFeatures.SyncToolSpecification.builder()
|
McpServerFeatures.SyncToolSpecification tool = McpServerFeatures.SyncToolSpecification.builder()
|
||||||
.tool(Tool.builder("tool1", EMPTY_JSON_SCHEMA).description("tool1 description").build())
|
.tool(Tool.builder("tool1", EMPTY_JSON_SCHEMA).description("tool1 description").build())
|
||||||
.callHandler((exchange, request) -> {
|
.callHandler((exchange, request) -> {
|
||||||
|
|
@ -1131,7 +1051,7 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
try (
|
try (
|
||||||
// Create client without roots capability
|
// Create client without roots capability
|
||||||
// No roots capability
|
// No roots capability
|
||||||
var mcpClient = clientBuilder.capabilities(ClientCapabilities.builder().build()).build()) {
|
var mcpClient = getMcpClientBuilder().capabilities(ClientCapabilities.builder().build()).build()) {
|
||||||
|
|
||||||
assertThat(mcpClient.initialize()).isNotNull();
|
assertThat(mcpClient.initialize()).isNotNull();
|
||||||
|
|
||||||
|
|
@ -1148,19 +1068,15 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest(name = "{0} : {displayName} ")
|
@Test
|
||||||
@MethodSource("clientsForTesting")
|
void testRootsNotificationWithEmptyRootsList() {
|
||||||
void testRootsNotificationWithEmptyRootsList(String clientType) {
|
|
||||||
|
|
||||||
var clientBuilder = clientBuilders.get(clientType);
|
|
||||||
|
|
||||||
AtomicReference<List<Root>> rootsRef = new AtomicReference<>();
|
AtomicReference<List<Root>> rootsRef = new AtomicReference<>();
|
||||||
|
|
||||||
var mcpServer = prepareSyncServerBuilder()
|
var mcpServer = prepareSyncServerBuilder()
|
||||||
.rootsChangeHandler((exchange, rootsUpdate) -> rootsRef.set(rootsUpdate))
|
.rootsChangeHandler((exchange, rootsUpdate) -> rootsRef.set(rootsUpdate))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try (var mcpClient = clientBuilder.capabilities(ClientCapabilities.builder().roots(true).build())
|
try (var mcpClient = getMcpClientBuilder().capabilities(ClientCapabilities.builder().roots(true).build())
|
||||||
.roots(List.of()) // Empty roots list
|
.roots(List.of()) // Empty roots list
|
||||||
.build()) {
|
.build()) {
|
||||||
|
|
||||||
|
|
@ -1178,12 +1094,8 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest(name = "{0} : {displayName} ")
|
@Test
|
||||||
@MethodSource("clientsForTesting")
|
void testRootsWithMultipleHandlers() {
|
||||||
void testRootsWithMultipleHandlers(String clientType) {
|
|
||||||
|
|
||||||
var clientBuilder = clientBuilders.get(clientType);
|
|
||||||
|
|
||||||
List<Root> roots = List.of(Root.builder("uri1://").name("root1").build());
|
List<Root> roots = List.of(Root.builder("uri1://").name("root1").build());
|
||||||
|
|
||||||
AtomicReference<List<Root>> rootsRef1 = new AtomicReference<>();
|
AtomicReference<List<Root>> rootsRef1 = new AtomicReference<>();
|
||||||
|
|
@ -1194,7 +1106,7 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
.rootsChangeHandler((exchange, rootsUpdate) -> rootsRef2.set(rootsUpdate))
|
.rootsChangeHandler((exchange, rootsUpdate) -> rootsRef2.set(rootsUpdate))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try (var mcpClient = clientBuilder.capabilities(ClientCapabilities.builder().roots(true).build())
|
try (var mcpClient = getMcpClientBuilder().capabilities(ClientCapabilities.builder().roots(true).build())
|
||||||
.roots(roots)
|
.roots(roots)
|
||||||
.build()) {
|
.build()) {
|
||||||
|
|
||||||
|
|
@ -1212,12 +1124,8 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest(name = "{0} : {displayName} ")
|
@Test
|
||||||
@MethodSource("clientsForTesting")
|
void testRootsServerCloseWithActiveSubscription() {
|
||||||
void testRootsServerCloseWithActiveSubscription(String clientType) {
|
|
||||||
|
|
||||||
var clientBuilder = clientBuilders.get(clientType);
|
|
||||||
|
|
||||||
List<Root> roots = List.of(Root.builder("uri1://").name("root1").build());
|
List<Root> roots = List.of(Root.builder("uri1://").name("root1").build());
|
||||||
|
|
||||||
AtomicReference<List<Root>> rootsRef = new AtomicReference<>();
|
AtomicReference<List<Root>> rootsRef = new AtomicReference<>();
|
||||||
|
|
@ -1226,7 +1134,7 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
.rootsChangeHandler((exchange, rootsUpdate) -> rootsRef.set(rootsUpdate))
|
.rootsChangeHandler((exchange, rootsUpdate) -> rootsRef.set(rootsUpdate))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try (var mcpClient = clientBuilder.capabilities(ClientCapabilities.builder().roots(true).build())
|
try (var mcpClient = getMcpClientBuilder().capabilities(ClientCapabilities.builder().roots(true).build())
|
||||||
.roots(roots)
|
.roots(roots)
|
||||||
.build()) {
|
.build()) {
|
||||||
|
|
||||||
|
|
@ -1247,12 +1155,8 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
// ---------------------------------------
|
// ---------------------------------------
|
||||||
// Tools Tests
|
// Tools Tests
|
||||||
// ---------------------------------------
|
// ---------------------------------------
|
||||||
@ParameterizedTest(name = "{0} : {displayName} ")
|
@Test
|
||||||
@MethodSource("clientsForTesting")
|
void testToolCallSuccess() {
|
||||||
void testToolCallSuccess(String clientType) {
|
|
||||||
|
|
||||||
var clientBuilder = clientBuilders.get(clientType);
|
|
||||||
|
|
||||||
var responseBodyIsNullOrBlank = new AtomicBoolean(false);
|
var responseBodyIsNullOrBlank = new AtomicBoolean(false);
|
||||||
var callResponse = McpSchema.CallToolResult.builder()
|
var callResponse = McpSchema.CallToolResult.builder()
|
||||||
.addContent(McpSchema.TextContent.builder("CALL RESPONSE; ctx=importantValue").build())
|
.addContent(McpSchema.TextContent.builder("CALL RESPONSE; ctx=importantValue").build())
|
||||||
|
|
@ -1283,7 +1187,7 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
.tools(tool1)
|
.tools(tool1)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try (var mcpClient = clientBuilder.build()) {
|
try (var mcpClient = getMcpClientBuilder().build()) {
|
||||||
|
|
||||||
InitializeResult initResult = mcpClient.initialize();
|
InitializeResult initResult = mcpClient.initialize();
|
||||||
assertThat(initResult).isNotNull();
|
assertThat(initResult).isNotNull();
|
||||||
|
|
@ -1301,12 +1205,8 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest(name = "{0} : {displayName} ")
|
@Test
|
||||||
@MethodSource("clientsForTesting")
|
void testThrowingToolCallIsCaughtBeforeTimeout() {
|
||||||
void testThrowingToolCallIsCaughtBeforeTimeout(String clientType) {
|
|
||||||
|
|
||||||
var clientBuilder = clientBuilders.get(clientType);
|
|
||||||
|
|
||||||
McpSyncServer mcpServer = prepareSyncServerBuilder()
|
McpSyncServer mcpServer = prepareSyncServerBuilder()
|
||||||
.capabilities(ServerCapabilities.builder().tools(true).build())
|
.capabilities(ServerCapabilities.builder().tools(true).build())
|
||||||
.tools(McpServerFeatures.SyncToolSpecification.builder()
|
.tools(McpServerFeatures.SyncToolSpecification.builder()
|
||||||
|
|
@ -1319,7 +1219,7 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
.build())
|
.build())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try (var mcpClient = clientBuilder.requestTimeout(Duration.ofMillis(6666)).build()) {
|
try (var mcpClient = getMcpClientBuilder().requestTimeout(Duration.ofMillis(6666)).build()) {
|
||||||
InitializeResult initResult = mcpClient.initialize();
|
InitializeResult initResult = mcpClient.initialize();
|
||||||
assertThat(initResult).isNotNull();
|
assertThat(initResult).isNotNull();
|
||||||
|
|
||||||
|
|
@ -1334,12 +1234,8 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest(name = "{0} : {displayName} ")
|
@Test
|
||||||
@MethodSource("clientsForTesting")
|
void testToolCallSuccessWithTranportContextExtraction() {
|
||||||
void testToolCallSuccessWithTranportContextExtraction(String clientType) {
|
|
||||||
|
|
||||||
var clientBuilder = clientBuilders.get(clientType);
|
|
||||||
|
|
||||||
var transportContextIsNull = new AtomicBoolean(false);
|
var transportContextIsNull = new AtomicBoolean(false);
|
||||||
var transportContextIsEmpty = new AtomicBoolean(false);
|
var transportContextIsEmpty = new AtomicBoolean(false);
|
||||||
var responseBodyIsNullOrBlank = new AtomicBoolean(false);
|
var responseBodyIsNullOrBlank = new AtomicBoolean(false);
|
||||||
|
|
@ -1374,7 +1270,7 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
.tools(tool1)
|
.tools(tool1)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try (var mcpClient = clientBuilder.build()) {
|
try (var mcpClient = getMcpClientBuilder().build()) {
|
||||||
|
|
||||||
InitializeResult initResult = mcpClient.initialize();
|
InitializeResult initResult = mcpClient.initialize();
|
||||||
assertThat(initResult).isNotNull();
|
assertThat(initResult).isNotNull();
|
||||||
|
|
@ -1394,11 +1290,8 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest(name = "{0} : {displayName} ")
|
@Test
|
||||||
@MethodSource("clientsForTesting")
|
void testToolWithNonAsciiCharacters() {
|
||||||
void testToolWithNonAsciiCharacters(String clientType) {
|
|
||||||
var clientBuilder = clientBuilders.get(clientType);
|
|
||||||
|
|
||||||
String inputSchema = """
|
String inputSchema = """
|
||||||
{
|
{
|
||||||
"type": "object",
|
"type": "object",
|
||||||
|
|
@ -1423,7 +1316,7 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
.tools(nonAsciiTool)
|
.tools(nonAsciiTool)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try (var mcpClient = clientBuilder.build()) {
|
try (var mcpClient = getMcpClientBuilder().build()) {
|
||||||
|
|
||||||
InitializeResult initResult = mcpClient.initialize();
|
InitializeResult initResult = mcpClient.initialize();
|
||||||
assertThat(initResult).isNotNull();
|
assertThat(initResult).isNotNull();
|
||||||
|
|
@ -1446,12 +1339,8 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest(name = "{0} : {displayName} ")
|
@Test
|
||||||
@MethodSource("clientsForTesting")
|
void testToolListChangeHandlingSuccess() {
|
||||||
void testToolListChangeHandlingSuccess(String clientType) {
|
|
||||||
|
|
||||||
var clientBuilder = clientBuilders.get(clientType);
|
|
||||||
|
|
||||||
var callResponse = McpSchema.CallToolResult.builder()
|
var callResponse = McpSchema.CallToolResult.builder()
|
||||||
.addContent(McpSchema.TextContent.builder("CALL RESPONSE").build())
|
.addContent(McpSchema.TextContent.builder("CALL RESPONSE").build())
|
||||||
.build();
|
.build();
|
||||||
|
|
@ -1483,7 +1372,7 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
.tools(tool1)
|
.tools(tool1)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try (var mcpClient = clientBuilder.toolsChangeConsumer(toolsUpdate -> {
|
try (var mcpClient = getMcpClientBuilder().toolsChangeConsumer(toolsUpdate -> {
|
||||||
// perform a blocking call to a remote service
|
// perform a blocking call to a remote service
|
||||||
try {
|
try {
|
||||||
HttpResponse<String> response = HttpClient.newHttpClient()
|
HttpResponse<String> response = HttpClient.newHttpClient()
|
||||||
|
|
@ -1538,15 +1427,11 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest(name = "{0} : {displayName} ")
|
@Test
|
||||||
@MethodSource("clientsForTesting")
|
void testInitialize() {
|
||||||
void testInitialize(String clientType) {
|
|
||||||
|
|
||||||
var clientBuilder = clientBuilders.get(clientType);
|
|
||||||
|
|
||||||
var mcpServer = prepareSyncServerBuilder().build();
|
var mcpServer = prepareSyncServerBuilder().build();
|
||||||
|
|
||||||
try (var mcpClient = clientBuilder.build()) {
|
try (var mcpClient = getMcpClientBuilder().build()) {
|
||||||
|
|
||||||
InitializeResult initResult = mcpClient.initialize();
|
InitializeResult initResult = mcpClient.initialize();
|
||||||
assertThat(initResult).isNotNull();
|
assertThat(initResult).isNotNull();
|
||||||
|
|
@ -1559,16 +1444,13 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
// ---------------------------------------
|
// ---------------------------------------
|
||||||
// Logging Tests
|
// Logging Tests
|
||||||
// ---------------------------------------
|
// ---------------------------------------
|
||||||
@ParameterizedTest(name = "{0} : {displayName} ")
|
@Test
|
||||||
@MethodSource("clientsForTesting")
|
void testLoggingNotification() throws InterruptedException {
|
||||||
void testLoggingNotification(String clientType) throws InterruptedException {
|
|
||||||
int expectedNotificationsCount = 3;
|
int expectedNotificationsCount = 3;
|
||||||
CountDownLatch latch = new CountDownLatch(expectedNotificationsCount);
|
CountDownLatch latch = new CountDownLatch(expectedNotificationsCount);
|
||||||
// Create a list to store received logging notifications
|
// Create a list to store received logging notifications
|
||||||
List<McpSchema.LoggingMessageNotification> receivedNotifications = new CopyOnWriteArrayList<>();
|
List<McpSchema.LoggingMessageNotification> receivedNotifications = new CopyOnWriteArrayList<>();
|
||||||
|
|
||||||
var clientBuilder = clientBuilders.get(clientType);
|
|
||||||
|
|
||||||
// Create server with a tool that sends logging notifications
|
// Create server with a tool that sends logging notifications
|
||||||
McpServerFeatures.AsyncToolSpecification tool = McpServerFeatures.AsyncToolSpecification.builder()
|
McpServerFeatures.AsyncToolSpecification tool = McpServerFeatures.AsyncToolSpecification.builder()
|
||||||
.tool(Tool.builder("logging-test", EMPTY_JSON_SCHEMA).description("Test logging notifications").build())
|
.tool(Tool.builder("logging-test", EMPTY_JSON_SCHEMA).description("Test logging notifications").build())
|
||||||
|
|
@ -1617,7 +1499,7 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
|
|
||||||
try (
|
try (
|
||||||
// Create client with logging notification handler
|
// Create client with logging notification handler
|
||||||
var mcpClient = clientBuilder.loggingConsumer(notification -> {
|
var mcpClient = getMcpClientBuilder().loggingConsumer(notification -> {
|
||||||
receivedNotifications.add(notification);
|
receivedNotifications.add(notification);
|
||||||
latch.countDown();
|
latch.countDown();
|
||||||
}).build()) {
|
}).build()) {
|
||||||
|
|
@ -1667,17 +1549,14 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
// ---------------------------------------
|
// ---------------------------------------
|
||||||
// Progress Tests
|
// Progress Tests
|
||||||
// ---------------------------------------
|
// ---------------------------------------
|
||||||
@ParameterizedTest(name = "{0} : {displayName} ")
|
@Test
|
||||||
@MethodSource("clientsForTesting")
|
void testProgressNotification() throws InterruptedException {
|
||||||
void testProgressNotification(String clientType) throws InterruptedException {
|
|
||||||
int expectedNotificationsCount = 4; // 3 notifications + 1 for another progress
|
int expectedNotificationsCount = 4; // 3 notifications + 1 for another progress
|
||||||
// token
|
// token
|
||||||
CountDownLatch latch = new CountDownLatch(expectedNotificationsCount);
|
CountDownLatch latch = new CountDownLatch(expectedNotificationsCount);
|
||||||
// Create a list to store received logging notifications
|
// Create a list to store received logging notifications
|
||||||
List<McpSchema.ProgressNotification> receivedNotifications = new CopyOnWriteArrayList<>();
|
List<McpSchema.ProgressNotification> receivedNotifications = new CopyOnWriteArrayList<>();
|
||||||
|
|
||||||
var clientBuilder = clientBuilders.get(clientType);
|
|
||||||
|
|
||||||
// Create server with a tool that sends logging notifications
|
// Create server with a tool that sends logging notifications
|
||||||
McpServerFeatures.AsyncToolSpecification tool = McpServerFeatures.AsyncToolSpecification.builder()
|
McpServerFeatures.AsyncToolSpecification tool = McpServerFeatures.AsyncToolSpecification.builder()
|
||||||
.tool(McpSchema.Tool.builder("progress-test", EMPTY_JSON_SCHEMA)
|
.tool(McpSchema.Tool.builder("progress-test", EMPTY_JSON_SCHEMA)
|
||||||
|
|
@ -1720,7 +1599,7 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
|
|
||||||
try (
|
try (
|
||||||
// Create client with progress notification handler
|
// Create client with progress notification handler
|
||||||
var mcpClient = clientBuilder.progressConsumer(notification -> {
|
var mcpClient = getMcpClientBuilder().progressConsumer(notification -> {
|
||||||
receivedNotifications.add(notification);
|
receivedNotifications.add(notification);
|
||||||
latch.countDown();
|
latch.countDown();
|
||||||
}).build()) {
|
}).build()) {
|
||||||
|
|
@ -1781,11 +1660,8 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
// ---------------------------------------
|
// ---------------------------------------
|
||||||
// Completion Tests
|
// Completion Tests
|
||||||
// ---------------------------------------
|
// ---------------------------------------
|
||||||
@ParameterizedTest(name = "{0} : Completion call")
|
@Test
|
||||||
@MethodSource("clientsForTesting")
|
void testCompletionShouldReturnExpectedSuggestions() {
|
||||||
void testCompletionShouldReturnExpectedSuggestions(String clientType) {
|
|
||||||
var clientBuilder = clientBuilders.get(clientType);
|
|
||||||
|
|
||||||
var expectedValues = List.of("python", "pytorch", "pyside");
|
var expectedValues = List.of("python", "pytorch", "pyside");
|
||||||
var completionResponse = new McpSchema.CompleteResult(
|
var completionResponse = new McpSchema.CompleteResult(
|
||||||
new CompleteResult.CompleteCompletion(expectedValues, 10, true));
|
new CompleteResult.CompleteCompletion(expectedValues, 10, true));
|
||||||
|
|
@ -1811,7 +1687,7 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
McpSchema.PromptReference.builder("code_review").title("Code review").build(), completionHandler))
|
McpSchema.PromptReference.builder("code_review").title("Code review").build(), completionHandler))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try (var mcpClient = clientBuilder.build()) {
|
try (var mcpClient = getMcpClientBuilder().build()) {
|
||||||
|
|
||||||
InitializeResult initResult = mcpClient.initialize();
|
InitializeResult initResult = mcpClient.initialize();
|
||||||
assertThat(initResult).isNotNull();
|
assertThat(initResult).isNotNull();
|
||||||
|
|
@ -1837,12 +1713,8 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
// ---------------------------------------
|
// ---------------------------------------
|
||||||
// Ping Tests
|
// Ping Tests
|
||||||
// ---------------------------------------
|
// ---------------------------------------
|
||||||
@ParameterizedTest(name = "{0} : {displayName} ")
|
@Test
|
||||||
@MethodSource("clientsForTesting")
|
void testPingSuccess() {
|
||||||
void testPingSuccess(String clientType) {
|
|
||||||
|
|
||||||
var clientBuilder = clientBuilders.get(clientType);
|
|
||||||
|
|
||||||
// Create server with a tool that uses ping functionality
|
// Create server with a tool that uses ping functionality
|
||||||
AtomicReference<String> executionOrder = new AtomicReference<>("");
|
AtomicReference<String> executionOrder = new AtomicReference<>("");
|
||||||
|
|
||||||
|
|
@ -1876,7 +1748,7 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
.tools(tool)
|
.tools(tool)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try (var mcpClient = clientBuilder.build()) {
|
try (var mcpClient = getMcpClientBuilder().build()) {
|
||||||
|
|
||||||
// Initialize client
|
// Initialize client
|
||||||
InitializeResult initResult = mcpClient.initialize();
|
InitializeResult initResult = mcpClient.initialize();
|
||||||
|
|
@ -1900,11 +1772,8 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
// ---------------------------------------
|
// ---------------------------------------
|
||||||
// Tool Structured Output Schema Tests
|
// Tool Structured Output Schema Tests
|
||||||
// ---------------------------------------
|
// ---------------------------------------
|
||||||
@ParameterizedTest(name = "{0} : {displayName} ")
|
@Test
|
||||||
@MethodSource("clientsForTesting")
|
void testStructuredOutputValidationSuccess() {
|
||||||
void testStructuredOutputValidationSuccess(String clientType) {
|
|
||||||
var clientBuilder = clientBuilders.get(clientType);
|
|
||||||
|
|
||||||
// Create a tool with output schema
|
// Create a tool with output schema
|
||||||
Map<String, Object> outputSchema = Map.of(
|
Map<String, Object> outputSchema = Map.of(
|
||||||
"type", "object", "properties", Map.of("result", Map.of("type", "number"), "operation",
|
"type", "object", "properties", Map.of("result", Map.of("type", "number"), "operation",
|
||||||
|
|
@ -1933,7 +1802,7 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
.tools(tool)
|
.tools(tool)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try (var mcpClient = clientBuilder.build()) {
|
try (var mcpClient = getMcpClientBuilder().build()) {
|
||||||
InitializeResult initResult = mcpClient.initialize();
|
InitializeResult initResult = mcpClient.initialize();
|
||||||
assertThat(initResult).isNotNull();
|
assertThat(initResult).isNotNull();
|
||||||
|
|
||||||
|
|
@ -1973,11 +1842,8 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest(name = "{0} : {displayName} ")
|
@Test
|
||||||
@ValueSource(strings = { "httpclient" })
|
void testStructuredOutputOfObjectArrayValidationSuccess() {
|
||||||
void testStructuredOutputOfObjectArrayValidationSuccess(String clientType) {
|
|
||||||
var clientBuilder = clientBuilders.get(clientType);
|
|
||||||
|
|
||||||
// Create a tool with output schema that returns an array of objects
|
// Create a tool with output schema that returns an array of objects
|
||||||
Map<String, Object> outputSchema = Map
|
Map<String, Object> outputSchema = Map
|
||||||
.of( // @formatter:off
|
.of( // @formatter:off
|
||||||
|
|
@ -2008,7 +1874,7 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
.tools(tool)
|
.tools(tool)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try (var mcpClient = clientBuilder.build()) {
|
try (var mcpClient = getMcpClientBuilder().build()) {
|
||||||
assertThat(mcpClient.initialize()).isNotNull();
|
assertThat(mcpClient.initialize()).isNotNull();
|
||||||
|
|
||||||
// Call tool with valid structured output of type array
|
// Call tool with valid structured output of type array
|
||||||
|
|
@ -2032,11 +1898,8 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest(name = "{0} : {displayName} ")
|
@Test
|
||||||
@ValueSource(strings = { "httpclient" })
|
void testStructuredOutputWithInHandlerError() {
|
||||||
void testStructuredOutputWithInHandlerError(String clientType) {
|
|
||||||
var clientBuilder = clientBuilders.get(clientType);
|
|
||||||
|
|
||||||
// Create a tool with output schema
|
// Create a tool with output schema
|
||||||
Map<String, Object> outputSchema = Map.of(
|
Map<String, Object> outputSchema = Map.of(
|
||||||
"type", "object", "properties", Map.of("result", Map.of("type", "number"), "operation",
|
"type", "object", "properties", Map.of("result", Map.of("type", "number"), "operation",
|
||||||
|
|
@ -2062,7 +1925,7 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
.tools(tool)
|
.tools(tool)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try (var mcpClient = clientBuilder.build()) {
|
try (var mcpClient = getMcpClientBuilder().build()) {
|
||||||
InitializeResult initResult = mcpClient.initialize();
|
InitializeResult initResult = mcpClient.initialize();
|
||||||
assertThat(initResult).isNotNull();
|
assertThat(initResult).isNotNull();
|
||||||
|
|
||||||
|
|
@ -2088,12 +1951,8 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest(name = "{0} : {displayName} ")
|
@Test
|
||||||
@ValueSource(strings = { "httpclient" })
|
void testStructuredOutputValidationFailure() {
|
||||||
void testStructuredOutputValidationFailure(String clientType) {
|
|
||||||
|
|
||||||
var clientBuilder = clientBuilders.get(clientType);
|
|
||||||
|
|
||||||
// Create a tool with output schema
|
// Create a tool with output schema
|
||||||
Map<String, Object> outputSchema = Map.of("type", "object", "properties",
|
Map<String, Object> outputSchema = Map.of("type", "object", "properties",
|
||||||
Map.of("result", Map.of("type", "number"), "operation", Map.of("type", "string")), "required",
|
Map.of("result", Map.of("type", "number"), "operation", Map.of("type", "string")), "required",
|
||||||
|
|
@ -2121,7 +1980,7 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
.tools(tool)
|
.tools(tool)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try (var mcpClient = clientBuilder.build()) {
|
try (var mcpClient = getMcpClientBuilder().build()) {
|
||||||
InitializeResult initResult = mcpClient.initialize();
|
InitializeResult initResult = mcpClient.initialize();
|
||||||
assertThat(initResult).isNotNull();
|
assertThat(initResult).isNotNull();
|
||||||
|
|
||||||
|
|
@ -2142,12 +2001,8 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest(name = "{0} : {displayName} ")
|
@Test
|
||||||
@MethodSource("clientsForTesting")
|
void testStructuredOutputMissingStructuredContent() {
|
||||||
void testStructuredOutputMissingStructuredContent(String clientType) {
|
|
||||||
|
|
||||||
var clientBuilder = clientBuilders.get(clientType);
|
|
||||||
|
|
||||||
// Create a tool with output schema
|
// Create a tool with output schema
|
||||||
Map<String, Object> outputSchema = Map.of("type", "object", "properties",
|
Map<String, Object> outputSchema = Map.of("type", "object", "properties",
|
||||||
Map.of("result", Map.of("type", "number")), "required", List.of("result"));
|
Map.of("result", Map.of("type", "number")), "required", List.of("result"));
|
||||||
|
|
@ -2170,7 +2025,7 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
.tools(tool)
|
.tools(tool)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try (var mcpClient = clientBuilder.build()) {
|
try (var mcpClient = getMcpClientBuilder().build()) {
|
||||||
InitializeResult initResult = mcpClient.initialize();
|
InitializeResult initResult = mcpClient.initialize();
|
||||||
assertThat(initResult).isNotNull();
|
assertThat(initResult).isNotNull();
|
||||||
|
|
||||||
|
|
@ -2192,18 +2047,14 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest(name = "{0} : {displayName} ")
|
@Test
|
||||||
@MethodSource("clientsForTesting")
|
void testStructuredOutputRuntimeToolAddition() {
|
||||||
void testStructuredOutputRuntimeToolAddition(String clientType) {
|
|
||||||
|
|
||||||
var clientBuilder = clientBuilders.get(clientType);
|
|
||||||
|
|
||||||
// Start server without tools
|
// Start server without tools
|
||||||
var mcpServer = prepareSyncServerBuilder().serverInfo("test-server", "1.0.0")
|
var mcpServer = prepareSyncServerBuilder().serverInfo("test-server", "1.0.0")
|
||||||
.capabilities(ServerCapabilities.builder().tools(true).build())
|
.capabilities(ServerCapabilities.builder().tools(true).build())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try (var mcpClient = clientBuilder.build()) {
|
try (var mcpClient = getMcpClientBuilder().build()) {
|
||||||
InitializeResult initResult = mcpClient.initialize();
|
InitializeResult initResult = mcpClient.initialize();
|
||||||
assertThat(initResult).isNotNull();
|
assertThat(initResult).isNotNull();
|
||||||
|
|
||||||
|
|
@ -2273,12 +2124,8 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
// Resource Subscription Tests
|
// Resource Subscription Tests
|
||||||
// ---------------------------------------
|
// ---------------------------------------
|
||||||
|
|
||||||
@ParameterizedTest(name = "{0} : {displayName} ")
|
@Test
|
||||||
@MethodSource("clientsForTesting")
|
void testResourceSubscription() throws InterruptedException {
|
||||||
void testResourceSubscription(String clientType) throws InterruptedException {
|
|
||||||
|
|
||||||
var clientBuilder = clientBuilders.get(clientType);
|
|
||||||
|
|
||||||
String resourceUri = "test://subscribable-resource";
|
String resourceUri = "test://subscribable-resource";
|
||||||
var receivedContents = new AtomicReference<List<McpSchema.ResourceContents>>();
|
var receivedContents = new AtomicReference<List<McpSchema.ResourceContents>>();
|
||||||
var latch = new CountDownLatch(1);
|
var latch = new CountDownLatch(1);
|
||||||
|
|
@ -2296,7 +2143,7 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
.resources(resourceSpec)
|
.resources(resourceSpec)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try (var mcpClient = clientBuilder.resourcesUpdateConsumer(contents -> {
|
try (var mcpClient = getMcpClientBuilder().resourcesUpdateConsumer(contents -> {
|
||||||
receivedContents.set(contents);
|
receivedContents.set(contents);
|
||||||
latch.countDown();
|
latch.countDown();
|
||||||
}).build()) {
|
}).build()) {
|
||||||
|
|
@ -2317,12 +2164,8 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest(name = "{0} : {displayName} ")
|
@Test
|
||||||
@MethodSource("clientsForTesting")
|
void testResourceSubscription_afterUnsubscribe_noNotification() {
|
||||||
void testResourceSubscription_afterUnsubscribe_noNotification(String clientType) throws InterruptedException {
|
|
||||||
|
|
||||||
var clientBuilder = clientBuilders.get(clientType);
|
|
||||||
|
|
||||||
String resourceUri = "test://subscribable-resource-unsub";
|
String resourceUri = "test://subscribable-resource-unsub";
|
||||||
var notificationCount = new java.util.concurrent.atomic.AtomicInteger(0);
|
var notificationCount = new java.util.concurrent.atomic.AtomicInteger(0);
|
||||||
|
|
||||||
|
|
@ -2337,7 +2180,8 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
.resources(resourceSpec)
|
.resources(resourceSpec)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try (var mcpClient = clientBuilder.resourcesUpdateConsumer(contents -> notificationCount.incrementAndGet())
|
try (var mcpClient = getMcpClientBuilder()
|
||||||
|
.resourcesUpdateConsumer(contents -> notificationCount.incrementAndGet())
|
||||||
.build()) {
|
.build()) {
|
||||||
|
|
||||||
mcpClient.initialize();
|
mcpClient.initialize();
|
||||||
|
|
|
||||||
|
|
@ -61,12 +61,6 @@ class HttpServletSseIntegrationTests extends AbstractMcpClientServerIntegrationT
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
throw new RuntimeException("Failed to start Tomcat", e);
|
throw new RuntimeException("Failed to start Tomcat", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
clientBuilders
|
|
||||||
.put("httpclient",
|
|
||||||
McpClient.sync(HttpClientSseClientTransport.builder("http://localhost:" + PORT)
|
|
||||||
.sseEndpoint(CUSTOM_SSE_ENDPOINT)
|
|
||||||
.build()).requestTimeout(Duration.ofHours(10)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -79,6 +73,15 @@ class HttpServletSseIntegrationTests extends AbstractMcpClientServerIntegrationT
|
||||||
return McpServer.sync(this.mcpServerTransportProvider);
|
return McpServer.sync(this.mcpServerTransportProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected McpClient.SyncSpec getMcpClientBuilder() {
|
||||||
|
return McpClient
|
||||||
|
.sync(HttpClientSseClientTransport.builder("http://localhost:" + PORT)
|
||||||
|
.sseEndpoint(CUSTOM_SSE_ENDPOINT)
|
||||||
|
.build())
|
||||||
|
.requestTimeout(Duration.ofHours(10));
|
||||||
|
}
|
||||||
|
|
||||||
@AfterEach
|
@AfterEach
|
||||||
public void after() {
|
public void after() {
|
||||||
if (mcpServerTransportProvider != null) {
|
if (mcpServerTransportProvider != null) {
|
||||||
|
|
@ -95,10 +98,6 @@ class HttpServletSseIntegrationTests extends AbstractMcpClientServerIntegrationT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void prepareClients(int port, String mcpEndpoint) {
|
|
||||||
}
|
|
||||||
|
|
||||||
static McpTransportContextExtractor<HttpServletRequest> TEST_CONTEXT_EXTRACTOR = (r) -> McpTransportContext
|
static McpTransportContextExtractor<HttpServletRequest> TEST_CONTEXT_EXTRACTOR = (r) -> McpTransportContext
|
||||||
.create(Map.of("important", "value"));
|
.create(Map.of("important", "value"));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -59,12 +59,6 @@ class HttpServletStreamableIntegrationTests extends AbstractMcpClientServerInteg
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
throw new RuntimeException("Failed to start Tomcat", e);
|
throw new RuntimeException("Failed to start Tomcat", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
clientBuilders
|
|
||||||
.put("httpclient",
|
|
||||||
McpClient.sync(HttpClientStreamableHttpTransport.builder("http://localhost:" + PORT)
|
|
||||||
.endpoint(MESSAGE_ENDPOINT)
|
|
||||||
.build()).requestTimeout(Duration.ofHours(10)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -77,6 +71,15 @@ class HttpServletStreamableIntegrationTests extends AbstractMcpClientServerInteg
|
||||||
return McpServer.sync(this.mcpServerTransportProvider);
|
return McpServer.sync(this.mcpServerTransportProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected McpClient.SyncSpec getMcpClientBuilder() {
|
||||||
|
return McpClient
|
||||||
|
.sync(HttpClientStreamableHttpTransport.builder("http://localhost:" + PORT)
|
||||||
|
.endpoint(MESSAGE_ENDPOINT)
|
||||||
|
.build())
|
||||||
|
.requestTimeout(Duration.ofHours(10));
|
||||||
|
}
|
||||||
|
|
||||||
@AfterEach
|
@AfterEach
|
||||||
public void after() {
|
public void after() {
|
||||||
if (mcpServerTransportProvider != null) {
|
if (mcpServerTransportProvider != null) {
|
||||||
|
|
@ -93,10 +96,6 @@ class HttpServletStreamableIntegrationTests extends AbstractMcpClientServerInteg
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void prepareClients(int port, String mcpEndpoint) {
|
|
||||||
}
|
|
||||||
|
|
||||||
static McpTransportContextExtractor<HttpServletRequest> TEST_CONTEXT_EXTRACTOR = (r) -> McpTransportContext
|
static McpTransportContextExtractor<HttpServletRequest> TEST_CONTEXT_EXTRACTOR = (r) -> McpTransportContext
|
||||||
.create(Map.of("important", "value"));
|
.create(Map.of("important", "value"));
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue