Class: Resque::Mcp::EndpointController

Inherits:
ActionController::API
  • Object
show all
Defined in:
app/controllers/resque/mcp/endpoint_controller.rb

Instance Method Summary collapse

Instance Method Details

#handleObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/resque/mcp/endpoint_controller.rb', line 8

def handle
  server = ServerFactory.build(environment: Rails.env.to_s)
  config = Resque::Mcp.config
  # Passthrough first; our security-critical keys override, so nothing
  # in mcp_transport_options can weaken the DNS-rebinding posture.
  options = config.mcp_transport_options.merge(
    stateless: true,
    enable_json_response: true,
    dns_rebinding_protection: true,
    allowed_hosts: config.allowed_hosts,
    allowed_origins: config.allowed_origins
  )
  transport = ::MCP::Server::Transports::StreamableHTTPTransport.new(server, **options)

  status, headers, body = transport.handle_request(request)
  headers.each { |key, value| response.set_header(key, value) }

  payload = body.first
  if payload
    render json: payload, status: status
  else
    head status
  end
end

#method_not_allowedObject



33
34
35
# File 'app/controllers/resque/mcp/endpoint_controller.rb', line 33

def method_not_allowed
  head :method_not_allowed
end