Class: AdminSuite::McpController

Inherits:
ApplicationController show all
Defined in:
app/controllers/admin_suite/mcp_controller.rb

Instance Method Summary collapse

Instance Method Details

#create ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/admin_suite/mcp_controller.rb', line 10

def create
  return head :not_found unless AdminSuite.config.mcp.enabled
  return head :unauthorized unless admin_suite_actor
  return head :method_not_allowed unless request.post?

  AdminSuite::DefinitionLoader.load!(:resources)
  server = AdminSuite::Mcp.server_for(actor: admin_suite_actor, request: request)
  transport = ::MCP::Server::Transports::StreamableHTTPTransport.new(
    server, stateless: true, allowed_hosts: [request.host]
  )
  status, headers, body = transport.handle_request(request)
  self.status = status
  headers.each { |name, value| response.set_header(name, value) }
  self.response_body = body
end