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
-
#annotations ⇒ Hash?
readonly
Optional annotations describing tool behavior (e.g., readOnly, destructive).
-
#description ⇒ String
readonly
The description of the tool.
-
#name ⇒ String
readonly
The name of the tool.
-
#output_schema ⇒ Hash?
readonly
Optional JSON schema for structured tool outputs (MCP 2025-06-18).
-
#schema ⇒ Hash
readonly
The JSON schema for the tool inputs.
-
#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
-
#destructive? ⇒ Boolean
Check if the tool is marked as destructive.
-
#initialize(name:, description:, schema:, output_schema: nil, annotations: nil, server: nil) ⇒ Tool
constructor
Initialize a new Tool.
-
#read_only? ⇒ Boolean
Check if the tool is marked as read-only.
-
#requires_confirmation? ⇒ Boolean
Check if the tool requires confirmation before execution.
-
#structured_output? ⇒ Boolean
Check if the tool supports structured outputs (MCP 2025-06-18).
-
#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:, output_schema: nil, annotations: nil, server: nil) ⇒ Tool
Initialize a new Tool
27 28 29 30 31 32 33 34 |
# File 'lib/mcp_client/tool.rb', line 27 def initialize(name:, description:, schema:, output_schema: nil, annotations: nil, server: nil) @name = name @description = description @schema = schema @output_schema = output_schema @annotations = annotations @server = server end |
Instance Attribute Details
#annotations ⇒ Hash? (readonly)
Returns optional annotations describing tool behavior (e.g., readOnly, destructive).
18 |
# File 'lib/mcp_client/tool.rb', line 18 attr_reader :name, :description, :schema, :output_schema, :annotations, :server |
#description ⇒ String (readonly)
Returns the description of the tool.
18 |
# File 'lib/mcp_client/tool.rb', line 18 attr_reader :name, :description, :schema, :output_schema, :annotations, :server |
#name ⇒ String (readonly)
Returns the name of the tool.
18 19 20 |
# File 'lib/mcp_client/tool.rb', line 18 def name @name end |
#output_schema ⇒ Hash? (readonly)
Returns optional JSON schema for structured tool outputs (MCP 2025-06-18).
18 |
# File 'lib/mcp_client/tool.rb', line 18 attr_reader :name, :description, :schema, :output_schema, :annotations, :server |
#schema ⇒ Hash (readonly)
Returns the JSON schema for the tool inputs.
18 |
# File 'lib/mcp_client/tool.rb', line 18 attr_reader :name, :description, :schema, :output_schema, :annotations, :server |
#server ⇒ Object (readonly)
Returns the value of attribute server.
18 |
# File 'lib/mcp_client/tool.rb', line 18 attr_reader :name, :description, :schema, :output_schema, :annotations, :server |
Class Method Details
.from_json(data, server: nil) ⇒ MCPClient::Tool
Create a Tool instance from JSON data
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/mcp_client/tool.rb', line 40 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] output_schema = data['outputSchema'] || data[:outputSchema] annotations = data['annotations'] || data[:annotations] new( name: data['name'] || data[:name], description: data['description'] || data[:description], schema: schema, output_schema: output_schema, annotations: annotations, server: server ) end |
Instance Method Details
#destructive? ⇒ Boolean
Check if the tool is marked as destructive
97 98 99 |
# File 'lib/mcp_client/tool.rb', line 97 def destructive? @annotations && @annotations['destructive'] == true end |
#read_only? ⇒ Boolean
Check if the tool is marked as read-only
91 92 93 |
# File 'lib/mcp_client/tool.rb', line 91 def read_only? @annotations && @annotations['readOnly'] == true end |
#requires_confirmation? ⇒ Boolean
Check if the tool requires confirmation before execution
103 104 105 |
# File 'lib/mcp_client/tool.rb', line 103 def requires_confirmation? @annotations && @annotations['requiresConfirmation'] == true end |
#structured_output? ⇒ Boolean
Check if the tool supports structured outputs (MCP 2025-06-18)
109 110 111 |
# File 'lib/mcp_client/tool.rb', line 109 def structured_output? !@output_schema.nil? && !@output_schema.empty? end |
#to_anthropic_tool ⇒ Hash
Convert tool to Anthropic Claude tool specification format
71 72 73 74 75 76 77 |
# File 'lib/mcp_client/tool.rb', line 71 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
81 82 83 84 85 86 87 |
# File 'lib/mcp_client/tool.rb', line 81 def to_google_tool { name: @name, description: @description, parameters: cleaned_schema(@schema) } end |
#to_openai_tool ⇒ Hash
Convert tool to OpenAI function specification format
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/mcp_client/tool.rb', line 58 def to_openai_tool { type: 'function', function: { name: @name, description: @description, parameters: @schema } } end |