Class: Yorishiro::MCP::Tool
- Inherits:
-
Tool
- Object
- Tool
- Yorishiro::MCP::Tool
- Defined in:
- lib/yorishiro/mcp/tool.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#mcp_tool ⇒ Object
readonly
Returns the value of attribute mcp_tool.
-
#server_name ⇒ Object
readonly
Returns the value of attribute server_name.
Instance Method Summary collapse
- #description ⇒ Object
- #execute(**params) ⇒ Object
-
#initialize(mcp_tool:, client:, server_name:) ⇒ Tool
constructor
A new instance of Tool.
- #name ⇒ Object
- #parameters ⇒ Object
- #permission_check(_arguments) ⇒ Object
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
#client ⇒ Object (readonly)
Returns the value of attribute client.
6 7 8 |
# File 'lib/yorishiro/mcp/tool.rb', line 6 def client @client end |
#mcp_tool ⇒ Object (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_name ⇒ Object (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
#description ⇒ Object
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 |
#name ⇒ Object
15 16 17 |
# File 'lib/yorishiro/mcp/tool.rb', line 15 def name @mcp_tool.name end |
#parameters ⇒ Object
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 (_arguments) :ask end |