Class: ModelContextProtocol::Server::StreamableHttpConfiguration
- Inherits:
-
Configuration
- Object
- Configuration
- ModelContextProtocol::Server::StreamableHttpConfiguration
- 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
-
#allowed_origins ⇒ Array<String>
Retrieve the list of permitted CORS origins.
-
#ping_timeout ⇒ Integer
Retrieve the ping response timeout in seconds.
-
#redis_enable_reaper ⇒ Boolean
Whether the idle connection reaper is enabled (default: true).
-
#redis_idle_timeout ⇒ Integer
Seconds before idle connections are reaped (default: 300).
-
#redis_pool_size ⇒ Integer
Number of Redis connections in the pool (default: 20).
-
#redis_pool_timeout ⇒ Integer
Seconds to wait for a pool connection (default: 5).
-
#redis_reaper_interval ⇒ Integer
Seconds between reaper checks (default: 60).
-
#redis_ssl_params ⇒ Hash?
SSL parameters for Redis connections.
-
#redis_url ⇒ String?
The Redis connection URL.
-
#require_sessions ⇒ Boolean
Check whether session IDs are mandatory for incoming requests.
-
#session_ttl ⇒ Integer
Retrieve the session expiration time in seconds.
-
#validate_origin ⇒ Boolean
Check whether CORS origin validation is enforced.
Attributes inherited from Configuration
#client_logger, #instructions, #name, #pagination, #title, #version
Instance Method Summary collapse
-
#supports_list_changed? ⇒ Boolean
True (Router advertises listChanged in initialize response capabilities; StreamableHttpTransport can push unsolicited notifications to clients).
-
#transport_type ⇒ Symbol
:streamable_http (used by Server.start to instantiate StreamableHttpTransport).
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_origins ⇒ Array<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_timeout ⇒ Integer
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_reaper ⇒ Boolean
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_timeout ⇒ Integer
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_size ⇒ Integer
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_timeout ⇒ Integer
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_interval ⇒ Integer
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_params ⇒ Hash?
151 152 153 |
# File 'lib/model_context_protocol/server/streamable_http_configuration.rb', line 151 def redis_ssl_params @redis_ssl_params end |
#redis_url ⇒ String?
138 139 140 |
# File 'lib/model_context_protocol/server/streamable_http_configuration.rb', line 138 def redis_url @redis_url end |
#require_sessions ⇒ Boolean
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_ttl ⇒ Integer
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_origin ⇒ Boolean
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_type ⇒ Symbol
19 |
# File 'lib/model_context_protocol/server/streamable_http_configuration.rb', line 19 def transport_type = :streamable_http |