Class: Yorishiro::MCP::Tool

Inherits:
Tool
  • Object
show all
Defined in:
lib/yorishiro/mcp/tool.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mcp_tool:, client:, server_name:) ⇒ Tool

Returns a new instance of Tool.



8
9
10
11
12
13
# File 'lib/yorishiro/mcp/tool.rb', line 8

def initialize(mcp_tool:, client:, server_name:)
  super()
  @mcp_tool = mcp_tool
  @client = client
  @server_name = server_name
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



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

def client
  @client
end

#mcp_toolObject (readonly)

Returns the value of attribute mcp_tool.



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

def mcp_tool
  @mcp_tool
end

#server_nameObject (readonly)

Returns the value of attribute server_name.



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

def server_name
  @server_name
end

Instance Method Details

#descriptionObject



19
20
21
# File 'lib/yorishiro/mcp/tool.rb', line 19

def description
  @mcp_tool.description || "MCP tool from #{@server_name}"
end

#execute(**params) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/yorishiro/mcp/tool.rb', line 27

def execute(**params)
  response = @client.call_tool(tool: @mcp_tool, arguments: params)

  content = response.dig("result", "content")
  return response.to_s unless content

  content.map { |c| c["text"] || c.to_s }.join("\n")
end

#nameObject



15
16
17
# File 'lib/yorishiro/mcp/tool.rb', line 15

def name
  @mcp_tool.name
end

#parametersObject



23
24
25
# File 'lib/yorishiro/mcp/tool.rb', line 23

def parameters
  @mcp_tool.input_schema || { type: "object", properties: {}, required: [] }
end

#permission_check(_arguments) ⇒ Object



36
37
38
# File 'lib/yorishiro/mcp/tool.rb', line 36

def permission_check(_arguments)
  :ask
end