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, instrumentation_callback: nil, protocol_version: nil, validate_tool_call_arguments: true) ⇒ Configuration



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/mcp/configuration.rb', line 12

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

#exception_reporterObject



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

def exception_reporter
  @exception_reporter || default_exception_reporter
end

#instrumentation_callbackObject



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

def instrumentation_callback
  @instrumentation_callback || default_instrumentation_callback
end

#validate_tool_call_argumentsObject

Returns the value of attribute validate_tool_call_arguments.



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

def validate_tool_call_arguments
  @validate_tool_call_arguments
end

Instance Method Details

#exception_reporter?Boolean



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

def exception_reporter?
  !@exception_reporter.nil?
end

#instrumentation_callback?Boolean



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

def instrumentation_callback?
  !@instrumentation_callback.nil?
end

#merge(other) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/mcp/configuration.rb', line 67

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

  exception_reporter = if other.exception_reporter?
    other.exception_reporter
  else
    @exception_reporter
  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,
    instrumentation_callback: instrumentation_callback,
    protocol_version: protocol_version,
    validate_tool_call_arguments: validate_tool_call_arguments,
  )
end

#protocol_versionObject



37
38
39
# File 'lib/mcp/configuration.rb', line 37

def protocol_version
  @protocol_version || LATEST_STABLE_PROTOCOL_VERSION
end

#protocol_version=(protocol_version) ⇒ Object



25
26
27
28
29
# File 'lib/mcp/configuration.rb', line 25

def protocol_version=(protocol_version)
  validate_protocol_version!(protocol_version)

  @protocol_version = protocol_version
end

#protocol_version?Boolean



41
42
43
# File 'lib/mcp/configuration.rb', line 41

def protocol_version?
  !@protocol_version.nil?
end

#validate_tool_call_arguments?Boolean



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

def validate_tool_call_arguments?
  !!@validate_tool_call_arguments
end