Merge pull request #85 from SheldonNunes/sheldon.fix-tools-with-no-args
Fix tools with no args
This commit is contained in:
commit
a84b56c87a
2 changed files with 33 additions and 1 deletions
|
|
@ -314,7 +314,7 @@ module MCP
|
|||
end
|
||||
|
||||
def call_tool_with_args(tool, arguments)
|
||||
args = arguments.transform_keys(&:to_sym)
|
||||
args = arguments&.transform_keys(&:to_sym) || {}
|
||||
|
||||
if accepts_server_context?(tool.method(:call))
|
||||
tool.call(**args, server_context: server_context).to_h
|
||||
|
|
|
|||
|
|
@ -17,6 +17,17 @@ module MCP
|
|||
input_schema: { type: "object", properties: { message: { type: "string" } }, required: ["message"] },
|
||||
) { raise StandardError, "Tool error" }
|
||||
|
||||
@tool_with_no_args = Tool.define(
|
||||
name: "tool_with_no_args",
|
||||
description: "This tool performs specific functionality...",
|
||||
annotations: {
|
||||
title: "Tool with no args",
|
||||
read_only_hint: true,
|
||||
},
|
||||
) do
|
||||
Tool::Response.new([{ type: "text", content: "OK" }])
|
||||
end
|
||||
|
||||
@prompt = Prompt.define(
|
||||
name: "test_prompt",
|
||||
description: "Test prompt",
|
||||
|
|
@ -896,6 +907,27 @@ module MCP
|
|||
assert_equal "OK", response[:result][:content][0][:content]
|
||||
end
|
||||
|
||||
test "tools/call with no args" do
|
||||
server = Server.new(tools: [@tool_with_no_args])
|
||||
|
||||
response = server.handle(
|
||||
{
|
||||
jsonrpc: "2.0",
|
||||
id: 1,
|
||||
method: "tools/call",
|
||||
params: {
|
||||
name: "tool_with_no_args",
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
assert_equal "2.0", response[:jsonrpc]
|
||||
assert_equal 1, response[:id]
|
||||
assert response[:result], "Expected result key in response"
|
||||
assert_equal "text", response[:result][:content][0][:type]
|
||||
assert_equal "OK", response[:result][:content][0][:content]
|
||||
end
|
||||
|
||||
class TestTool < Tool
|
||||
tool_name "test_tool"
|
||||
description "a test tool for testing"
|
||||
|
|
|
|||
Loading…
Reference in a new issue