Class: ActionMCP::Client::Toolbox::Tool

Inherits:
Object
  • Object
show all
Defined in:
lib/action_mcp/client/toolbox.rb

Overview

Internal Tool class to represent individual tools

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Tool

Initialize a new Tool instance



113
114
115
116
117
118
# File 'lib/action_mcp/client/toolbox.rb', line 113

def initialize(data)
  @name = data["name"]
  @description = data["description"]
  @input_schema = data["inputSchema"] || {}
  @annotations = data["annotations"] || {}
end

Instance Attribute Details

#annotationsObject (readonly)

Returns the value of attribute annotations.



107
108
109
# File 'lib/action_mcp/client/toolbox.rb', line 107

def annotations
  @annotations
end

#descriptionObject (readonly)

Returns the value of attribute description.



107
108
109
# File 'lib/action_mcp/client/toolbox.rb', line 107

def description
  @description
end

#input_schemaObject (readonly)

Returns the value of attribute input_schema.



107
108
109
# File 'lib/action_mcp/client/toolbox.rb', line 107

def input_schema
  @input_schema
end

#nameObject (readonly)

Returns the value of attribute name.



107
108
109
# File 'lib/action_mcp/client/toolbox.rb', line 107

def name
  @name
end

Instance Method Details

#has_property?(name) ⇒ Boolean

Check if the tool has a specific property



146
147
148
# File 'lib/action_mcp/client/toolbox.rb', line 146

def has_property?(name)
  properties.key?(name)
end

#propertiesHash

Get all properties for this tool



130
131
132
# File 'lib/action_mcp/client/toolbox.rb', line 130

def properties
  @input_schema["properties"] || {}
end

#property(name) ⇒ Hash?

Get property details by name



154
155
156
# File 'lib/action_mcp/client/toolbox.rb', line 154

def property(name)
  properties[name]
end

#required_propertiesArray<String>

Get all required properties for this tool



123
124
125
# File 'lib/action_mcp/client/toolbox.rb', line 123

def required_properties
  @input_schema["required"] || []
end

#requires?(name) ⇒ Boolean

Check if the tool requires a specific property



138
139
140
# File 'lib/action_mcp/client/toolbox.rb', line 138

def requires?(name)
  required_properties.include?(name)
end

#to_claude_hHash

Generate a hash representation of the tool in Claude format



173
174
175
176
177
178
179
180
# File 'lib/action_mcp/client/toolbox.rb', line 173

def to_claude_h
  {
    "name" => @name,
    "description" => @description,
    "input_schema" => @input_schema.transform_keys { |k| k == "inputSchema" ? "input_schema" : k },
    "annotations" => @annotations
  }
end

#to_hHash

Generate a hash representation of the tool (default format)



161
162
163
164
165
166
167
168
# File 'lib/action_mcp/client/toolbox.rb', line 161

def to_h
  {
    "name" => @name,
    "description" => @description,
    "inputSchema" => @input_schema,
    "annotations" => @annotations
  }
end

#to_openai_hHash

Generate a hash representation of the tool in OpenAI format



185
186
187
188
189
190
191
192
193
194
195
# File 'lib/action_mcp/client/toolbox.rb', line 185

def to_openai_h
  {
    "type" => "function",
    "function" => {
      "name" => @name,
      "description" => @description,
      "parameters" => @input_schema,
      "annotations" => @annotations
    }
  }
end