@@ -240,55 +240,14 @@ void testRequestHandlerThrowsGenericException() {
240240 McpSchema .JSONRPCRequest request = new McpSchema .JSONRPCRequest (testMethod , "test-id" );
241241 transport .simulateIncomingMessage (request );
242242
243- // Verify: The response should contain INTERNAL_ERROR with aggregated exception
244- // messages in data field
243+ // Verify: The response should contain INTERNAL_ERROR with the exception message
245244 McpSchema .JSONRPCMessage sentMessage = transport .getLastSentMessage ();
246245 assertThat (sentMessage ).isInstanceOf (McpSchema .JSONRPCResponse .class );
247246 McpSchema .JSONRPCResponse response = (McpSchema .JSONRPCResponse ) sentMessage ;
248247 assertThat (response .error ()).isNotNull ();
249248 assertThat (response .error ().code ()).isEqualTo (McpSchema .ErrorCodes .INTERNAL_ERROR );
250249 assertThat (response .error ().message ()).isEqualTo ("Something went wrong" );
251- // Verify data field contains aggregated exception messages
252- assertThat (response .error ().data ()).isNotNull ();
253- assertThat (response .error ().data ().toString ()).contains ("RuntimeException" );
254- assertThat (response .error ().data ().toString ()).contains ("Something went wrong" );
255-
256- session .close ();
257- }
258-
259- @ Test
260- void testRequestHandlerThrowsExceptionWithCause () {
261- // Setup: Create a request handler that throws an exception with a cause chain
262- String testMethod = "test.chainedError" ;
263- RuntimeException rootCause = new IllegalArgumentException ("Root cause message" );
264- RuntimeException middleCause = new IllegalStateException ("Middle cause message" , rootCause );
265- RuntimeException topException = new RuntimeException ("Top level message" , middleCause );
266- McpClientSession .RequestHandler <?> failingHandler = params -> Mono .error (topException );
267-
268- var transport = new MockMcpClientTransport ();
269- var session = new McpClientSession (TIMEOUT , transport , Map .of (testMethod , failingHandler ), Map .of (),
270- Function .identity ());
271-
272- // Simulate incoming request that will trigger the error
273- McpSchema .JSONRPCRequest request = new McpSchema .JSONRPCRequest (testMethod , "test-id" );
274- transport .simulateIncomingMessage (request );
275-
276- // Verify: The response should contain INTERNAL_ERROR with full exception chain
277- // in data field
278- McpSchema .JSONRPCMessage sentMessage = transport .getLastSentMessage ();
279- assertThat (sentMessage ).isInstanceOf (McpSchema .JSONRPCResponse .class );
280- McpSchema .JSONRPCResponse response = (McpSchema .JSONRPCResponse ) sentMessage ;
281- assertThat (response .error ()).isNotNull ();
282- assertThat (response .error ().code ()).isEqualTo (McpSchema .ErrorCodes .INTERNAL_ERROR );
283- assertThat (response .error ().message ()).isEqualTo ("Top level message" );
284- // Verify data field contains the full exception chain
285- String dataString = response .error ().data ().toString ();
286- assertThat (dataString ).contains ("RuntimeException" );
287- assertThat (dataString ).contains ("Top level message" );
288- assertThat (dataString ).contains ("IllegalStateException" );
289- assertThat (dataString ).contains ("Middle cause message" );
290- assertThat (dataString ).contains ("IllegalArgumentException" );
291- assertThat (dataString ).contains ("Root cause message" );
250+ assertThat (response .error ().data ()).isNull ();
292251
293252 session .close ();
294253 }
0 commit comments