Class: Otto::MCP::InternalHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/otto/mcp/server.rb

Overview

Internal handler class for MCP protocol endpoints

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.otto_instanceObject

Returns the value of attribute otto_instance.



292
293
294
# File 'lib/otto/mcp/server.rb', line 292

def otto_instance
  @otto_instance
end

Class Method Details

.handle_request(req, res) ⇒ Object



295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
# File 'lib/otto/mcp/server.rb', line 295

def self.handle_request(req, res)
  otto_instance = @otto_instance

  if otto_instance.nil?
    return [500, { 'content-type' => 'application/json' },
            [JSON.generate({ error: 'Otto instance not available' })]]
  end

  mcp_server = otto_instance.mcp_server

  unless mcp_server&.enabled?
    return [404, { 'content-type' => 'application/json' },
            [JSON.generate({ error: 'MCP not enabled' })]]
  end

  status, headers, body = mcp_server.protocol.handle_request(req.env)

  res.status                   = status
  headers.each { |k, v| res[k] = v }
  res.body                     = body
  res.finish
end