ruby-sdk/lib/model_context_protocol/tool.rb
Topher Bullock a4df3b8688 Internal Release v0.1.1
- implement `Prompt`
- adjust Tool approach
- update readme for tool calling
- document usage of `Prompt`
2025-05-08 17:37:27 -04:00

35 lines
783 B
Ruby

# frozen_string_literal: true
module ModelContextProtocol
class Tool
class Response
attr_reader :content, :is_error
def initialize(content, is_error = false)
@content = content
@is_error = is_error
end
def to_h
{ content:, is_error: }.compact
end
end
attr_reader :name, :description, :input_schema
def initialize(name:, description: nil, input_schema: nil, &block)
@name = name
@description = description
@input_schema = input_schema
@tool_block = block_given? ? block : -> { Response.new([{ type: "text", content: "OK" }]) }
end
def call(*args)
@tool_block.call(*args)
end
def to_h
{ name:, description:, inputSchema: input_schema }
end
end
end