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:) ⇒ 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

#descriptionObject (readonly)

Returns the value of attribute description.



6
7
8
# File 'lib/mcp_client/tool.rb', line 6

def description
  @description
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/mcp_client/tool.rb', line 6

def name
  @name
end

#schemaObject (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

Parameters:

  • data (Hash)

    JSON data from MCP server

Returns:



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_toolHash

Convert tool to Anthropic Claude tool specification format

Returns:

  • (Hash)

    Anthropic Claude tool specification



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_toolHash

Convert tool to OpenAI function specification format

Returns:

  • (Hash)

    OpenAI function specification



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