Skip to content

Commit 5dab3b5

Browse files
committed
Replace HttpServletSseServerTransportProviderIntegrationTests with HttpServletSseIntegrationTests extending the AbstractMcpClientServerIntegrationTests
1 parent 56c2bdf commit 5dab3b5

6 files changed

Lines changed: 108 additions & 1426 deletions

File tree

mcp-spring/mcp-spring-webmvc/src/test/java/io/modelcontextprotocol/server/WebMvcSseIntegrationTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ protected void prepareClients(int port, String mcpEndpoint) {
4242

4343
clientBuilders.put("httpclient",
4444
McpClient.sync(HttpClientSseClientTransport.builder("http://localhost:" + port).build())
45-
.initializationTimeout(Duration.ofHours(10))
4645
.requestTimeout(Duration.ofHours(10)));
4746

4847
clientBuilders.put("webflux", McpClient
49-
.sync(WebFluxSseClientTransport.builder(WebClient.builder().baseUrl("http://localhost:" + port)).build()));
48+
.sync(WebFluxSseClientTransport.builder(WebClient.builder().baseUrl("http://localhost:" + port)).build())
49+
.requestTimeout(Duration.ofHours(10)));
5050
}
5151

5252
@Configuration

mcp-spring/mcp-spring-webmvc/src/test/java/io/modelcontextprotocol/server/WebMvcStatelessIntegrationTests.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,15 @@ protected void prepareClients(int port, String mcpEndpoint) {
7575

7676
clientBuilders.put("httpclient", McpClient
7777
.sync(HttpClientStreamableHttpTransport.builder("http://localhost:" + port).endpoint(mcpEndpoint).build())
78-
.initializationTimeout(Duration.ofHours(10))
7978
.requestTimeout(Duration.ofHours(10)));
8079

8180
clientBuilders.put("webflux",
82-
McpClient.sync(WebClientStreamableHttpTransport
83-
.builder(WebClient.builder().baseUrl("http://localhost:" + port))
84-
.endpoint(mcpEndpoint)
85-
.build()));
81+
McpClient
82+
.sync(WebClientStreamableHttpTransport
83+
.builder(WebClient.builder().baseUrl("http://localhost:" + port))
84+
.endpoint(mcpEndpoint)
85+
.build())
86+
.requestTimeout(Duration.ofHours(10)));
8687
}
8788

8889
@BeforeEach

mcp-spring/mcp-spring-webmvc/src/test/java/io/modelcontextprotocol/server/WebMvcStreamableIntegrationTests.java

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -124,42 +124,20 @@ public void after() {
124124
}
125125
}
126126

127-
@ParameterizedTest(name = "{0} : {displayName} ")
128-
@ValueSource(strings = { "httpclient", "webflux" })
129-
void simple(String clientType) {
130-
131-
var clientBuilder = clientBuilders.get(clientType);
132-
133-
var server = McpServer.async(mcpServerTransportProvider)
134-
.serverInfo("test-server", "1.0.0")
135-
.requestTimeout(Duration.ofSeconds(1000))
136-
.build();
137-
138-
try (
139-
// Create client without sampling capabilities
140-
var client = clientBuilder.clientInfo(new McpSchema.Implementation("Sample " + "client", "0.0.0"))
141-
.requestTimeout(Duration.ofSeconds(1000))
142-
.build()) {
143-
144-
assertThat(client.initialize()).isNotNull();
145-
146-
}
147-
server.closeGracefully();
148-
}
149-
150127
@Override
151128
protected void prepareClients(int port, String mcpEndpoint) {
152129

153130
clientBuilders.put("httpclient", McpClient
154131
.sync(HttpClientStreamableHttpTransport.builder("http://localhost:" + port).endpoint(mcpEndpoint).build())
155-
.initializationTimeout(Duration.ofHours(10))
156132
.requestTimeout(Duration.ofHours(10)));
157133

158134
clientBuilders.put("webflux",
159-
McpClient.sync(WebClientStreamableHttpTransport
160-
.builder(WebClient.builder().baseUrl("http://localhost:" + port))
161-
.endpoint(mcpEndpoint)
162-
.build()));
135+
McpClient
136+
.sync(WebClientStreamableHttpTransport
137+
.builder(WebClient.builder().baseUrl("http://localhost:" + port))
138+
.endpoint(mcpEndpoint)
139+
.build())
140+
.requestTimeout(Duration.ofHours(10)));
163141
}
164142

165143
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Copyright 2024 - 2024 the original author or authors.
3+
*/
4+
5+
package io.modelcontextprotocol.server;
6+
7+
import static org.assertj.core.api.Assertions.assertThat;
8+
9+
import java.time.Duration;
10+
11+
import org.apache.catalina.LifecycleException;
12+
import org.apache.catalina.LifecycleState;
13+
import org.apache.catalina.startup.Tomcat;
14+
import org.junit.jupiter.api.AfterEach;
15+
import org.junit.jupiter.api.BeforeEach;
16+
17+
import com.fasterxml.jackson.databind.ObjectMapper;
18+
19+
import io.modelcontextprotocol.client.McpClient;
20+
import io.modelcontextprotocol.client.transport.HttpClientSseClientTransport;
21+
import io.modelcontextprotocol.server.McpServer.AsyncSpecification;
22+
import io.modelcontextprotocol.server.McpServer.SyncSpecification;
23+
import io.modelcontextprotocol.server.transport.HttpServletSseServerTransportProvider;
24+
import io.modelcontextprotocol.server.transport.TomcatTestUtil;
25+
26+
class HttpServletSseIntegrationTests extends AbstractMcpClientServerIntegrationTests {
27+
28+
private static final int PORT = TomcatTestUtil.findAvailablePort();
29+
30+
private static final String CUSTOM_SSE_ENDPOINT = "/somePath/sse";
31+
32+
private static final String CUSTOM_MESSAGE_ENDPOINT = "/otherPath/mcp/message";
33+
34+
private HttpServletSseServerTransportProvider mcpServerTransportProvider;
35+
36+
private Tomcat tomcat;
37+
38+
@BeforeEach
39+
public void before() {
40+
// Create and configure the transport provider
41+
mcpServerTransportProvider = HttpServletSseServerTransportProvider.builder()
42+
.objectMapper(new ObjectMapper())
43+
.messageEndpoint(CUSTOM_MESSAGE_ENDPOINT)
44+
.sseEndpoint(CUSTOM_SSE_ENDPOINT)
45+
.build();
46+
47+
tomcat = TomcatTestUtil.createTomcatServer("", PORT, mcpServerTransportProvider);
48+
try {
49+
tomcat.start();
50+
assertThat(tomcat.getServer().getState()).isEqualTo(LifecycleState.STARTED);
51+
}
52+
catch (Exception e) {
53+
throw new RuntimeException("Failed to start Tomcat", e);
54+
}
55+
56+
clientBuilders
57+
.put("httpclient",
58+
McpClient.sync(HttpClientSseClientTransport.builder("http://localhost:" + PORT)
59+
.sseEndpoint(CUSTOM_SSE_ENDPOINT)
60+
.build()).requestTimeout(Duration.ofHours(10)));
61+
}
62+
63+
@Override
64+
protected AsyncSpecification<?> prepareAsyncServerBuilder() {
65+
return McpServer.async(this.mcpServerTransportProvider);
66+
}
67+
68+
@Override
69+
protected SyncSpecification<?> prepareSyncServerBuilder() {
70+
return McpServer.sync(this.mcpServerTransportProvider);
71+
}
72+
73+
@AfterEach
74+
public void after() {
75+
if (mcpServerTransportProvider != null) {
76+
mcpServerTransportProvider.closeGracefully().block();
77+
}
78+
if (tomcat != null) {
79+
try {
80+
tomcat.stop();
81+
tomcat.destroy();
82+
}
83+
catch (LifecycleException e) {
84+
throw new RuntimeException("Failed to stop Tomcat", e);
85+
}
86+
}
87+
}
88+
89+
@Override
90+
protected void prepareClients(int port, String mcpEndpoint) {
91+
}
92+
93+
}

mcp/src/test/java/io/modelcontextprotocol/server/HttpServletStreamableIntegrationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void before() {
5555
.put("httpclient",
5656
McpClient.sync(HttpClientStreamableHttpTransport.builder("http://localhost:" + PORT)
5757
.endpoint(MESSAGE_ENDPOINT)
58-
.build()).initializationTimeout(Duration.ofHours(10)).requestTimeout(Duration.ofHours(10)));
58+
.build()).requestTimeout(Duration.ofHours(10)));
5959
}
6060

6161
@Override

0 commit comments

Comments
 (0)