Class: ToolRegistry::Definition
- Inherits:
-
Object
- Object
- ToolRegistry::Definition
- Defined in:
- lib/stack-service-base/mcp/mcp_tool_registry.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #annotations(value = nil) ⇒ Object
- #call(&block) ⇒ Object
- #call_tool(arguments) ⇒ Object
- #description(text = nil) ⇒ Object
-
#initialize(name) ⇒ Definition
constructor
A new instance of Definition.
- #input(fields = {}) ⇒ Object
- #input_schema(schema = nil) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(name) ⇒ Definition
Returns a new instance of Definition.
31 32 33 34 35 |
# File 'lib/stack-service-base/mcp/mcp_tool_registry.rb', line 31 def initialize(name) @name = name.to_s @inputs = {} @annotations = {} end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
29 30 31 |
# File 'lib/stack-service-base/mcp/mcp_tool_registry.rb', line 29 def name @name end |
Instance Method Details
#annotations(value = nil) ⇒ Object
52 53 54 55 56 |
# File 'lib/stack-service-base/mcp/mcp_tool_registry.rb', line 52 def annotations(value = nil) return @annotations if value.nil? @annotations = stringify_keys(value) end |
#call(&block) ⇒ Object
58 |
# File 'lib/stack-service-base/mcp/mcp_tool_registry.rb', line 58 def call(&block) = @executor = block |
#call_tool(arguments) ⇒ Object
70 71 72 73 74 |
# File 'lib/stack-service-base/mcp/mcp_tool_registry.rb', line 70 def call_tool(arguments) raise JsonRpcError.new(code: -32603, message: "Tool #{name} missing executor") unless @executor ExecutionContext.new.instance_exec(symbolize_keys(arguments || {}), &@executor) end |
#description(text = nil) ⇒ Object
37 38 39 40 |
# File 'lib/stack-service-base/mcp/mcp_tool_registry.rb', line 37 def description(text = nil) return @description if text.nil? @description = text end |
#input(fields = {}) ⇒ Object
42 43 44 |
# File 'lib/stack-service-base/mcp/mcp_tool_registry.rb', line 42 def input(fields = {}) @inputs.merge!(fields.transform_keys(&:to_s)) end |
#input_schema(schema = nil) ⇒ Object
46 47 48 49 50 |
# File 'lib/stack-service-base/mcp/mcp_tool_registry.rb', line 46 def input_schema(schema = nil) return @input_schema || build_input_schema if schema.nil? @input_schema = stringify_keys(schema) end |
#to_h ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/stack-service-base/mcp/mcp_tool_registry.rb', line 60 def to_h payload = { name: name, description: description, inputSchema: input_schema } payload[:annotations] = annotations unless annotations.empty? payload end |