Class: ProxyToolBuilder

Inherits:
Object
  • Object
show all
Defined in:
app/mcp/proxy_tool_builder.rb

Overview

Builds dynamic MCP::Tool subclasses that proxy calls to upstream MCP servers.

Each tool is namespaced with the upstream service key to avoid name collisions:
service_tool-name → calls upstream tool "tool-name" on that service

Access control is enforced per-call by checking Thread.current[:mcp_auth_result],
which is set by the McpBearerAuth middleware in config.ru.

Examples:

proxy = UpstreamProxy.new(upstream)
tool_classes = ProxyToolBuilder.build(proxy)
# => [<Class service_tool-a>, <Class service_tool-b>, ...]

Class Method Summary collapse

Class Method Details

.build(upstream_proxy) ⇒ Array<Class>

Build tool classes for all tools advertised by an upstream proxy.

Parameters:

Returns:

  • (Array<Class>)

    Array of MCP::Tool subclasses ready to register with the server



23
24
25
26
27
28
29
30
31
32
# File 'app/mcp/proxy_tool_builder.rb', line 23

def self.build(upstream_proxy)
  service_key = upstream_proxy.service_key

  upstream_proxy.list_tools.filter_map do |remote_tool|
    build_one(service_key, upstream_proxy, remote_tool)
  rescue => e
    Rails.logger.warn "[MCP Proxy] Skipping tool #{remote_tool.name} from #{service_key}: #{e.message}"
    nil
  end
end