module RubyLLM::MCP

def add_client(options)

def add_client(options)
  clients[options[:name]] ||= Client.new(**options)
end

def client(...)

def client(...)
  Client.new(...)
end

def clients(config = RubyLLM::MCP.config.mcp_configuration)

def clients(config = RubyLLM::MCP.config.mcp_configuration)
  if @clients.nil?
    @clients = {}
    config.map do |options|
      @clients[options[:name]] ||= Client.new(**options)
    end
  end
  @clients
end

def close_connection

def close_connection
  clients.each_value do |client|
    client.stop if client.alive?
  end
end

def config

def config
  @config ||= Configuration.new
end

def configure

def configure
  yield config
end

def establish_connection(&)

def establish_connection(&)
  clients.each_value(&:start)
  if block_given?
    begin
      yield clients
    ensure
      close_connection
    end
  else
    clients
  end
end

def logger

def logger
  config.logger
end

def remove_client(name)

def remove_client(name)
  client = clients.delete(name)
  client&.stop
  client
end

def support_complex_parameters!

def support_complex_parameters!
  warn "[DEPRECATION] RubyLLM::MCP.support_complex_parameters! is no longer needed " \
       "and will be removed in version 0.8.0"
  # No-op: Complex parameters are now supported by default
end

def tools(blacklist: [], whitelist: [])

def tools(blacklist: [], whitelist: [])
  tools = @clients.values.map(&:tools)
                  .flatten
                  .reject { |tool| blacklist.include?(tool.name) }
  tools = tools.select { |tool| whitelist.include?(tool.name) } if whitelist.any?
  tools.uniq(&:name)
end