Skip to content

Autoload MCP::ServerContext from the gem entry point - #656

Open
koic wants to merge 1 commit into
modelcontextprotocol:mainfrom
koic:autoload_server_context_from_the_gem_entry_point
Open

koic wants to merge 1 commit into
modelcontextprotocol:mainfrom
koic:autoload_server_context_from_the_gem_entry_point

Conversation

@koic

@koic koic commented Nov 4, 2026

Copy link
Copy Markdown
Member

Motivation and Context

MCP::ServerContext is the class a handler receives as server_context:, and the docs name it as such, but lib/mcp.rb never listed it: its file was required by lib/mcp/server.rb alone, so an application referring to the class before anything had loaded MCP::Server, in a type check or a test double, got NameError: uninitialized constant MCP::ServerContext. Every other class the docs name resolves from the entry point; this adds the missing entry.

Closes #655

How Has This Been Tested?

test/mcp/server_context_test.rb: a fresh process that requires mcp and resolves MCP::ServerContext without touching MCP::Server; before the change it ends with the NameError above.

Breaking Changes

None.

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

`MCP::ServerContext` is the class a handler receives as `server_context:`, and the docs name it as such,
but `lib/mcp.rb` never listed it: its file was required by `lib/mcp/server.rb` alone, so an application
referring to the class before anything had loaded `MCP::Server`, in a type check or a test double,
got `NameError: uninitialized constant MCP::ServerContext`. Every other class the docs name resolves
from the entry point; this adds the missing entry.

Closes modelcontextprotocol#655

## How Has This Been Tested?

test/mcp/server_context_test.rb: a fresh process that requires `mcp` and resolves `MCP::ServerContext`
without touching `MCP::Server`; before the change it ends with the `NameError` above.

## Breaking Changes

None.

This branch has not been deployed

No deployments
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.

server_context is not (auto)loaded

1 participant