Class: RubyLLM::MCP::Adapters::BaseAdapter
- Inherits:
-
Object
- Object
- RubyLLM::MCP::Adapters::BaseAdapter
show all
- Defined in:
- lib/ruby_llm/mcp/adapters/base_adapter.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
-
#alive? ⇒ Boolean
-
#build_client_extensions_capabilities(protocol_version:) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument.
-
#cancelled_notification(reason:, request_id:) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument.
-
#capabilities ⇒ Object
-
#client_capabilities ⇒ Object
-
#completion_prompt(name:, argument:, value:, context: nil) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument.
-
#completion_resource(uri:, argument:, value:, context: nil) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument.
-
#elicitation_response(id:, elicitation:) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument.
-
#error_response(id:, message:, code: -32_000)) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument.
-
#execute_prompt(name:, arguments:) ⇒ Object
-
#execute_tool(name:, parameters:) ⇒ Object
-
#extension_mode ⇒ Object
-
#initialize(client, transport_type:, config: {}) ⇒ BaseAdapter
constructor
A new instance of BaseAdapter.
-
#initialize_notification ⇒ Object
-
#ping ⇒ Object
-
#ping_response(id:) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument.
-
#prompt_list(cursor: nil) ⇒ Object
-
#register_resource(_resource) ⇒ Object
-
#resource_list(cursor: nil) ⇒ Object
-
#resource_read(uri:) ⇒ Object
-
#resource_template_list(cursor: nil) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument.
-
#resources_subscribe(uri:) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument.
-
#resources_unsubscribe(uri:) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument.
-
#restart! ⇒ Object
-
#roots_list_change_notification ⇒ Object
-
#roots_list_response(id:) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument.
-
#sampling_create_message_response(id:, model:, message:, **_options) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument.
-
#set_logging(level:) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument.
-
#start ⇒ Object
-
#stop ⇒ Object
-
#supports?(feature) ⇒ Boolean
-
#supports_extension_negotiation? ⇒ Boolean
-
#task_cancel(task_id:) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument.
-
#task_get(task_id:) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument.
-
#task_result(task_id:) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument.
-
#task_status_notification(task:) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument.
-
#tasks_list(cursor: nil) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument.
-
#tool_list(cursor: nil) ⇒ Object
-
#validate_transport!(transport_type) ⇒ Object
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
#client ⇒ Object
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
16
17
18
|
# File 'lib/ruby_llm/mcp/adapters/base_adapter.rb', line 16
def support?(feature)
supported_features[feature] || false
end
|
.supported_features ⇒ Object
8
9
10
|
# File 'lib/ruby_llm/mcp/adapters/base_adapter.rb', line 8
def supported_features
@supported_features ||= {}
end
|
.supported_transports ⇒ Object
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
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
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:) {}
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:) raise_unsupported_feature(:notifications)
end
|
#capabilities ⇒ Object
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_capabilities ⇒ Object
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) 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) 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:) 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) raise_unsupported_feature(:responses)
end
|
#execute_prompt(name:, arguments:) ⇒ Object
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
|
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_mode ⇒ Object
49
50
51
|
# File 'lib/ruby_llm/mcp/adapters/base_adapter.rb', line 49
def extension_mode
:none
end
|
#initialize_notification ⇒ Object
164
165
166
|
# File 'lib/ruby_llm/mcp/adapters/base_adapter.rb', line 164
def initialize_notification
raise_unsupported_feature(:notifications)
end
|
#ping ⇒ Object
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:) raise_unsupported_feature(:responses)
end
|
#prompt_list(cursor: nil) ⇒ Object
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
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
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) 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:) 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:) raise_unsupported_feature(:subscriptions)
end
|
#restart! ⇒ Object
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_notification ⇒ Object
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:) 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) 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:) raise_unsupported_feature(:logging)
end
|
#start ⇒ Object
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
|
#stop ⇒ Object
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
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
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:) 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:) 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:) 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:) 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) raise_unsupported_feature(:tasks)
end
|
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
|