Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/mcp/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ def prompts(cancellation: nil)
#
# @param name [String] The name of the tool to call.
# @param tool [MCP::Client::Tool] The tool to be called.
# @param arguments [Object, nil] The arguments to pass to the tool.
# @param arguments [Object, nil] The arguments to pass to the tool. Omitted from the request when nil.
# @param progress_token [String, Integer, nil] A token to request progress notifications from the server during tool execution.
# @param meta [Hash, nil] Additional `_meta` entries to send with the request,
# e.g. the W3C Trace Context keys reserved by SEP-414
Expand Down Expand Up @@ -516,7 +516,8 @@ def call_tool(name: nil, tool: nil, arguments: nil, progress_token: nil, meta: n
tool_name = name || tool&.name
raise ArgumentError, "Either `name:` or `tool:` must be provided." unless tool_name

params = { name: tool_name, arguments: arguments }
params = { name: tool_name }
params[:arguments] = arguments unless arguments.nil?
meta_entries = meta ? meta.dup : {}
if progress_token
meta_entries.delete("progressToken")
Expand Down
9 changes: 9 additions & 0 deletions test/mcp/client_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,15 @@ def test_call_tool_sends_request_to_transport_and_returns_content
assert_equal([{ type: "text", text: "Hello, world!" }], content)
end

def test_call_tool_omits_arguments_when_none_are_given
transport = mock
transport.expects(:send_request).with do |args|
args.dig(:request, :params) == { name: "ping" }
end.returns({ "result" => { "content" => [] } })

Client.new(transport: transport).call_tool(name: "ping")
end

def test_call_tool_by_name
transport = mock
arguments = { foo: "bar" }
Expand Down