Module: ActionMCP::Server::Handlers::ResourceHandler

Includes:
ErrorAware
Included in:
JsonRpcHandler
Defined in:
lib/action_mcp/server/handlers/resource_handler.rb

Instance Method Summary collapse

Instance Method Details

#process_resources(rpc_method, id, params) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/action_mcp/server/handlers/resource_handler.rb', line 11

def process_resources(rpc_method, id, params)
  params ||= {}

  with_error_handling(id) do
    unless params.is_a?(Hash)
      raise JSON_RPC::JsonRpcError.new(:invalid_params, message: "Resource params must be an object")
    end

    capabilities = negotiated_resource_capabilities
    unless capabilities
      raise JSON_RPC::JsonRpcError.new(:method_not_found,
                                       message: "Resources are not available for this session")
    end

    if subscription_method?(rpc_method) && capabilities[:subscribe] != true
      raise JSON_RPC::JsonRpcError.new(:method_not_found,
                                       message: "Resource subscriptions are not available for this session")
    end

    handler = resource_method_handlers[rpc_method]
    if handler
      send(handler, id, params)
    else
      Rails.logger.warn("Unknown resources method: #{rpc_method}")
      raise JSON_RPC::JsonRpcError.new(:method_not_found, message: "Unknown resources method: #{rpc_method}")
    end
  end
end