@@ -46,6 +46,10 @@ def initialize(
4646 @resource_index = index_resources_by_uri ( resources )
4747 @server_context = server_context
4848 @configuration = MCP . configuration . merge ( configuration )
49+ @capabilities = Capabilities . new ( capabilities )
50+ @capabilities . support_tools if tools . any?
51+ @capabilities . support_prompts if prompts . any?
52+ @capabilities . support_resources if resources . any? || resource_templates . any?
4953
5054 @handlers = {
5155 Methods ::RESOURCES_LIST => method ( :list_resources ) ,
@@ -67,7 +71,7 @@ def initialize(
6771 end
6872
6973 def capabilities
70- @capabilities ||= determine_capabilities
74+ @capabilities . to_h
7175 end
7276
7377 def handle ( request )
@@ -93,6 +97,7 @@ def define_prompt(name: nil, description: nil, arguments: [], &block)
9397 end
9498
9599 def resources_list_handler ( &block )
100+ @capabilities . support_resources
96101 @handlers [ Methods ::RESOURCES_LIST ] = block
97102 end
98103
@@ -101,10 +106,12 @@ def resources_read_handler(&block)
101106 end
102107
103108 def resources_templates_list_handler ( &block )
109+ @capabilities . support_resources
104110 @handlers [ Methods ::RESOURCES_TEMPLATES_LIST ] = block
105111 end
106112
107113 def tools_list_handler ( &block )
114+ @capabilities . support_tools
108115 @handlers [ Methods ::TOOLS_LIST ] = block
109116 end
110117
@@ -113,6 +120,7 @@ def tools_call_handler(&block)
113120 end
114121
115122 def prompts_list_handler ( &block )
123+ @capabilities . support_prompts
116124 @handlers [ Methods ::PROMPTS_LIST ] = block
117125 end
118126
@@ -160,18 +168,6 @@ def handle_request(request, method)
160168 }
161169 end
162170
163- def determine_capabilities
164- defines_prompts = @prompts . any? || @handlers [ Methods ::PROMPTS_LIST ] != method ( :list_prompts )
165- defines_tools = @tools . any? || @handlers [ Methods ::TOOLS_LIST ] != method ( :list_tools )
166- defines_resources = @resources . any? || @handlers [ Methods ::RESOURCES_LIST ] != method ( :list_resources )
167- defines_resource_templates = @resource_templates . any? || @handlers [ Methods ::RESOURCES_TEMPLATES_LIST ] != method ( :list_resource_templates )
168- {
169- prompts : defines_prompts ? { } : nil ,
170- resources : defines_resources || defines_resource_templates ? { } : nil ,
171- tools : defines_tools ? { } : nil ,
172- } . compact
173- end
174-
175171 def server_info
176172 @server_info ||= {
177173 name :,
0 commit comments