Skip to content

Commit a0ad5a5

Browse files
committed
WIP: resolve integration test issues
Signed-off-by: Dariusz Jędrzejczyk <[email protected]>
1 parent c0e3129 commit a0ad5a5

File tree

2 files changed

+26
-23
lines changed

2 files changed

+26
-23
lines changed

mcp-spring/mcp-spring-webflux/src/test/java/io/modelcontextprotocol/WebFluxStreamableIntegrationTests.java

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ public void after() {
117117
// ---------------------------------------
118118
// Sampling Tests
119119
// ---------------------------------------
120-
// @ParameterizedTest(name = "{0} : {displayName} ")
121-
// @ValueSource(strings = { "httpclient", "webflux" })
120+
@ParameterizedTest(name = "{0} : {displayName} ")
121+
@ValueSource(strings = { "httpclient", "webflux" })
122122
void testCreateMessageWithoutSamplingCapabilities(String clientType) {
123123

124124
var clientBuilder = clientBuilders.get(clientType);
@@ -298,8 +298,8 @@ void testCreateMessageWithRequestTimeoutSuccess(String clientType) throws Interr
298298
mcpServer.closeGracefully().block();
299299
}
300300

301-
// @ParameterizedTest(name = "{0} : {displayName} ")
302-
// @ValueSource(strings = { "httpclient", "webflux" })
301+
@ParameterizedTest(name = "{0} : {displayName} ")
302+
@ValueSource(strings = { "httpclient", "webflux" })
303303
void testCreateMessageWithRequestTimeoutFail(String clientType) throws InterruptedException {
304304

305305
// Client
@@ -361,20 +361,16 @@ void testCreateMessageWithRequestTimeoutFail(String clientType) throws Interrupt
361361
// ---------------------------------------
362362
// Elicitation Tests
363363
// ---------------------------------------
364-
// @ParameterizedTest(name = "{0} : {displayName} ")
365-
// @ValueSource(strings = { "httpclient", "webflux" })
364+
@ParameterizedTest(name = "{0} : {displayName} ")
365+
@ValueSource(strings = { "httpclient", "webflux" })
366366
void testCreateElicitationWithoutElicitationCapabilities(String clientType) {
367367

368368
var clientBuilder = clientBuilders.get(clientType);
369369

370370
McpServerFeatures.AsyncToolSpecification tool = McpServerFeatures.AsyncToolSpecification.builder()
371371
.tool(new Tool("tool1", "tool1 description", emptyJsonSchema))
372-
.callHandler((exchange, request) -> {
373-
374-
exchange.createElicitation(mock(ElicitRequest.class)).block();
375-
376-
return Mono.just(mock(CallToolResult.class));
377-
})
372+
.callHandler((exchange, request) -> exchange.createElicitation(mock(ElicitRequest.class))
373+
.then(Mono.just(mock(CallToolResult.class))))
378374
.build();
379375

380376
var server = McpServer.async(mcpStreamableServerTransportProvider)
@@ -515,8 +511,8 @@ void testCreateElicitationWithRequestTimeoutSuccess(String clientType) {
515511
mcpServer.closeGracefully().block();
516512
}
517513

518-
// @ParameterizedTest(name = "{0} : {displayName} ")
519-
// @ValueSource(strings = { "httpclient", "webflux" })
514+
@ParameterizedTest(name = "{0} : {displayName} ")
515+
@ValueSource(strings = { "httpclient", "webflux" })
520516
void testCreateElicitationWithRequestTimeoutFail(String clientType) {
521517

522518
var latch = new CountDownLatch(1);
@@ -547,6 +543,8 @@ void testCreateElicitationWithRequestTimeoutFail(String clientType) {
547543

548544
CallToolResult callResponse = new CallToolResult(List.of(new McpSchema.TextContent("CALL RESPONSE")), null);
549545

546+
AtomicReference<ElicitResult> resultRef = new AtomicReference<>();
547+
550548
McpServerFeatures.AsyncToolSpecification tool = McpServerFeatures.AsyncToolSpecification.builder()
551549
.tool(new Tool("tool1", "tool1 description", emptyJsonSchema))
552550
.callHandler((exchange, request) -> {
@@ -557,13 +555,9 @@ void testCreateElicitationWithRequestTimeoutFail(String clientType) {
557555
Map.of("type", "object", "properties", Map.of("message", Map.of("type", "string"))))
558556
.build();
559557

560-
StepVerifier.create(exchange.createElicitation(elicitationRequest)).consumeNextWith(result -> {
561-
assertThat(result).isNotNull();
562-
assertThat(result.action()).isEqualTo(ElicitResult.Action.ACCEPT);
563-
assertThat(result.content().get("message")).isEqualTo("Test message");
564-
}).verifyComplete();
565-
566-
return Mono.just(callResponse);
558+
return exchange.createElicitation(elicitationRequest)
559+
.doOnNext(resultRef::set)
560+
.then(Mono.just(callResponse));
567561
})
568562
.build();
569563

@@ -580,6 +574,9 @@ void testCreateElicitationWithRequestTimeoutFail(String clientType) {
580574
mcpClient.callTool(new McpSchema.CallToolRequest("tool1", Map.of()));
581575
}).withMessageContaining("within 1000ms");
582576

577+
ElicitResult elicitResult = resultRef.get();
578+
assertThat(elicitResult).isNull();
579+
583580
mcpClient.closeGracefully();
584581
mcpServer.closeGracefully().block();
585582
}
@@ -634,8 +631,8 @@ void testRootsSuccess(String clientType) {
634631
mcpServer.close();
635632
}
636633

637-
// @ParameterizedTest(name = "{0} : {displayName} ")
638-
// @ValueSource(strings = { "httpclient", "webflux" })
634+
@ParameterizedTest(name = "{0} : {displayName} ")
635+
@ValueSource(strings = { "httpclient", "webflux" })
639636
void testRootsWithoutCapability(String clientType) {
640637

641638
var clientBuilder = clientBuilders.get(clientType);

mcp/src/main/java/io/modelcontextprotocol/spec/McpStreamableServerSession.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,12 @@ public Mono<Void> responseStream(McpSchema.JSONRPCRequest jsonrpcRequest, McpStr
146146
transportContext), jsonrpcRequest.params())
147147
.map(result -> new McpSchema.JSONRPCResponse(McpSchema.JSONRPC_VERSION, jsonrpcRequest.id(), result,
148148
null))
149+
.onErrorResume(e -> {
150+
var errorResponse = new McpSchema.JSONRPCResponse(McpSchema.JSONRPC_VERSION, jsonrpcRequest.id(),
151+
null, new McpSchema.JSONRPCResponse.JSONRPCError(McpSchema.ErrorCodes.INTERNAL_ERROR,
152+
e.getMessage(), null));
153+
return Mono.just(errorResponse);
154+
})
149155
.flatMap(transport::sendMessage)
150156
.then(transport.closeGracefully());
151157
});

0 commit comments

Comments
 (0)