Class: Raix::MCP::Tool

Inherits:
Object
  • Object
show all
Defined in:
lib/mcp/tool.rb

Overview

Represents an MCP (Model Context Protocol) tool with metadata and schema

Examples:

tool = Tool.new(
  name: "weather",
  description: "Get weather info",
  input_schema: { "type" => "object", "properties" => { "city" => { "type" => "string" } } }
)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#descriptionObject (readonly)

Returns the value of attribute description.



12
13
14
# File 'lib/mcp/tool.rb', line 12

def description
  @description
end

#input_schemaObject (readonly)

Returns the value of attribute input_schema.



12
13
14
# File 'lib/mcp/tool.rb', line 12

def input_schema
  @input_schema
end

#nameObject (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_typeString?

Get the input schema type



40
41
42
# File 'lib/mcp/tool.rb', line 40

def input_type
  input_schema["type"]
end

#propertiesHash

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_propertiesArray<String>

Get required properties array



54
55
56
# File 'lib/mcp/tool.rb', line 54

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