Class: MCP::Configuration

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

Constant Summary collapse

LATEST_STABLE_PROTOCOL_VERSION =
"2025-11-25"
SUPPORTED_STABLE_PROTOCOL_VERSIONS =
[
  LATEST_STABLE_PROTOCOL_VERSION, "2025-06-18", "2025-03-26", "2024-11-05",
]

Instance Attribute 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) ⇒ Configuration

Returns a new instance of Configuration.



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/mcp/configuration.rb', line 18

def initialize(exception_reporter: nil, around_request: nil, instrumentation_callback: nil, protocol_version: nil,
  validate_tool_call_arguments: true)
  @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_tool_call_arguments = validate_tool_call_arguments
end

Instance Attribute Details

#around_requestObject



60
61
62
# File 'lib/mcp/configuration.rb', line 60

def around_request
  @around_request || default_around_request
end

#exception_reporterObject



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

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:



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

def instrumentation_callback
  @instrumentation_callback || default_instrumentation_callback
end

#validate_tool_call_argumentsObject

Returns the value of attribute validate_tool_call_arguments.



82
83
84
# File 'lib/mcp/configuration.rb', line 82

def validate_tool_call_arguments
  @validate_tool_call_arguments
end

Instance Method Details

#around_request?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/mcp/configuration.rb', line 64

def around_request?
  !@around_request.nil?
end

#exception_reporter?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/mcp/configuration.rb', line 56

def exception_reporter?
  !@exception_reporter.nil?
end

#instrumentation_callback?Boolean

Deprecated.

Use #around_request? instead.

Returns:

  • (Boolean)

See Also:



78
79
80
# File 'lib/mcp/configuration.rb', line 78

def instrumentation_callback?
  !@instrumentation_callback.nil?
end

#merge(other) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/mcp/configuration.rb', line 88

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

  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,
  )
end

#protocol_versionObject



44
45
46
# File 'lib/mcp/configuration.rb', line 44

def protocol_version
  @protocol_version || LATEST_STABLE_PROTOCOL_VERSION
end

#protocol_version=(protocol_version) ⇒ Object



32
33
34
35
36
# File 'lib/mcp/configuration.rb', line 32

def protocol_version=(protocol_version)
  validate_protocol_version!(protocol_version)

  @protocol_version = protocol_version
end

#protocol_version?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/mcp/configuration.rb', line 48

def protocol_version?
  !@protocol_version.nil?
end

#validate_tool_call_arguments?Boolean

Returns:

  • (Boolean)


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

def validate_tool_call_arguments?
  !!@validate_tool_call_arguments
end