Module: Otto::MCP::Core

Included in:
Otto
Defined in:
lib/otto/mcp/core.rb

Overview

Core MCP (Model Context Protocol) methods included in the Otto class. Provides the public API for enabling and querying MCP server support.

Instance Method Summary collapse

Instance Method Details

#enable_mcp!(options = {}) ⇒ Object

Enable MCP (Model Context Protocol) server support

Options are normalized by Otto::MCP::Server.normalize_options under the :explicit scope. That scope accepts the canonical keys below and their mcp_-prefixed spellings (:mcp_endpoint, :mcp_auth_tokens, ...), as String or Symbol keys, so one hash can feed both Otto.new and this method.

It is STRICT: any other key raises ArgumentError rather than being ignored, so a typo such as enable_mcp!(auth_token: 'x') fails at boot instead of quietly leaving the endpoint unauthenticated. That includes the constructor-only gating keys (:mcp_enabled, :mcp_http, :mcp_stdio): this method always enables the HTTP endpoint, so it cannot honour them.

Examples:

otto.enable_mcp!(http_endpoint: '/api/mcp', auth_tokens: ['secret'])

Parameters:

  • options (Hash) (defaults to: {})

    MCP configuration options

Options Hash (options):

  • :http_endpoint (String)

    HTTP endpoint path (default: '/_mcp')

  • :auth_tokens (Array<String>, String)

    Bearer tokens required on the MCP endpoint (default: none, which logs a warning)

  • :allow_unauthenticated (Boolean)

    Acknowledge an intentionally unauthenticated endpoint, silencing that warning (default: false)

  • :enable_validation (Boolean)

    Enable JSON schema validation (default: true)

  • :enable_rate_limiting (Boolean)

    Enable rate limiting (default: true)

  • :requests_per_minute (Integer)

    MCP endpoint limit (default: 60)

  • :tools_per_minute (Integer)

    tools/call limit (default: 20)



36
37
38
39
40
41
42
# File 'lib/otto/mcp/core.rb', line 36

def enable_mcp!(options = {})
  ensure_not_frozen!
  @mcp_server ||= Otto::MCP::Server.new(self)

  @mcp_server.enable!(Otto::MCP::Server.normalize_options(options))
  Otto.logger.info '[MCP] Enabled MCP server' if Otto.debug
end

#mcp_enabled?Boolean

Check if MCP is enabled

Returns:

  • (Boolean)


46
47
48
# File 'lib/otto/mcp/core.rb', line 46

def mcp_enabled?
  @mcp_server&.enabled?
end