Class: Raix::MCP::Tool
- Inherits:
-
Object
- Object
- Raix::MCP::Tool
- Defined in:
- lib/mcp/tool.rb
Overview
Represents an MCP (Model Context Protocol) tool with metadata and schema
Instance Attribute Summary collapse
-
#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.
Class Method Summary collapse
-
.from_json(json) ⇒ Tool
Initialize from raw MCP JSON response.
Instance Method Summary collapse
-
#initialize(name:, description:, input_schema: {}) ⇒ Tool
constructor
Initialize a new Tool.
-
#input_type ⇒ String?
Get the input schema type.
-
#properties ⇒ Hash
Get the properties hash.
-
#required?(property_name) ⇒ Boolean
Check if a property is required.
-
#required_properties ⇒ Array<String>
Get required properties array.
Constructor Details
#initialize(name:, description:, input_schema: {}) ⇒ Tool
Initialize a new Tool
19 20 21 22 23 |
# File 'lib/mcp/tool.rb', line 19 def initialize(name:, description:, input_schema: {}) @name = name @description = description @input_schema = input_schema end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
12 13 14 |
# File 'lib/mcp/tool.rb', line 12 def description @description end |
#input_schema ⇒ Object (readonly)
Returns the value of attribute input_schema.
12 13 14 |
# File 'lib/mcp/tool.rb', line 12 def input_schema @input_schema end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
12 13 14 |
# File 'lib/mcp/tool.rb', line 12 def name @name end |
Class Method Details
.from_json(json) ⇒ Tool
Initialize from raw MCP JSON response
29 30 31 32 33 34 35 |
# File 'lib/mcp/tool.rb', line 29 def self.from_json(json) new( name: json[:name] || json["name"], description: json[:description] || json["description"], input_schema: json[:inputSchema] || json["inputSchema"] || {} ) end |
Instance Method Details
#input_type ⇒ String?
Get the input schema type
40 41 42 |
# File 'lib/mcp/tool.rb', line 40 def input_type input_schema["type"] end |
#properties ⇒ Hash
Get the properties hash
47 48 49 |
# File 'lib/mcp/tool.rb', line 47 def properties input_schema["properties"] || {} end |
#required?(property_name) ⇒ Boolean
Check if a property is required
62 63 64 |
# File 'lib/mcp/tool.rb', line 62 def required?(property_name) required_properties.include?(property_name) end |
#required_properties ⇒ Array<String>
Get required properties array
54 55 56 |
# File 'lib/mcp/tool.rb', line 54 def required_properties input_schema["required"] || [] end |