33require "json_rpc_handler"
44require_relative "instrumentation"
55require_relative "methods"
6- require_relative "server/capabilities"
76
87module MCP
98 class Server
@@ -23,8 +22,7 @@ def initialize(message, request, error_type: :internal_error, original_error: ni
2322
2423 include Instrumentation
2524
26- attr_writer :capabilities
27- attr_accessor :name , :version , :tools , :prompts , :resources , :server_context , :configuration , :transport
25+ attr_accessor :name , :version , :tools , :prompts , :resources , :server_context , :configuration , :capabilities , :transport
2826
2927 def initialize (
3028 name : "model_context_protocol" ,
@@ -47,10 +45,7 @@ def initialize(
4745 @resource_index = index_resources_by_uri ( resources )
4846 @server_context = server_context
4947 @configuration = MCP . configuration . merge ( configuration )
50- @capabilities = Capabilities . new ( capabilities )
51- @capabilities . support_tools if tools . any?
52- @capabilities . support_prompts if prompts . any?
53- @capabilities . support_resources if resources . any? || resource_templates . any?
48+ @capabilities = capabilities || default_capabilities
5449
5550 @handlers = {
5651 Methods ::RESOURCES_LIST => method ( :list_resources ) ,
@@ -72,10 +67,6 @@ def initialize(
7267 @transport = transport
7368 end
7469
75- def capabilities
76- @capabilities . to_h
77- end
78-
7970 def handle ( request )
8071 JsonRpcHandler . handle ( request ) do |method |
8172 handle_request ( request , method )
@@ -123,7 +114,6 @@ def notify_resources_list_changed
123114 end
124115
125116 def resources_list_handler ( &block )
126- @capabilities . support_resources
127117 @handlers [ Methods ::RESOURCES_LIST ] = block
128118 end
129119
@@ -132,12 +122,10 @@ def resources_read_handler(&block)
132122 end
133123
134124 def resources_templates_list_handler ( &block )
135- @capabilities . support_resources
136125 @handlers [ Methods ::RESOURCES_TEMPLATES_LIST ] = block
137126 end
138127
139128 def tools_list_handler ( &block )
140- @capabilities . support_tools
141129 @handlers [ Methods ::TOOLS_LIST ] = block
142130 end
143131
@@ -146,7 +134,6 @@ def tools_call_handler(&block)
146134 end
147135
148136 def prompts_list_handler ( &block )
149- @capabilities . support_prompts
150137 @handlers [ Methods ::PROMPTS_LIST ] = block
151138 end
152139
@@ -194,6 +181,14 @@ def handle_request(request, method)
194181 }
195182 end
196183
184+ def default_capabilities
185+ {
186+ tools : { listChanged : true } ,
187+ prompts : { listChanged : true } ,
188+ resources : { listChanged : true } ,
189+ }
190+ end
191+
197192 def server_info
198193 @server_info ||= {
199194 name :,
0 commit comments