Class: Rubyagents::MCP::MCPToolWrapper
- Defined in:
- lib/rubyagents/mcp.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#mcp_tool ⇒ Object
readonly
Returns the value of attribute mcp_tool.
Class Method Summary collapse
Instance Method Summary collapse
- #call(**kwargs) ⇒ Object
-
#initialize(mcp_tool, client) ⇒ MCPToolWrapper
constructor
A new instance of MCPToolWrapper.
Methods inherited from Tool
description, inherited, input, inputs, output_type, to_prompt, to_schema, tool_name
Constructor Details
#initialize(mcp_tool, client) ⇒ MCPToolWrapper
Returns a new instance of MCPToolWrapper.
89 90 91 92 |
# File 'lib/rubyagents/mcp.rb', line 89 def initialize(mcp_tool, client) @mcp_tool = mcp_tool @client = client end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
70 71 72 |
# File 'lib/rubyagents/mcp.rb', line 70 def client @client end |
#mcp_tool ⇒ Object (readonly)
Returns the value of attribute mcp_tool.
70 71 72 |
# File 'lib/rubyagents/mcp.rb', line 70 def mcp_tool @mcp_tool end |
Class Method Details
.for(mcp_tool, client) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/rubyagents/mcp.rb', line 72 def self.for(mcp_tool, client) klass = Class.new(self) do tool_name(mcp_tool["name"]) description(mcp_tool["description"] || "") schema = mcp_tool.dig("inputSchema", "properties") || {} required_fields = mcp_tool.dig("inputSchema", "required") || [] schema.each do |param_name, param_def| input param_name.to_sym, type: (param_def["type"] || "string").to_sym, description: param_def["description"] || "", required: required_fields.include?(param_name) end end klass.new(mcp_tool, client) end |
Instance Method Details
#call(**kwargs) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/rubyagents/mcp.rb', line 94 def call(**kwargs) response = @client.send_request( request: { method: "tools/call", params: { name: @mcp_tool["name"], arguments: kwargs.transform_keys(&:to_s) } } ) # Extract text content from MCP response content = response.dig("result", "content") || [] content.filter_map { |c| c["text"] if c["type"] == "text" }.join("\n") end |