@@ -739,5 +739,67 @@ class ServerTest < ActiveSupport::TestCase
739739 response = server . handle ( request )
740740 assert_equal custom_version , response [ :result ] [ :protocolVersion ]
741741 end
742+
743+ test "has tool capability only if tools or a tools_list_handler is defined" do
744+ server_with_tools = Server . new ( name : "test_server" , tools : [ @tool ] )
745+
746+ assert_includes server_with_tools . capabilities , :tools
747+
748+ server_with_handler = Server . new ( name : "test_server" )
749+ server_with_handler . tools_list_handler do
750+ [ { name : "test_tool" , description : "Test tool" } ]
751+ end
752+
753+ assert_includes server_with_handler . capabilities , :tools
754+
755+ server_without_tools = Server . new ( name : "test_server" )
756+
757+ refute_includes server_without_tools . capabilities , :tools
758+ end
759+
760+ test "has prompt capability only if prompts or a prompts_list_handler is defined" do
761+ server_with_prompts = Server . new ( name : "test_server" , prompts : [ @prompt ] )
762+
763+ assert_includes server_with_prompts . capabilities , :prompts
764+
765+ server_with_handler = Server . new ( name : "test_server" )
766+ server_with_handler . prompts_list_handler do
767+ [ { name : "test_prompt" , description : "Test prompt" } ]
768+ end
769+
770+ assert_includes server_with_handler . capabilities , :prompts
771+
772+ server_without_prompts = Server . new ( name : "test_server" )
773+
774+ refute_includes server_without_prompts . capabilities , :prompts
775+ end
776+
777+ test "has resources capability only if resources, template or custom handler is defined" do
778+ server_with_resources = Server . new ( name : "test_server" , resources : [ @resource ] )
779+
780+ assert_includes server_with_resources . capabilities , :resources
781+
782+ server_with_resource_template = Server . new ( name : "test_server" , resource_templates : [ @resource_template ] )
783+
784+ assert_includes server_with_resource_template . capabilities , :resources
785+
786+ server_with_resources_list_handler = Server . new ( name : "test_server" )
787+ server_with_resources_list_handler . resources_list_handler do
788+ [ { uri : "test_resource" , name : "Test resource" , description : "Test resource" } ]
789+ end
790+
791+ assert_includes server_with_resources_list_handler . capabilities , :resources
792+
793+ server_with_resources_templates_list_handler = Server . new ( name : "test_server" )
794+ server_with_resources_templates_list_handler . resources_templates_list_handler do
795+ [ { uri_template : "test_resource/{id}" , name : "Test resource" , description : "Test resource" } ]
796+ end
797+
798+ assert_includes server_with_resources_templates_list_handler . capabilities , :resources
799+
800+ server_without_resources = Server . new ( name : "test_server" )
801+
802+ refute_includes server_without_resources . capabilities , :resources
803+ end
742804 end
743805end
0 commit comments