Skip to content

Use autoload to defer loading of unused subsystems#255

Merged
koic merged 1 commit intomodelcontextprotocol:mainfrom
koic:use_autoload_to_defer_loading_of_unused_subsystems
Mar 15, 2026
Merged

Use autoload to defer loading of unused subsystems#255
koic merged 1 commit intomodelcontextprotocol:mainfrom
koic:use_autoload_to_defer_loading_of_unused_subsystems

Conversation

@koic
Copy link
Member

@koic koic commented Mar 13, 2026

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.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

## 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.
@koic koic merged commit 628e520 into modelcontextprotocol:main Mar 15, 2026
11 checks passed
@koic koic deleted the use_autoload_to_defer_loading_of_unused_subsystems branch March 15, 2026 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants