@@ -296,34 +296,10 @@ void testCreateMessageWithRequestTimeoutSuccess() throws Exception {
296296
297297 @ Test
298298 void testCreateMessageWithRequestTimeoutFail () throws Exception {
299-
300- // Client
301-
302- Function <CreateMessageRequest , CreateMessageResult > samplingHandler = request -> {
303- assertThat (request .messages ()).hasSize (1 );
304- assertThat (request .messages ().get (0 ).content ()).isInstanceOf (McpSchema .TextContent .class );
305- try {
306- TimeUnit .SECONDS .sleep (2 );
307- }
308- catch (InterruptedException e ) {
309- throw new RuntimeException (e );
310- }
311- return new CreateMessageResult (Role .USER , new McpSchema .TextContent ("Test message" ), "MockModelName" ,
312- CreateMessageResult .StopReason .STOP_SEQUENCE );
313- };
314-
315- var mcpClient = clientBuilder .clientInfo (new McpSchema .Implementation ("Sample client" , "0.0.0" ))
316- .capabilities (ClientCapabilities .builder ().sampling ().build ())
317- .sampling (samplingHandler )
318- .build ();
319-
320299 // Server
321- CallToolResult callResponse = new McpSchema .CallToolResult (List .of (new McpSchema .TextContent ("CALL RESPONSE" )),
322- null );
323-
324- McpSchema .JsonSchema jsonSchema = mcpJacksonCodec .getMapper ()
325- .readValue (emptyJsonSchema , McpSchema .JsonSchema .class );
326- McpServerFeatures .AsyncToolSpecification tool = new McpServerFeatures .AsyncToolSpecification (
300+ var callResponse = new McpSchema .CallToolResult (List .of (new McpSchema .TextContent ("CALL RESPONSE" )),null );
301+ var jsonSchema = mcpJacksonCodec .getMapper ().readValue (emptyJsonSchema , McpSchema .JsonSchema .class );
302+ var tool = new McpServerFeatures .AsyncToolSpecification (
327303 new McpSchema .Tool ("tool1" , "tool1 description" , jsonSchema ), (exchange , request ) -> {
328304
329305 var craeteMessageRequest = McpSchema .CreateMessageRequest .builder ()
@@ -348,13 +324,30 @@ void testCreateMessageWithRequestTimeoutFail() throws Exception {
348324
349325 return Mono .just (callResponse );
350326 });
351-
352327 var mcpServer = McpServerFactory .async (mcpServerTransportProvider )
353328 .serverInfo ("test-server" , "1.0.0" )
354329 .requestTimeout (Duration .ofSeconds (1 ))
355330 .tools (tool )
356331 .build ();
357332
333+ // Client
334+ Function <CreateMessageRequest , CreateMessageResult > samplingHandler = request -> {
335+ assertThat (request .messages ()).hasSize (1 );
336+ assertThat (request .messages ().get (0 ).content ()).isInstanceOf (McpSchema .TextContent .class );
337+ try {
338+ TimeUnit .SECONDS .sleep (2 );
339+ }
340+ catch (InterruptedException e ) {
341+ throw new RuntimeException (e );
342+ }
343+ return new CreateMessageResult (Role .USER , new McpSchema .TextContent ("Test message" ), "MockModelName" ,
344+ CreateMessageResult .StopReason .STOP_SEQUENCE );
345+ };
346+ var mcpClient = clientBuilder .clientInfo (new McpSchema .Implementation ("Sample client" , "0.0.0" ))
347+ .capabilities (ClientCapabilities .builder ().sampling ().build ())
348+ .sampling (samplingHandler )
349+ .build ();
350+
358351 InitializeResult initResult = mcpClient .initialize ();
359352 assertThat (initResult ).isNotNull ();
360353
0 commit comments