diff --git a/lib/mcp.rb b/lib/mcp.rb index 99c083e4..ea612459 100644 --- a/lib/mcp.rb +++ b/lib/mcp.rb @@ -23,6 +23,7 @@ module MCP autoload :ResourceTemplate, "mcp/resource_template" autoload :ResultType, "mcp/result_type" autoload :Server, "mcp/server" + autoload :ServerContext, "mcp/server_context" autoload :ServerSession, "mcp/server_session" autoload :Skill, "mcp/skill" autoload :Tool, "mcp/tool" diff --git a/test/mcp/server_context_test.rb b/test/mcp/server_context_test.rb index 0cc38277..ce591e5b 100644 --- a/test/mcp/server_context_test.rb +++ b/test/mcp/server_context_test.rb @@ -1,9 +1,21 @@ # frozen_string_literal: true require "test_helper" +require "open3" module MCP class ServerContextTest < ActiveSupport::TestCase + # The docs name the class as what a handler receives, so an application may refer to it before anything has + # loaded `MCP::Server`, whose file used to be the only one requiring it. Checked in a fresh process, since this + # one has loaded everything already, and without this one's `RUBYOPT`, so nothing preloads the file for it. + test "ServerContext resolves after the gem alone is required" do + lib = File.expand_path("../../lib", __dir__) + script = 'require "mcp"; MCP::ServerContext' + _stdout, stderr, status = Open3.capture3({ "RUBYOPT" => nil }, RbConfig.ruby, "-I", lib, "-e", script) + + assert_predicate status, :success?, stderr + end + test "ServerContext delegates method calls to the underlying context" do context = { user: "test_user" } progress = Progress.new(notification_target: mock, progress_token: nil)