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: AnnotationsDSL, DefinitionDSL, OutputSchemaValidationError
Class Attribute Summary collapse
-
.annotations ⇒ Object
readonly
Returns the value of attribute annotations.
-
.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.
-
.security_schemes ⇒ Object
readonly
Returns the value of attribute security_schemes.
-
.title ⇒ Object
readonly
Returns the value of attribute title.
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
Returns the value of attribute arguments.
-
#client_logger ⇒ Object
readonly
Returns the value of attribute client_logger.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#server_logger ⇒ Object
readonly
Returns the value of attribute server_logger.
Class Method Summary collapse
- .call(arguments, client_logger, server_logger, context = {}) ⇒ Object
- .define(&block) ⇒ Object
- .definition ⇒ Object
- .inherited(subclass) ⇒ Object
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(arguments, client_logger, server_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, client_logger, server_logger, context = {}) ⇒ Tool
Returns a new instance of Tool.
14 15 16 17 18 19 20 |
# File 'lib/model_context_protocol/server/tool.rb', line 14 def initialize(arguments, client_logger, server_logger, context = {}) validate!(arguments) @arguments = arguments @context = context @client_logger = client_logger @server_logger = server_logger end |
Class Attribute Details
.annotations ⇒ Object (readonly)
Returns the value of attribute annotations.
86 87 88 |
# File 'lib/model_context_protocol/server/tool.rb', line 86 def annotations @annotations end |
.description ⇒ Object (readonly)
Returns the value of attribute description.
86 87 88 |
# File 'lib/model_context_protocol/server/tool.rb', line 86 def description @description end |
.input_schema ⇒ Object (readonly)
Returns the value of attribute input_schema.
86 87 88 |
# File 'lib/model_context_protocol/server/tool.rb', line 86 def input_schema @input_schema end |
.name ⇒ Object (readonly)
Returns the value of attribute name.
86 87 88 |
# File 'lib/model_context_protocol/server/tool.rb', line 86 def name @name end |
.output_schema ⇒ Object (readonly)
Returns the value of attribute output_schema.
86 87 88 |
# File 'lib/model_context_protocol/server/tool.rb', line 86 def output_schema @output_schema end |
.security_schemes ⇒ Object (readonly)
Returns the value of attribute security_schemes.
86 87 88 |
# File 'lib/model_context_protocol/server/tool.rb', line 86 def security_schemes @security_schemes end |
.title ⇒ Object (readonly)
Returns the value of attribute title.
86 87 88 |
# File 'lib/model_context_protocol/server/tool.rb', line 86 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 |
#client_logger ⇒ Object (readonly)
Returns the value of attribute client_logger.
12 13 14 |
# File 'lib/model_context_protocol/server/tool.rb', line 12 def client_logger @client_logger 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 |
#server_logger ⇒ Object (readonly)
Returns the value of attribute server_logger.
12 13 14 |
# File 'lib/model_context_protocol/server/tool.rb', line 12 def server_logger @server_logger end |
Class Method Details
.call(arguments, client_logger, server_logger, context = {}) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/model_context_protocol/server/tool.rb', line 111 def call(arguments, client_logger, server_logger, context = {}) new(arguments, client_logger, server_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
88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/model_context_protocol/server/tool.rb', line 88 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 @annotations = definition_dsl.defined_annotations @security_schemes = definition_dsl.security_schemes end |
.definition ⇒ Object
123 124 125 126 127 128 129 130 131 |
# File 'lib/model_context_protocol/server/tool.rb', line 123 def definition result = {name: @name, description: @description, inputSchema: @input_schema} result[:title] = @title if @title result[:outputSchema] = @output_schema if @output_schema annotations_hash = @annotations&.serialized result[:annotations] = annotations_hash if annotations_hash result[:securitySchemes] = @security_schemes if @security_schemes result end |
.inherited(subclass) ⇒ Object
101 102 103 104 105 106 107 108 109 |
# File 'lib/model_context_protocol/server/tool.rb', line 101 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) subclass.instance_variable_set(:@annotations, @annotations&.dup) subclass.instance_variable_set(:@security_schemes, @security_schemes) end |
Instance Method Details
#call ⇒ Object
22 23 24 |
# File 'lib/model_context_protocol/server/tool.rb', line 22 def call raise NotImplementedError, "Subclasses must implement the call method" end |