@@ -726,5 +726,67 @@ class ServerTest < ActiveSupport::TestCase
726726 response = server . handle ( request )
727727 assert_equal custom_version , response [ :result ] [ :protocolVersion ]
728728 end
729+
730+ test "has tool capability only if tools or a tools_list_handler is defined" do
731+ server_with_tools = Server . new ( name : "test_server" , tools : [ @tool ] )
732+
733+ assert_includes server_with_tools . capabilities , :tools
734+
735+ server_with_handler = Server . new ( name : "test_server" )
736+ server_with_handler . tools_list_handler do
737+ [ { name : "test_tool" , description : "Test tool" } ]
738+ end
739+
740+ assert_includes server_with_handler . capabilities , :tools
741+
742+ server_without_tools = Server . new ( name : "test_server" )
743+
744+ refute_includes server_without_tools . capabilities , :tools
745+ end
746+
747+ test "has prompt capability only if prompts or a prompts_list_handler is defined" do
748+ server_with_prompts = Server . new ( name : "test_server" , prompts : [ @prompt ] )
749+
750+ assert_includes server_with_prompts . capabilities , :prompts
751+
752+ server_with_handler = Server . new ( name : "test_server" )
753+ server_with_handler . prompts_list_handler do
754+ [ { name : "test_prompt" , description : "Test prompt" } ]
755+ end
756+
757+ assert_includes server_with_handler . capabilities , :prompts
758+
759+ server_without_prompts = Server . new ( name : "test_server" )
760+
761+ refute_includes server_without_prompts . capabilities , :prompts
762+ end
763+
764+ test "has resources capability only if resources, template or custom handler is defined" do
765+ server_with_resources = Server . new ( name : "test_server" , resources : [ @resource ] )
766+
767+ assert_includes server_with_resources . capabilities , :resources
768+
769+ server_with_resource_template = Server . new ( name : "test_server" , resource_templates : [ @resource_template ] )
770+
771+ assert_includes server_with_resource_template . capabilities , :resources
772+
773+ server_with_resources_list_handler = Server . new ( name : "test_server" )
774+ server_with_resources_list_handler . resources_list_handler do
775+ [ { uri : "test_resource" , name : "Test resource" , description : "Test resource" } ]
776+ end
777+
778+ assert_includes server_with_resources_list_handler . capabilities , :resources
779+
780+ server_with_resources_templates_list_handler = Server . new ( name : "test_server" )
781+ server_with_resources_templates_list_handler . resources_templates_list_handler do
782+ [ { uri_template : "test_resource/{id}" , name : "Test resource" , description : "Test resource" } ]
783+ end
784+
785+ assert_includes server_with_resources_templates_list_handler . capabilities , :resources
786+
787+ server_without_resources = Server . new ( name : "test_server" )
788+
789+ refute_includes server_without_resources . capabilities , :resources
790+ end
729791 end
730792end
0 commit comments