Merge pull request #86 from alexandru-calinoiu/account-for-missing-arguments

Account for missing arguments
This commit is contained in:
Koichi ITO 2025-07-25 01:37:36 +09:00 • committed by GitHub
commit 4f9bc6e316
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
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],