Class: RailsAiBridge::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_ai_bridge/middleware.rb

Overview

Rack middleware that intercepts requests at the configured HTTP path and delegates to the MCP StreamableHTTPTransport. All other requests pass through to the Rails app.

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Middleware

Returns a new instance of Middleware.



10
11
12
13
14
# File 'lib/rails_ai_bridge/middleware.rb', line 10

def initialize(app)
  @app = app
  @mcp_transport = nil
  @mutex = Mutex.new
end

Instance Method Details

#call(env) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/rails_ai_bridge/middleware.rb', line 16

def call(env)
  config = RailsAiBridge.configuration
  path = config.http_path

  if [path, "#{path}/"].include?(env['PATH_INFO'])
    rack_app.call(env)
  else
    @app.call(env)
  end
end