35
35
import org .junit .jupiter .api .BeforeEach ;
36
36
import org .junit .jupiter .params .ParameterizedTest ;
37
37
import org .junit .jupiter .params .provider .ValueSource ;
38
- import reactor .core .publisher .Mono ;
39
38
import reactor .netty .DisposableServer ;
40
39
import reactor .netty .http .server .HttpServer ;
41
- import reactor .test .StepVerifier ;
42
40
43
41
import org .springframework .http .server .reactive .HttpHandler ;
44
42
import org .springframework .http .server .reactive .ReactorHttpHandlerAdapter ;
47
45
import org .springframework .web .reactive .function .server .RouterFunctions ;
48
46
49
47
import static org .assertj .core .api .Assertions .assertThat ;
48
+ import static org .assertj .core .api .Assertions .assertWith ;
50
49
import static org .awaitility .Awaitility .await ;
51
50
import static org .mockito .Mockito .mock ;
52
51
@@ -106,12 +105,9 @@ void testCreateMessageWithoutSamplingCapabilities(String clientType) {
106
105
var clientBuilder = clientBuilders .get (clientType );
107
106
108
107
McpServerFeatures .AsyncToolSpecification tool = new McpServerFeatures .AsyncToolSpecification (
109
- new McpSchema .Tool ("tool1" , "tool1 description" , emptyJsonSchema ), (exchange , request ) -> {
110
-
111
- exchange .createMessage (mock (McpSchema .CreateMessageRequest .class )).block ();
112
-
113
- return Mono .just (mock (CallToolResult .class ));
114
- });
108
+ new McpSchema .Tool ("tool1" , "tool1 description" , emptyJsonSchema ),
109
+ (exchange , request ) -> exchange .createMessage (mock (CreateMessageRequest .class ))
110
+ .thenReturn (mock (CallToolResult .class )));
115
111
116
112
var server = McpServer .async (mcpServerTransportProvider ).serverInfo ("test-server" , "1.0.0" ).tools (tool ).build ();
117
113
@@ -148,6 +144,8 @@ void testCreateMessageSuccess(String clientType) throws InterruptedException {
148
144
CallToolResult callResponse = new McpSchema .CallToolResult (List .of (new McpSchema .TextContent ("CALL RESPONSE" )),
149
145
null );
150
146
147
+ AtomicReference <CreateMessageResult > samplingResult = new AtomicReference <>();
148
+
151
149
McpServerFeatures .AsyncToolSpecification tool = new McpServerFeatures .AsyncToolSpecification (
152
150
new McpSchema .Tool ("tool1" , "tool1 description" , emptyJsonSchema ), (exchange , request ) -> {
153
151
@@ -162,16 +160,9 @@ void testCreateMessageSuccess(String clientType) throws InterruptedException {
162
160
.build ())
163
161
.build ();
164
162
165
- StepVerifier .create (exchange .createMessage (craeteMessageRequest )).consumeNextWith (result -> {
166
- assertThat (result ).isNotNull ();
167
- assertThat (result .role ()).isEqualTo (Role .USER );
168
- assertThat (result .content ()).isInstanceOf (McpSchema .TextContent .class );
169
- assertThat (((McpSchema .TextContent ) result .content ()).text ()).isEqualTo ("Test message" );
170
- assertThat (result .model ()).isEqualTo ("MockModelName" );
171
- assertThat (result .stopReason ()).isEqualTo (CreateMessageResult .StopReason .STOP_SEQUENCE );
172
- }).verifyComplete ();
173
-
174
- return Mono .just (callResponse );
163
+ return exchange .createMessage (craeteMessageRequest )
164
+ .doOnNext (samplingResult ::set )
165
+ .thenReturn (callResponse );
175
166
});
176
167
177
168
var mcpServer = McpServer .async (mcpServerTransportProvider )
@@ -191,8 +182,17 @@ void testCreateMessageSuccess(String clientType) throws InterruptedException {
191
182
192
183
assertThat (response ).isNotNull ();
193
184
assertThat (response ).isEqualTo (callResponse );
185
+
186
+ assertWith (samplingResult .get (), result -> {
187
+ assertThat (result ).isNotNull ();
188
+ assertThat (result .role ()).isEqualTo (Role .USER );
189
+ assertThat (result .content ()).isInstanceOf (McpSchema .TextContent .class );
190
+ assertThat (((McpSchema .TextContent ) result .content ()).text ()).isEqualTo ("Test message" );
191
+ assertThat (result .model ()).isEqualTo ("MockModelName" );
192
+ assertThat (result .stopReason ()).isEqualTo (CreateMessageResult .StopReason .STOP_SEQUENCE );
193
+ });
194
194
}
195
- mcpServer .close ();
195
+ mcpServer .closeGracefully (). block ();
196
196
}
197
197
198
198
// ---------------------------------------
0 commit comments