@@ -431,6 +431,36 @@ class Example < Tool
431431 assert_instrumentation_data ( { method : "tools/call" , tool_name : "tool_that_raises" } )
432432 end
433433
434+ test "#handle tools/call returns error response with isError true if input_schema raises an error during validation" do
435+ tool = Tool . define (
436+ name : "tool_with_faulty_schema" ,
437+ title : "Tool with faulty schema" ,
438+ description : "A tool with a faulty schema" ,
439+ input_schema : { type : "object" , properties : { message : { type : "string" } } , required : [ "message" ] } ,
440+ ) { Tool ::Response . new ( "success" ) }
441+
442+ tool . input_schema . expects ( :missing_required_arguments? ) . raises ( RuntimeError , "Unexpected schema error" )
443+
444+ server = Server . new ( name : "test_server" , tools : [ tool ] )
445+
446+ request = {
447+ jsonrpc : "2.0" ,
448+ method : "tools/call" ,
449+ params : {
450+ name : "tool_with_faulty_schema" ,
451+ arguments : { message : "test" } ,
452+ } ,
453+ id : 1 ,
454+ }
455+
456+ response = server . handle ( request )
457+
458+ assert_nil response [ :error ] , "Expected no JSON-RPC error"
459+ assert response [ :result ] [ :isError ]
460+ assert_equal "text" , response [ :result ] [ :content ] [ 0 ] [ :type ]
461+ assert_match ( /Internal error calling tool tool_with_faulty_schema: Unexpected schema error/ , response [ :result ] [ :content ] [ 0 ] [ :text ] )
462+ end
463+
434464 test "#handle tools/call returns error response with isError true for unknown tool" do
435465 request = {
436466 jsonrpc : "2.0" ,
0 commit comments