diff --git a/lib/mcp/client.rb b/lib/mcp/client.rb index be6d63d..0147561 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 c7868f9..c226d03 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