Skip to content

Commit 48c0cc9

Browse files
authored
Merge pull request #656 from koic/autoload_server_context_from_the_gem_entry_point
Autoload `MCP::ServerContext` from the gem entry point
2 parents 2cd02af + 1972d6f commit 48c0cc9

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

‎lib/mcp.rb‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ module MCP
2323
autoload :ResourceTemplate, "mcp/resource_template"
2424
autoload :ResultType, "mcp/result_type"
2525
autoload :Server, "mcp/server"
26+
autoload :ServerContext, "mcp/server_context"
2627
autoload :ServerSession, "mcp/server_session"
2728
autoload :Skill, "mcp/skill"
2829
autoload :Tool, "mcp/tool"

‎test/mcp/server_context_test.rb‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
# frozen_string_literal: true
22

33
require "test_helper"
4+
require "open3"
45

56
module MCP
67
class ServerContextTest < ActiveSupport::TestCase
8+
# The docs name the class as what a handler receives, so an application may refer to it before anything has
9+
# loaded `MCP::Server`, whose file used to be the only one requiring it. Checked in a fresh process, since this
10+
# one has loaded everything already, and without this one's `RUBYOPT`, so nothing preloads the file for it.
11+
test "ServerContext resolves after the gem alone is required" do
12+
lib = File.expand_path("../../lib", __dir__)
13+
script = 'require "mcp"; MCP::ServerContext'
14+
_stdout, stderr, status = Open3.capture3({ "RUBYOPT" => nil }, RbConfig.ruby, "-I", lib, "-e", script)
15+
16+
assert_predicate status, :success?, stderr
17+
end
18+
719
test "ServerContext delegates method calls to the underlying context" do
820
context = { user: "test_user" }
921
progress = Progress.new(notification_target: mock, progress_token: nil)

0 commit comments

Comments
 (0)