ruby-sdk/lib/mcp.rb
Koichi ITO 0c729d0a2d 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.
2026-03-12 14:08:27 +09:00

29 lines
696 B
Ruby

# frozen_string_literal: true
require_relative "json_rpc_handler"
require_relative "mcp/configuration"
require_relative "mcp/string_utils"
require_relative "mcp/transport"
require_relative "mcp/version"
module MCP
autoload :Annotations, "mcp/annotations"
autoload :Client, "mcp/client"
autoload :Content, "mcp/content"
autoload :Icon, "mcp/icon"
autoload :Prompt, "mcp/prompt"
autoload :Resource, "mcp/resource"
autoload :ResourceTemplate, "mcp/resource_template"
autoload :Server, "mcp/server"
autoload :Tool, "mcp/tool"
class << self
def configure
yield(configuration)
end
def configuration
@configuration ||= Configuration.new
end
end
end