Merge pull request #149 from juharris/client-call_tool_raw

[client] Change call_tool method to return the full tool response to help get structuredContent
This commit is contained in:
Topher Bullock 2025-10-01 15:37:49 -04:00 • committed by GitHub
commit c0f7605d25
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 7 deletions

View file

@ -44,28 +44,27 @@ module MCP
end || [] end || []
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 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.
# @return [Object] The result of the tool call, as returned by the transport. # @return [Hash] The full JSON-RPC response from the transport.
# #
# @example # @example
# tool = client.tools.first # 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 # @note
# The exact requirements for `arguments` are determined by the transport layer in use. # 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. # Consult the documentation for your transport (e.g., MCP::Client::HTTP) for details.
def call_tool(tool:, arguments: nil) def call_tool(tool:, arguments: nil)
response = transport.send_request(request: { transport.send_request(request: {
jsonrpc: JsonRpcHandler::Version::V2_0, jsonrpc: JsonRpcHandler::Version::V2_0,
id: request_id, id: request_id,
method: "tools/call", method: "tools/call",
params: { name: tool.name, arguments: arguments }, params: { name: tool.name, arguments: arguments },
}) })
response.dig("result", "content")
end end
private private

View file

@ -53,8 +53,9 @@ module MCP
client = Client.new(transport: transport) client = Client.new(transport: transport)
result = client.call_tool(tool: tool, arguments: arguments) result = client.call_tool(tool: tool, arguments: arguments)
content = result.dig("result", "content")
assert_equal("result", result) assert_equal("result", content)
end end
end end
end end