Module: SwarmSDK::V3::MCP::ToolProxy
Overview
Bridges MCP tools into RubyLLM::Tool instances
Creates anonymous RubyLLM::Tool subclasses that delegate execution to an MCP connector. Each MCP tool gets its own Tool subclass with the correct name, description, and JSON Schema parameters.
Instance Method Summary collapse
-
#create(mcp_tool, connector) ⇒ RubyLLM::Tool
Create a RubyLLM::Tool instance from an MCP tool.
Instance Method Details
#create(mcp_tool, connector) ⇒ RubyLLM::Tool
Create a RubyLLM::Tool instance from an MCP tool
Builds an anonymous subclass of RubyLLM::Tool with the MCP tool’s name, description, and input schema. The ‘execute` method delegates to the connector’s ‘call_tool`.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/swarm_sdk/v3/mcp/tool_proxy.rb', line 33 def create(mcp_tool, connector) tool_name = mcp_tool.name tool_desc = mcp_tool.description || "MCP tool: #{tool_name}" schema = mcp_tool.input_schema klass = Class.new(RubyLLM::Tool) do description tool_desc params schema if schema end klass.define_method(:name) { tool_name } klass.define_method(:execute) do |**args| connector.call_tool(tool_name, **args) end klass.new end |