Class: ActiveMcp::Tool::Base
- Inherits:
-
Object
- Object
- ActiveMcp::Tool::Base
- Defined in:
- lib/active_mcp/tool/base.rb
Class Attribute Summary collapse
-
.schema ⇒ Object
readonly
Returns the value of attribute schema.
Class Method Summary collapse
Instance Method Summary collapse
- #call(context: {}, **args) ⇒ Object
- #description ⇒ Object
-
#initialize ⇒ Base
constructor
A new instance of Base.
- #tool_name ⇒ Object
- #validate_arguments(args) ⇒ Object
- #visible?(context: {}) ⇒ Boolean
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
26 27 |
# File 'lib/active_mcp/tool/base.rb', line 26 def initialize end |
Class Attribute Details
.schema ⇒ Object (readonly)
Returns the value of attribute schema.
7 8 9 |
# File 'lib/active_mcp/tool/base.rb', line 7 def schema @schema end |
Class Method Details
.argument(name, type, required: false, description: nil) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/active_mcp/tool/base.rb', line 9 def argument(name, type, required: false, description: nil) @schema ||= default_schema @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 |
.default_schema ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/active_mcp/tool/base.rb', line 17 def default_schema { "type" => "object", "properties" => {}, "required" => [] } end |
Instance Method Details
#call(context: {}, **args) ⇒ Object
39 40 41 |
# File 'lib/active_mcp/tool/base.rb', line 39 def call(context: {}, **args) raise NotImplementedError, "#{self.class.name}#call must be implemented" end |
#description ⇒ Object
32 33 |
# File 'lib/active_mcp/tool/base.rb', line 32 def description end |
#tool_name ⇒ Object
29 30 |
# File 'lib/active_mcp/tool/base.rb', line 29 def tool_name end |
#validate_arguments(args) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/active_mcp/tool/base.rb', line 43 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 |
#visible?(context: {}) ⇒ Boolean
35 36 37 |
# File 'lib/active_mcp/tool/base.rb', line 35 def visible?(context: {}) true end |