Class: Otto::MCP::Server

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

Overview

MCP server implementation providing Model Context Protocol endpoints

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(otto_instance) ⇒ Server

Returns a new instance of Server.



18
19
20
21
22
# File 'lib/otto/mcp/server.rb', line 18

def initialize(otto_instance)
  @otto_instance = otto_instance
  @protocol      = Protocol.new(otto_instance)
  @enabled       = false
end

Instance Attribute Details

#otto_instanceObject (readonly)

Returns the value of attribute otto_instance.



16
17
18
# File 'lib/otto/mcp/server.rb', line 16

def otto_instance
  @otto_instance
end

#protocolObject (readonly)

Returns the value of attribute protocol.



16
17
18
# File 'lib/otto/mcp/server.rb', line 16

def protocol
  @protocol
end

Instance Method Details

#enable!(options = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/otto/mcp/server.rb', line 24

def enable!(options = {})
  @enabled              = true
  @http_endpoint        = options.fetch(:http_endpoint, '/_mcp')
  @auth_tokens          = options[:auth_tokens] || []
  @enable_validation    = options.fetch(:enable_validation, true)
  @enable_rate_limiting = options.fetch(:enable_rate_limiting, true)

  # Configure middleware
  configure_middleware(options)

  # Add MCP endpoint route to Otto
  add_mcp_endpoint_route

  Otto.logger.info "[MCP] Server enabled with HTTP endpoint: #{@http_endpoint}" if Otto.debug
end

#enabled?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/otto/mcp/server.rb', line 40

def enabled?
  @enabled
end

#register_mcp_route(route_info) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/otto/mcp/server.rb', line 44

def register_mcp_route(route_info)
  case route_info[:type]
  when :mcp_resource
    register_resource(route_info)
  when :mcp_tool
    register_tool(route_info)
  end
end