Class: RCrewAI::MCP::ToolAdapter
Overview
Wraps a tool advertised by an MCP server as an RCrewAI::Tools::Base.
Names are prefixed with the server name to avoid collisions when an
agent has tools from multiple MCP servers.
Constant Summary
Constants included
from ToolSchema
ToolSchema::TYPE_MAP
Instance Method Summary
collapse
Methods inherited from Tools::Base
available_tools, create_tool, list_available_tools, #validate_params!
Methods included from ToolSchema
extended, #param, #params, #tool_name
Constructor Details
#initialize(client, mcp_tool_descriptor, server_name) ⇒ ToolAdapter
Returns a new instance of ToolAdapter.
11
12
13
14
15
16
17
18
|
# File 'lib/rcrewai/mcp/tool_adapter.rb', line 11
def initialize(client, mcp_tool_descriptor, server_name)
super()
@client = client
@descriptor = mcp_tool_descriptor
@server_name = server_name
@adapter_name = "#{server_name}__#{mcp_tool_descriptor['name']}"
@adapter_description = mcp_tool_descriptor['description'].to_s
end
|
Instance Method Details
#description ⇒ Object
24
25
26
|
# File 'lib/rcrewai/mcp/tool_adapter.rb', line 24
def description
@adapter_description
end
|
#execute(**args) ⇒ Object
37
38
39
|
# File 'lib/rcrewai/mcp/tool_adapter.rb', line 37
def execute(**args)
@client.call_tool(@adapter_name, args)
end
|
#execute_with_validation(args_hash) ⇒ Object
41
42
43
|
# File 'lib/rcrewai/mcp/tool_adapter.rb', line 41
def execute_with_validation(args_hash)
execute(**args_hash.transform_keys(&:to_sym))
end
|
#json_schema ⇒ Object
28
29
30
31
32
33
34
35
|
# File 'lib/rcrewai/mcp/tool_adapter.rb', line 28
def json_schema
{
name: @adapter_name,
description: @adapter_description,
parameters: stringify_keys(@descriptor['inputSchema'] ||
{ 'type' => 'object', 'additionalProperties' => true })
}
end
|
#name ⇒ Object
20
21
22
|
# File 'lib/rcrewai/mcp/tool_adapter.rb', line 20
def name
@adapter_name
end
|