Refactor MCP tool and server to handle optional server_context parameter
- Updated `call` method in `MCP::Tool` and `MCP::Prompt` to accept `server_context` as an optional parameter. - Refactored `MCP::Server` to streamline argument handling for tool and prompt calls, introducing helper methods `call_tool_with_args` and `call_prompt_template_with_args`. - Adjusted tests to reflect changes in method signatures and ensure compatibility with optional `server_context` parameter.
This commit is contained in:
parent
04710ac472
commit
c10c0ddf9d
1 changed files with 477 additions and 24 deletions
|
|
@ -226,5 +226,40 @@ module MCP
|
|||
assert_equal response.content, [{ type: "text", content: "OK" }]
|
||||
assert_equal response.is_error, false
|
||||
end
|
||||
|
||||
class TestToolWithoutServerContext < Tool
|
||||
tool_name "test_tool_without_server_context"
|
||||
description "a test tool for testing without server context"
|
||||
input_schema({ properties: { message: { type: "string" } }, required: ["message"] })
|
||||
|
||||
class << self
|
||||
def call(message:)
|
||||
Tool::Response.new([{ type: "text", content: "OK" }])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class TestToolWithoutRequired < Tool
|
||||
tool_name "test_tool_without_required"
|
||||
description "a test tool for testing without required server context"
|
||||
|
||||
class << self
|
||||
def call(message, server_context: nil)
|
||||
Tool::Response.new([{ type: "text", content: "OK" }])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
test "tool call without server context" do
|
||||
tool = TestToolWithoutServerContext
|
||||
response = tool.call(message: "test")
|
||||
assert_equal response.content, [{ type: "text", content: "OK" }]
|
||||
end
|
||||
|
||||
test "tool call with server context and without required" do
|
||||
tool = TestToolWithoutRequired
|
||||
response = tool.call("test", server_context: { foo: "bar" })
|
||||
assert_equal response.content, [{ type: "text", content: "OK" }]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue