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)
Returns the description of the tool.
14 |
# File 'lib/mcp_client/tool.rb', line 14 attr_reader :name, :description, :schema, :server |
#name ⇒ String (readonly)
Returns the name of the tool.
14 15 16 |
# File 'lib/mcp_client/tool.rb', line 14 def name @name end |
#schema ⇒ Hash (readonly)
Returns the JSON schema for the tool.
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 42 |
# 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' # Handle both string and symbol keys schema = data['inputSchema'] || data[:inputSchema] || data['schema'] || data[:schema] new( name: data['name'] || data[:name], description: data['description'] || data[:description], schema: schema, server: server ) end |
Instance Method Details
#to_anthropic_tool ⇒ Hash
Convert tool to Anthropic Claude tool specification format
59 60 61 62 63 64 65 |
# File 'lib/mcp_client/tool.rb', line 59 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
69 70 71 72 73 74 75 |
# File 'lib/mcp_client/tool.rb', line 69 def to_google_tool { name: @name, description: @description, parameters: cleaned_schema(@schema) } end |
#to_openai_tool ⇒ Hash
Convert tool to OpenAI function specification format
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/mcp_client/tool.rb', line 46 def to_openai_tool { type: 'function', function: { name: @name, description: @description, parameters: @schema } } end |