Account for missing arguments

This commit is contained in:
calin 2025-07-23 15:17:23 +03:00
commit 47215c98ce
2 changed files with 24 additions and 1 deletions

View file

@ -233,7 +233,7 @@ module MCP
raise RequestHandlerError.new("Tool not found #{tool_name}", request, error_type: :tool_not_found)
end
arguments = request[:arguments]
arguments = request[:arguments] || {}
add_instrumentation_data(tool_name:)
if tool.input_schema&.missing_required_arguments?(arguments)

View file

@ -829,6 +829,29 @@ module MCP
assert_equal custom_version, response[:result][:protocolVersion]
end
test "tools/call handles missing arguments field" do
server = Server.new(
tools: [TestTool],
configuration: Configuration.new(validate_tool_call_arguments: true),
)
response = server.handle(
{
jsonrpc: "2.0",
id: 1,
method: "tools/call",
params: {
name: "test_tool",
},
},
)
assert_equal "2.0", response[:jsonrpc]
assert_equal 1, response[:id]
assert_equal(-32603, response[:error][:code])
assert_includes response[:error][:data], "Missing required arguments"
end
test "tools/call validates arguments against input schema when validate_tool_call_arguments is true" do
server = Server.new(
tools: [TestTool],