Class: ModelContextProtocol::Server::StreamableHttpConfiguration

Inherits:
Configuration
  • Object
show all
Defined in:
lib/model_context_protocol/server/streamable_http_configuration.rb

Overview

Settings for servers that communicate via the MCP streamable HTTP transport, typically used by Rack applications serving multiple clients concurrently with Redis-backed coordination.

Created by Server.with_streamable_http_transport, which yields an instance to a configuration block before passing it to Router. Adds session management (require_sessions), CORS control (validate_origin, allowed_origins), connection timeouts (session_ttl, ping_timeout), and Redis connection pool settings (redis_url, redis_pool_size, etc.) on top of the base class. validate_transport! verifies that redis_url is a valid Redis URL, and setup_transport! configures the Redis connection pool via RedisConfig before the server starts.

Router queries supports_list_changed? (true for this subclass, false for stdio) to advertise listChanged capabilities in the initialize response. StreamableHttpTransport reads require_sessions, validate_origin, allowed_origins, session_ttl, and ping_timeout directly from this configuration.

Instance Attribute Summary collapse

Attributes inherited from Configuration

#client_logger, #instructions, #name, #pagination, #title, #version

Instance Method Summary collapse

Methods inherited from Configuration

#apply_environment_variables?, #context, #context=, #initialize, #pagination_enabled?, #pagination_options, #registry, #server_logger, #validate!

Constructor Details

This class inherits a constructor from ModelContextProtocol::Server::Configuration

Instance Attribute Details

#allowed_originsArray<String>

Retrieve the list of permitted CORS origins. StreamableHttpTransport reads this during OPTIONS preflight handling to check the request's Origin header against allowed values.



114
115
116
# File 'lib/model_context_protocol/server/streamable_http_configuration.rb', line 114

def allowed_origins
  @allowed_origins || DEFAULT_ALLOWED_ORIGINS
end

#ping_timeoutInteger

Retrieve the ping response timeout in seconds. StreamableHttpTransport passes this to StreamMonitor, which closes streams that don't respond to ping messages within this window (indicating client disconnection or network failure).



133
134
135
# File 'lib/model_context_protocol/server/streamable_http_configuration.rb', line 133

def ping_timeout
  @ping_timeout || 10
end

#redis_enable_reaperBoolean



154
155
156
# File 'lib/model_context_protocol/server/streamable_http_configuration.rb', line 154

def redis_enable_reaper
  @redis_enable_reaper.nil? ? true : @redis_enable_reaper
end

#redis_idle_timeoutInteger



164
165
166
# File 'lib/model_context_protocol/server/streamable_http_configuration.rb', line 164

def redis_idle_timeout
  @redis_idle_timeout || 300
end

#redis_pool_sizeInteger



141
142
143
# File 'lib/model_context_protocol/server/streamable_http_configuration.rb', line 141

def redis_pool_size
  @redis_pool_size || 20
end

#redis_pool_timeoutInteger



146
147
148
# File 'lib/model_context_protocol/server/streamable_http_configuration.rb', line 146

def redis_pool_timeout
  @redis_pool_timeout || 5
end

#redis_reaper_intervalInteger



159
160
161
# File 'lib/model_context_protocol/server/streamable_http_configuration.rb', line 159

def redis_reaper_interval
  @redis_reaper_interval || 60
end

#redis_ssl_paramsHash?



151
152
153
# File 'lib/model_context_protocol/server/streamable_http_configuration.rb', line 151

def redis_ssl_params
  @redis_ssl_params
end

#redis_urlString?



138
139
140
# File 'lib/model_context_protocol/server/streamable_http_configuration.rb', line 138

def redis_url
  @redis_url
end

#require_sessionsBoolean

Check whether session IDs are mandatory for incoming requests. StreamableHttpTransport reads this at request handling time to decide whether to reject requests without session_id query parameters.



95
96
97
# File 'lib/model_context_protocol/server/streamable_http_configuration.rb', line 95

def require_sessions
  @require_sessions.nil? ? true : @require_sessions
end

#session_ttlInteger

Retrieve the session expiration time in seconds. StreamableHttpTransport passes this to SessionStore.new, which sets Redis key TTLs to automatically expire inactive sessions.



123
124
125
# File 'lib/model_context_protocol/server/streamable_http_configuration.rb', line 123

def session_ttl
  @session_ttl || 3600
end

#validate_originBoolean

Check whether CORS origin validation is enforced. StreamableHttpTransport reads this during OPTIONS preflight handling to decide whether to reject requests with disallowed Origin headers.



104
105
106
# File 'lib/model_context_protocol/server/streamable_http_configuration.rb', line 104

def validate_origin
  @validate_origin.nil? ? true : @validate_origin
end

Instance Method Details

#supports_list_changed?Boolean



23
# File 'lib/model_context_protocol/server/streamable_http_configuration.rb', line 23

def supports_list_changed? = true

#transport_typeSymbol



19
# File 'lib/model_context_protocol/server/streamable_http_configuration.rb', line 19

def transport_type = :streamable_http