From ae60e2d904e0d3ce9dd8bc18c18f97e05dc6cca4 Mon Sep 17 00:00:00 2001 From: Justin Harris Date: Wed, 1 Oct 2025 14:48:39 -0400 Subject: [PATCH] [client] Add call_tool_raw method to get the full tool response to help get structuredContent --- lib/mcp/client.rb | 11 +++++------ test/mcp/client_test.rb | 3 ++- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/mcp/client.rb b/lib/mcp/client.rb index be6d63dd..01475618 100644 --- a/lib/mcp/client.rb +++ b/lib/mcp/client.rb @@ -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 diff --git a/test/mcp/client_test.rb b/test/mcp/client_test.rb index c7868f9e..c226d03f 100644 --- a/test/mcp/client_test.rb +++ b/test/mcp/client_test.rb @@ -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