Class: ActiveMcp::Tool
- Inherits:
-
Object
- Object
- ActiveMcp::Tool
- Defined in:
- lib/active_mcp/tool.rb
Class Attribute Summary collapse
-
.desc ⇒ Object
readonly
Returns the value of attribute desc.
- .registered_tools ⇒ Object
-
.schema ⇒ Object
readonly
Returns the value of attribute schema.
Class Method Summary collapse
- .argument ⇒ Object
- .description(value) ⇒ Object
- .inherited(subclass) ⇒ Object
- .property(name, type, required: false, description: nil) ⇒ Object
- .tool_name ⇒ Object
- .visible?(auth_info) ⇒ Boolean
Instance Method Summary collapse
- #call(**args) ⇒ Object
-
#initialize ⇒ Tool
constructor
A new instance of Tool.
- #validate_arguments(args) ⇒ Object
Constructor Details
#initialize ⇒ Tool
Returns a new instance of Tool.
47 48 |
# File 'lib/active_mcp/tool.rb', line 47 def initialize end |
Class Attribute Details
.desc ⇒ Object (readonly)
Returns the value of attribute desc.
6 7 8 |
# File 'lib/active_mcp/tool.rb', line 6 def desc @desc end |
.registered_tools ⇒ Object
32 33 34 |
# File 'lib/active_mcp/tool.rb', line 32 def registered_tools @registered_tools ||= [] end |
.schema ⇒ Object (readonly)
Returns the value of attribute schema.
6 7 8 |
# File 'lib/active_mcp/tool.rb', line 6 def schema @schema end |
Class Method Details
.argument ⇒ Object
28 29 30 |
# File 'lib/active_mcp/tool.rb', line 28 def argument(...) property(...) end |
.description(value) ⇒ Object
12 13 14 |
# File 'lib/active_mcp/tool.rb', line 12 def description(value) @desc = value end |
.inherited(subclass) ⇒ Object
38 39 40 |
# File 'lib/active_mcp/tool.rb', line 38 def inherited(subclass) registered_tools << subclass end |
.property(name, type, required: false, description: nil) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/active_mcp/tool.rb', line 16 def property(name, type, required: false, description: nil) @schema ||= { "type" => "object", "properties" => {}, "required" => [] } @schema["properties"][name.to_s] = {"type" => type.to_s} @schema["properties"][name.to_s]["description"] = description if description @schema["required"] << name.to_s if required end |
.tool_name ⇒ Object
8 9 10 |
# File 'lib/active_mcp/tool.rb', line 8 def tool_name name ? name.underscore.sub(/_tool$/, "") : "" end |
.visible?(auth_info) ⇒ Boolean
42 43 44 |
# File 'lib/active_mcp/tool.rb', line 42 def visible?(auth_info) true end |
Instance Method Details
#call(**args) ⇒ Object
50 51 52 |
# File 'lib/active_mcp/tool.rb', line 50 def call(**args) raise NotImplementedError, "#{self.class.name}#call must be implemented" end |
#validate_arguments(args) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/active_mcp/tool.rb', line 54 def validate_arguments(args) return true unless self.class.schema JSON::Validator.validate!(self.class.schema, args) rescue JSON::Schema::ValidationError => e {error: e.} end |