Use autoload to defer loading of unused subsystems

## Motivation and Context

`lib/mcp.rb` currently declares all `require_relative` statements in one place.
As a result, Server and Client are both loaded, the stdio and Streamable HTTP
transports are both loaded, and Tool, Prompt, and Resource are all loaded,
regardless of which components are actually used.

These components are selected by the user depending on their use case,
so loading everything upfront is unnecessary.

Using `autoload` for selected constants defers loading until the constant
is actually referenced, so only the subsystems required by the user are loaded.

## How Has This Been Tested?

All existing tests pass unchanged.

## Breaking Change

None. This change only defers loading of unused components.
This commit is contained in:
Koichi ITO 2026-03-12 03:42:12 +09:00
commit 0c729d0a2d
2 changed files with 42 additions and 28 deletions

View file

@ -1,6 +1,7 @@
# frozen_string_literal: true
require "test_helper"
require "mcp/instrumentation"
module MCP
class InstrumentationTest < ActiveSupport::TestCase

View file

@ -1,6 +1,7 @@
# frozen_string_literal: true
require "test_helper"
require "mcp/methods"
module MCP
class MethodsTest < ActiveSupport::TestCase