@@ -117,6 +117,8 @@ def initialize(
117117 Methods ::RESOURCES_LIST => method ( :list_resources ) ,
118118 Methods ::RESOURCES_READ => method ( :read_resource_no_content ) ,
119119 Methods ::RESOURCES_TEMPLATES_LIST => method ( :list_resource_templates ) ,
120+ Methods ::RESOURCES_SUBSCRIBE => -> ( _ ) { { } } ,
121+ Methods ::RESOURCES_UNSUBSCRIBE => -> ( _ ) { { } } ,
120122 Methods ::TOOLS_LIST => method ( :list_tools ) ,
121123 Methods ::TOOLS_CALL => method ( :call_tool ) ,
122124 Methods ::PROMPTS_LIST => method ( :list_prompts ) ,
@@ -128,10 +130,6 @@ def initialize(
128130 Methods ::NOTIFICATIONS_ROOTS_LIST_CHANGED => -> ( _ ) { } ,
129131 Methods ::COMPLETION_COMPLETE => -> ( _ ) { DEFAULT_COMPLETION_RESULT } ,
130132 Methods ::LOGGING_SET_LEVEL => method ( :configure_logging_level ) ,
131-
132- # No op handlers for currently unsupported methods
133- Methods ::RESOURCES_SUBSCRIBE => -> ( _ ) { { } } ,
134- Methods ::RESOURCES_UNSUBSCRIBE => -> ( _ ) { { } } ,
135133 }
136134 @transport = transport
137135 end
@@ -258,6 +256,24 @@ def completion_handler(&block)
258256 @handlers [ Methods ::COMPLETION_COMPLETE ] = block
259257 end
260258
259+ # Sets a custom handler for `resources/subscribe` requests.
260+ # The block receives the parsed request params. The return value is
261+ # ignored; the response is always an empty result `{}` per the MCP specification.
262+ #
263+ # @yield [params] The request params containing `:uri`.
264+ def resources_subscribe_handler ( &block )
265+ @handlers [ Methods ::RESOURCES_SUBSCRIBE ] = block
266+ end
267+
268+ # Sets a custom handler for `resources/unsubscribe` requests.
269+ # The block receives the parsed request params. The return value is
270+ # ignored; the response is always an empty result `{}` per the MCP specification.
271+ #
272+ # @yield [params] The request params containing `:uri`.
273+ def resources_unsubscribe_handler ( &block )
274+ @handlers [ Methods ::RESOURCES_UNSUBSCRIBE ] = block
275+ end
276+
261277 def build_sampling_params (
262278 capabilities ,
263279 messages :,
@@ -391,6 +407,9 @@ def handle_request(request, method, session: nil, related_request_id: nil)
391407 init ( params , session : session )
392408 when Methods ::RESOURCES_READ
393409 { contents : @handlers [ Methods ::RESOURCES_READ ] . call ( params ) }
410+ when Methods ::RESOURCES_SUBSCRIBE , Methods ::RESOURCES_UNSUBSCRIBE
411+ @handlers [ method ] . call ( params )
412+ { }
394413 when Methods ::TOOLS_CALL
395414 call_tool ( params , session : session , related_request_id : related_request_id )
396415 when Methods ::COMPLETION_COMPLETE
0 commit comments