Skip to content

Commit 4f9bc6e

Browse files
authored
Merge pull request #86 from alexandru-calinoiu/account-for-missing-arguments
Account for missing arguments
2 parents a84b56c + 47215c9 commit 4f9bc6e

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lib/mcp/server.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ def call_tool(request)
233233
raise RequestHandlerError.new("Tool not found #{tool_name}", request, error_type: :tool_not_found)
234234
end
235235

236-
arguments = request[:arguments]
236+
arguments = request[:arguments] || {}
237237
add_instrumentation_data(tool_name:)
238238

239239
if tool.input_schema&.missing_required_arguments?(arguments)

test/mcp/server_test.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,29 @@ def call(message:, server_context: nil)
829829
assert_equal custom_version, response[:result][:protocolVersion]
830830
end
831831

832+
test "tools/call handles missing arguments field" do
833+
server = Server.new(
834+
tools: [TestTool],
835+
configuration: Configuration.new(validate_tool_call_arguments: true),
836+
)
837+
838+
response = server.handle(
839+
{
840+
jsonrpc: "2.0",
841+
id: 1,
842+
method: "tools/call",
843+
params: {
844+
name: "test_tool",
845+
},
846+
},
847+
)
848+
849+
assert_equal "2.0", response[:jsonrpc]
850+
assert_equal 1, response[:id]
851+
assert_equal(-32603, response[:error][:code])
852+
assert_includes response[:error][:data], "Missing required arguments"
853+
end
854+
832855
test "tools/call validates arguments against input schema when validate_tool_call_arguments is true" do
833856
server = Server.new(
834857
tools: [TestTool],

0 commit comments

Comments
 (0)