@@ -92,21 +92,29 @@ def prompts
9292
9393 # Calls a tool via the transport layer and returns the full response from the server.
9494 #
95+ # @param name [String] The name of the tool to call.
9596 # @param tool [MCP::Client::Tool] The tool to be called.
9697 # @param arguments [Object, nil] The arguments to pass to the tool.
9798 # @param progress_token [String, Integer, nil] A token to request progress notifications from the server during tool execution.
9899 # @return [Hash] The full JSON-RPC response from the transport.
99100 #
100- # @example
101+ # @example Call by name
102+ # response = client.call_tool(name: "my_tool", arguments: { foo: "bar" })
103+ # content = response.dig("result", "content")
104+ #
105+ # @example Call with a tool object
101106 # tool = client.tools.first
102107 # response = client.call_tool(tool: tool, arguments: { foo: "bar" })
103108 # structured_content = response.dig("result", "structuredContent")
104109 #
105110 # @note
106111 # The exact requirements for `arguments` are determined by the transport layer in use.
107112 # Consult the documentation for your transport (e.g., MCP::Client::HTTP) for details.
108- def call_tool ( tool :, arguments : nil , progress_token : nil )
109- params = { name : tool . name , arguments : arguments }
113+ def call_tool ( name : nil , tool : nil , arguments : nil , progress_token : nil )
114+ tool_name = name || tool &.name
115+ raise ArgumentError , "Either `name:` or `tool:` must be provided." unless tool_name
116+
117+ params = { name : tool_name , arguments : arguments }
110118 if progress_token
111119 params [ :_meta ] = { progressToken : progress_token }
112120 end
0 commit comments