Class: ModelContextProtocol::Server::Tool
- Inherits:
-
Object
- Object
- ModelContextProtocol::Server::Tool
- Includes:
- Cancellable, ContentHelpers, Progressable
- Defined in:
- lib/model_context_protocol/server/tool.rb
Defined Under Namespace
Classes: DefinitionDSL, OutputSchemaValidationError
Class 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.
-
.output_schema ⇒ Object
readonly
Returns the value of attribute output_schema.
-
.title ⇒ Object
readonly
Returns the value of attribute title.
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
Returns the value of attribute arguments.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Class Method Summary collapse
- .call(arguments, logger, context = {}) ⇒ Object
- .define(&block) ⇒ Object
- .definition ⇒ Object
- .inherited(subclass) ⇒ Object
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(arguments, logger, context = {}) ⇒ Tool
constructor
A new instance of Tool.
Methods included from Progressable
Methods included from ContentHelpers
#audio_content, #embedded_resource_content, #image_content, #resource_link, #text_content
Methods included from Cancellable
Constructor Details
#initialize(arguments, logger, context = {}) ⇒ Tool
Returns a new instance of Tool.
14 15 16 17 18 19 |
# File 'lib/model_context_protocol/server/tool.rb', line 14 def initialize(arguments, logger, context = {}) validate!(arguments) @arguments = arguments @context = context @logger = logger end |
Class Attribute Details
.description ⇒ Object (readonly)
Returns the value of attribute description.
85 86 87 |
# File 'lib/model_context_protocol/server/tool.rb', line 85 def description @description end |
.input_schema ⇒ Object (readonly)
Returns the value of attribute input_schema.
85 86 87 |
# File 'lib/model_context_protocol/server/tool.rb', line 85 def input_schema @input_schema end |
.name ⇒ Object (readonly)
Returns the value of attribute name.
85 86 87 |
# File 'lib/model_context_protocol/server/tool.rb', line 85 def name @name end |
.output_schema ⇒ Object (readonly)
Returns the value of attribute output_schema.
85 86 87 |
# File 'lib/model_context_protocol/server/tool.rb', line 85 def output_schema @output_schema end |
.title ⇒ Object (readonly)
Returns the value of attribute title.
85 86 87 |
# File 'lib/model_context_protocol/server/tool.rb', line 85 def title @title end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
Returns the value of attribute arguments.
12 13 14 |
# File 'lib/model_context_protocol/server/tool.rb', line 12 def arguments @arguments end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
12 13 14 |
# File 'lib/model_context_protocol/server/tool.rb', line 12 def context @context end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
12 13 14 |
# File 'lib/model_context_protocol/server/tool.rb', line 12 def logger @logger end |
Class Method Details
.call(arguments, logger, context = {}) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/model_context_protocol/server/tool.rb', line 106 def call(arguments, logger, context = {}) new(arguments, logger, context).call rescue JSON::Schema::ValidationError => validation_error raise ModelContextProtocol::Server::ParameterValidationError, validation_error. rescue OutputSchemaValidationError, ModelContextProtocol::Server::ResponseArgumentsError => tool_error raise tool_error, tool_error. rescue Server::Cancellable::CancellationError raise rescue => error ErrorResponse[error: error.] end |
.define(&block) ⇒ Object
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/model_context_protocol/server/tool.rb', line 87 def define(&block) definition_dsl = DefinitionDSL.new definition_dsl.instance_eval(&block) @name = definition_dsl.name @description = definition_dsl.description @title = definition_dsl.title @input_schema = definition_dsl.input_schema @output_schema = definition_dsl.output_schema end |
.definition ⇒ Object
118 119 120 121 122 123 |
# File 'lib/model_context_protocol/server/tool.rb', line 118 def definition result = {name: @name, description: @description, inputSchema: @input_schema} result[:title] = @title if @title result[:outputSchema] = @output_schema if @output_schema result end |
.inherited(subclass) ⇒ Object
98 99 100 101 102 103 104 |
# File 'lib/model_context_protocol/server/tool.rb', line 98 def inherited(subclass) subclass.instance_variable_set(:@name, @name) subclass.instance_variable_set(:@description, @description) subclass.instance_variable_set(:@title, @title) subclass.instance_variable_set(:@input_schema, @input_schema) subclass.instance_variable_set(:@output_schema, @output_schema) end |
Instance Method Details
#call ⇒ Object
21 22 23 |
# File 'lib/model_context_protocol/server/tool.rb', line 21 def call raise NotImplementedError, "Subclasses must implement the call method" end |