Skip to content
Merged
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
11 changes: 5 additions & 6 deletions lib/mcp/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,27 @@ def tools
end || []
end

# Calls a tool via the transport layer.
# Calls a tool via the transport layer and returns the full response from the server.
#
# @param tool [MCP::Client::Tool] The tool to be called.
# @param arguments [Object, nil] The arguments to pass to the tool.
# @return [Object] The result of the tool call, as returned by the transport.
# @return [Hash] The full JSON-RPC response from the transport.
#
# @example
# tool = client.tools.first
# result = client.call_tool(tool: tool, arguments: { foo: "bar" })
# response = client.call_tool(tool: tool, arguments: { foo: "bar" })
# structured_content = response.dig("result", "structuredContent")
#
# @note
# The exact requirements for `arguments` are determined by the transport layer in use.
# Consult the documentation for your transport (e.g., MCP::Client::HTTP) for details.
def call_tool(tool:, arguments: nil)
response = transport.send_request(request: {
transport.send_request(request: {
jsonrpc: JsonRpcHandler::Version::V2_0,
id: request_id,
method: "tools/call",
params: { name: tool.name, arguments: arguments },
})

response.dig("result", "content")
end

private
Expand Down
3 changes: 2 additions & 1 deletion test/mcp/client_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ def test_call_tool_sends_request_to_transport_and_returns_content

client = Client.new(transport: transport)
result = client.call_tool(tool: tool, arguments: arguments)
content = result.dig("result", "content")

assert_equal("result", result)
assert_equal("result", content)
end
end
end