6
6
import java .util .Arrays ;
7
7
import java .util .Collections ;
8
8
import java .util .HashMap ;
9
+ import java .util .List ;
9
10
import java .util .Map ;
10
11
11
12
import com .fasterxml .jackson .databind .ObjectMapper ;
@@ -493,6 +494,25 @@ void testCallToolRequest() throws Exception {
493
494
{"name":"test-tool","arguments":{"name":"test","value":42}}""" ));
494
495
}
495
496
497
+ @ Test
498
+ void testCallToolRequestJsonArguments () throws Exception {
499
+
500
+ McpSchema .CallToolRequest request = new McpSchema .CallToolRequest ("test-tool" , """
501
+ {
502
+ "name": "test",
503
+ "value": 42
504
+ }
505
+ """ );
506
+
507
+ String value = mapper .writeValueAsString (request );
508
+
509
+ assertThatJson (value ).when (Option .IGNORING_ARRAY_ORDER )
510
+ .when (Option .IGNORING_EXTRA_ARRAY_ITEMS )
511
+ .isObject ()
512
+ .isEqualTo (json ("""
513
+ {"name":"test-tool","arguments":{"name":"test","value":42}}""" ));
514
+ }
515
+
496
516
@ Test
497
517
void testCallToolResult () throws Exception {
498
518
McpSchema .TextContent content = new McpSchema .TextContent ("Tool execution result" );
@@ -508,6 +528,98 @@ void testCallToolResult() throws Exception {
508
528
{"content":[{"type":"text","text":"Tool execution result"}],"isError":false}""" ));
509
529
}
510
530
531
+ @ Test
532
+ void testCallToolResultBuilder () throws Exception {
533
+ McpSchema .CallToolResult result = McpSchema .CallToolResult .builder ()
534
+ .addTextContent ("Tool execution result" )
535
+ .isError (false )
536
+ .build ();
537
+
538
+ String value = mapper .writeValueAsString (result );
539
+
540
+ assertThatJson (value ).when (Option .IGNORING_ARRAY_ORDER )
541
+ .when (Option .IGNORING_EXTRA_ARRAY_ITEMS )
542
+ .isObject ()
543
+ .isEqualTo (json ("""
544
+ {"content":[{"type":"text","text":"Tool execution result"}],"isError":false}""" ));
545
+ }
546
+
547
+ @ Test
548
+ void testCallToolResultBuilderWithMultipleContents () throws Exception {
549
+ McpSchema .TextContent textContent = new McpSchema .TextContent ("Text result" );
550
+ McpSchema .ImageContent imageContent = new McpSchema .ImageContent (null , null , "base64data" , "image/png" );
551
+
552
+ McpSchema .CallToolResult result = McpSchema .CallToolResult .builder ()
553
+ .addContent (textContent )
554
+ .addContent (imageContent )
555
+ .isError (false )
556
+ .build ();
557
+
558
+ String value = mapper .writeValueAsString (result );
559
+
560
+ assertThatJson (value ).when (Option .IGNORING_ARRAY_ORDER )
561
+ .when (Option .IGNORING_EXTRA_ARRAY_ITEMS )
562
+ .isObject ()
563
+ .isEqualTo (
564
+ json ("""
565
+ {"content":[{"type":"text","text":"Text result"},{"type":"image","data":"base64data","mimeType":"image/png"}],"isError":false}""" ));
566
+ }
567
+
568
+ @ Test
569
+ void testCallToolResultBuilderWithContentList () throws Exception {
570
+ McpSchema .TextContent textContent = new McpSchema .TextContent ("Text result" );
571
+ McpSchema .ImageContent imageContent = new McpSchema .ImageContent (null , null , "base64data" , "image/png" );
572
+ List <McpSchema .Content > contents = Arrays .asList (textContent , imageContent );
573
+
574
+ McpSchema .CallToolResult result = McpSchema .CallToolResult .builder ().content (contents ).isError (true ).build ();
575
+
576
+ String value = mapper .writeValueAsString (result );
577
+
578
+ assertThatJson (value ).when (Option .IGNORING_ARRAY_ORDER )
579
+ .when (Option .IGNORING_EXTRA_ARRAY_ITEMS )
580
+ .isObject ()
581
+ .isEqualTo (
582
+ json ("""
583
+ {"content":[{"type":"text","text":"Text result"},{"type":"image","data":"base64data","mimeType":"image/png"}],"isError":true}""" ));
584
+ }
585
+
586
+ @ Test
587
+ void testCallToolResultBuilderWithErrorResult () throws Exception {
588
+ McpSchema .CallToolResult result = McpSchema .CallToolResult .builder ()
589
+ .addTextContent ("Error: Operation failed" )
590
+ .isError (true )
591
+ .build ();
592
+
593
+ String value = mapper .writeValueAsString (result );
594
+
595
+ assertThatJson (value ).when (Option .IGNORING_ARRAY_ORDER )
596
+ .when (Option .IGNORING_EXTRA_ARRAY_ITEMS )
597
+ .isObject ()
598
+ .isEqualTo (json ("""
599
+ {"content":[{"type":"text","text":"Error: Operation failed"}],"isError":true}""" ));
600
+ }
601
+
602
+ @ Test
603
+ void testCallToolResultStringConstructor () throws Exception {
604
+ // Test the existing string constructor alongside the builder
605
+ McpSchema .CallToolResult result1 = new McpSchema .CallToolResult ("Simple result" , false );
606
+ McpSchema .CallToolResult result2 = McpSchema .CallToolResult .builder ()
607
+ .addTextContent ("Simple result" )
608
+ .isError (false )
609
+ .build ();
610
+
611
+ String value1 = mapper .writeValueAsString (result1 );
612
+ String value2 = mapper .writeValueAsString (result2 );
613
+
614
+ // Both should produce the same JSON
615
+ assertThat (value1 ).isEqualTo (value2 );
616
+ assertThatJson (value1 ).when (Option .IGNORING_ARRAY_ORDER )
617
+ .when (Option .IGNORING_EXTRA_ARRAY_ITEMS )
618
+ .isObject ()
619
+ .isEqualTo (json ("""
620
+ {"content":[{"type":"text","text":"Simple result"}],"isError":false}""" ));
621
+ }
622
+
511
623
// Sampling Tests
512
624
513
625
@ Test
0 commit comments