From 7412197e52fd7668e18caca0c0b3458c2fc731d8 Mon Sep 17 00:00:00 2001 From: Mikhail Dubov Date: Wed, 21 Jan 2026 17:18:28 +0000 Subject: [PATCH] feat: add tool_arguments to instrumentation data Include the tool arguments in instrumentation callback data when tools/call is invoked. This allows consumers to track which arguments were passed to each tool call for analytics and debugging purposes. --- lib/mcp/server.rb | 2 +- test/mcp/server_test.rb | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/mcp/server.rb b/lib/mcp/server.rb index e5b4711..adf7817 100644 --- a/lib/mcp/server.rb +++ b/lib/mcp/server.rb @@ -322,7 +322,7 @@ def call_tool(request) end arguments = request[:arguments] || {} - add_instrumentation_data(tool_name: tool_name) + add_instrumentation_data(tool_name: tool_name, tool_arguments: arguments) if tool.input_schema&.missing_required_arguments?(arguments) add_instrumentation_data(error: :missing_required_arguments) diff --git a/test/mcp/server_test.rb b/test/mcp/server_test.rb index 0f54cae..98e546c 100644 --- a/test/mcp/server_test.rb +++ b/test/mcp/server_test.rb @@ -264,7 +264,7 @@ class ServerTest < ActiveSupport::TestCase response = @server.handle(request) assert_equal tool_response.to_h, response[:result] - assert_instrumentation_data({ method: "tools/call", tool_name: tool_name }) + assert_instrumentation_data({ method: "tools/call", tool_name: tool_name, tool_arguments: tool_args }) end test "#handle tools/call returns error response with isError true if required tool arguments are missing" do @@ -320,7 +320,7 @@ class ServerTest < ActiveSupport::TestCase raw_response = @server.handle_json(request) response = JSON.parse(raw_response, symbolize_names: true) if raw_response assert_equal tool_response.to_h, response[:result] if response - assert_instrumentation_data({ method: "tools/call", tool_name: tool_name }) + assert_instrumentation_data({ method: "tools/call", tool_name: tool_name, tool_arguments: { arg: "value" } }) end test "#handle_json tools/call executes tool and returns result, when the tool is typed with Sorbet" do @@ -389,7 +389,7 @@ def call(message:, server_context: nil) assert response[:result][:isError] assert_equal "text", response[:result][:content][0][:type] assert_match(/Internal error calling tool tool_that_raises: /, response[:result][:content][0][:text]) - assert_instrumentation_data({ method: "tools/call", tool_name: "tool_that_raises" }) + assert_instrumentation_data({ method: "tools/call", tool_name: "tool_that_raises", tool_arguments: { message: "test" } }) end test "registers tools with the same class name in different namespaces" do @@ -446,7 +446,7 @@ class Example < Tool assert response[:result][:isError] assert_equal "text", response[:result][:content][0][:type] assert_match(/Internal error calling tool tool_that_raises: /, response[:result][:content][0][:text]) - assert_instrumentation_data({ method: "tools/call", tool_name: "tool_that_raises" }) + assert_instrumentation_data({ method: "tools/call", tool_name: "tool_that_raises", tool_arguments: { message: "test" } }) end test "#handle tools/call returns error response with isError true if input_schema raises an error during validation" do