Skip to content

Commit caf458b

Browse files
authored
mcp-test: remove dependency on Spring (#1258)
Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
1 parent c7bd7ec commit caf458b

4 files changed

Lines changed: 27 additions & 73 deletions

File tree

‎mcp-test/pom.xml‎

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -96,27 +96,6 @@
9696
</dependency>
9797

9898
<!-- Test-scoped dependencies for integration tests -->
99-
<dependency>
100-
<groupId>org.springframework</groupId>
101-
<artifactId>spring-webmvc</artifactId>
102-
<version>${springframework.version}</version>
103-
<scope>test</scope>
104-
</dependency>
105-
106-
<dependency>
107-
<groupId>org.springframework</groupId>
108-
<artifactId>spring-context</artifactId>
109-
<version>${springframework.version}</version>
110-
<scope>test</scope>
111-
</dependency>
112-
113-
<dependency>
114-
<groupId>org.springframework</groupId>
115-
<artifactId>spring-test</artifactId>
116-
<version>${springframework.version}</version>
117-
<scope>test</scope>
118-
</dependency>
119-
12099
<dependency>
121100
<groupId>io.projectreactor.netty</groupId>
122101
<artifactId>reactor-netty-http</artifactId>

‎mcp-test/src/test/java/io/modelcontextprotocol/client/transport/HttpClientSseClientTransportTests.java‎

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package io.modelcontextprotocol.client.transport;
66

77
import java.net.URI;
8+
import java.net.URISyntaxException;
89
import java.net.http.HttpClient;
910
import java.net.http.HttpRequest;
1011
import java.time.Duration;
@@ -30,11 +31,8 @@
3031
import org.testcontainers.containers.GenericContainer;
3132
import org.testcontainers.containers.wait.strategy.Wait;
3233
import reactor.core.publisher.Mono;
33-
import reactor.core.publisher.Sinks;
3434
import reactor.test.StepVerifier;
3535

36-
import org.springframework.http.codec.ServerSentEvent;
37-
import org.springframework.web.util.UriComponentsBuilder;
3836
import static io.modelcontextprotocol.util.McpJsonMapperUtils.JSON_MAPPER;
3937
import static org.assertj.core.api.Assertions.assertThat;
4038
import static org.assertj.core.api.Assertions.assertThatCode;
@@ -78,8 +76,6 @@ static class TestHttpClientSseClientTransport extends HttpClientSseClientTranspo
7876

7977
private final AtomicInteger inboundMessageCount = new AtomicInteger(0);
8078

81-
private Sinks.Many<ServerSentEvent<String>> events = Sinks.many().unicast().onBackpressureBuffer();
82-
8379
public TestHttpClientSseClientTransport(final String baseUri,
8480
SseMessageEndpointValidator sseMessageEndpointValidator) {
8581
super(HttpClient.newBuilder().version(HttpClient.Version.HTTP_1_1).build(),
@@ -91,13 +87,7 @@ public int getInboundMessageCount() {
9187
return inboundMessageCount.get();
9288
}
9389

94-
public void simulateEndpointEvent(String jsonMessage) {
95-
events.tryEmitNext(ServerSentEvent.<String>builder().event("endpoint").data(jsonMessage).build());
96-
inboundMessageCount.incrementAndGet();
97-
}
98-
9990
public void simulateMessageEvent(String jsonMessage) {
100-
events.tryEmitNext(ServerSentEvent.<String>builder().event("message").data(jsonMessage).build());
10191
inboundMessageCount.incrementAndGet();
10292
}
10393

@@ -333,7 +323,7 @@ void testCustomizeClient() {
333323
}
334324

335325
@Test
336-
void testRequestCustomizer() {
326+
void testRequestCustomizer() throws URISyntaxException {
337327
var mockCustomizer = mock(McpSyncHttpClientRequestCustomizer.class);
338328

339329
// Create a transport with the customizer
@@ -348,8 +338,7 @@ void testRequestCustomizer() {
348338
.verifyComplete();
349339

350340
// Verify the customizer was called
351-
verify(mockCustomizer).customize(any(), eq("GET"),
352-
eq(UriComponentsBuilder.fromUriString(host).path("/sse").build().toUri()), isNull(), eq(context));
341+
verify(mockCustomizer).customize(any(), eq("GET"), eq(new URI(host + "/sse")), isNull(), eq(context));
353342
clearInvocations(mockCustomizer);
354343

355344
// Send test message
@@ -373,7 +362,7 @@ void testRequestCustomizer() {
373362
}
374363

375364
@Test
376-
void testAsyncRequestCustomizer() {
365+
void testAsyncRequestCustomizer() throws URISyntaxException {
377366
var mockCustomizer = mock(McpAsyncHttpClientRequestCustomizer.class);
378367
when(mockCustomizer.customize(any(), any(), any(), any(), any()))
379368
.thenAnswer(invocation -> Mono.just(invocation.getArguments()[0]));
@@ -390,8 +379,7 @@ void testAsyncRequestCustomizer() {
390379
.verifyComplete();
391380

392381
// Verify the customizer was called
393-
verify(mockCustomizer).customize(any(), eq("GET"),
394-
eq(UriComponentsBuilder.fromUriString(host).path("/sse").build().toUri()), isNull(), eq(context));
382+
verify(mockCustomizer).customize(any(), eq("GET"), eq(new URI(host + "/sse")), isNull(), eq(context));
395383
clearInvocations(mockCustomizer);
396384

397385
// Send test message

‎mcp-test/src/test/java/io/modelcontextprotocol/server/HttpServletStatelessIntegrationTests.java‎

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,6 @@
6060
import reactor.core.publisher.Mono;
6161
import reactor.test.StepVerifier;
6262

63-
import org.springframework.mock.web.MockHttpServletRequest;
64-
import org.springframework.mock.web.MockHttpServletResponse;
65-
import org.springframework.web.client.RestClient;
6663
import static io.modelcontextprotocol.server.transport.HttpServletStatelessServerTransport.APPLICATION_JSON;
6764
import static io.modelcontextprotocol.server.transport.HttpServletStatelessServerTransport.TEXT_EVENT_STREAM;
6865
import static io.modelcontextprotocol.util.McpJsonMapperUtils.JSON_MAPPER;
@@ -140,12 +137,18 @@ void testToolCallSuccess() {
140137
Tool.builder("tool1", EMPTY_JSON_SCHEMA).title("tool1 description").build(),
141138
(transportContext, request) -> {
142139
// perform a blocking call to a remote service
143-
String response = RestClient.create()
144-
.get()
145-
.uri("https://raw.githubusercontent.com/modelcontextprotocol/java-sdk/refs/heads/main/README.md")
146-
.retrieve()
147-
.body(String.class);
148-
assertThat(response).isNotBlank();
140+
try {
141+
HttpResponse<String> response = HttpClient.newHttpClient()
142+
.send(HttpRequest.newBuilder()
143+
.uri(URI.create(
144+
"https://raw.githubusercontent.com/modelcontextprotocol/java-sdk/refs/heads/main/README.md"))
145+
.GET()
146+
.build(), HttpResponse.BodyHandlers.ofString());
147+
assertThat(response.body()).isNotBlank();
148+
}
149+
catch (Exception e) {
150+
throw new RuntimeException(e);
151+
}
149152
return callResponse;
150153
});
151154

@@ -714,34 +717,19 @@ void testThrownMcpErrorAndJsonRpcError() throws Exception {
714717

715718
mcpServer.addTool(toolSpec);
716719

717-
McpSchema.CallToolRequest callToolRequest = McpSchema.CallToolRequest.builder("test")
718-
.arguments(Map.of())
720+
var request = HttpRequest.newBuilder()
721+
.uri(URI.create("http://localhost:" + PORT + CUSTOM_MESSAGE_ENDPOINT))
722+
.header("Content-Type", APPLICATION_JSON)
723+
.header("Accept", APPLICATION_JSON + ", " + TEXT_EVENT_STREAM)
724+
.header(HttpHeaders.PROTOCOL_VERSION, ProtocolVersions.MCP_2025_03_26)
725+
.POST(HttpRequest.BodyPublishers.ofString("""
726+
{"jsonrpc":"2.0","id":"test","method":"tools/call","params":{"name":"test","arguments":{}}}"""))
719727
.build();
720-
McpSchema.JSONRPCRequest jsonrpcRequest = new McpSchema.JSONRPCRequest(McpSchema.METHOD_TOOLS_CALL, "test",
721-
callToolRequest);
722-
723-
MockHttpServletRequest request = new MockHttpServletRequest("POST", CUSTOM_MESSAGE_ENDPOINT);
724-
MockHttpServletResponse response = new MockHttpServletResponse();
725-
726-
byte[] content = JSON_MAPPER.writeValueAsBytes(jsonrpcRequest);
727-
request.setContent(content);
728-
request.addHeader("Content-Type", "application/json");
729-
request.addHeader("Content-Length", Integer.toString(content.length));
730-
request.addHeader("Content-Length", Integer.toString(content.length));
731-
request.addHeader("Accept", APPLICATION_JSON + ", " + TEXT_EVENT_STREAM);
732-
request.addHeader("Content-Type", APPLICATION_JSON);
733-
request.addHeader("Cache-Control", "no-cache");
734-
request.addHeader(HttpHeaders.PROTOCOL_VERSION, ProtocolVersions.MCP_2025_03_26);
735728

736-
mcpStatelessServerTransport.service(request, response);
737-
738-
McpSchema.JSONRPCResponse jsonrpcResponse = JSON_MAPPER.readValue(response.getContentAsByteArray(),
739-
McpSchema.JSONRPCResponse.class);
729+
var response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
740730

741-
assertThat(jsonrpcResponse).isNotNull();
742-
assertThat(jsonrpcResponse.error()).isNotNull();
743-
assertThat(jsonrpcResponse.error().code()).isEqualTo(ErrorCodes.INTERNAL_ERROR);
744-
assertThat(jsonrpcResponse.error().message()).isEqualTo("testing");
731+
assertThatJson(response.body()).inPath("error.code").isEqualTo(ErrorCodes.INTERNAL_ERROR);
732+
assertThatJson(response.body()).inPath("error.message").isEqualTo("testing");
745733
}
746734

747735
@Test

‎pom.xml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@
7575
<jackson-annotations.version>2.21</jackson-annotations.version>
7676
<jackson2.version>2.21.1</jackson2.version>
7777
<jackson3.version>3.1.4</jackson3.version>
78-
<springframework.version>6.2.19</springframework.version>
7978

8079
<!-- plugin versions -->
8180
<maven-compiler-plugin.version>3.16.0</maven-compiler-plugin.version>

0 commit comments

Comments
 (0)