Skip to content
This repository was archived by the owner on Feb 14, 2025. It is now read-only.

Commit 9aba371

Browse files
committed
feat: Add SSE transport tests for MCP client and server
- Add tests for HttpServletSseServerTransport implementation - Add tests for HttpClientSseClientTransport implementation - Rename STDIO transport test classes for clarity
1 parent 5a73a30 commit 9aba371

File tree

6 files changed

+198
-2
lines changed

6 files changed

+198
-2
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright 2024-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.ai.mcp.client;
18+
19+
import org.junit.jupiter.api.Timeout;
20+
import org.testcontainers.containers.GenericContainer;
21+
import org.testcontainers.containers.wait.strategy.Wait;
22+
23+
import org.springframework.ai.mcp.client.transport.HttpClientSseClientTransport;
24+
import org.springframework.ai.mcp.spec.ClientMcpTransport;
25+
26+
/**
27+
* Tests for the {@link McpSyncClient} with {@link HttpClientSseClientTransport}.
28+
*
29+
* @author Christian Tzolov
30+
*/
31+
@Timeout(15) // Giving extra time beyond the client timeout
32+
class ServletSseMcpAsyncClientTests extends AbstractMcpAsyncClientTests {
33+
34+
String host = "http://localhost:3004";
35+
36+
// Uses the https://github.com/tzolov/mcp-everything-server-docker-image
37+
@SuppressWarnings("resource")
38+
GenericContainer<?> container = new GenericContainer<>("docker.io/tzolov/mcp-everything-server:v1")
39+
.withLogConsumer(outputFrame -> System.out.println(outputFrame.getUtf8String()))
40+
.withExposedPorts(3001)
41+
.waitingFor(Wait.forHttp("/").forStatusCode(404));
42+
43+
@Override
44+
protected ClientMcpTransport createMcpTransport() {
45+
return new HttpClientSseClientTransport(host);
46+
}
47+
48+
@Override
49+
protected void onStart() {
50+
container.start();
51+
int port = container.getMappedPort(3001);
52+
host = "http://" + container.getHost() + ":" + port;
53+
}
54+
55+
@Override
56+
protected void onClose() {
57+
container.stop();
58+
}
59+
60+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright 2024-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.ai.mcp.client;
18+
19+
import org.junit.jupiter.api.Timeout;
20+
import org.testcontainers.containers.GenericContainer;
21+
import org.testcontainers.containers.wait.strategy.Wait;
22+
23+
import org.springframework.ai.mcp.client.transport.HttpClientSseClientTransport;
24+
import org.springframework.ai.mcp.spec.ClientMcpTransport;
25+
26+
/**
27+
* Tests for the {@link McpSyncClient} with {@link HttpClientSseClientTransport}.
28+
*
29+
* @author Christian Tzolov
30+
*/
31+
@Timeout(15) // Giving extra time beyond the client timeout
32+
class ServletSseMcpSyncClientTests extends AbstractMcpSyncClientTests {
33+
34+
String host = "http://localhost:3003";
35+
36+
// Uses the https://github.com/tzolov/mcp-everything-server-docker-image
37+
@SuppressWarnings("resource")
38+
GenericContainer<?> container = new GenericContainer<>("docker.io/tzolov/mcp-everything-server:v1")
39+
.withLogConsumer(outputFrame -> System.out.println(outputFrame.getUtf8String()))
40+
.withExposedPorts(3001)
41+
.waitingFor(Wait.forHttp("/").forStatusCode(404));
42+
43+
@Override
44+
protected ClientMcpTransport createMcpTransport() {
45+
return new HttpClientSseClientTransport(host);
46+
}
47+
48+
@Override
49+
protected void onStart() {
50+
container.start();
51+
int port = container.getMappedPort(3001);
52+
host = "http://" + container.getHost() + ":" + port;
53+
}
54+
55+
@Override
56+
protected void onClose() {
57+
container.stop();
58+
}
59+
60+
}

mcp/src/test/java/org/springframework/ai/mcp/client/McpAsyncClientTests.java renamed to mcp/src/test/java/org/springframework/ai/mcp/client/StdioMcpAsyncClientTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* @author Dariusz Jędrzejczyk
3030
*/
3131
@Timeout(15) // Giving extra time beyond the client timeout
32-
class McpAsyncClientTests extends AbstractMcpAsyncClientTests {
32+
class StdioMcpAsyncClientTests extends AbstractMcpAsyncClientTests {
3333

3434
@Override
3535
protected ClientMcpTransport createMcpTransport() {

mcp/src/test/java/org/springframework/ai/mcp/client/McpSyncClientTests.java renamed to mcp/src/test/java/org/springframework/ai/mcp/client/StdioMcpSyncClientTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
* @author Dariusz Jędrzejczyk
3535
*/
3636
@Timeout(15) // Giving extra time beyond the client timeout
37-
class McpSyncClientTests extends AbstractMcpSyncClientTests {
37+
class StdioMcpSyncClientTests extends AbstractMcpSyncClientTests {
3838

3939
@Override
4040
protected ClientMcpTransport createMcpTransport() {
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2024-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.ai.mcp.server;
18+
19+
import com.fasterxml.jackson.databind.ObjectMapper;
20+
import org.junit.jupiter.api.Timeout;
21+
22+
import org.springframework.ai.mcp.server.transport.HttpServletSseServerTransport;
23+
import org.springframework.ai.mcp.spec.ServerMcpTransport;
24+
25+
/**
26+
* Tests for {@link McpAsyncServer} using {@link HttpServletSseServerTransport}.
27+
*
28+
* @author Christian Tzolov
29+
*/
30+
@Timeout(15) // Giving extra time beyond the client timeout
31+
class ServletSseMcpAsyncServerTests extends AbstractMcpAsyncServerTests {
32+
33+
@Override
34+
protected ServerMcpTransport createMcpTransport() {
35+
return new HttpServletSseServerTransport(new ObjectMapper(), "/mcp/message");
36+
}
37+
38+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2024-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.ai.mcp.server;
18+
19+
import com.fasterxml.jackson.databind.ObjectMapper;
20+
import org.junit.jupiter.api.Timeout;
21+
22+
import org.springframework.ai.mcp.server.transport.HttpServletSseServerTransport;
23+
import org.springframework.ai.mcp.spec.ServerMcpTransport;
24+
25+
/**
26+
* Tests for {@link McpSyncServer} using {@link HttpServletSseServerTransport}.
27+
*
28+
* @author Christian Tzolov
29+
*/
30+
@Timeout(15) // Giving extra time beyond the client timeout
31+
class ServletSseMcpSyncServerTests extends AbstractMcpSyncServerTests {
32+
33+
@Override
34+
protected ServerMcpTransport createMcpTransport() {
35+
return new HttpServletSseServerTransport(new ObjectMapper(), "/mcp/message");
36+
}
37+
38+
}

0 commit comments

Comments
 (0)