Class: MCP::Configuration

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

Constant Summary collapse

LATEST_STABLE_PROTOCOL_VERSION =
"2026-07-28"
SUPPORTED_STABLE_PROTOCOL_VERSIONS =
[
  LATEST_STABLE_PROTOCOL_VERSION, "2025-11-25", "2025-06-18", "2025-03-26", "2024-11-05",
].freeze
DEFAULT_NEGOTIATED_PROTOCOL_VERSION =
"2025-03-26"
LATEST_MODERN_PROTOCOL_VERSION =

Protocol versions of the stateless "modern" lifecycle introduced by the MCP 2026-07-28 spec release (SEP-2575). 2026-07-28 serves both lifecycles of the dual-era model: it is negotiable through the legacy initialize handshake (so it also appears in SUPPORTED_STABLE_PROTOCOL_VERSIONS), and it is the version of the modern lifecycle, where each request carries its own version in _meta and is validated against this list independently, with no handshake. https://github.com/modelcontextprotocol/modelcontextprotocol/pull/2575

"2026-07-28"
SUPPORTED_MODERN_PROTOCOL_VERSIONS =
[LATEST_MODERN_PROTOCOL_VERSION].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(exception_reporter: nil, around_request: nil, instrumentation_callback: nil, protocol_version: nil, validate_tool_call_arguments: true, validate_tool_call_results: false) ⇒ Configuration

Returns a new instance of Configuration.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/mcp/configuration.rb', line 34

def initialize(exception_reporter: nil, around_request: nil, instrumentation_callback: nil, protocol_version: nil,
  validate_tool_call_arguments: true, validate_tool_call_results: false)
  @exception_reporter = exception_reporter
  @around_request = around_request
  @instrumentation_callback = instrumentation_callback
  @protocol_version = protocol_version
  if protocol_version
    validate_protocol_version!(protocol_version)
  end
  validate_value_of_validate_tool_call_arguments!(validate_tool_call_arguments)
  validate_value_of_validate_tool_call_results!(validate_tool_call_results)

  @validate_tool_call_arguments = validate_tool_call_arguments
  @validate_tool_call_results = validate_tool_call_results
end

Instance Attribute Details

#around_requestObject



84
85
86
# File 'lib/mcp/configuration.rb', line 84

def around_request
  @around_request || default_around_request
end

#exception_reporterObject



76
77
78
# File 'lib/mcp/configuration.rb', line 76

def exception_reporter
  @exception_reporter || default_exception_reporter
end

#instrumentation_callbackObject

Deprecated.

Use #around_request instead. instrumentation_callback fires only after a request completes and cannot wrap execution in a surrounding block (e.g. for Application Performance Monitoring (APM) spans).

See Also:



96
97
98
# File 'lib/mcp/configuration.rb', line 96

def instrumentation_callback
  @instrumentation_callback || default_instrumentation_callback
end

#validate_tool_call_argumentsObject

Returns the value of attribute validate_tool_call_arguments.



106
107
108
# File 'lib/mcp/configuration.rb', line 106

def validate_tool_call_arguments
  @validate_tool_call_arguments
end

#validate_tool_call_resultsObject

Returns the value of attribute validate_tool_call_results.



107
108
109
# File 'lib/mcp/configuration.rb', line 107

def validate_tool_call_results
  @validate_tool_call_results
end

Class Method Details

.modern_protocol_version?(version) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/mcp/configuration.rb', line 21

def modern_protocol_version?(version)
  SUPPORTED_MODERN_PROTOCOL_VERSIONS.include?(version)
end

Instance Method Details

#around_request?Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/mcp/configuration.rb', line 88

def around_request?
  !@around_request.nil?
end

#exception_reporter?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/mcp/configuration.rb', line 80

def exception_reporter?
  !@exception_reporter.nil?
end

#instrumentation_callback?Boolean

Deprecated.

Use #around_request? instead.

Returns:

  • (Boolean)

See Also:



102
103
104
# File 'lib/mcp/configuration.rb', line 102

def instrumentation_callback?
  !@instrumentation_callback.nil?
end

#merge(other) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/mcp/configuration.rb', line 117

def merge(other)
  return self if other.nil?

  exception_reporter = if other.exception_reporter?
    other.exception_reporter
  else
    @exception_reporter
  end

  around_request = if other.around_request?
    other.around_request
  else
    @around_request
  end

  instrumentation_callback = if other.instrumentation_callback?
    other.instrumentation_callback
  else
    @instrumentation_callback
  end

  protocol_version = if other.protocol_version?
    other.protocol_version
  else
    @protocol_version
  end

  validate_tool_call_arguments = other.validate_tool_call_arguments
  validate_tool_call_results = other.validate_tool_call_results

  Configuration.new(
    exception_reporter: exception_reporter,
    around_request: around_request,
    instrumentation_callback: instrumentation_callback,
    protocol_version: protocol_version,
    validate_tool_call_arguments: validate_tool_call_arguments,
    validate_tool_call_results: validate_tool_call_results,
  )
end

#protocol_versionObject



68
69
70
# File 'lib/mcp/configuration.rb', line 68

def protocol_version
  @protocol_version || LATEST_STABLE_PROTOCOL_VERSION
end

#protocol_version=(protocol_version) ⇒ Object



50
51
52
53
54
# File 'lib/mcp/configuration.rb', line 50

def protocol_version=(protocol_version)
  validate_protocol_version!(protocol_version)

  @protocol_version = protocol_version
end

#protocol_version?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/mcp/configuration.rb', line 72

def protocol_version?
  !@protocol_version.nil?
end

#validate_tool_call_arguments?Boolean

Returns:

  • (Boolean)


109
110
111
# File 'lib/mcp/configuration.rb', line 109

def validate_tool_call_arguments?
  !!@validate_tool_call_arguments
end

#validate_tool_call_results?Boolean

Returns:

  • (Boolean)


113
114
115
# File 'lib/mcp/configuration.rb', line 113

def validate_tool_call_results?
  !!@validate_tool_call_results
end