Module: RubyLLM::MCP::Native::Protocol

Defined in:
lib/ruby_llm/mcp/native/protocol.rb

Constant Summary collapse

LATEST_PROTOCOL_VERSION =
"2025-11-25"
EXTENSIONS_PROTOCOL_VERSION =
"2025-06-18"
DRAFT_PROTOCOL_VERSION =
"2026-01-26"
DEFAULT_NEGOTIATED_PROTOCOL_VERSION =
"2025-03-26"
SUPPORTED_PROTOCOL_VERSIONS =
[
  DRAFT_PROTOCOL_VERSION,
  LATEST_PROTOCOL_VERSION,
  EXTENSIONS_PROTOCOL_VERSION,
  "2025-03-26",
  "2024-11-05",
  "2024-10-07"
].freeze

Class Method Summary collapse

Class Method Details

.compare_date_versions(version_a, version_b) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/ruby_llm/mcp/native/protocol.rb', line 48

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

.date_version?(value) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
45
46
# File 'lib/ruby_llm/mcp/native/protocol.rb', line 42

def date_version?(value)
  return false unless value.is_a?(String)

  /\A\d{4}-\d{2}-\d{2}\z/.match?(value)
end

.default_negotiated_versionObject



38
39
40
# File 'lib/ruby_llm/mcp/native/protocol.rb', line 38

def default_negotiated_version
  DEFAULT_NEGOTIATED_PROTOCOL_VERSION
end

.draft_or_newer?(version) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
59
60
61
62
63
64
# File 'lib/ruby_llm/mcp/native/protocol.rb', line 56

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

.draft_versionObject



34
35
36
# File 'lib/ruby_llm/mcp/native/protocol.rb', line 34

def draft_version
  DRAFT_PROTOCOL_VERSION
end

.extensions_supported?(version) ⇒ Boolean

Extensions are part of the stable protocol track from 2025-06-18 onward.

Returns:

  • (Boolean)


67
68
69
70
71
72
73
74
75
# File 'lib/ruby_llm/mcp/native/protocol.rb', line 67

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

.latest_versionObject



30
31
32
# File 'lib/ruby_llm/mcp/native/protocol.rb', line 30

def latest_version
  LATEST_PROTOCOL_VERSION
end

.supported_version?(version) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/ruby_llm/mcp/native/protocol.rb', line 22

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

.supported_versionsObject



26
27
28
# File 'lib/ruby_llm/mcp/native/protocol.rb', line 26

def supported_versions
  SUPPORTED_PROTOCOL_VERSIONS
end