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:
Juliano Julio Costa 2025-06-09 13:02:20 -04:00
commit c10c0ddf9d

View file

@ -193,7 +193,7 @@ module MCP
tool_args = { arg: "value" }
tool_response = Tool::Response.new([{ result: "success" }])
@tool.expects(:call).with(arg: "value").returns(tool_response)
@tool.expects(:call).with(arg: "value", server_context: nil).returns(tool_response)
request = {
jsonrpc: "2.0",
@ -242,7 +242,7 @@ module MCP
tool_args = { arg: "value" }
tool_response = Tool::Response.new([{ result: "success" }])
@tool.expects(:call).with(arg: "value").returns(tool_response)
@tool.expects(:call).with(arg: "value", server_context: nil).returns(tool_response)
request = JSON.generate({
jsonrpc: "2.0",