Class: MCP::Configuration

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

Constant Summary collapse

DEFAULT_PROTOCOL_VERSION =
"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

Returns a new instance of Configuration.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/mcp/configuration.rb', line 9

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
  unless validate_tool_call_arguments.is_a?(TrueClass) || validate_tool_call_arguments.is_a?(FalseClass)
    raise ArgumentError, "validate_tool_call_arguments must be a boolean"
  end

  @validate_tool_call_arguments = validate_tool_call_arguments
end

Instance Attribute Details

#exception_reporterObject



29
30
31
# File 'lib/mcp/configuration.rb', line 29

def exception_reporter
  @exception_reporter || default_exception_reporter
end

#instrumentation_callbackObject



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

def instrumentation_callback
  @instrumentation_callback || default_instrumentation_callback
end

#protocol_versionObject



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

def protocol_version
  @protocol_version || DEFAULT_PROTOCOL_VERSION
end

#validate_tool_call_argumentsObject

Returns the value of attribute validate_tool_call_arguments.



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

def validate_tool_call_arguments
  @validate_tool_call_arguments
end

Instance Method Details

#exception_reporter?Boolean

Returns:

  • (Boolean)


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

def exception_reporter?
  !@exception_reporter.nil?
end

#instrumentation_callback?Boolean

Returns:

  • (Boolean)


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

def instrumentation_callback?
  !@instrumentation_callback.nil?
end

#merge(other) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/mcp/configuration.rb', line 51

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:,
    instrumentation_callback:,
    protocol_version:,
    validate_tool_call_arguments:,
  )
end

#protocol_version?Boolean

Returns:

  • (Boolean)


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

def protocol_version?
  !@protocol_version.nil?
end

#validate_tool_call_arguments?Boolean

Returns:

  • (Boolean)


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

def validate_tool_call_arguments?
  !!@validate_tool_call_arguments
end