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.



192
193
194
# File 'lib/otto/mcp/server.rb', line 192

def otto_instance
  @otto_instance
end

Class Method Details

.handle_request(req, res) ⇒ Object



195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/otto/mcp/server.rb', line 195

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