@@ -839,5 +839,123 @@ def call(message:, server_context: nil)
839839
840840 refute_includes server_without_resources . capabilities , :resources
841841 end
842+
843+ test "tools/call validates arguments against input schema when validate_tool_call_arguments is true" do
844+ server = Server . new (
845+ tools : [ TestTool ] ,
846+ configuration : Configuration . new ( validate_tool_call_arguments : true ) ,
847+ )
848+
849+ response = server . handle (
850+ {
851+ jsonrpc : "2.0" ,
852+ id : 1 ,
853+ method : "tools/call" ,
854+ params : {
855+ name : "test_tool" ,
856+ arguments : { message : 123 } ,
857+ } ,
858+ } ,
859+ )
860+
861+ assert_equal "2.0" , response [ :jsonrpc ]
862+ assert_equal 1 , response [ :id ]
863+ assert_equal ( -32603 , response [ :error ] [ :code ] )
864+ assert_includes response [ :error ] [ :data ] , "Invalid arguments"
865+ end
866+
867+ test "tools/call skips argument validation when validate_tool_call_arguments is false" do
868+ server = Server . new (
869+ tools : [ TestTool ] ,
870+ configuration : Configuration . new ( validate_tool_call_arguments : false ) ,
871+ )
872+
873+ response = server . handle (
874+ {
875+ jsonrpc : "2.0" ,
876+ id : 1 ,
877+ method : "tools/call" ,
878+ params : {
879+ name : "test_tool" ,
880+ arguments : { message : 123 } ,
881+ } ,
882+ } ,
883+ )
884+
885+ assert_equal "2.0" , response [ :jsonrpc ]
886+ assert_equal 1 , response [ :id ]
887+ assert response [ :result ] , "Expected result key in response"
888+ assert_equal "text" , response [ :result ] [ :content ] [ 0 ] [ :type ]
889+ assert_equal "OK" , response [ :result ] [ :content ] [ 0 ] [ :content ]
890+ end
891+
892+ test "tools/call validates arguments with complex types" do
893+ server = Server . new (
894+ tools : [ ComplexTypesTool ] ,
895+ configuration : Configuration . new ( validate_tool_call_arguments : true ) ,
896+ )
897+
898+ response = server . handle (
899+ {
900+ jsonrpc : "2.0" ,
901+ id : 1 ,
902+ method : "tools/call" ,
903+ params : {
904+ name : "complex_types_tool" ,
905+ arguments : {
906+ numbers : [ 1 , 2 , 3 ] ,
907+ strings : [ "a" , "b" , "c" ] ,
908+ objects : [ { name : "test" } ] ,
909+ } ,
910+ } ,
911+ } ,
912+ )
913+
914+ assert_equal "2.0" , response [ :jsonrpc ]
915+ assert_equal 1 , response [ :id ]
916+ assert response [ :result ] , "Expected result key in response"
917+ assert_equal "text" , response [ :result ] [ :content ] [ 0 ] [ :type ]
918+ assert_equal "OK" , response [ :result ] [ :content ] [ 0 ] [ :content ]
919+ end
920+
921+ class TestTool < Tool
922+ tool_name "test_tool"
923+ description "a test tool for testing"
924+ input_schema ( { properties : { message : { type : "string" } } , required : [ "message" ] } )
925+
926+ class << self
927+ def call ( message :, server_context : nil )
928+ Tool ::Response . new ( [ { type : "text" , content : "OK" } ] )
929+ end
930+ end
931+ end
932+
933+ class ComplexTypesTool < Tool
934+ tool_name "complex_types_tool"
935+ description "a test tool with complex types"
936+ input_schema ( {
937+ properties : {
938+ numbers : { type : "array" , items : { type : "number" } } ,
939+ strings : { type : "array" , items : { type : "string" } } ,
940+ objects : {
941+ type : "array" ,
942+ items : {
943+ type : "object" ,
944+ properties : {
945+ name : { type : "string" } ,
946+ } ,
947+ required : [ "name" ] ,
948+ } ,
949+ } ,
950+ } ,
951+ required : [ "numbers" , "strings" , "objects" ] ,
952+ } )
953+
954+ class << self
955+ def call ( numbers :, strings :, objects :, server_context : nil )
956+ Tool ::Response . new ( [ { type : "text" , content : "OK" } ] )
957+ end
958+ end
959+ end
842960 end
843961end
0 commit comments