Class: ActionMCP::Client::Toolbox::Tool
- Inherits:
-
Object
- Object
- ActionMCP::Client::Toolbox::Tool
- Defined in:
- lib/action_mcp/client/toolbox.rb
Overview
Internal Tool class to represent individual tools
Instance Attribute Summary collapse
-
#annotations ⇒ Object
readonly
Returns the value of attribute annotations.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#input_schema ⇒ Object
readonly
Returns the value of attribute input_schema.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#has_property?(name) ⇒ Boolean
Check if the tool has a specific property.
-
#initialize(data) ⇒ Tool
constructor
Initialize a new Tool instance.
-
#properties ⇒ Hash
Get all properties for this tool.
-
#property(name) ⇒ Hash?
Get property details by name.
-
#required_properties ⇒ Array<String>
Get all required properties for this tool.
-
#requires?(name) ⇒ Boolean
Check if the tool requires a specific property.
-
#to_claude_h ⇒ Hash
Generate a hash representation of the tool in Claude format.
-
#to_h ⇒ Hash
Generate a hash representation of the tool (default format).
-
#to_openai_h ⇒ Hash
Generate a hash representation of the tool in OpenAI format.
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
#annotations ⇒ Object (readonly)
Returns the value of attribute annotations.
107 108 109 |
# File 'lib/action_mcp/client/toolbox.rb', line 107 def annotations @annotations end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
107 108 109 |
# File 'lib/action_mcp/client/toolbox.rb', line 107 def description @description end |
#input_schema ⇒ Object (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 |
#name ⇒ Object (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 |
#properties ⇒ Hash
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_properties ⇒ Array<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_h ⇒ Hash
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_h ⇒ Hash
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_h ⇒ Hash
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 |