Class: RubyLLM::MCP::Configuration

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

Defined Under Namespace

Classes: AdapterConfig, ConfigFile, Elicitation, OAuth, Sampling, Tasks

Constant Summary collapse

REQUEST_TIMEOUT_DEFAULT =
8000
VALID_PROTOCOL_TRACKS =
%i[stable draft].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



221
222
223
224
225
226
227
228
229
# File 'lib/ruby_llm/mcp/configuration.rb', line 221

def initialize
  @sampling = Sampling.new
  @elicitation = Elicitation.new
  @tasks = Tasks.new
  @adapter_config = AdapterConfig.new
  @extensions = Extensions::Configuration.new
  @oauth = OAuth.new
  set_defaults
end

Instance Attribute Details

#adapter_configObject

Returns the value of attribute adapter_config.



200
201
202
# File 'lib/ruby_llm/mcp/configuration.rb', line 200

def adapter_config
  @adapter_config
end

#config_pathObject

Returns the value of attribute config_path.



200
201
202
# File 'lib/ruby_llm/mcp/configuration.rb', line 200

def config_path
  @config_path
end

#elicitationObject

Returns the value of attribute elicitation.



200
201
202
# File 'lib/ruby_llm/mcp/configuration.rb', line 200

def elicitation
  @elicitation
end

#extensionsObject (readonly)

Returns the value of attribute extensions.



215
216
217
# File 'lib/ruby_llm/mcp/configuration.rb', line 215

def extensions
  @extensions
end

#launch_controlObject

Returns the value of attribute launch_control.



200
201
202
# File 'lib/ruby_llm/mcp/configuration.rb', line 200

def launch_control
  @launch_control
end

#log_fileObject

Returns the value of attribute log_file.



200
201
202
# File 'lib/ruby_llm/mcp/configuration.rb', line 200

def log_file
  @log_file
end

#log_levelObject

Returns the value of attribute log_level.



200
201
202
# File 'lib/ruby_llm/mcp/configuration.rb', line 200

def log_level
  @log_level
end

#loggerObject



235
236
237
238
239
240
241
# File 'lib/ruby_llm/mcp/configuration.rb', line 235

def logger
  @logger ||= Logger.new(
    log_file,
    progname: "RubyLLM::MCP",
    level: log_level
  )
end

#max_connectionsObject

Returns the value of attribute max_connections.



200
201
202
# File 'lib/ruby_llm/mcp/configuration.rb', line 200

def max_connections
  @max_connections
end

#mcp_configurationObject

Validate MCP configuration before use



253
254
255
256
257
# File 'lib/ruby_llm/mcp/configuration.rb', line 253

def mcp_configuration
  configs = @mcp_configuration + load_mcps_config
  validate_configurations!(configs)
  configs
end

#oauthObject

Returns the value of attribute oauth.



200
201
202
# File 'lib/ruby_llm/mcp/configuration.rb', line 200

def oauth
  @oauth
end

#on_logging_levelObject

Returns the value of attribute on_logging_level.



200
201
202
# File 'lib/ruby_llm/mcp/configuration.rb', line 200

def on_logging_level
  @on_logging_level
end

#pool_timeoutObject

Returns the value of attribute pool_timeout.



200
201
202
# File 'lib/ruby_llm/mcp/configuration.rb', line 200

def pool_timeout
  @pool_timeout
end

#protocol_trackObject

Returns the value of attribute protocol_track.



215
216
217
# File 'lib/ruby_llm/mcp/configuration.rb', line 215

def protocol_track
  @protocol_track
end

#protocol_versionObject

Returns the effective protocol version: explicit protocol_version > protocol_track-derived default.



297
298
299
300
301
302
303
# File 'lib/ruby_llm/mcp/configuration.rb', line 297

def protocol_version
  return @protocol_version unless @protocol_version.nil?

  return Native::Protocol.draft_version if @protocol_track == :draft

  Native::Protocol.latest_version
end

#request_timeoutObject

Returns the value of attribute request_timeout.



200
201
202
# File 'lib/ruby_llm/mcp/configuration.rb', line 200

def request_timeout
  @request_timeout
end

#rootsObject

Returns the value of attribute roots.



200
201
202
# File 'lib/ruby_llm/mcp/configuration.rb', line 200

def roots
  @roots
end

#samplingObject

Returns the value of attribute sampling.



200
201
202
# File 'lib/ruby_llm/mcp/configuration.rb', line 200

def sampling
  @sampling
end

#tasksObject

Returns the value of attribute tasks.



200
201
202
# File 'lib/ruby_llm/mcp/configuration.rb', line 200

def tasks
  @tasks
end

Instance Method Details

#default_adapterObject



248
249
250
# File 'lib/ruby_llm/mcp/configuration.rb', line 248

def default_adapter
  @adapter_config.default_adapter
end

#default_adapter=(adapter) ⇒ Object

Convenience method for setting default adapter



244
245
246
# File 'lib/ruby_llm/mcp/configuration.rb', line 244

def default_adapter=(adapter)
  @adapter_config.default_adapter = adapter
end

#inspectObject



305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
# File 'lib/ruby_llm/mcp/configuration.rb', line 305

def inspect
  redacted = lambda do |name, value|
    if name.match?(/_id|_key|_secret|_token$/)
      value.nil? ? "nil" : "[FILTERED]"
    else
      value
    end
  end

  inspection = instance_variables.map do |ivar|
    name = ivar.to_s.delete_prefix("@")
    value = redacted[name, instance_variable_get(ivar)]
    "#{name}: #{value}"
  end.join(", ")

  "#<#{self.class}:0x#{object_id.to_s(16)} #{inspection}>"
end

#on_elicitation(&block) ⇒ Object



280
281
282
283
# File 'lib/ruby_llm/mcp/configuration.rb', line 280

def on_elicitation(&block)
  @on_elicitation = block if block_given?
  @on_elicitation
end

#on_human_in_the_loop(handler_class = nil, **options) ⇒ Object



264
265
266
267
268
269
270
271
272
273
# File 'lib/ruby_llm/mcp/configuration.rb', line 264

def on_human_in_the_loop(handler_class = nil, **options)
  if block_given?
    raise ArgumentError, "Block-based human-in-the-loop callbacks are no longer supported. Use a handler class."
  end

  if handler_class
    @on_human_in_the_loop = { class: handler_class, options: options }
  end
  @on_human_in_the_loop
end

#on_logging(&block) ⇒ Object



275
276
277
278
# File 'lib/ruby_llm/mcp/configuration.rb', line 275

def on_logging(&block)
  @on_logging = block if block_given?
  @on_logging
end

#on_progress(&block) ⇒ Object



259
260
261
262
# File 'lib/ruby_llm/mcp/configuration.rb', line 259

def on_progress(&block)
  @on_progress = block if block_given?
  @on_progress
end

#reset!Object



231
232
233
# File 'lib/ruby_llm/mcp/configuration.rb', line 231

def reset!
  set_defaults
end