Class: McpOnRuby::Configuration

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

Overview

Configuration class for MCP server

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/mcp_on_ruby/configuration.rb', line 20

def initialize
  @log_level = Logger::INFO
  @path = '/mcp'
  @authentication_required = false
  @authentication_token = nil
  @allowed_origins = []
  @localhost_only = false
  @rate_limit_per_minute = 60
  @enable_sse = true
  @request_timeout = 30
  @cors_enabled = true
  @dns_rebinding_protection = true
end

Instance Attribute Details

#allowed_originsObject

Returns the value of attribute allowed_origins.



8
9
10
# File 'lib/mcp_on_ruby/configuration.rb', line 8

def allowed_origins
  @allowed_origins
end

#authentication_requiredObject

Returns the value of attribute authentication_required.



8
9
10
# File 'lib/mcp_on_ruby/configuration.rb', line 8

def authentication_required
  @authentication_required
end

#authentication_tokenObject

Returns the value of attribute authentication_token.



8
9
10
# File 'lib/mcp_on_ruby/configuration.rb', line 8

def authentication_token
  @authentication_token
end

#cors_enabledObject

Returns the value of attribute cors_enabled.



8
9
10
# File 'lib/mcp_on_ruby/configuration.rb', line 8

def cors_enabled
  @cors_enabled
end

#dns_rebinding_protectionObject

Returns the value of attribute dns_rebinding_protection.



8
9
10
# File 'lib/mcp_on_ruby/configuration.rb', line 8

def dns_rebinding_protection
  @dns_rebinding_protection
end

#enable_sseObject

Returns the value of attribute enable_sse.



8
9
10
# File 'lib/mcp_on_ruby/configuration.rb', line 8

def enable_sse
  @enable_sse
end

#localhost_onlyObject

Returns the value of attribute localhost_only.



8
9
10
# File 'lib/mcp_on_ruby/configuration.rb', line 8

def localhost_only
  @localhost_only
end

#log_levelObject

Returns the value of attribute log_level.



8
9
10
# File 'lib/mcp_on_ruby/configuration.rb', line 8

def log_level
  @log_level
end

#pathObject

Returns the value of attribute path.



8
9
10
# File 'lib/mcp_on_ruby/configuration.rb', line 8

def path
  @path
end

#rate_limit_per_minuteObject

Returns the value of attribute rate_limit_per_minute.



8
9
10
# File 'lib/mcp_on_ruby/configuration.rb', line 8

def rate_limit_per_minute
  @rate_limit_per_minute
end

#request_timeoutObject

Returns the value of attribute request_timeout.



8
9
10
# File 'lib/mcp_on_ruby/configuration.rb', line 8

def request_timeout
  @request_timeout
end

Instance Method Details

#authentication_configured?Boolean

Check if authentication is configured

Returns:

  • (Boolean)

    True if authentication is properly configured



36
37
38
# File 'lib/mcp_on_ruby/configuration.rb', line 36

def authentication_configured?
  authentication_required && !authentication_token.nil?
end

#localhost_allowed?(origin) ⇒ Boolean

Check if localhost only mode and origin is localhost

Parameters:

  • origin (String)

    The origin to check

Returns:

  • (Boolean)

    True if localhost only and origin is localhost



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/mcp_on_ruby/configuration.rb', line 61

def localhost_allowed?(origin)
  return true unless localhost_only
  
  localhost_patterns = [
    'http://localhost',
    'https://localhost',
    'http://127.0.0.1',
    'https://127.0.0.1'
  ]
  
  localhost_patterns.any? { |pattern| origin&.start_with?(pattern) }
end

#origin_allowed?(origin) ⇒ Boolean

Check if origin is allowed

Parameters:

  • origin (String)

    The origin to check

Returns:

  • (Boolean)

    True if origin is allowed



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/mcp_on_ruby/configuration.rb', line 43

def origin_allowed?(origin)
  return true if allowed_origins.empty?
  
  allowed_origins.any? do |allowed|
    case allowed
    when String
      origin == allowed
    when Regexp
      origin =~ allowed
    else
      false
    end
  end
end