Class: FastMcp::Transports::AuthenticatedRackTransport
- Inherits:
-
RackTransport
- Object
- BaseTransport
- RackTransport
- FastMcp::Transports::AuthenticatedRackTransport
- Defined in:
- lib/mcp/transports/authenticated_rack_transport.rb
Constant Summary
Constants inherited from RackTransport
RackTransport::DEFAULT_ALLOWED_IPS, RackTransport::DEFAULT_ALLOWED_ORIGINS, RackTransport::DEFAULT_PATH_PREFIX, RackTransport::SERVER_ENV_KEY, RackTransport::SSE_HEADERS
Instance Attribute Summary
Attributes inherited from RackTransport
#allowed_ips, #allowed_origins, #app, #localhost_only, #messages_route, #path_prefix, #sse_clients, #sse_route
Attributes inherited from BaseTransport
Instance Method Summary collapse
- #handle_mcp_request(request, env) ⇒ Object
-
#initialize(app, server, options = {}) ⇒ AuthenticatedRackTransport
constructor
A new instance of AuthenticatedRackTransport.
Methods inherited from RackTransport
#call, #register_sse_client, #send_message, #start, #stop, #unregister_sse_client
Methods inherited from BaseTransport
#process_message, #send_message, #start, #stop
Constructor Details
#initialize(app, server, options = {}) ⇒ AuthenticatedRackTransport
Returns a new instance of AuthenticatedRackTransport.
8 9 10 11 12 13 14 15 |
# File 'lib/mcp/transports/authenticated_rack_transport.rb', line 8 def initialize(app, server, = {}) super @auth_token = [:auth_token] @auth_header_name = [:auth_header_name] || 'Authorization' @auth_exempt_paths = [:auth_exempt_paths] || [] @auth_enabled = !@auth_token.nil? end |
Instance Method Details
#handle_mcp_request(request, env) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/mcp/transports/authenticated_rack_transport.rb', line 17 def handle_mcp_request(request, env) if auth_enabled? && !exempt_from_auth?(request.path) auth_header = request.env["HTTP_#{@auth_header_name.upcase.gsub('-', '_')}"] token = auth_header&.gsub('Bearer ', '') return (request) unless valid_token?(token) end super end |