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
|
|
@ -9,7 +9,7 @@ module MCP
|
|||
attr_reader :description_value
|
||||
attr_reader :arguments_value
|
||||
|
||||
def template(args, server_context:)
|
||||
def template(args, server_context: nil)
|
||||
raise NotImplementedError, "Subclasses must implement template"
|
||||
end
|
||||
|
||||
|
|
@ -57,7 +57,7 @@ module MCP
|
|||
prompt_name name
|
||||
description description
|
||||
arguments arguments
|
||||
define_singleton_method(:template) do |args, server_context:|
|
||||
define_singleton_method(:template) do |args, server_context: nil|
|
||||
instance_exec(args, server_context:, &block)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue