Fix tools with no args
This commit is contained in:
parent
6bace861b2
commit
74737223a0
2 changed files with 33 additions and 1 deletions
|
|
@ -314,7 +314,7 @@ module MCP
|
||||||
end
|
end
|
||||||
|
|
||||||
def call_tool_with_args(tool, arguments)
|
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))
|
if accepts_server_context?(tool.method(:call))
|
||||||
tool.call(**args, server_context: server_context).to_h
|
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"] },
|
input_schema: { type: "object", properties: { message: { type: "string" } }, required: ["message"] },
|
||||||
) { raise StandardError, "Tool error" }
|
) { 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(
|
@prompt = Prompt.define(
|
||||||
name: "test_prompt",
|
name: "test_prompt",
|
||||||
description: "Test prompt",
|
description: "Test prompt",
|
||||||
|
|
@ -896,6 +907,27 @@ module MCP
|
||||||
assert_equal "OK", response[:result][:content][0][:content]
|
assert_equal "OK", response[:result][:content][0][:content]
|
||||||
end
|
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
|
class TestTool < Tool
|
||||||
tool_name "test_tool"
|
tool_name "test_tool"
|
||||||
description "a test tool for testing"
|
description "a test tool for testing"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue