Account for missing arguments
This commit is contained in:
parent
a84b56c87a
commit
47215c98ce
2 changed files with 24 additions and 1 deletions
|
|
@ -233,7 +233,7 @@ module MCP
|
||||||
raise RequestHandlerError.new("Tool not found #{tool_name}", request, error_type: :tool_not_found)
|
raise RequestHandlerError.new("Tool not found #{tool_name}", request, error_type: :tool_not_found)
|
||||||
end
|
end
|
||||||
|
|
||||||
arguments = request[:arguments]
|
arguments = request[:arguments] || {}
|
||||||
add_instrumentation_data(tool_name:)
|
add_instrumentation_data(tool_name:)
|
||||||
|
|
||||||
if tool.input_schema&.missing_required_arguments?(arguments)
|
if tool.input_schema&.missing_required_arguments?(arguments)
|
||||||
|
|
|
||||||
|
|
@ -829,6 +829,29 @@ module MCP
|
||||||
assert_equal custom_version, response[:result][:protocolVersion]
|
assert_equal custom_version, response[:result][:protocolVersion]
|
||||||
end
|
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
|
test "tools/call validates arguments against input schema when validate_tool_call_arguments is true" do
|
||||||
server = Server.new(
|
server = Server.new(
|
||||||
tools: [TestTool],
|
tools: [TestTool],
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue