module RubyLLM::MCP::Native::Protocol

def compare_date_versions(version_a, version_b)

def compare_date_versions(version_a, version_b)
  return nil unless date_version?(version_a) && date_version?(version_b)
  Date.iso8601(version_a) <=> Date.iso8601(version_b)
rescue Date::Error
  nil
end

def date_version?(value)

def date_version?(value)
  return false unless value.is_a?(String)
  /\A\d{4}-\d{2}-\d{2}\z/.match?(value)
end

def default_negotiated_version

def default_negotiated_version
  DEFAULT_NEGOTIATED_PROTOCOL_VERSION
end

def draft_or_newer?(version)

def draft_or_newer?(version)
  return false if version.nil?
  normalized = version.to_s
  return true if normalized.start_with?("DRAFT-")
  comparison = compare_date_versions(normalized, DRAFT_PROTOCOL_VERSION)
  !comparison.nil? && comparison >= 0
end

def draft_version

def draft_version
  DRAFT_PROTOCOL_VERSION
end

def extensions_supported?(version)

Extensions are part of the stable protocol track from 2025-06-18 onward.
def extensions_supported?(version)
  return false if version.nil?
  normalized = version.to_s
  return true if normalized.start_with?("DRAFT-")
  comparison = compare_date_versions(normalized, EXTENSIONS_PROTOCOL_VERSION)
  !comparison.nil? && comparison >= 0
end

def latest_version

def latest_version
  LATEST_PROTOCOL_VERSION
end

def supported_version?(version)

def supported_version?(version)
  SUPPORTED_PROTOCOL_VERSIONS.include?(version)
end

def supported_versions

def supported_versions
  SUPPORTED_PROTOCOL_VERSIONS
end