Skip to content

Commit 446c633

Browse files
committed
feat: Add tests
1 parent a1266cd commit 446c633

File tree

2 files changed

+72
-1
lines changed

2 files changed

+72
-1
lines changed

mcp/src/main/java/io/modelcontextprotocol/server/McpServerFeatures.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ record Sync(McpSchema.Implementation serverInfo, McpSchema.ServerCapabilities se
209209
* represents a specific capability.
210210
*
211211
* @param tool The tool definition including name, description, and parameter schema
212-
* @param call Deprecated. Uset he {@link AsyncToolSpecification#callHandler} instead.
212+
* @param call Deprecated. Use the {@link AsyncToolSpecification#callHandler} instead.
213213
* @param callHandler The function that implements the tool's logic, receiving a
214214
* {@link McpAsyncServerExchange} and a
215215
* {@link io.modelcontextprotocol.spec.McpSchema.CallToolRequest} and returning

mcp/src/test/java/io/modelcontextprotocol/server/transport/HttpServletSseServerTransportProviderIntegrationTests.java

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,4 +1070,75 @@ void testPingSuccess() {
10701070
mcpServer.close();
10711071
}
10721072

1073+
// ---------------------------------------
1074+
// Progress Tests
1075+
// ---------------------------------------
1076+
@Test
1077+
void testProgressNotification() {
1078+
// Create a list to store received logging notifications
1079+
List<McpSchema.ProgressNotification> receivedNotifications = new ArrayList<>();
1080+
1081+
// Create server with a tool that sends logging notifications
1082+
1083+
McpServerFeatures.AsyncToolSpecification tool = new McpServerFeatures.AsyncToolSpecification(
1084+
new McpSchema.Tool("progress-test", "Test progress notifications", emptyJsonSchema), null,
1085+
(exchange, request) -> {
1086+
var progressToken = (String) request.meta().get("progressToken");
1087+
1088+
exchange
1089+
.progressNotification(
1090+
new McpSchema.ProgressNotification(progressToken, 0.1, 1.0, "Test progress 1/10"))
1091+
.block();
1092+
1093+
exchange
1094+
.progressNotification(
1095+
new McpSchema.ProgressNotification(progressToken, 0.5, 1.0, "Test progress 5/10"))
1096+
.block();
1097+
1098+
exchange
1099+
.progressNotification(
1100+
new McpSchema.ProgressNotification(progressToken, 1.0, 1.0, "Test progress 10/10"))
1101+
.block();
1102+
1103+
return Mono.just(new CallToolResult("Progress test completed", false));
1104+
});
1105+
1106+
var mcpServer = McpServer.async(mcpServerTransportProvider)
1107+
.serverInfo("test-server", "1.0.0")
1108+
.capabilities(ServerCapabilities.builder().logging().tools(true).build())
1109+
.tools(tool)
1110+
.build();
1111+
try (
1112+
// Create client with progress notification handler
1113+
var mcpClient = clientBuilder.progressConsumer(receivedNotifications::add).build()) {
1114+
1115+
// Initialize client
1116+
InitializeResult initResult = mcpClient.initialize();
1117+
assertThat(initResult).isNotNull();
1118+
1119+
// Call the tool that sends progress notifications
1120+
CallToolResult result = mcpClient.callTool(
1121+
new McpSchema.CallToolRequest("progress-test", Map.of(), Map.of("progressToken", "test-token")));
1122+
assertThat(result).isNotNull();
1123+
assertThat(result.content().get(0)).isInstanceOf(McpSchema.TextContent.class);
1124+
assertThat(((McpSchema.TextContent) result.content().get(0)).text()).isEqualTo("Progress test completed");
1125+
1126+
// Wait for notifications to be processed
1127+
await().atMost(Duration.ofSeconds(5)).untilAsserted(() -> {
1128+
1129+
System.out.println("Received notifications: " + receivedNotifications);
1130+
1131+
// Should have received 3 notifications
1132+
assertThat(receivedNotifications).hasSize(3);
1133+
1134+
// Check the progress notifications
1135+
assertThat(receivedNotifications.stream().map(McpSchema.ProgressNotification::progressToken))
1136+
.containsExactlyInAnyOrder("test-token", "test-token", "test-token");
1137+
assertThat(receivedNotifications.stream().map(McpSchema.ProgressNotification::progress))
1138+
.containsExactlyInAnyOrder(0.1, 0.5, 1.0);
1139+
});
1140+
}
1141+
mcpServer.close();
1142+
}
1143+
10731144
}

0 commit comments

Comments
 (0)