Class: Encom::Server::Tool
- Inherits:
-
Object
- Object
- Encom::Server::Tool
- Defined in:
- lib/encom/server/tool.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
Instance Method Summary collapse
- #call(arguments) ⇒ Object
- #definition ⇒ Object
-
#initialize(name:, description:, schema:, proc:) ⇒ Tool
constructor
Initialize a new tool.
Constructor Details
#initialize(name:, description:, schema:, proc:) ⇒ Tool
Initialize a new tool
14 15 16 17 18 19 |
# File 'lib/encom/server/tool.rb', line 14 def initialize(name:, description:, schema:, proc:) @name = name @description = description @schema = schema @proc = proc end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
6 7 8 |
# File 'lib/encom/server/tool.rb', line 6 def description @description end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/encom/server/tool.rb', line 6 def name @name end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
6 7 8 |
# File 'lib/encom/server/tool.rb', line 6 def schema @schema end |
Instance Method Details
#call(arguments) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/encom/server/tool.rb', line 29 def call(arguments) result = nil begin if @proc.parameters.first && @proc.parameters.first[0] == :keyreq # If the proc expects keyword arguments, pass the arguments hash result = @proc.call(**arguments) else # Otherwise, pass arguments as an array result = @proc.call(*arguments) end # Ensure the result is in the standard format standardize_tool_response(result) rescue StandardError => e # Return error in MCP-compliant format as per docs { isError: true, content: [ { type: 'text', text: "Error: #{e.message}" } ] } end end |
#definition ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/encom/server/tool.rb', line 21 def definition { name: @name.to_s, description: @description, inputSchema: schema_definition }.compact end |