3
3
require "json_rpc_handler"
4
4
require_relative "instrumentation"
5
5
require_relative "methods"
6
- require_relative "server/capabilities"
7
6
8
7
module MCP
9
8
class Server
@@ -23,8 +22,7 @@ def initialize(message, request, error_type: :internal_error, original_error: ni
23
22
24
23
include Instrumentation
25
24
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
28
26
29
27
def initialize (
30
28
name : "model_context_protocol" ,
@@ -47,10 +45,7 @@ def initialize(
47
45
@resource_index = index_resources_by_uri ( resources )
48
46
@server_context = server_context
49
47
@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
54
49
55
50
@handlers = {
56
51
Methods ::RESOURCES_LIST => method ( :list_resources ) ,
@@ -72,10 +67,6 @@ def initialize(
72
67
@transport = transport
73
68
end
74
69
75
- def capabilities
76
- @capabilities . to_h
77
- end
78
-
79
70
def handle ( request )
80
71
JsonRpcHandler . handle ( request ) do |method |
81
72
handle_request ( request , method )
@@ -123,7 +114,6 @@ def notify_resources_list_changed
123
114
end
124
115
125
116
def resources_list_handler ( &block )
126
- @capabilities . support_resources
127
117
@handlers [ Methods ::RESOURCES_LIST ] = block
128
118
end
129
119
@@ -132,12 +122,10 @@ def resources_read_handler(&block)
132
122
end
133
123
134
124
def resources_templates_list_handler ( &block )
135
- @capabilities . support_resources
136
125
@handlers [ Methods ::RESOURCES_TEMPLATES_LIST ] = block
137
126
end
138
127
139
128
def tools_list_handler ( &block )
140
- @capabilities . support_tools
141
129
@handlers [ Methods ::TOOLS_LIST ] = block
142
130
end
143
131
@@ -146,7 +134,6 @@ def tools_call_handler(&block)
146
134
end
147
135
148
136
def prompts_list_handler ( &block )
149
- @capabilities . support_prompts
150
137
@handlers [ Methods ::PROMPTS_LIST ] = block
151
138
end
152
139
@@ -194,6 +181,14 @@ def handle_request(request, method)
194
181
}
195
182
end
196
183
184
+ def default_capabilities
185
+ {
186
+ tools : { listChanged : true } ,
187
+ prompts : { listChanged : true } ,
188
+ resources : { listChanged : true } ,
189
+ }
190
+ end
191
+
197
192
def server_info
198
193
@server_info ||= {
199
194
name :,
0 commit comments