Class: MCPClient::Tool
- Inherits:
-
Object
- Object
- MCPClient::Tool
- Defined in:
- lib/mcp_client/tool.rb
Overview
Representation of an MCP tool
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.
Class Method Summary collapse
-
.from_json(data) ⇒ MCPClient::Tool
Create a Tool instance from JSON data.
Instance Method Summary collapse
-
#initialize(name:, description:, schema:) ⇒ Tool
constructor
A new instance of Tool.
-
#to_anthropic_tool ⇒ Hash
Convert tool to Anthropic Claude tool specification format.
-
#to_openai_tool ⇒ Hash
Convert tool to OpenAI function specification format.
Constructor Details
#initialize(name:, description:, schema:) ⇒ Tool
Returns a new instance of Tool.
8 9 10 11 12 |
# File 'lib/mcp_client/tool.rb', line 8 def initialize(name:, description:, schema:) @name = name @description = description @schema = schema end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
6 7 8 |
# File 'lib/mcp_client/tool.rb', line 6 def description @description end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/mcp_client/tool.rb', line 6 def name @name end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
6 7 8 |
# File 'lib/mcp_client/tool.rb', line 6 def schema @schema end |
Class Method Details
.from_json(data) ⇒ MCPClient::Tool
Create a Tool instance from JSON data
17 18 19 20 21 22 23 24 25 |
# File 'lib/mcp_client/tool.rb', line 17 def self.from_json(data) # Some servers (Playwright MCP CLI) use 'inputSchema' instead of 'schema' schema = data['inputSchema'] || data['schema'] new( name: data['name'], description: data['description'], schema: schema ) end |
Instance Method Details
#to_anthropic_tool ⇒ Hash
Convert tool to Anthropic Claude tool specification format
42 43 44 45 46 47 48 |
# File 'lib/mcp_client/tool.rb', line 42 def to_anthropic_tool { name: @name, description: @description, input_schema: @schema } end |
#to_openai_tool ⇒ Hash
Convert tool to OpenAI function specification format
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/mcp_client/tool.rb', line 29 def to_openai_tool { type: 'function', function: { name: @name, description: @description, parameters: @schema } } end |