Class: MCPClient::Tool

Inherits:
Object
  • Object
show all
Defined in:
lib/mcp_client/tool.rb

Overview

Representation of an MCP tool

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#descriptionString (readonly)



14
# File 'lib/mcp_client/tool.rb', line 14

attr_reader :name, :description, :schema, :server

#nameString (readonly)



14
15
16
# File 'lib/mcp_client/tool.rb', line 14

def name
  @name
end

#schemaHash (readonly)



14
# File 'lib/mcp_client/tool.rb', line 14

attr_reader :name, :description, :schema, :server

#serverObject (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_toolHash

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_toolHash

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_toolHash

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