Class: RubyLLM::MCP::Adapters::BaseAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_llm/mcp/adapters/base_adapter.rb

Direct Known Subclasses

MCPSdkAdapter, RubyLLMAdapter

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of BaseAdapter.



35
36
37
38
39
# File 'lib/ruby_llm/mcp/adapters/base_adapter.rb', line 35

def initialize(client, transport_type:, config: {})
  @client = client
  @transport_type = transport_type
  @config = config
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



33
34
35
# File 'lib/ruby_llm/mcp/adapters/base_adapter.rb', line 33

def client
  @client
end

Class Method Details

.support?(feature) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/ruby_llm/mcp/adapters/base_adapter.rb', line 16

def support?(feature)
  supported_features[feature] || false
end

.supported_featuresObject



8
9
10
# File 'lib/ruby_llm/mcp/adapters/base_adapter.rb', line 8

def supported_features
  @supported_features ||= {}
end

.supported_transportsObject



20
21
22
# File 'lib/ruby_llm/mcp/adapters/base_adapter.rb', line 20

def supported_transports
  @supported_transports ||= []
end

.supports(*features) ⇒ Object



12
13
14
# File 'lib/ruby_llm/mcp/adapters/base_adapter.rb', line 12

def supports(*features)
  features.each { |f| supported_features[f] = true }
end

.supports_transport(*transports) ⇒ Object



24
25
26
# File 'lib/ruby_llm/mcp/adapters/base_adapter.rb', line 24

def supports_transport(*transports)
  @supported_transports = transports
end

.transport_supported?(transport) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/ruby_llm/mcp/adapters/base_adapter.rb', line 28

def transport_supported?(transport)
  supported_transports.include?(transport.to_sym)
end

Instance Method Details

#alive?Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


80
81
82
# File 'lib/ruby_llm/mcp/adapters/base_adapter.rb', line 80

def alive?
  raise NotImplementedError, "#{self.class.name} must implement #alive?"
end

#build_client_extensions_capabilities(protocol_version:) ⇒ Object

rubocop:disable Lint/UnusedMethodArgument



53
54
55
# File 'lib/ruby_llm/mcp/adapters/base_adapter.rb', line 53

def build_client_extensions_capabilities(protocol_version:) # rubocop:disable Lint/UnusedMethodArgument
  {}
end

#cancelled_notification(reason:, request_id:) ⇒ Object

rubocop:disable Lint/UnusedMethodArgument



168
169
170
# File 'lib/ruby_llm/mcp/adapters/base_adapter.rb', line 168

def cancelled_notification(reason:, request_id:) # rubocop:disable Lint/UnusedMethodArgument
  raise_unsupported_feature(:notifications)
end

#capabilitiesObject

Raises:

  • (NotImplementedError)


88
89
90
# File 'lib/ruby_llm/mcp/adapters/base_adapter.rb', line 88

def capabilities
  raise NotImplementedError, "#{self.class.name} must implement #capabilities"
end

#client_capabilitiesObject

Raises:

  • (NotImplementedError)


92
93
94
# File 'lib/ruby_llm/mcp/adapters/base_adapter.rb', line 92

def client_capabilities
  raise NotImplementedError, "#{self.class.name} must implement #client_capabilities"
end

#completion_prompt(name:, argument:, value:, context: nil) ⇒ Object

rubocop:disable Lint/UnusedMethodArgument



128
129
130
# File 'lib/ruby_llm/mcp/adapters/base_adapter.rb', line 128

def completion_prompt(name:, argument:, value:, context: nil) # rubocop:disable Lint/UnusedMethodArgument
  raise_unsupported_feature(:completions)
end

#completion_resource(uri:, argument:, value:, context: nil) ⇒ Object

rubocop:disable Lint/UnusedMethodArgument



124
125
126
# File 'lib/ruby_llm/mcp/adapters/base_adapter.rb', line 124

def completion_resource(uri:, argument:, value:, context: nil) # rubocop:disable Lint/UnusedMethodArgument
  raise_unsupported_feature(:completions)
end

#elicitation_response(id:, elicitation:) ⇒ Object

rubocop:disable Lint/UnusedMethodArgument



192
193
194
# File 'lib/ruby_llm/mcp/adapters/base_adapter.rb', line 192

def elicitation_response(id:, elicitation:) # rubocop:disable Lint/UnusedMethodArgument
  raise_unsupported_feature(:elicitation)
end

#error_response(id:, message:, code: -32_000)) ⇒ Object

rubocop:disable Lint/UnusedMethodArgument



188
189
190
# File 'lib/ruby_llm/mcp/adapters/base_adapter.rb', line 188

def error_response(id:, message:, code: -32_000) # rubocop:disable Lint/UnusedMethodArgument
  raise_unsupported_feature(:responses)
end

#execute_prompt(name:, arguments:) ⇒ Object

Raises:

  • (NotImplementedError)


116
117
118
# File 'lib/ruby_llm/mcp/adapters/base_adapter.rb', line 116

def execute_prompt(name:, arguments:)
  raise NotImplementedError, "#{self.class.name} must implement #execute_prompt"
end

#execute_tool(name:, parameters:) ⇒ Object

Raises:

  • (NotImplementedError)


100
101
102
# File 'lib/ruby_llm/mcp/adapters/base_adapter.rb', line 100

def execute_tool(name:, parameters:)
  raise NotImplementedError, "#{self.class.name} must implement #execute_tool"
end

#extension_modeObject



49
50
51
# File 'lib/ruby_llm/mcp/adapters/base_adapter.rb', line 49

def extension_mode
  :none
end

#initialize_notificationObject



164
165
166
# File 'lib/ruby_llm/mcp/adapters/base_adapter.rb', line 164

def initialize_notification
  raise_unsupported_feature(:notifications)
end

#pingObject

Raises:

  • (NotImplementedError)


84
85
86
# File 'lib/ruby_llm/mcp/adapters/base_adapter.rb', line 84

def ping
  raise NotImplementedError, "#{self.class.name} must implement #ping"
end

#ping_response(id:) ⇒ Object

rubocop:disable Lint/UnusedMethodArgument



176
177
178
# File 'lib/ruby_llm/mcp/adapters/base_adapter.rb', line 176

def ping_response(id:) # rubocop:disable Lint/UnusedMethodArgument
  raise_unsupported_feature(:responses)
end

#prompt_list(cursor: nil) ⇒ Object

Raises:

  • (NotImplementedError)


112
113
114
# File 'lib/ruby_llm/mcp/adapters/base_adapter.rb', line 112

def prompt_list(cursor: nil)
  raise NotImplementedError, "#{self.class.name} must implement #prompt_list"
end

#register_resource(_resource) ⇒ Object



196
197
198
# File 'lib/ruby_llm/mcp/adapters/base_adapter.rb', line 196

def register_resource(_resource)
  raise_unsupported_feature(:resource_registration)
end

#resource_list(cursor: nil) ⇒ Object

Raises:

  • (NotImplementedError)


104
105
106
# File 'lib/ruby_llm/mcp/adapters/base_adapter.rb', line 104

def resource_list(cursor: nil)
  raise NotImplementedError, "#{self.class.name} must implement #resource_list"
end

#resource_read(uri:) ⇒ Object

Raises:

  • (NotImplementedError)


108
109
110
# File 'lib/ruby_llm/mcp/adapters/base_adapter.rb', line 108

def resource_read(uri:)
  raise NotImplementedError, "#{self.class.name} must implement #resource_read"
end

#resource_template_list(cursor: nil) ⇒ Object

rubocop:disable Lint/UnusedMethodArgument



120
121
122
# File 'lib/ruby_llm/mcp/adapters/base_adapter.rb', line 120

def resource_template_list(cursor: nil) # rubocop:disable Lint/UnusedMethodArgument
  raise_unsupported_feature(:resource_templates)
end

#resources_subscribe(uri:) ⇒ Object

rubocop:disable Lint/UnusedMethodArgument



136
137
138
# File 'lib/ruby_llm/mcp/adapters/base_adapter.rb', line 136

def resources_subscribe(uri:) # rubocop:disable Lint/UnusedMethodArgument
  raise_unsupported_feature(:subscriptions)
end

#resources_unsubscribe(uri:) ⇒ Object

rubocop:disable Lint/UnusedMethodArgument



140
141
142
# File 'lib/ruby_llm/mcp/adapters/base_adapter.rb', line 140

def resources_unsubscribe(uri:) # rubocop:disable Lint/UnusedMethodArgument
  raise_unsupported_feature(:subscriptions)
end

#restart!Object

Raises:

  • (NotImplementedError)


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

def restart!
  raise NotImplementedError, "#{self.class.name} must implement #restart!"
end

#roots_list_change_notificationObject



172
173
174
# File 'lib/ruby_llm/mcp/adapters/base_adapter.rb', line 172

def roots_list_change_notification
  raise_unsupported_feature(:notifications)
end

#roots_list_response(id:) ⇒ Object

rubocop:disable Lint/UnusedMethodArgument



180
181
182
# File 'lib/ruby_llm/mcp/adapters/base_adapter.rb', line 180

def roots_list_response(id:) # rubocop:disable Lint/UnusedMethodArgument
  raise_unsupported_feature(:responses)
end

#sampling_create_message_response(id:, model:, message:, **_options) ⇒ Object

rubocop:disable Lint/UnusedMethodArgument



184
185
186
# File 'lib/ruby_llm/mcp/adapters/base_adapter.rb', line 184

def sampling_create_message_response(id:, model:, message:, **_options) # rubocop:disable Lint/UnusedMethodArgument
  raise_unsupported_feature(:sampling)
end

#set_logging(level:) ⇒ Object

rubocop:disable Lint/UnusedMethodArgument



132
133
134
# File 'lib/ruby_llm/mcp/adapters/base_adapter.rb', line 132

def set_logging(level:) # rubocop:disable Lint/UnusedMethodArgument
  raise_unsupported_feature(:logging)
end

#startObject

Raises:

  • (NotImplementedError)


68
69
70
# File 'lib/ruby_llm/mcp/adapters/base_adapter.rb', line 68

def start
  raise NotImplementedError, "#{self.class.name} must implement #start"
end

#stopObject

Raises:

  • (NotImplementedError)


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

def stop
  raise NotImplementedError, "#{self.class.name} must implement #stop"
end

#supports?(feature) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/ruby_llm/mcp/adapters/base_adapter.rb', line 41

def supports?(feature)
  self.class.support?(feature)
end

#supports_extension_negotiation?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/ruby_llm/mcp/adapters/base_adapter.rb', line 45

def supports_extension_negotiation?
  false
end

#task_cancel(task_id:) ⇒ Object

rubocop:disable Lint/UnusedMethodArgument



156
157
158
# File 'lib/ruby_llm/mcp/adapters/base_adapter.rb', line 156

def task_cancel(task_id:) # rubocop:disable Lint/UnusedMethodArgument
  raise_unsupported_feature(:tasks)
end

#task_get(task_id:) ⇒ Object

rubocop:disable Lint/UnusedMethodArgument



148
149
150
# File 'lib/ruby_llm/mcp/adapters/base_adapter.rb', line 148

def task_get(task_id:) # rubocop:disable Lint/UnusedMethodArgument
  raise_unsupported_feature(:tasks)
end

#task_result(task_id:) ⇒ Object

rubocop:disable Lint/UnusedMethodArgument



152
153
154
# File 'lib/ruby_llm/mcp/adapters/base_adapter.rb', line 152

def task_result(task_id:) # rubocop:disable Lint/UnusedMethodArgument
  raise_unsupported_feature(:tasks)
end

#task_status_notification(task:) ⇒ Object

rubocop:disable Lint/UnusedMethodArgument



160
161
162
# File 'lib/ruby_llm/mcp/adapters/base_adapter.rb', line 160

def task_status_notification(task:) # rubocop:disable Lint/UnusedMethodArgument
  raise_unsupported_feature(:tasks)
end

#tasks_list(cursor: nil) ⇒ Object

rubocop:disable Lint/UnusedMethodArgument



144
145
146
# File 'lib/ruby_llm/mcp/adapters/base_adapter.rb', line 144

def tasks_list(cursor: nil) # rubocop:disable Lint/UnusedMethodArgument
  raise_unsupported_feature(:tasks)
end

#tool_list(cursor: nil) ⇒ Object

Raises:

  • (NotImplementedError)


96
97
98
# File 'lib/ruby_llm/mcp/adapters/base_adapter.rb', line 96

def tool_list(cursor: nil)
  raise NotImplementedError, "#{self.class.name} must implement #tool_list"
end

#validate_transport!(transport_type) ⇒ Object



57
58
59
60
61
62
63
64
65
66
# File 'lib/ruby_llm/mcp/adapters/base_adapter.rb', line 57

def validate_transport!(transport_type)
  unless self.class.transport_supported?(transport_type)
    raise Errors::UnsupportedTransport.new(
      message: <<~MSG.strip
        Transport '#{transport_type}' is not supported by #{self.class.name}.
        Supported transports: #{self.class.supported_transports.join(', ')}
      MSG
    )
  end
end