Module: Rubino::MCP

Defined in:
lib/rubino/mcp.rb,
lib/rubino/mcp/manager.rb,
lib/rubino/mcp/mcp_tool_wrapper.rb

Overview

MCP (Model Context Protocol) integration module. Manages connections to MCP servers and exposes their tools to the agent via the standard Tools::Registry.

Defined Under Namespace

Classes: MCPToolWrapper, Manager

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.managerObject (readonly)

The shared, booted Manager (nil until boot! succeeds).



10
11
12
# File 'lib/rubino/mcp.rb', line 10

def manager
  @manager
end

Class Method Details

.boot!Object

Boots the shared Manager once per process: connects to every configured server and registers their prefixed tools in Tools::Registry (#91). Best-effort — MCP is an optional integration and must never break boot, so any failure is a warning, not an error.



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rubino/mcp.rb', line 27

def boot!
  return @manager if @manager
  return nil unless enabled?

  manager = Manager.new
  manager.start_all!
  @manager = manager
rescue StandardError => e
  Rubino.ui.warning("MCP startup failed: #{e.message}")
  nil
end

.enabled?(config = Rubino.configuration) ⇒ Boolean

MCP is opt-in by configuration (#95): a non-empty ‘mcp.servers` block enables it; an explicit `mcp.enabled: false` switches it off without deleting the server definitions.

Returns:

  • (Boolean)


15
16
17
18
19
20
# File 'lib/rubino/mcp.rb', line 15

def enabled?(config = Rubino.configuration)
  servers = config.dig("mcp", "servers")
  return false unless servers.is_a?(Hash) && !servers.empty?

  config.dig("mcp", "enabled") != false
end

.reload!Object

‘/mcp reload` (#182): stop every server (deregistering their tools), drop the memoized Manager, re-read config.yml fresh and boot again —so a server added to config becomes usable without restarting chat. Returns the new Manager, or nil when the re-read config leaves MCP disabled (no servers / mcp.enabled: false).



44
45
46
47
48
49
# File 'lib/rubino/mcp.rb', line 44

def reload!
  @manager&.stop_all!
  @manager = nil
  Rubino.reload_configuration!
  boot!
end

.reset!Object

Clears the booted Manager (used by tests).



52
53
54
# File 'lib/rubino/mcp.rb', line 52

def reset!
  @manager = nil
end