Internal Release 0.6.0

Rename Context Arg
This commit is contained in:
Tyler Rowsell 2025-04-23 16:30:01 -04:00 • committed by Topher Bullock
commit 62184957e0
3 changed files with 52 additions and 52 deletions

View file

@ -10,10 +10,10 @@ module ModelContextProtocol
# The default reporter should be callable but do nothing
exception = StandardError.new("test error")
context = { test: "context" }
server_context = { test: "context" }
# Should not raise any errors
config.exception_reporter.call(exception, context)
config.exception_reporter.call(exception, server_context)
end
test "allows setting a custom exception reporter" do
@ -21,9 +21,9 @@ module ModelContextProtocol
reported_exception = nil
reported_context = nil
config.exception_reporter = ->(exception, context) do
config.exception_reporter = ->(exception, server_context) do
reported_exception = exception
reported_context = context
reported_context = server_context
end
test_exception = StandardError.new("test error")

View file

@ -12,7 +12,7 @@ module ModelContextProtocol
]
class << self
def template(args, context:)
def template(args, server_context:)
Prompt::Result.new(
description: "Hello, world!",
messages: [
@ -35,7 +35,7 @@ module ModelContextProtocol
],
}
result = prompt.template({ "test_argument" => "Hello, friend!" }, context: { user_id: 123 })
result = prompt.template({ "test_argument" => "Hello, friend!" }, server_context: { user_id: 123 })
assert_equal expected_template_result, result.to_h
end
@ -49,7 +49,7 @@ module ModelContextProtocol
]
class << self
def template(args, context:)
def template(args, server_context:)
Prompt::Result.new(
description: "Hello, world!",
messages: [
@ -77,7 +77,7 @@ module ModelContextProtocol
],
}
result = prompt.template({ "test_argument" => "Hello, friend!" }, context: { user_id: 123 })
result = prompt.template({ "test_argument" => "Hello, friend!" }, server_context: { user_id: 123 })
assert_equal expected_template_result, result.to_h
end
@ -89,7 +89,7 @@ module ModelContextProtocol
]
class << self
def template(args, context:)
def template(args, server_context:)
Prompt::Result.new(
description: "Hello, world!",
messages: [
@ -115,8 +115,8 @@ module ModelContextProtocol
arguments: [
Prompt::Argument.new(name: "test_argument", description: "Test argument", required: true),
],
) do |args, context:|
content = Content::Text.new(args["test_argument"] + " user: #{context[:user_id]}")
) do |args, server_context:|
content = Content::Text.new(args["test_argument"] + " user: #{server_context[:user_id]}")
Prompt::Result.new(
description: "Hello, world!",
@ -139,7 +139,7 @@ module ModelContextProtocol
],
}
result = prompt.template({ "test_argument" => "Hello, friend!" }, context: { user_id: 123 })
result = prompt.template({ "test_argument" => "Hello, friend!" }, server_context: { user_id: 123 })
assert_equal expected, result.to_h
end
end

View file

@ -182,7 +182,7 @@ module ModelContextProtocol
tool_args = { "arg" => "value" }
tool_response = Tool::Response.new([{ "result" => "success" }])
@tool.expects(:call).with(**tool_args, context: @server.context).returns(tool_response)
@tool.expects(:call).with(**tool_args, server_context: @server.server_context).returns(tool_response)
request = {
jsonrpc: "2.0",
@ -204,7 +204,7 @@ module ModelContextProtocol
tool_args = { arg: "value" }
tool_response = Tool::Response.new([{ result: "success" }])
@tool.expects(:call).with(**tool_args, context: @server.context).returns(tool_response)
@tool.expects(:call).with(**tool_args, server_context: @server.server_context).returns(tool_response)
request = JSON.generate({
jsonrpc: "2.0",
@ -219,7 +219,7 @@ module ModelContextProtocol
end
test "#handle tools/call returns internal error and reports exception if the tool raises an error" do
@server.configuration.exception_reporter.expects(:call).with do |exception, context|
@server.configuration.exception_reporter.expects(:call).with do |exception, server_context|
assert_not_nil exception
assert_equal(
{
@ -230,7 +230,7 @@ module ModelContextProtocol
id: 1,
},
},
context,
server_context,
)
end
@ -553,8 +553,8 @@ module ModelContextProtocol
test "the server configuration takes precedence over the global configuration" do
configuration = ModelContextProtocol::Configuration.new
local_callback = ->(data) { puts "Local callback #{data.inspect}" }
local_exception_reporter = ->(exception, context) {
puts "Local exception reporter #{exception.inspect} #{context.inspect}"
local_exception_reporter = ->(exception, server_context) {
puts "Local exception reporter #{exception.inspect} #{server_context.inspect}"
}
configuration.instrumentation_callback = local_callback
configuration.exception_reporter = local_exception_reporter