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 ⇒ String
readonly
The description of the tool.
-
#name ⇒ String
readonly
The name of the tool.
-
#schema ⇒ Hash
readonly
The JSON schema for the tool.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
Class Method Summary collapse
-
.from_json(data, server: nil) ⇒ MCPClient::Tool
Create a Tool instance from JSON data.
Instance Method Summary collapse
-
#initialize(name:, description:, schema:, server: nil) ⇒ Tool
constructor
Initialize a new Tool.
-
#to_anthropic_tool ⇒ Hash
Convert tool to Anthropic Claude tool specification format.
-
#to_google_tool ⇒ Hash
Convert tool to Google Vertex AI tool specification format.
-
#to_openai_tool ⇒ Hash
Convert tool to OpenAI function specification format.
Constructor Details
#initialize(name:, description:, schema:, server: nil) ⇒ Tool
Initialize a new Tool
21 22 23 24 25 26 |
# File 'lib/mcp_client/tool.rb', line 21 def initialize(name:, description:, schema:, server: nil) @name = name @description = description @schema = schema @server = server end |
Instance Attribute Details
#description ⇒ String (readonly)
14 |
# File 'lib/mcp_client/tool.rb', line 14 attr_reader :name, :description, :schema, :server |
#name ⇒ String (readonly)
14 15 16 |
# File 'lib/mcp_client/tool.rb', line 14 def name @name end |
#schema ⇒ Hash (readonly)
14 |
# File 'lib/mcp_client/tool.rb', line 14 attr_reader :name, :description, :schema, :server |
#server ⇒ Object (readonly)
Returns the value of attribute server.
14 |
# File 'lib/mcp_client/tool.rb', line 14 attr_reader :name, :description, :schema, :server |
Class Method Details
.from_json(data, server: nil) ⇒ MCPClient::Tool
Create a Tool instance from JSON data
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/mcp_client/tool.rb', line 32 def self.from_json(data, server: nil) # Some servers (Playwright MCP CLI) use 'inputSchema' instead of 'schema' schema = data['inputSchema'] || data['schema'] new( name: data['name'], description: data['description'], schema: schema, server: server ) end |
Instance Method Details
#to_anthropic_tool ⇒ Hash
Convert tool to Anthropic Claude tool specification format
58 59 60 61 62 63 64 |
# File 'lib/mcp_client/tool.rb', line 58 def to_anthropic_tool { name: @name, description: @description, input_schema: @schema } end |
#to_google_tool ⇒ Hash
Convert tool to Google Vertex AI tool specification format
68 69 70 71 72 73 74 |
# File 'lib/mcp_client/tool.rb', line 68 def to_google_tool { name: @name, description: @description, parameters: cleaned_schema(@schema) } end |
#to_openai_tool ⇒ Hash
Convert tool to OpenAI function specification format
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/mcp_client/tool.rb', line 45 def to_openai_tool { type: 'function', function: { name: @name, description: @description, parameters: @schema } } end |