Class: RubyLLM::MCP::Adapters::RubyLLMAdapter

Inherits:
BaseAdapter
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/ruby_llm/mcp/adapters/ruby_llm_adapter.rb

Overview

RubyLLM Adapter - wraps the Native protocol implementation This is a thin bridge between the public API and Native::Client

Instance Attribute Summary collapse

Attributes inherited from BaseAdapter

#client

Instance Method Summary collapse

Methods inherited from BaseAdapter

#alive?, #cancelled_notification, #capabilities, #client_capabilities, #completion_prompt, #completion_resource, #elicitation_response, #error_response, #execute_prompt, #execute_tool, #initialize_notification, #ping, #ping_response, #prompt_list, #resource_list, #resource_read, #resource_template_list, #resources_subscribe, #resources_unsubscribe, #restart!, #roots_list_change_notification, #roots_list_response, #sampling_create_message_response, #set_logging, #start, #stop, support?, supported_features, supported_transports, supports, #supports?, supports_transport, #task_cancel, #task_get, #task_result, #task_status_notification, #tasks_list, #tool_list, transport_supported?, #validate_transport!

Constructor Details

#initialize(client, transport_type:, config: {}) ⇒ RubyLLMAdapter

Returns a new instance of RubyLLMAdapter.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/ruby_llm/mcp/adapters/ruby_llm_adapter.rb', line 23

def initialize(client, transport_type:, config: {})
  validate_transport!(transport_type)
  super

  request_timeout = config.delete(:request_timeout)
  protocol_version = @config[:protocol_version]
  extensions_capabilities = build_client_extensions_capabilities(protocol_version: protocol_version)
  transport_config = prepare_transport_config(config, transport_type)

  @native_client = Native::Client.new(
    name: client.name,
    transport_type: transport_type,
    transport_config: transport_config,
    request_timeout: request_timeout,
    human_in_the_loop_callback: build_human_in_the_loop_callback(client),
    roots_callback: -> { client.roots.paths },
    logging_enabled: client.logging_handler_enabled?,
    logging_level: client.on_logging_level,
    # Always advertise elicitation capability for native adapter clients.
    # If no handler is set, requests are safely rejected by the callback path.
    elicitation_enabled: true,
    progress_tracking_enabled: client.tracking_progress?,
    elicitation_callback: build_elicitation_callback(client),
    sampling_callback: build_sampling_callback(client),
    notification_callback: ->(notification) { NotificationHandler.new(client).execute(notification) },
    protocol_version: @config[:protocol_version],
    extensions_capabilities: extensions_capabilities
  )
end

Instance Attribute Details

#native_clientObject (readonly)

Returns the value of attribute native_client.



21
22
23
# File 'lib/ruby_llm/mcp/adapters/ruby_llm_adapter.rb', line 21

def native_client
  @native_client
end

Instance Method Details

#build_client_extensions_capabilities(protocol_version:) ⇒ Object



80
81
82
83
84
# File 'lib/ruby_llm/mcp/adapters/ruby_llm_adapter.rb', line 80

def build_client_extensions_capabilities(protocol_version:)
  return {} unless Native::Protocol.extensions_supported?(protocol_version)

  Extensions::Registry.normalize_map(@config[:extensions]).transform_values { |value| value || {} }
end

#extension_modeObject



76
77
78
# File 'lib/ruby_llm/mcp/adapters/ruby_llm_adapter.rb', line 76

def extension_mode
  :full
end

#register_resource(resource) ⇒ Object



86
87
88
89
# File 'lib/ruby_llm/mcp/adapters/ruby_llm_adapter.rb', line 86

def register_resource(resource)
  client.linked_resources << resource
  client.resources[resource.name] = resource
end

#supports_extension_negotiation?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/ruby_llm/mcp/adapters/ruby_llm_adapter.rb', line 72

def supports_extension_negotiation?
  true
end